Aurora.Uix.Templates.ThemeHelper (Aurora UIX v0.1.4-rc.3)

Copy Markdown

Provides helper functions for embedding theme-based styles within HEEx templates.

Offers a convenient way to include compiled or dynamic themeable stylesheets. Leverages the configured theme module to apply consistent styling and manage CSS rule generation.

Summary

Functions

Generates the rules half of the stylesheet.

Generates a complete stylesheet from all rules in the theme module.

Generates the variables half of the stylesheet.

Extracts the rule contents and replace and create a new rule using the target_name.

Registers and retrieves all available themes.

Returns the configured theme module.

Returns the name of the configured theme.

Functions

generate_rules_stylesheet()

@spec generate_rules_stylesheet() :: binary()

Generates the rules half of the stylesheet.

Emits every theme rule except :root and :root_colors, which are handled by generate_variables_stylesheet/0.

Returns

binary() - The component CSS rules.

generate_stylesheet()

@spec generate_stylesheet() :: binary()

Generates a complete stylesheet from all rules in the theme module.

Returns

binary() - All the :root_colors from all the registered themes plus the CSS rules from the configured theme module.

Examples

iex> generate_stylesheet(MyApp.Theme)
["<style>.button { color: blue; }</style>", "<style>.card { ... }</style>"]

generate_variables_stylesheet()

@spec generate_variables_stylesheet() :: binary()

Generates the variables half of the stylesheet.

Emits the :root declarations from the configured theme (sizes, typography, shadows) followed by every registered palette's :root_colors. Host applications can @import this file, override individual --auix-* vars, and then @import the rules file.

Returns

binary() - The combined CSS variable declarations.

import_rule(rule_source, target_name)

(macro)
@spec import_rule(atom(), binary() | atom()) :: Macro.t()

Extracts the rule contents and replace and create a new rule using the target_name.

Parameters

  • rule_source (atom()) - rule name to import from.
  • target_name (binary() | atom()) - rule to create.

Returns

  • binary() - The new css rule.

registered_themes()

@spec registered_themes() :: map()

Registers and retrieves all available themes.

theme_module()

@spec theme_module() :: module()

Returns the configured theme module.

Returns

module() | nil - The theme module configured at compile time, nil if the configured module name is not registered. This might provoke an error in calling modules.

Examples

iex> theme_module()
Aurora.Uix.Templates.Basic.Themes.WhiteCharcoal

theme_name()

@spec theme_name() :: atom()

Returns the name of the configured theme.

Returns

atom() - The name of the configured theme.

Examples

iex> theme_name()
:white_charcoal