Button
The <smart-button> component is the button of @smartsoft001/angular. It is configured through an IButtonOptions object (click plus the look: variant, color, size, rounded, circular), renders its projected content as the label, shows a spinner while options.loading() is true, and with options.confirm turns the first click into a Cancel / Confirm pair before click runs. It renders a default ButtonStandardComponent which can be replaced via BUTTON_STANDARD_COMPONENT_TOKEN.
Usage
<smart-button [options]="options">Save changes</smart-button>
<p>Saves: {{ saveCount() }}</p>
The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Components
ButtonComponent (<smart-button>)
Main wrapper component. Renders ButtonStandardComponent by default. When BUTTON_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet, passes it every input (class included) and projects the label into the injected component's first <ng-content>.
ButtonStandardComponent (<smart-button-standard>)
Default concrete implementation: a Tailwind-styled <button> coloured by COMPONENT_COLORS[color][variant], with size-dependent padding and rounding (rounded-sm for xs / sm, rounded-md otherwise). It does not read rounded, circular or iconPosition.
ButtonPresetComponent (<smart-button-preset>)
Fully-styled, drop-in preset implementation extending ButtonBaseComponent. Register it through BUTTON_STANDARD_COMPONENT_TOKEN to restyle every <smart-button>, register every preset at once with provideSmartPresets(), or use the <smart-button-preset> selector directly (it takes the extra classes as class or [cssClass]).
Groups the Preline button types into one component, selected via the existing options.variant: primary → solid, secondary → outline, soft → soft. Works across the full SmartColor palette and every SmartSize, and honours options.rounded (pill), options.circular (square padding + pill), options.loading, options.confirm, and the disabled input (disabled:opacity-50 disabled:pointer-events-none). All classes are smart:-prefixed vanilla Tailwind with explicit dark: variants.
ButtonBaseComponent (abstract)
Abstract base directive for extending custom button implementations. It holds the inputs and the confirm mode.
| Member | Type | Description |
|---|---|---|
mode | WritableSignal<'default' | 'confirm'> | 'confirm' after a first click on a confirm button, 'default' otherwise. |
variantClasses | Signal<string[]> | The colour classes of options.variant / options.color from COMPONENT_COLORS, plus smart:opacity-50 smart:cursor-not-allowed while disabled. |
invoke() | method | The click handler: runs options.click, or enters the confirm mode when options.confirm. |
confirmInvoke() | method | Runs options.click and leaves the confirm mode. |
confirmCancel() | method | Leaves the confirm mode without running click. |
API
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
options | InputSignal<IButtonOptions> | required | Button configuration |
disabled | InputSignal<boolean> | false | Disables the <button> |
class | InputSignal<string> | '' | External CSS classes appended to the <button> (alias for cssClass) |
Content projection
| Selector | Description |
|---|---|
| default | The label. Replaced by the spinner while options.loading() is true. |
IButtonOptions
| Field | Type | Default | Description |
|---|---|---|---|
type | 'submit' | 'button' | 'button' | The type attribute of the <button>. Use 'submit' inside a <form> of your own. |
confirm | boolean | undefined | The first click shows Cancel / Confirm buttons (translated cancel / confirm); click runs only after Confirm. |
click | () => void | required | Called on click (after the confirmation when confirm is set). |
loading | Signal<boolean> | undefined | While it reads true, the spinner replaces the label and the button is disabled. |
variant | SmartVariant | 'primary' | primary (solid), secondary (outline) or soft. |
size | SmartSize | 'md' | Padding and text size (xs to xl); the standard also uses smaller rounding for xs / sm. |
color | SmartColor | 'indigo' | One of the 22 Tailwind palette names. |
rounded | boolean | undefined | Preset only: pill shape. The standard ignores it. |
circular | boolean | undefined | Preset only: square padding plus pill shape, for an icon-only button. The standard ignores it. |
iconPosition | 'leading' | 'trailing' | undefined | Not read by the built-in implementations (standard and preset); available to a custom implementation. |
BUTTON_STANDARD_COMPONENT_TOKEN
InjectionToken that allows replacing the default ButtonStandardComponent with a custom implementation. Provide a Type<ButtonBaseComponent> to override; every <smart-button> in that injector renders it, with the label projected into its <ng-content>.
Extending the base class
import {
ChangeDetectionStrategy,
Component,
computed,
signal,
ViewEncapsulation,
} from '@angular/core';
import {
ButtonBaseComponent,
ButtonComponent,
BUTTON_STANDARD_COMPONENT_TOKEN,
IButtonOptions,
} from '@smartsoft001/angular';
@Component({
selector: 'docs-custom-button',
template: `
<button
type="button"
[class]="buttonClasses()"
[disabled]="disabled()"
(click)="invoke()"
>
<ng-content />
</button>
`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomButtonComponent extends ButtonBaseComponent {
buttonClasses = computed(() =>
['docs-button', ...this.variantClasses(), this.cssClass()]
.filter(Boolean)
.join(' '),
);
}
// Registering the token makes every <smart-button> in this injector render
// CustomButtonComponent; the label between the tags reaches its <ng-content>.
@Component({
selector: 'docs-button-custom-example',
imports: [ButtonComponent],
providers: [
{
provide: BUTTON_STANDARD_COMPONENT_TOKEN,
useValue: CustomButtonComponent,
},
],
template: `
<smart-button [options]="options">Save</smart-button>
@if (saved()) {
<p>Saved.</p>
}
`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ButtonCustomExampleComponent {
saved = signal(false);
options: IButtonOptions = {
color: 'emerald',
click: () => this.saved.set(true),
};
}
Source
The component lives in packages/shared/angular/src/lib/components/button and is documented for Claude Code by the angular-components-button skill.
SmartButton is the button of @smartsoft001/react. It is configured through an IButtonOptions object (click plus the look: variant, color, size, rounded, circular), renders its children as the label, shows a spinner while options.loading is true, and with options.confirm turns the first click into a Cancel / Confirm pair before click runs. The wrapper renders whatever is registered under the button key of SmartProvider (SmartButtonStandard by default), so one registration restyles every button of the application.
Usage
import { useState } from 'react';
import { IButtonOptions, SmartButton } from '@smartsoft001/react';
export function ButtonUsageExample() {
const [saveCount, setSaveCount] = useState(0);
const options: IButtonOptions = {
color: 'emerald',
size: 'lg',
click: () => setSaveCount((count) => count + 1),
};
return (
<>
<SmartButton options={options}>Save changes</SmartButton>
<p>Saves: {saveCount}</p>
</>
);
}
The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Exports
All from @smartsoft001/react.
| Export | Kind | What it is |
|---|---|---|
SmartButton | component | Renders the implementation registered as components.button on SmartProvider, SmartButtonStandard by default. |
SmartButtonPreset | component | Styled button variation (preset). |
SmartButtonStandard | component | The default button rendering. |
useButton | hook | The behaviour every button variant shares: the colour classes of the variant, and the confirm mode, where a first click asks for confirmation instead of running options.click. |
The preset's class helpers (toButtonPresetVariant, getButtonPresetClasses) and their types (SmartButtonPresetVariant: 'solid' | 'outline' | 'soft'; ButtonPresetShape: { rounded: boolean; circular: boolean }) are exported too, for a custom implementation that wants the preset look.
Props and Types
SmartButtonProps
| Prop | Type | Default | Description |
|---|---|---|---|
options | IButtonOptions | required | The button configuration; click is required. |
disabled? | boolean | false | Disables the button; the standard adds smart:opacity-50 smart:cursor-not-allowed, the preset smart:disabled:opacity-50 smart:disabled:pointer-events-none. |
className? | string | — | Classes appended to the <button>. |
children? | ReactNode | — | The label (any ReactNode). Replaced by the spinner while options.loading. |
IButtonOptions
| Field | Type | Default | Description |
|---|---|---|---|
type? | 'submit' | 'button' | 'button' | The type attribute of the <button>. Use 'submit' inside a <form> of your own. |
confirm? | boolean | — | The first click shows Cancel / Confirm buttons (translated cancel / confirm); click runs only after Confirm. |
click | () => void | required | Called on click (after the confirmation when confirm is set). |
loading? | boolean | — | Shows the spinner instead of the label and disables the button. |
variant? | SmartVariant | 'primary' | primary (solid), secondary (outline) or soft. |
size? | SmartSize | 'md' | Padding and text size; the standard also uses smaller rounding for xs / sm. |
color? | SmartColor | 'indigo' | One of the 22 Tailwind palette names. |
rounded? | boolean | — | Pill shape. Read by SmartButtonPreset only. |
circular? | boolean | — | Square padding plus pill shape, for an icon-only button. Read by SmartButtonPreset only. |
iconPosition? | 'leading' | 'trailing' | — | Not read by the built-in implementations (SmartButtonStandard, SmartButtonPreset); available to a custom implementation. |
SmartColor, SmartSize, SmartVariant are described in the react-provider skill.
Behaviour
- There is no
onClickprop: the handler isoptions.click. options.loadinganddisabledboth disable the<button>; while loading, the label is replaced by<SmartIcon name="spinner" />.- With
options.confirmthe button switches to a confirm mode: it renders a Cancel and a Confirm button instead of itself. Confirm runsclickand returns to the normal mode; Cancel only returns. The labels come from the provider's translations (cancel,confirm). options.typedefaults to'button', so aSmartButtoninside a<form>does not submit it unless you passtype: 'submit'.
Replacing the Implementation
SmartButton renders the component registered under the 'button' key of SmartProvider's components, and SmartButtonStandard when nothing is registered there. Every SmartButton below the provider then renders the registered component, which receives the same props.
SmartButtonPreset is the styled (preset) implementation: register it under the 'button' key of SmartProvider's components, render it directly in place of SmartButton, or spread SMART_PRESET_COMPONENTS on the provider to register every preset at once (see the react-provider skill). Pass components as a stable object (a module constant or a memoised value), or the context changes on every render.
The useButton hook
The behaviour every button variant shares: the colour classes of the variant, and the confirm mode, where a first click asks for confirmation instead of running options.click.
| Returns | Type | Description |
|---|---|---|
mode | "default" | "confirm" | 'confirm' after a first click on a confirm button, 'default' otherwise. |
loading | boolean | !!options.loading. |
variantClasses | string[] | The colour classes of options.variant / options.color from COMPONENT_COLORS, plus the disabled classes. |
invoke | () => void | The click handler: runs options.click, or enters the confirm mode when options.confirm. |
confirmInvoke | () => void | Runs options.click and leaves the confirm mode. |
confirmCancel | () => void | Leaves the confirm mode without running click. |
A custom button builds on useButton, which keeps the confirm mode and computes the colour classes of options.variant / options.color:
import { useState } from 'react';
import {
IButtonOptions,
SmartButton,
SmartButtonProps,
SmartProvider,
useButton,
} from '@smartsoft001/react';
export function CustomButton(props: SmartButtonProps) {
const { disabled = false, className, children } = props;
const { variantClasses, invoke } = useButton(props);
return (
<button
type="button"
className={['docs-button', ...variantClasses, className]
.filter(Boolean)
.join(' ')}
disabled={disabled}
onClick={invoke}
>
{children}
</button>
);
}
// A module constant: a new object on every render would change the context.
const components = { button: CustomButton };
export function ButtonCustomExample() {
const [saved, setSaved] = useState(false);
const options: IButtonOptions = {
color: 'emerald',
click: () => setSaved(true),
};
return (
<SmartProvider components={components}>
<SmartButton options={options}>Save</SmartButton>
{saved && <p>Saved.</p>}
</SmartProvider>
);
}
Styling
- Classes are Tailwind 4 utilities with the
smart:prefix; import@smartsoft001/react/styles.cssonce in the app. - Every colour of
COMPONENT_COLORS(used byuseButton().variantClasses) carriessmart:dark:variants, and the preset classes do too, so the button follows thedarkclass on<html>. classNameis appended last, so it can add spacing or override utilities.
Source
The component lives in packages/shared/react/src/lib/components/button and is documented for Claude Code by the react-components-button skill.