Drafter.Style.WidgetStyles (drafter v0.3.2)

Copy Markdown View Source

The built-in stylesheet every app starts from.

One rule set per widget kind, written against theme colour tokens such as :primary and :text_muted rather than RGB values, so the same rules follow whichever theme is current. Drafter.Style.Computed resolves the tokens at render time.

Rules use the selector syntax of Drafter.Style.Selector: a bare widget type for the widget's base style, :pseudo_class for state, and ::part for a sub-region. Because a stylesheet resolves by specificity and then by insertion order, an app's own rules layered on top of these win a tie.

Widget kinds covered: button, checkbox, text_input, label, collapsible, switch, slider, progress_bar, option_list, data_table, tree, scrollbar, radio_set, selection_list, tabbed_content, digits, placeholder, markdown, text_area, command_palette, header and footer.

The assembled stylesheet is built once and kept in :persistent_term.

Summary

Functions

Discard the cached stylesheet so the next default_stylesheet/0 rebuilds it.

The built-in stylesheet.

Functions

clear_cache()

@spec clear_cache() :: :ok

Discard the cached stylesheet so the next default_stylesheet/0 rebuilds it.

Always returns :ok, whether or not anything was cached.

default_stylesheet()

@spec default_stylesheet() :: Drafter.Style.Stylesheet.t()

The built-in stylesheet.

Built on the first call and then served from :persistent_term, so every caller shares one copy. clear_cache/0 forces the next call to rebuild it.

Examples

iex> Drafter.Style.WidgetStyles.default_stylesheet()
...> |> Drafter.Style.Stylesheet.compute_style(%{widget_type: :label, classes: [:error]})
%{background: :background, color: :error}