MithrilUI.Theme (Mithril UI v0.1.2)

View Source

Runtime theme management for Mithril UI.

This module provides functions to query available themes, get the default theme, and generate theme metadata for UI components like theme switchers.

Configuration

# config/config.exs
config :mithril_ui,
  default_theme: "light",
  dark_theme: "dark",
  builtin_themes: :all,  # or [:light, :dark, :corporate] or :none
  themes: [
    %{
      name: "brand_light",
      label: "Brand Light",
      extends: "light",
      color_scheme: :light,
      colors: %{
        primary: "#4F46E5",
        primary_content: "#FFFFFF"
      }
    }
  ]

Built-in DaisyUI Themes

The following 35 themes are available when builtin_themes: :all:

light, dark, cupcake, bumblebee, emerald, corporate, synthwave, retro,
cyberpunk, valentine, halloween, garden, forest, aqua, lofi, pastel,
fantasy, wireframe, black, luxury, dracula, cmyk, autumn, business,
acid, lemonade, night, coffee, winter, dim, nord, sunset,
caramellatte, abyss, silk

Summary

Functions

Returns the list of all available theme names (builtin + custom).

Returns the list of all built-in DaisyUI theme names.

Returns the dark mode theme name from configuration.

Returns the default theme name from configuration.

Returns a custom theme definition by name, or nil if not found.

Returns the color scheme (:light or :dark) for a theme.

Checks if a theme exists in the available themes.

Returns the human-readable label for a theme.

Returns theme metadata for UI display (e.g., theme switcher dropdowns).

Functions

available_themes()

@spec available_themes() :: [String.t()]

Returns the list of all available theme names (builtin + custom).

Examples

iex> MithrilUI.Theme.available_themes()
["light", "dark", "cupcake", ...]

builtin_themes()

@spec builtin_themes() :: [String.t()]

Returns the list of all built-in DaisyUI theme names.

dark_theme()

@spec dark_theme() :: String.t()

Returns the dark mode theme name from configuration.

This theme is used when the user's system prefers dark mode. Defaults to "dark" if not configured.

Examples

iex> MithrilUI.Theme.dark_theme()
"dark"

default_theme()

@spec default_theme() :: String.t()

Returns the default theme name from configuration.

Defaults to "light" if not configured.

Examples

iex> MithrilUI.Theme.default_theme()
"light"

get_custom_theme(name)

@spec get_custom_theme(String.t()) :: map() | nil

Returns a custom theme definition by name, or nil if not found.

theme_color_scheme(name)

@spec theme_color_scheme(String.t()) :: :light | :dark

Returns the color scheme (:light or :dark) for a theme.

Examples

iex> MithrilUI.Theme.theme_color_scheme("light")
:light

iex> MithrilUI.Theme.theme_color_scheme("dark")
:dark

theme_exists?(name)

@spec theme_exists?(String.t()) :: boolean()

Checks if a theme exists in the available themes.

Examples

iex> MithrilUI.Theme.theme_exists?("light")
true

iex> MithrilUI.Theme.theme_exists?("nonexistent")
false

theme_label(name)

@spec theme_label(String.t()) :: String.t()

Returns the human-readable label for a theme.

For builtin themes, returns a capitalized version of the name. For custom themes, returns the configured label or capitalized name.

Examples

iex> MithrilUI.Theme.theme_label("light")
"Light"

iex> MithrilUI.Theme.theme_label("cupcake")
"Cupcake"

theme_options()

@spec theme_options() :: [map()]

Returns theme metadata for UI display (e.g., theme switcher dropdowns).

Each theme includes:

  • name - The theme identifier used in data-theme
  • label - Human-readable display name
  • color_scheme - :light or :dark

Examples

iex> MithrilUI.Theme.theme_options()
[
  %{name: "light", label: "Light", color_scheme: :light},
  %{name: "dark", label: "Dark", color_scheme: :dark},
  ...
]