Plushie.Widget.RichText (Plushie v0.7.1)

Copy Markdown View Source

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

NameTypeDefaultDescription
spans[map()]nilList of span descriptors. Use Plushie.Widget.RichText.Span or plain maps.
width:fill | :shrink | {:fill_portion, pos_integer()} | number()nilWidget width. Default: shrink.
height:fill | :shrink | {:fill_portion, pos_integer()} | number()nilWidget height. Default: shrink.
sizenumber()nilDefault font size for all spans.
font:default | :monospace | String.t() | %Plushie.Type.Font{}nilDefault font for all spans.
colorString.t()nilDefault text color for all spans.
line_heightnumber() | %{relative: number()} | %{absolute: number()}nilLine height. Number is relative; map for explicit control.
wrapping:none | :word | :glyph | :word_or_glyphnilText wrapping mode.
ellipsis:none | :start | :middle | :endnilText ellipsis mode: :none, :start, :middle, :end.
event_rateinteger()nilMax events per second for coalescable events.
a11y%Plushie.Type.A11y{} | map() | keyword()%{role: :label}Accessibility annotations.

Summary

Functions

Accessibility annotations.

Converts this widget struct to a ui_node() map.

Default text color for all spans.

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

Max events per second for coalescable events.

Default font for all spans.

Widget height. Default: shrink.

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

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

Creates a :rich_text widget.

Default font size for all spans.

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

Widget width. Default: shrink.

Applies keyword options to an existing widget struct.

Text wrapping mode.

Types

option()

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

@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
}

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

build(widget)

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

Converts this widget struct to a ui_node() map.

color(widget, descriptor)

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

Default text color for all spans.

Accepts String.t().

ellipsis(widget, descriptor)

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

Default font for all spans.

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

height(widget, descriptor)

@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(widget, descriptor)

@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(id, opts \\ [])

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

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

rich_text(id, opts \\ [])

(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(widget, descriptor)

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

Default font size for all spans.

Accepts number().

spans(widget, descriptor)

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

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

Accepts [map()].

width(widget, descriptor)

@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(widget, opts)

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

Applies keyword options to an existing widget struct.

wrapping(widget, descriptor)

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

Text wrapping mode.

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