AsterUIDocsv1.0.2

Docs / Component reference

Toggle & ToggleGroup

Keep the pressed state of a toolbar action visible. ToggleGroup can hold one selection or several.

Toggle example

Install

sh
npx @fierst/ui@1.0.2 add toggle

Registry dependencies: theme.

Exports from ./ui/toggle: Toggle, ToggleOption, ToggleGroup.

Download the registry source for toggle 1.0.2.

API contracts

ts
export function* Toggle(
  props: {
    pressed?: boolean;
    defaultPressed?: boolean;
    variant?: 'default' | 'outline';
    size?: 'sm' | 'md';
    disabled?: boolean;
    label?: string;
    onPressedChange?: (pressed: boolean) => void;
    class?: string;
    children?: View;
  },
  ctx: Ctx,
)

export interface ToggleOption {
  value: string;
  label: string;
  content: View;
  disabled?: boolean;
}

export function* ToggleGroup(
  props: {
    type?: 'single' | 'multiple';
    options: readonly ToggleOption[];
    value?: string | readonly string[];
    defaultValue?: string | readonly string[];
    size?: 'sm' | 'md';
    label?: string;
    onChange?: (value: any) => void;
    class?: string;
  },
  ctx: Ctx,
)