Raxol.UI.Components.Input.TextInput (Raxol v0.5.0)

View Source

A text input component for capturing user text input.

Features:

  • Customizable placeholder text
  • Value binding
  • Focus handling
  • Character validation
  • Input masking (for password fields)
  • Event callbacks

Summary

Functions

Handles events for the TextInput component, such as keypresses, focus, blur, and mouse events.

Initializes the TextInput component state from the given props.

Mounts the TextInput component. Performs any setup needed after initialization.

Renders the TextInput component using the current state and context.

Unmounts the TextInput component, performing any necessary cleanup.

Updates the TextInput component state in response to messages or prop changes.

Types

props()

@type props() :: %{
  optional(:id) => String.t(),
  optional(:value) => String.t(),
  optional(:placeholder) => String.t(),
  optional(:on_change) => (String.t() -> any()),
  optional(:on_submit) => (String.t() -> any()),
  optional(:on_cancel) => (-> any()) | nil,
  optional(:theme) => map(),
  optional(:style) => map(),
  optional(:mask_char) => String.t() | nil,
  optional(:max_length) => integer() | nil,
  optional(:validator) => (String.t() -> boolean()) | nil
}

state()

@type state() :: %{
  cursor_pos: non_neg_integer(),
  focused: boolean(),
  value: String.t(),
  placeholder: String.t(),
  max_length: non_neg_integer() | nil,
  validator: (String.t() -> boolean()) | nil,
  on_submit: (String.t() -> any()) | nil,
  on_change: (String.t() -> any()) | nil,
  mask_char: String.t() | nil,
  theme: map(),
  style: map()
}

Functions

handle_event(state, arg2, context)

@spec handle_event(map(), map(), map()) :: {map(), list()}

Handles events for the TextInput component, such as keypresses, focus, blur, and mouse events.

init(props)

@spec init(map()) :: {:ok, map()}

Initializes the TextInput component state from the given props.

mount(state)

@spec mount(map()) :: map()

Mounts the TextInput component. Performs any setup needed after initialization.

render(state, context)

@spec render(map(), map()) :: any()

Renders the TextInput component using the current state and context.

unmount(state)

@spec unmount(map()) :: map()

Unmounts the TextInput component, performing any necessary cleanup.

update(message, state)

@spec update(term(), map()) :: map()

Updates the TextInput component state in response to messages or prop changes.