Aurora.Uix.Templates.Theme behaviour (Aurora UIX v0.1.0)

Defines the behaviour for a theme module in Aurora.Uix.

A theme module is responsible for providing the CSS rules that are used to style the components. This module provides the __using__ macro to inject the necessary behaviour and callbacks into your theme module.

## Example

  defmodule MyApp.Theme do
    use Aurora.Uix.Templates.Theme

    def rule(:root) do
      """
      :root {
        --primary-color: #3b82f6;
        --secondary-color: #6b7280;
      }
      """
    end

    def rule(:button) do
      """
      .button {
        background-color: var(--primary-color);
        color: white;
        padding: 0.5rem 1rem;
        border-radius: 0.25rem;
      }
      """
    end
  end

Summary

Callbacks

Callback that should return the CSS rule for a given rule name.

Callback that should return a list of all available rule names in the theme.

Functions

Injects the rule_names/0 function into the module before compilation.

Injects the Theme behaviour and callbacks into the calling module.

Callbacks

rule(rule)

@callback rule(rule :: atom()) :: binary()

Callback that should return the CSS rule for a given rule name.

Parameters

  • rule (atom()) - The name of the rule.

Returns

(binary()) - The CSS rule as a string.

rule_names()

@callback rule_names() :: list()

Callback that should return a list of all available rule names in the theme.

Returns

(list(atom())) - A list of rule names.

Functions

__before_compile__(env)

(macro)
@spec __before_compile__(Macro.Env.t()) :: Macro.t()

Injects the rule_names/0 function into the module before compilation.

This function is generated based on the rule/1 function definitions in the module.

__using__(opts \\ [])

(macro)
@spec __using__(any()) :: Macro.t()

Injects the Theme behaviour and callbacks into the calling module.