Toddy.Iced.Widget.Button (Toddy v0.3.0)

Copy Markdown View Source

Button -- clickable widget that emits %Widget{type: :click, id: id} events.

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

Props

  • label (string) -- text label displayed on the button. Also accepts content as an alias.
  • style -- named preset atom (:primary (default), :secondary, :success, :warning, :danger, :text, :background, :subtle) or StyleMap.t() for custom styling. See Toddy.Iced.StyleMap.
  • width (length) -- button width. Default: shrink. See Toddy.Iced.Length.
  • height (length) -- button height. Default: shrink.
  • padding (number | map) -- internal padding. See Toddy.Iced.Padding.

  • clip (boolean) -- clip child content that overflows. Default: false.
  • disabled (boolean) -- disable the button (no click events). Default: false.
  • enabled (boolean) -- inverse of disabled. Default: true.
  • a11y (map) -- accessibility overrides. See Toddy.Iced.A11y.

Events

  • %Widget{type: :click, id: id} -- emitted on press (unless disabled).

Summary

Functions

Sets accessibility annotations.

Converts this button struct to a ui_node() map via the Toddy.Iced.Widget protocol.

Sets whether child content is clipped on overflow.

Sets whether the button is disabled.

Sets the button height.

Creates a new button struct with the given label and optional keyword opts.

Sets the button padding.

Sets the button style. Accepts a preset atom or StyleMap.

Sets the button width.

Applies keyword options to an existing button struct.

Types

option()

@type option() ::
  {:width, Toddy.Iced.Length.t()}
  | {:height, Toddy.Iced.Length.t()}
  | {:padding, Toddy.Iced.Padding.t()}
  | {:clip, boolean()}
  | {:style, style()}
  | {:disabled, boolean()}
  | {:enabled, boolean()}
  | {:a11y, Toddy.Iced.A11y.t()}

preset()

@type preset() ::
  :subtle
  | :background
  | :text
  | :danger
  | :warning
  | :success
  | :secondary
  | :primary

style()

@type style() :: preset() | Toddy.Iced.StyleMap.t()

t()

@type t() :: %Toddy.Iced.Widget.Button{
  a11y: Toddy.Iced.A11y.t() | nil,
  clip: boolean() | nil,
  disabled: boolean() | nil,
  height: Toddy.Iced.Length.t() | nil,
  id: String.t(),
  label: String.t(),
  padding: Toddy.Iced.Padding.t() | nil,
  style: style() | nil,
  width: Toddy.Iced.Length.t() | nil
}

Functions

a11y(btn, a11y)

@spec a11y(button :: t(), a11y :: Toddy.Iced.A11y.t()) :: t()

Sets accessibility annotations.

build(btn)

@spec build(button :: t()) :: Toddy.Iced.ui_node()

Converts this button struct to a ui_node() map via the Toddy.Iced.Widget protocol.

clip(btn, clip)

@spec clip(button :: t(), clip :: boolean()) :: t()

Sets whether child content is clipped on overflow.

disabled(btn, disabled)

@spec disabled(button :: t(), disabled :: boolean()) :: t()

Sets whether the button is disabled.

height(btn, height)

@spec height(button :: t(), height :: Toddy.Iced.Length.t()) :: t()

Sets the button height.

new(id, label, opts \\ [])

@spec new(id :: String.t(), label :: String.t(), opts :: [option()]) :: t()

Creates a new button struct with the given label and optional keyword opts.

padding(btn, padding)

@spec padding(button :: t(), padding :: Toddy.Iced.Padding.t()) :: t()

Sets the button padding.

style(btn, style)

@spec style(button :: t(), style :: style()) :: t()

Sets the button style. Accepts a preset atom or StyleMap.

width(btn, width)

@spec width(button :: t(), width :: Toddy.Iced.Length.t()) :: t()

Sets the button width.

with_options(btn, opts)

@spec with_options(button :: t(), opts :: [option()]) :: t()

Applies keyword options to an existing button struct.