Raxol.Style.Theme (Raxol v0.2.0)

View Source

Theme management for Raxol applications.

This module provides functionality for creating, switching, and customizing themes. Themes define the visual appearance of the application, including colors, borders, and component-specific styles.

Summary

Functions

Applies a theme by its name, setting it as the current theme for the process.

Creates and registers a high-contrast variant based on predefined high-contrast colors. This variant overrides the color palette.

Gets the current active theme. Returns the default theme if none is set.

Exports the current theme as a map suitable for serialization.

Gets a color from the current theme's palette, considering active variants. Checks the active variant first, then the base palette. (Note: Need a way to know the active variant - maybe from Accessibility state?) This is a placeholder - the logic to check active variant needs refinement.

Gets a style from the current theme by name.

Gets a specific theme struct by its name. Returns nil if the theme name is not found.

Imports a theme from the given map data.

Returns a list of available theme structs.

Creates a new theme with the specified attributes.

Registers a new style in the current theme.

Registers a theme variant. Theme variants allow for alternate visual styles like high-contrast, dark mode, etc. A variant can include overrides for both :styles and :color_palette.

Sets the color palette for the current theme.

Sets the current active theme.

Types

t()

@type t() :: %Raxol.Style.Theme{
  color_palette: map(),
  description: String.t(),
  metadata: map(),
  name: String.t(),
  styles: map(),
  variants: map()
}

Functions

apply_theme(name)

@spec apply_theme(String.t()) :: :ok | :error

Applies a theme by its name, setting it as the current theme for the process.

Returns :ok if the theme was found and applied, :error otherwise.

available_themes()

@spec available_themes() :: %{required(String.t()) => t()}

create_high_contrast_variant()

Creates and registers a high-contrast variant based on predefined high-contrast colors. This variant overrides the color palette.

current()

Gets the current active theme. Returns the default theme if none is set.

export()

Exports the current theme as a map suitable for serialization.

get_color(name, active_variant \\ nil)

Gets a color from the current theme's palette, considering active variants. Checks the active variant first, then the base palette. (Note: Need a way to know the active variant - maybe from Accessibility state?) This is a placeholder - the logic to check active variant needs refinement.

get_style(name)

Gets a style from the current theme by name.

get_theme_by_name(name)

@spec get_theme_by_name(String.t()) :: t() | nil

Gets a specific theme struct by its name. Returns nil if the theme name is not found.

import(data)

Imports a theme from the given map data.

list_themes()

@spec list_themes() :: [t()]

Returns a list of available theme structs.

new(attrs \\ %{})

Creates a new theme with the specified attributes.

register_style(name, style)

Registers a new style in the current theme.

register_variant(name, variant_overrides)

Registers a theme variant. Theme variants allow for alternate visual styles like high-contrast, dark mode, etc. A variant can include overrides for both :styles and :color_palette.

set_color_palette(palette)

Sets the color palette for the current theme.

set_current(theme)

Sets the current active theme.