# `Plushie.Widget.Button`
[🔗](https://github.com/plushie-ui/plushie-elixir/blob/v0.7.2/lib/plushie/widget/button.ex#L24)

Button, clickable widget that emits `%WidgetEvent{type: :click}` events.

The button can contain either a text label (via the `label` prop)
or arbitrary child content (if children are provided, the first child is rendered).

## Props

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `label` | `String.t() \| atom()` | required | Text label displayed on the button. |
| `width` | `:fill \| :shrink \| {:fill_portion, pos_integer()} \| number()` | `nil` | Button width. Default: shrink. |
| `height` | `:fill \| :shrink \| {:fill_portion, pos_integer()} \| number()` | `nil` | Button height. Default: shrink. |
| `padding` | `number() \| {number(), number()} \| %Plushie.Type.Padding{}` | `nil` | Internal padding. |
| `clip` | `boolean()` | `nil` | Clip child content that overflows. Default: false. |
| `style` | `:default
\| :primary
\| :secondary
\| :success
\| :danger
\| :warning
\| :dark
\| :weak
\| :rounded_box
\| term()` | `nil` | Named preset or custom `StyleMap`. |
| `disabled` | `boolean()` | `nil` | Disable the button (no click events). Default: false. |
| `event_rate` | `integer()` | `nil` | Max events per second for coalescable events. |
| `a11y` | `%Plushie.Type.A11y{} \| map() \| keyword()` | `%{role: :button, label_from: :label}` | Accessibility annotations. |

## Events

| Event | Type | Description |
|-------|------|-------------|
| `:click` | none | Emitted on press (unless disabled). |

## Constructor

    Button.new(id, label)
    Button.new(id, label, opts)

# `option`

```elixir
@type option() ::
  (((((({:width, :fill | :shrink | {:fill_portion, pos_integer()} | number()}
        | {:height, :fill | :shrink | {:fill_portion, pos_integer()} | number()})
       | {:padding,
          number()
          | {number(), number()}
          | %Plushie.Type.Padding{
              bottom: term(),
              left: term(),
              right: term(),
              top: term()
            }})
      | {:clip, boolean()})
     | {:style,
        :default
        | :primary
        | :secondary
        | :success
        | :danger
        | :warning
        | :dark
        | :weak
        | :rounded_box
        | term()})
    | {:disabled, boolean()})
   | {:event_rate, integer()})
  | {:a11y,
     %Plushie.Type.A11y{
       active_descendant: term(),
       busy: term(),
       described_by: term(),
       description: term(),
       disabled: term(),
       error_message: term(),
       expanded: term(),
       has_popup: term(),
       hidden: term(),
       invalid: term(),
       label: term(),
       label_from: term(),
       labelled_by: term(),
       level: term(),
       live: term(),
       mnemonic: term(),
       modal: term(),
       orientation: term(),
       position_in_set: term(),
       radio_group: term(),
       read_only: term(),
       required: term(),
       role: term(),
       selected: term(),
       size_of_set: term(),
       toggled: term(),
       value: term()
     }
     | map()
     | keyword()}
```

# `t`

```elixir
@type t() :: %Plushie.Widget.Button{
  a11y:
    (%Plushie.Type.A11y{
       active_descendant: term(),
       busy: term(),
       described_by: term(),
       description: term(),
       disabled: term(),
       error_message: term(),
       expanded: term(),
       has_popup: term(),
       hidden: term(),
       invalid: term(),
       label: term(),
       label_from: term(),
       labelled_by: term(),
       level: term(),
       live: term(),
       mnemonic: term(),
       modal: term(),
       orientation: term(),
       position_in_set: term(),
       radio_group: term(),
       read_only: term(),
       required: term(),
       role: term(),
       selected: term(),
       size_of_set: term(),
       toggled: term(),
       value: term()
     }
     | map()
     | keyword())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  clip:
    boolean()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  disabled:
    boolean()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  event_rate:
    integer()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  height:
    (:fill | :shrink | {:fill_portion, pos_integer()} | number())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  id: String.t(),
  label:
    (String.t() | atom())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  padding:
    (number()
     | {number(), number()}
     | %Plushie.Type.Padding{
         bottom: term(),
         left: term(),
         right: term(),
         top: term()
       })
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  style:
    (:default
     | :primary
     | :secondary
     | :success
     | :danger
     | :warning
     | :dark
     | :weak
     | :rounded_box
     | term())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  width:
    (:fill | :shrink | {:fill_portion, pos_integer()} | number())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil
}
```

# `a11y`

```elixir
@spec a11y(
  widget :: t(),
  value ::
    (%Plushie.Type.A11y{
       active_descendant: term(),
       busy: term(),
       described_by: term(),
       description: term(),
       disabled: term(),
       error_message: term(),
       expanded: term(),
       has_popup: term(),
       hidden: term(),
       invalid: term(),
       label: term(),
       label_from: term(),
       labelled_by: term(),
       level: term(),
       live: term(),
       mnemonic: term(),
       modal: term(),
       orientation: term(),
       position_in_set: term(),
       radio_group: term(),
       read_only: term(),
       required: term(),
       role: term(),
       selected: term(),
       size_of_set: term(),
       toggled: term(),
       value: term()
     }
     | map()
     | keyword())
    | nil
) :: t()
```

Accessibility annotations.

Accepts `%Plushie.Type.A11y{} | map() | keyword()`.

# `build`

```elixir
@spec build(widget :: t()) :: Plushie.Widget.ui_node()
```

Converts this widget struct to a `ui_node()` map.

# `button`
*macro* 

Creates a `:button` widget.

Shorthand for `new/2`. Import this macro to use the widget name
directly in view functions:

    import Plushie.Widget.Button, only: [button: 2]

    button("my-id", prop: value)

# `clip`

```elixir
@spec clip(widget :: t(), value :: boolean() | nil) :: t()
```

Clip child content that overflows. Default: false.

Accepts `boolean()`.

# `disabled`

```elixir
@spec disabled(widget :: t(), value :: boolean() | nil) :: t()
```

Disable the button (no click events). Default: false.

Accepts `boolean()`.

# `event_rate`

```elixir
@spec event_rate(widget :: t(), value :: integer() | nil) :: t()
```

Max events per second for coalescable events.

Accepts `integer()`.

# `height`

```elixir
@spec height(
  widget :: t(),
  value :: (:fill | :shrink | {:fill_portion, pos_integer()} | number()) | nil
) :: t()
```

Button height. Default: shrink.

Accepts `:fill | :shrink | {:fill_portion, pos_integer()} | number()`.

# `label`

```elixir
@spec label(widget :: t(), value :: (String.t() | atom()) | nil) :: t()
```

Text label displayed on the button.

Accepts `String.t() | atom()`.

# `new`

Creates a new widget struct with the given positional args and keyword options.

## Arguments

- `id` - unique widget identifier
- `label` - Text label displayed on the button.
- `opts` - keyword list of optional props

# `padding`

```elixir
@spec padding(
  widget :: t(),
  value ::
    (number()
     | {number(), number()}
     | %Plushie.Type.Padding{
         bottom: term(),
         left: term(),
         right: term(),
         top: term()
       })
    | nil
) :: t()
```

Internal padding.

Accepts `number() | {number(), number()} | %Plushie.Type.Padding{}`.

# `style`

```elixir
@spec style(
  widget :: t(),
  value ::
    (:default
     | :primary
     | :secondary
     | :success
     | :danger
     | :warning
     | :dark
     | :weak
     | :rounded_box
     | term())
    | nil
) :: t()
```

Named preset or custom `StyleMap`.

Accepts `:default
| :primary
| :secondary
| :success
| :danger
| :warning
| :dark
| :weak
| :rounded_box
| term()`.

# `width`

```elixir
@spec width(
  widget :: t(),
  value :: (:fill | :shrink | {:fill_portion, pos_integer()} | number()) | nil
) ::
  t()
```

Button width. Default: shrink.

Accepts `:fill | :shrink | {:fill_portion, pos_integer()} | number()`.

# `with_options`

```elixir
@spec with_options(widget :: t(), opts :: [option()]) :: t()
```

Applies keyword options to an existing widget struct.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
