Raxol.UI.Components.Base (Raxol v0.4.0)

View Source

Provides base functionality and utilities for Raxol components.

This module contains shared functionality used across different components, including common validation, styling, and event handling patterns.

Summary

Functions

Creates a base style for components with common properties.

Handles common events like focus, blur, and keyboard navigation.

Validates component props against a schema.

Types

state()

@type state() :: map()

Functions

base_style(opts \\ [])

@spec base_style(Keyword.t()) :: any()

Creates a base style for components with common properties.

handle_common_events(event, state)

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

Handles common events like focus, blur, and keyboard navigation.

Should be called from a component's handle_event callback.

validate_props(props, schema)

@spec validate_props(map(), map()) :: :ok | {:error, any()}

Validates component props against a schema.

Example

def validate_props(props) do
  Base.validate_props(props, %{
    required: [:label],
    optional: [:style, :disabled],
    types: %{
      label: :string,
      style: {:one_of, [:primary, :secondary, :danger]},
      disabled: :boolean
    }
  })
end