# API of `@koobiq/components/button`

Documented on [Button](https://koobiq.io/en/components/button.md), [Button Group](https://koobiq.io/en/components/button-group.md). NgModule: `KbqButtonModule`.

## Components

### KbqButton (component)

```ts
@Component({ selector: '[kbq-button]' })
class KbqButton extends KbqColorDirective<KbqButtonColor> implements KbqTitleTextRef {
    kbqStyle = input<KbqButtonStyleInput | null | undefined>();
    disabled = input<boolean | undefined>();
    readonly color = input<T | null | undefined>();
    hasFocus: boolean;
    get textElement(): ElementRef<HTMLElement>;
    get parentTextElement(): ElementRef<HTMLElement>;
    haltDisabledEvents: (event: Event) => void;
    get colorClassName(): string;
    onFocus(): void;
    onBlur(): void;
    getHostElement(): HTMLElement;
    focus(): void;
    focusViaKeyboard(): void;
    projectContentChanged(): void;
    setDefaultColor(color: T): void;
}
```

- `[kbqStyle]`: `KbqButtonStyleInput | null | undefined` — Visual style of the button. Setting it to a value marks that value as owned by the button, so
  a surrounding `KbqButtonGroupRoot` no longer overrides it.

  Reads back as the resulting host class rather than the value that was set, because the host
  `[class]` binding is what consumes it.
- `[disabled]`: `boolean | undefined` — Whether the button is disabled. A surrounding `KbqButtonGroupRoot` can disable the button in
  addition to this input, but never re-enables a button disabled through it.
- `[color]`: `T | null | undefined` — Color of the component. A value set in code holds until the input changes, and the default color is used
  while both are unset or falsy.
- `textElement`: `ElementRef<HTMLElement>` — The text box of the button, measured by `kbq-title`. Always rendered by the template.
- `parentTextElement`: `ElementRef<HTMLElement>` — The flex row that lays out the icons and text, used as the overflow width constraint.
- `colorClassName`: `string` — current class name of color
- `setDefaultColor()`: `void` — this color will be used as a default value. For example [color]="'' | false | undefined | null".

### KbqButtonGroup (component)

Groups and styling related `KbqButton`s into a single visual unit.

```ts
@Component({ selector: 'kbq-button-group, [kbq-button-group]' })
class KbqButtonGroup {
    readonly orientation = input<KbqOrientation>('horizontal');
}
```

- `[orientation]`: `KbqOrientation` — Layout direction: `'horizontal'` or `'vertical'`. Defaults to `'horizontal'`.

## Directives

### KbqButtonCssStyler (directive)

Applies the `kbq-button`/`kbq-button-icon` host class and the left/right icon modifier classes.

A button is treated as an icon button when its projected content consists only of `KbqIcon`s
and there are at most 2 of them. When icons are mixed with other content, only the outermost
icons receive the left/right classes.

Must be used together with `KbqButton` (both match `[kbq-button]`): icon detection relies on
the `.kbq-button-wrapper` element rendered by the component's template.

```ts
@Directive({ selector: '[kbq-button]' })
class KbqButtonCssStyler {
    readonly icons: Signal<readonly KbqIcon[]>;
    readonly nativeElement: HTMLElement;
    get isIconButton(): boolean;
    get hasNoLabel(): boolean;
    updateClassModifierForIcons(): void;
}
```

- `isIconButton`: `boolean` — Whether the button contains only icons (at most 2).
- `hasNoLabel`: `boolean` — Whether the projected label holds no text at all, e.g. an icon-only button.

### KbqButtonDropdownTrigger (directive)

This directive enhances `kbq-button` elements acting as dropdown triggers,
visually indicating the active state with the `kbq-active` class,
following Koobiq Design System.

The directive relies on a separate `KbqDropdownTrigger` directive to get dropdown's state.

```ts
@Directive({ selector: '[kbq-button][kbqDropdownTriggerFor]' })
class KbqButtonDropdownTrigger {
    dropdownTrigger: KbqDropdownTrigger;
}
```

### KbqButtonGroupRoot (directive)

Root directive that groups related buttons,
propagating a shared style, color, and disabled state to every nested button

```ts
@Directive({ selector: '[kbqButtonGroupRoot]' })
class KbqButtonGroupRoot extends KbqColorDirective<KbqButtonColor> {
    kbqStyle = input<KbqButtonStyleInput | null | undefined>();
    disabled = input<boolean | undefined>();
    readonly color = input<T | null | undefined>();
    get colorClassName(): string;
    setDefaultColor(color: T): void;
}
```

- `[kbqStyle]`: `KbqButtonStyleInput | null | undefined` — Style applied to the group and propagated to every nested button.
  A button that sets its own `kbqStyle` keeps it.
- `[disabled]`: `boolean | undefined` — Whether the root is disabled. Disabling the group disables every nested button; re-enabling it
  leaves buttons that are disabled through their own input untouched.

  Stays `undefined` while the input is unbound so that nested buttons are not force-enabled.
- `[color]`: `T | null | undefined` — Color of the component. A value set in code holds until the input changes, and the default color is used
  while both are unset or falsy.
- `colorClassName`: `string` — current class name of color
- `setDefaultColor()`: `void` — this color will be used as a default value. For example [color]="'' | false | undefined | null".

### KbqButtonPrefix (directive)

Marks content to be projected into the prefix (leading) slot of a button.

```ts
@Directive({ selector: '[kbqButtonPrefix]' })
class KbqButtonPrefix {}
```

### KbqButtonSuffix (directive)

Marks content to be projected into the suffix (trailing) slot of a button.

```ts
@Directive({ selector: '[kbqButtonSuffix]' })
class KbqButtonSuffix {}
```

## Types

### KbqButtonColor (type)

Colors a button can be rendered in, as an enum member or its plain string form.

A narrower set than `KbqComponentColors`: the design system pairs each color with a subset of
the styles (`filled` with `contrast`/`contrast-fade`, `outline` with `theme-fade`/`contrast-fade`,
`transparent` with `theme`/`contrast`), and defines no button appearance for the status colors.
A pair the design system does not define falls back to the style's default color rather than
leaving the button unstyled.

```ts
type KbqButtonColor = KbqEnumValues<
    | KbqComponentColors.Theme
    | KbqComponentColors.ThemeFade
    | KbqComponentColors.Contrast
    | KbqComponentColors.ContrastFade
>;
```

### KbqButtonStyle (type)

Visual style of a button, as an enum member or its plain string form.

```ts
type KbqButtonStyle = KbqEnumValues<KbqButtonStyles>;
```

### KbqButtonStyleInput (type)

Value accepted by the `kbqStyle` input: one of the built-in styles, or a custom string that is
applied verbatim as the `kbq-button_<value>` host class and themed by whoever sets it —
`kbq-filter-bar` defines its `changed-filter` style that way. A custom style is not covered by
`kbq-button-theme()` and takes the `filled` default color.

```ts
type KbqButtonStyleInput = KbqButtonStyle | (string & {});
```

## Enums

### KbqButtonStyles (enum)

Visual style of a button.

```ts
enum KbqButtonStyles {
    Filled = 'filled',
    Outline = 'outline',
    Transparent = 'transparent'
}
```

## Constants

### buttonLeftIconClassName (const)

Class set on a button host whose first visible child is an icon.

Public CSS hook: consumed by `dropdown.scss` to detect an icon-only dropdown trigger.

```ts
const buttonLeftIconClassName: string;
```

### buttonRightIconClassName (const)

Class set on a button host whose last visible child is an icon.

Public CSS hook: consumed by `dropdown.scss` to detect an icon-only dropdown trigger.

```ts
const buttonRightIconClassName: string;
```
