Renders a horizontal or vertical divider line, optionally with an embedded title.
Component tag
Tag :rule, built by Drafter.App as {:rule, opts}:
rule(opts)There is no positional argument; every prop comes from opts.
Options
:orientation-:horizontal | :vertical. Default:horizontal. Any other value raises aCaseClauseErrorfromrender/2.:title-String.t/0embedded in a horizontal rule, ornil. Defaultnil. Ignored when the orientation is:vertical. A title that is as wide as the rect, once padded with a space on each side, is truncated and no line characters are drawn.:title_align-:left | :center | :right. Default:center. Only read when:titleis set.:line_style-:solid | :double | :dashed | :thick. Default:solid. Selects─ ═ ╌ ━horizontally and│ ║ ╎ ┃vertically. Any other value raises aKeyErrorfromrender/2.:style-map/0of style overrides merged over the computed theme style. Default%{}.:height-pos_integer/0read only bypreferred_height/2, never bymount/1. Default1.
Every option except :height is live-updatable: update/2 folds each recognised
key into the state and update_props_from_mount/3 passes the full mount props
through.
Usage
rule()
rule(title: "Section", line_style: :double)
rule(orientation: :vertical)
Summary
Functions
The component tag this widget registers under.
Builds the props map for a {:rule, opts} element.
Ignores every event and returns {:noreply, state}. The rule is not focusable.
Builds the widget state from props.
The number of rows the element asks for: opts[:height], default 1.
Draws the rule into rect.
Callback implementation for Drafter.Widget.unmount/1.
Folds props into state, one key at a time.
Passes the mount props through unchanged, so every option is live-updatable through the component tree.
Types
Functions
@spec component_tag() :: :rule
The component tag this widget registers under.
iex> Drafter.Widget.Rule.component_tag()
:rule
@spec from_component_opts( term(), keyword() ) :: Drafter.Widget.props()
Builds the props map for a {:rule, opts} element.
The positional argument is ignored. :__app_module__ becomes :app_module;
every other option keeps its name and the default stated in the module doc.
iex> Drafter.Widget.Rule.from_component_opts(nil, [])
%{orientation: :horizontal, title: nil, title_align: :center, style: %{}, line_style: :solid, app_module: nil}
iex> Drafter.Widget.Rule.from_component_opts(nil, title: "Section", title_align: :left).title_align
:left
@spec handle_event(Drafter.Event.t(), t()) :: {:noreply, t()}
Ignores every event and returns {:noreply, state}. The rule is not focusable.
@spec mount(Drafter.Widget.props()) :: t()
Builds the widget state from props.
Reads :orientation (default :horizontal), :title (default nil),
:title_align (default :center), :style (default %{}), :line_style
(default :solid) and :app_module (default nil).
iex> Drafter.Widget.Rule.mount(%{})
%Drafter.Widget.Rule{orientation: :horizontal, title: nil, title_align: :center, style: %{}, line_style: :solid, app_module: nil}
iex> Drafter.Widget.Rule.mount(%{title: "Section", line_style: :double}).line_style
:double
@spec preferred_height( term(), keyword() ) :: pos_integer()
The number of rows the element asks for: opts[:height], default 1.
iex> Drafter.Widget.Rule.preferred_height(nil, [])
1
iex> Drafter.Widget.Rule.preferred_height(nil, height: 3)
3
@spec render(t(), Drafter.Widget.rect()) :: [Drafter.Draw.Strip.t()]
Draws the rule into rect.
A horizontal rule returns rect.height strips with the line on row
div(rect.height, 2) and blanks elsewhere. A vertical rule returns
rect.height strips each holding the line character followed by
rect.width - 1 spaces, or [] when rect.width is not positive.
Callback implementation for Drafter.Widget.unmount/1.
@spec update(Drafter.Widget.props() | keyword(), t()) :: t()
Folds props into state, one key at a time.
Recognises :orientation, :title, :title_align, :style, :line_style and
:app_module; any other key is ignored and leaves the state untouched. props
may be a map or a keyword list.
iex> state = Drafter.Widget.Rule.mount(%{})
iex> Drafter.Widget.Rule.update(%{title: "New", unknown: 1}, state).title
"New"
@spec update_props_from_mount(Drafter.Widget.props(), term(), keyword()) :: Drafter.Widget.props()
Passes the mount props through unchanged, so every option is live-updatable through the component tree.
iex> props = Drafter.Widget.Rule.from_component_opts(nil, title: "Section")
iex> Drafter.Widget.Rule.update_props_from_mount(props, %{}, []) == props
true