Search documentation of Plushie

# Plushie.Widget.TextInput (Plushie v0.7.2)

Copy Markdown View Source

Text input field, single-line editable text.

## Props

Name | Type | Default | Description
--- | --- | --- | ---
`value` | `String.t() | atom()` | required | Current text content. Required for controlled input.
`placeholder` | `String.t() | atom()` | `nil` | Placeholder text shown when value is empty.
`padding` | `number() | {number(), number()} | %Plushie.Type.Padding{}` | `nil` | Internal padding.
`width` | `:fill | :shrink | {:fill_portion, pos_integer()} | number()` | `nil` | Input width. Default: fill.
`size` | `number()` | `nil` | Font size in pixels.
`font` | `:default | :monospace | String.t() | %Plushie.Type.Font{}` | `nil` | Font specification.
`line_height` | `number() | %{relative: number()} | %{absolute: number()}` | `nil` | Line height. Number is a relative multiplier; map for explicit control.
`align_x` | `:left | :center | :right | :top | :bottom` | `nil` | Text horizontal alignment: `:left`, `:center`, `:right`.
`icon` | `map()` | `nil` | Icon inside the input field. Map with `code_point`, `size`, `spacing`, `side`, `font` keys.
`on_submit` | `boolean()` | `nil` | When true, enables submit on Enter.
`on_paste` | `boolean()` | `nil` | When true, emits paste events. Default: false.
`secure` | `boolean()` | `nil` | Mask input as password dots. Default: false.
`input_purpose` | `:normal | :secure | :terminal | :number | :decimal | :phone | :email | :url | :search` | `nil` | Input purpose hint: `:normal`, `:secure`, `:terminal`, `:number`, `:decimal`, `:phone`, `:email`, `:url`, `:search`.

| `style` | `:default \| :primary \| :secondary \| :success \| :danger \| :warning \| :dark \| :weak \| :rounded_box \| term()` | `nil` | Named style preset or custom `StyleMap`. | | `placeholder_color` | `String.t()` | `nil` | Placeholder text color. | | `selection_color` | `String.t()` | `nil` | Text selection highlight color. | | `required` | `boolean()` | `nil` | Marks the field as required. Flows into `a11y.required` automatically. | | `validation` | `term()` | `nil` | Form validation state. Accepts `:valid`, `:pending`, or `{:invalid, message}`. Flows into `a11y.invalid` and `a11y.error_message` automatically. | | `event_rate` | `integer()` | `nil` | Max events per second for coalescable events. | | `a11y` | `%Plushie.Type.A11y{} \| map() \| keyword()` | `%{role: :text_input, label_from: :placeholder}` | Accessibility annotations. |

## Events

Event | Type | Description
--- | --- | ---
`:input` | `value: String.t() | atom()` | Emitted on every text change.
`:submit` | `value: String.t() | atom()` | Emitted on Enter (requires `on_submit` prop).
`:paste` | `value: String.t() | atom()` | Emitted on paste (requires `on_paste` prop).
`:focused` | none | Emitted when the input gains focus.
`:blurred` | none | Emitted when the input loses focus.

## Constructor

    TextInput.new(id, value)
    TextInput.new(id, value, opts)

## Summary

### Types

option()
t()

### Functions

a11y(widget, descriptor)

Accessibility annotations.

align_x(widget, descriptor)

Text horizontal alignment: `:left`, `:center`, `:right`.

build(widget)

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

event_rate(widget, descriptor)

Max events per second for coalescable events.

font(widget, descriptor)

Font specification.

icon(widget, descriptor)

Icon inside the input field. Map with `code_point`, `size`, `spacing`, `side`, `font` keys.

input_purpose(widget, descriptor)

Input purpose hint: `:normal`, `:secure`, `:terminal`, `:number`, `:decimal`, `:phone`, `:email`, `:url`, `:search`.

line_height(widget, descriptor)

Line height. Number is a relative multiplier; map for explicit control.

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

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

on_paste(widget, descriptor)

When true, emits paste events. Default: false.

on_submit(widget, descriptor)

When true, enables submit on Enter.

padding(widget, descriptor)

Internal padding.

placeholder(widget, descriptor)

Placeholder text shown when value is empty.

placeholder_color(widget, descriptor)

Placeholder text color.

required(widget, descriptor)

Marks the field as required. Flows into `a11y.required` automatically.

secure(widget, descriptor)

Mask input as password dots. Default: false.

selection_color(widget, descriptor)

Text selection highlight color.

size(widget, descriptor)

Font size in pixels.

style(widget, descriptor)

Named style preset or custom `StyleMap`.

text_input(id, opts \\ [])

Creates a `:text_input` widget.

validation(widget, descriptor)

Form validation state. Accepts `:valid`, `:pending`, or `{:invalid, message}`. Flows into `a11y.invalid` and `a11y.error_message` automatically.

value(widget, descriptor)

Current text content. Required for controlled input.

width(widget, descriptor)

Input width. Default: fill.

with_options(widget, opts)

Applies keyword options to an existing widget struct.

## Types

# option()

    @type option() ::
      ((((((((((((((((({:placeholder, String.t() | atom()}
                       | {:padding,
                          number()
                          | {number(), number()}
                          | %Plushie.Type.Padding{
                              bottom: term(),
                              left: term(),
                              right: term(),
                              top: term()
                            }})
                      | {:width,
                         :fill | :shrink | {:fill_portion, pos_integer()} | number()})
                     | {:size, number()})
                    | {:font,
                       :default
                       | :monospace
                       | String.t()
                       | %Plushie.Type.Font{
                           family: term(),
                           stretch: term(),
                           style: term(),
                           weight: term()
                         }})
                   | {:line_height,
                      number() | %{relative: number()} | %{absolute: number()}})
                  | {:align_x, :left | :center | :right | :top | :bottom})
                 | {:icon, map()})
                | {:on_submit, boolean()})
               | {:on_paste, boolean()})
              | {:secure, boolean()})
             | {:input_purpose,
                :normal
                | :secure
                | :terminal
                | :number
                | :decimal
                | :phone
                | :email
                | :url
                | :search})
            | {:style,
               :default
               | :primary
               | :secondary
               | :success
               | :danger
               | :warning
               | :dark
               | :weak
               | :rounded_box
               | term()})
           | {:placeholder_color, atom() | String.t() | map()})
          | {:selection_color, atom() | String.t() | map()})
         | {:required, boolean()})
        | {:validation, term()})
       | {: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()

    @type t() :: %Plushie.Widget.TextInput{
      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,
      align_x:
        (:left | :center | :right | :top | :bottom)
        | 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,
      font:
        (:default
         | :monospace
         | String.t()
         | %Plushie.Type.Font{
             family: term(),
             stretch: term(),
             style: term(),
             weight: term()
           })
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      icon:
        map()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      id: String.t(),
      input_purpose:
        (:normal
         | :secure
         | :terminal
         | :number
         | :decimal
         | :phone
         | :email
         | :url
         | :search)
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      line_height:
        (number() | %{relative: number()} | %{absolute: number()})
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      on_paste:
        boolean()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      on_submit:
        boolean()
        | 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,
      placeholder:
        (String.t() | atom())
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      placeholder_color:
        String.t()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      required:
        boolean()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      secure:
        boolean()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      selection_color:
        String.t()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      size:
        number()
        | 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,
      validation:
        term()
        | Plushie.Animation.Transition.t()
        | Plushie.Animation.Spring.t()
        | Plushie.Animation.Sequence.t()
        | nil,
      value:
        (String.t() | atom())
        | 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
    }

## Functions

# a11y(widget, descriptor)

    @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()`.

# align_x(widget, descriptor)

    @spec align_x(
      widget :: t(),
      value :: (:left | :center | :right | :top | :bottom) | nil
    ) :: t()

Text horizontal alignment: `:left`, `:center`, `:right`.

Accepts `:left | :center | :right | :top | :bottom`.

# build(widget)

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

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

# event_rate(widget, descriptor)

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

Max events per second for coalescable events.

Accepts `integer()`.

# font(widget, descriptor)

    @spec font(
      widget :: t(),
      value ::
        (:default
         | :monospace
         | String.t()
         | %Plushie.Type.Font{
             family: term(),
             stretch: term(),
             style: term(),
             weight: term()
           })
        | nil
    ) :: t()

Font specification.

Accepts `:default | :monospace | String.t() | %Plushie.Type.Font{}`.

# icon(widget, descriptor)

    @spec icon(widget :: t(), value :: map() | nil) :: t()

Icon inside the input field. Map with `code_point`, `size`, `spacing`, `side`, `font` keys.

Accepts `map()`.

# input_purpose(widget, descriptor)

    @spec input_purpose(
      widget :: t(),
      value ::
        (:normal
         | :secure
         | :terminal
         | :number
         | :decimal
         | :phone
         | :email
         | :url
         | :search)
        | nil
    ) :: t()

Input purpose hint: `:normal`, `:secure`, `:terminal`, `:number`, `:decimal`, `:phone`, `:email`, `:url`, `:search`.

Accepts `:normal | :secure | :terminal | :number | :decimal | :phone | :email | :url | :search`.

# line_height(widget, descriptor)

    @spec line_height(
      widget :: t(),
      value :: (number() | %{relative: number()} | %{absolute: number()}) | nil
    ) :: t()

Line height. Number is a relative multiplier; map for explicit control.

Accepts `number() | %{relative: number()} | %{absolute: number()}`.

# new(id, value, opts \\ [])

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

## Arguments

- `id` - unique widget identifier
- `value` - Current text content. Required for controlled input.
- `opts` - keyword list of optional props

# on_paste(widget, descriptor)

    @spec on_paste(widget :: t(), value :: boolean() | nil) :: t()

When true, emits paste events. Default: false.

Accepts `boolean()`.

# on_submit(widget, descriptor)

    @spec on_submit(widget :: t(), value :: boolean() | nil) :: t()

When true, enables submit on Enter.

Accepts `boolean()`.

# padding(widget, descriptor)

    @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{}`.

# placeholder(widget, descriptor)

    @spec placeholder(widget :: t(), value :: (String.t() | atom()) | nil) :: t()

Placeholder text shown when value is empty.

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

# placeholder_color(widget, descriptor)

    @spec placeholder_color(widget :: t(), value :: (atom() | String.t() | map()) | nil) ::
      t()

Placeholder text color.

Accepts `String.t()`.

# required(widget, descriptor)

    @spec required(widget :: t(), value :: boolean() | nil) :: t()

Marks the field as required. Flows into `a11y.required` automatically.

Accepts `boolean()`.

# secure(widget, descriptor)

    @spec secure(widget :: t(), value :: boolean() | nil) :: t()

Mask input as password dots. Default: false.

Accepts `boolean()`.

# selection_color(widget, descriptor)

    @spec selection_color(widget :: t(), value :: (atom() | String.t() | map()) | nil) ::
      t()

Text selection highlight color.

Accepts `String.t()`.

# size(widget, descriptor)

    @spec size(widget :: t(), value :: number() | nil) :: t()

Font size in pixels.

Accepts `number()`.

# style(widget, descriptor)

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

Named style preset or custom `StyleMap`.

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

# text_input(id, opts \\ [])

(macro)

Creates a `:text_input` widget.

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

    import Plushie.Widget.TextInput, only: [text_input: 2]

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

# validation(widget, descriptor)

    @spec validation(widget :: t(), value :: term() | nil) :: t()

Form validation state. Accepts `:valid`, `:pending`, or `{:invalid, message}`. Flows into `a11y.invalid` and `a11y.error_message` automatically.

Accepts `term()`.

# value(widget, descriptor)

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

Current text content. Required for controlled input.

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

# width(widget, descriptor)

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

Input width. Default: fill.

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

# with_options(widget, opts)

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

Applies keyword options to an existing widget struct.