MithrilUI.Theme (Mithril UI v0.1.2)
View SourceRuntime 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
@spec available_themes() :: [String.t()]
Returns the list of all available theme names (builtin + custom).
Examples
iex> MithrilUI.Theme.available_themes()
["light", "dark", "cupcake", ...]
@spec builtin_themes() :: [String.t()]
Returns the list of all built-in DaisyUI theme names.
@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"
@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"
Returns a custom theme definition by name, or nil if not found.
@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
Checks if a theme exists in the available themes.
Examples
iex> MithrilUI.Theme.theme_exists?("light")
true
iex> MithrilUI.Theme.theme_exists?("nonexistent")
false
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"
@spec theme_options() :: [map()]
Returns theme metadata for UI display (e.g., theme switcher dropdowns).
Each theme includes:
name- The theme identifier used indata-themelabel- Human-readable display namecolor_scheme-:lightor:dark
Examples
iex> MithrilUI.Theme.theme_options()
[
%{name: "light", label: "Light", color_scheme: :light},
%{name: "dark", label: "Dark", color_scheme: :dark},
...
]