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

Rich text display with individually styled spans.

Spans are typed via `Plushie.Widget.RichText.Span`. Construct them
with `span/1` plus chained setters or pass a plain map for ad-hoc
cases. Typed spans are encoded automatically; plain maps fall
through unchanged.

    alias Plushie.Widget.RichText.Span

    rich_text "status",
      spans: [
        Span.new("Build ") |> Span.color("#000000"),
        Span.new("ok") |> Span.color("#22aa22") |> Span.underline(true)
      ]

## Accessibility

Screen readers see individual spans but cannot infer the overall
meaning of the composed text. Set `a11y: %{label: "..."}` with a
plain-text summary so assistive technology can announce the full
content in one pass:

    rich_text "status", spans: spans,
      a11y: %{label: "Build succeeded in 3.2 seconds"}

For content that updates dynamically, combine `label` with a live
region annotation so changes are announced automatically:

    rich_text "output", spans: spans,
      a11y: %{label: summary_text, live: :polite}

## Props

| Name | Type | Default | Description |
|------|------|---------|-------------|
| `spans` | `[map()]` | `nil` | List of span descriptors. Use `Plushie.Widget.RichText.Span` or plain maps. |
| `width` | `:fill \| :shrink \| {:fill_portion, pos_integer()} \| number()` | `nil` | Widget width. Default: shrink. |
| `height` | `:fill \| :shrink \| {:fill_portion, pos_integer()} \| number()` | `nil` | Widget height. Default: shrink. |
| `size` | `number()` | `nil` | Default font size for all spans. |
| `font` | `:default \| :monospace \| String.t() \| %Plushie.Type.Font{}` | `nil` | Default font for all spans. |
| `color` | `String.t()` | `nil` | Default text color for all spans. |
| `line_height` | `number() \| %{relative: number()} \| %{absolute: number()}` | `nil` | Line height. Number is relative; map for explicit control. |
| `wrapping` | `:none \| :word \| :glyph \| :word_or_glyph` | `nil` | Text wrapping mode. |
| `ellipsis` | `:none \| :start \| :middle \| :end` | `nil` | Text ellipsis mode: `:none`, `:start`, `:middle`, `:end`. |
| `event_rate` | `integer()` | `nil` | Max events per second for coalescable events. |
| `a11y` | `%Plushie.Type.A11y{} \| map() \| keyword()` | `%{role: :label}` | Accessibility annotations. |

# `option`

```elixir
@type option() ::
  ((((((((({:spans, [map()]}
           | {:width,
              :fill | :shrink | {:fill_portion, pos_integer()} | number()})
          | {:height,
             :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()
             }})
       | {:color, atom() | String.t() | map()})
      | {:line_height, number() | %{relative: number()} | %{absolute: number()}})
     | {:wrapping, :none | :word | :glyph | :word_or_glyph})
    | {:ellipsis, :none | :start | :middle | :end})
   | {: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.RichText{
  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,
  color:
    String.t()
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  ellipsis:
    (:none | :start | :middle | :end)
    | 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,
  height:
    (:fill | :shrink | {:fill_portion, pos_integer()} | number())
    | Plushie.Animation.Transition.t()
    | Plushie.Animation.Spring.t()
    | Plushie.Animation.Sequence.t()
    | nil,
  id: String.t(),
  line_height:
    (number() | %{relative: number()} | %{absolute: number()})
    | 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,
  spans:
    [map()]
    | 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,
  wrapping:
    (:none | :word | :glyph | :word_or_glyph)
    | 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.

# `color`

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

Default text color for all spans.

Accepts `String.t()`.

# `ellipsis`

```elixir
@spec ellipsis(widget :: t(), value :: (:none | :start | :middle | :end) | nil) :: t()
```

Text ellipsis mode: `:none`, `:start`, `:middle`, `:end`.

Accepts `:none | :start | :middle | :end`.

# `event_rate`

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

Max events per second for coalescable events.

Accepts `integer()`.

# `font`

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

Default font for all spans.

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

# `height`

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

Widget height. Default: shrink.

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

# `line_height`

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

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

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

# `new`

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

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

# `rich_text`
*macro* 

Creates a `:rich_text` widget.

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

    import Plushie.Widget.RichText, only: [rich_text: 2]

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

# `size`

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

Default font size for all spans.

Accepts `number()`.

# `spans`

```elixir
@spec spans(widget :: t(), value :: [map()] | nil) :: t()
```

List of span descriptors. Use `Plushie.Widget.RichText.Span` or plain maps.

Accepts `[map()]`.

# `width`

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

Widget 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.

# `wrapping`

```elixir
@spec wrapping(
  widget :: t(),
  value :: (:none | :word | :glyph | :word_or_glyph) | nil
) :: t()
```

Text wrapping mode.

Accepts `:none | :word | :glyph | :word_or_glyph`.

---

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