LedgerUI.Components.ThemePicker (LedgerUI v0.2.0)

Copy Markdown View Source

Lets the user choose a named palette: a menu in the top bar or a grid of previews on a settings page. Each option previews its own colors.

<.theme_picker id="palette" />
<.theme_picker id="palette" variant="grid" />
<.theme_picker id="palette" themes={~w(ledger noite)} label="Tema" />

The palette is apart from the mode: theme_switch/1 picks light, dark or system, the picker picks which palette. The LedgerUI.ThemePicker hook puts the choice on <html data-palette>, keeps it in localStorage["ledger-palette"], marks the option and tells every picker through the ledger:palette window event. on_change also pushes %{"theme" => id} to the LiveView. Put <.theme_script theme="..." /> in the root layout so the stored palette is on before the first paint.

ledger.css ships two palettes, ledger (default) and crepusculo (<html data-palette="crepusculo">: indigo brand, Inter Tight headings, its own hero and auth art); themes/0 lists them first-class next to the sample previews. Pass themes={~w(ledger crepusculo)} for the real ones.

themes takes ids of the built-in list (themes/0) or maps %{id, label} (optionally bg, accent, ink for the preview).

Summary

Functions

theme_picker(assigns)

Attributes

  • id (:string) (required)
  • variant (:string) - Defaults to "menu". Must be one of "menu", or "grid".
  • themes (:list) - Ids or %{id, label} maps; default themes/0. Defaults to nil.
  • default (:string) - The theme shown when nothing is stored. Defaults to nil.
  • current (:string) - The same as default. Defaults to nil.
  • label (:string) - Defaults to "Theme".
  • placement (:string) - Defaults to "bottom-end". Must be one of "bottom-end", or "bottom-start".
  • on_change (:string) - Defaults to nil.
  • target (:any) - Defaults to nil.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

themes()

The built-in themes.