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.

MemberTypeDescription
modeWritableSignal<'default' | 'confirm'>'confirm' after a first click on a confirm button, 'default' otherwise.
variantClassesSignal<string[]>The colour classes of options.variant / options.color from COMPONENT_COLORS, plus smart:opacity-50 smart:cursor-not-allowed while disabled.
invoke()methodThe click handler: runs options.click, or enters the confirm mode when options.confirm.
confirmInvoke()methodRuns options.click and leaves the confirm mode.
confirmCancel()methodLeaves the confirm mode without running click.

API

Inputs

InputTypeDefaultDescription
optionsInputSignal<IButtonOptions>requiredButton configuration
disabledInputSignal<boolean>falseDisables the <button>
classInputSignal<string>''External CSS classes appended to the <button> (alias for cssClass)

Content projection

SelectorDescription
defaultThe label. Replaced by the spinner while options.loading() is true.

IButtonOptions

FieldTypeDefaultDescription
type'submit' | 'button''button'The type attribute of the <button>. Use 'submit' inside a <form> of your own.
confirmbooleanundefinedThe first click shows Cancel / Confirm buttons (translated cancel / confirm); click runs only after Confirm.
click() => voidrequiredCalled on click (after the confirmation when confirm is set).
loadingSignal<boolean>undefinedWhile it reads true, the spinner replaces the label and the button is disabled.
variantSmartVariant'primary'primary (solid), secondary (outline) or soft.
sizeSmartSize'md'Padding and text size (xs to xl); the standard also uses smaller rounding for xs / sm.
colorSmartColor'indigo'One of the 22 Tailwind palette names.
roundedbooleanundefinedPreset only: pill shape. The standard ignores it.
circularbooleanundefinedPreset only: square padding plus pill shape, for an icon-only button. The standard ignores it.
iconPosition'leading' | 'trailing'undefinedNot 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.

ExportKindWhat it is
SmartButtoncomponentRenders the implementation registered as components.button on SmartProvider, SmartButtonStandard by default.
SmartButtonPresetcomponentStyled button variation (preset).
SmartButtonStandardcomponentThe default button rendering.
useButtonhookThe 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

PropTypeDefaultDescription
optionsIButtonOptionsrequiredThe button configuration; click is required.
disabled?booleanfalseDisables 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

FieldTypeDefaultDescription
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() => voidrequiredCalled 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 onClick prop: the handler is options.click.
  • options.loading and disabled both disable the <button>; while loading, the label is replaced by <SmartIcon name="spinner" />.
  • With options.confirm the button switches to a confirm mode: it renders a Cancel and a Confirm button instead of itself. Confirm runs click and returns to the normal mode; Cancel only returns. The labels come from the provider's translations (cancel, confirm).
  • options.type defaults to 'button', so a SmartButton inside a <form> does not submit it unless you pass type: '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.

ReturnsTypeDescription
mode"default" | "confirm"'confirm' after a first click on a confirm button, 'default' otherwise.
loadingboolean!!options.loading.
variantClassesstring[]The colour classes of options.variant / options.color from COMPONENT_COLORS, plus the disabled classes.
invoke() => voidThe click handler: runs options.click, or enters the confirm mode when options.confirm.
confirmInvoke() => voidRuns options.click and leaves the confirm mode.
confirmCancel() => voidLeaves 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.css once in the app.
  • Every colour of COMPONENT_COLORS (used by useButton().variantClasses) carries smart:dark: variants, and the preset classes do too, so the button follows the dark class on <html>.
  • className is 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.