Twm.Config.Theme (Twm v0.1.0)

View Source

Theme helper functions for Twm.

This module provides functions for working with themes in Tailwind CSS classes. It converts the TypeScript fromTheme functions to Elixir.

Summary

Functions

Returns animate-related theme values.

Returns aspect-related theme values.

Returns blur-related theme values.

Returns breakpoint-related theme values.

Calls a theme getter function with the provided theme configuration.

Returns color-related theme values.

Returns container-related theme values.

Returns drop-shadow-related theme values.

Returns ease-related theme values.

Returns font-related theme values.

Returns font-weight-related theme values.

Creates a theme getter function for the specified theme key.

Returns inset-shadow-related theme values.

Returns leading-related theme values.

Returns perspective-related theme values.

Returns radius-related theme values.

Returns shadow-related theme values.

Returns spacing-related theme values.

Returns text-related theme values.

Returns text-shadow-related theme values.

Checks if a value is a theme getter.

Returns tracking-related theme values.

Functions

animate(theme_config)

@spec animate(map()) :: list()

Returns animate-related theme values.

This is a convenience function for the animate theme.

aspect(theme_config)

@spec aspect(map()) :: list()

Returns aspect-related theme values.

This is a convenience function for the aspect theme.

blur(theme_config)

@spec blur(map()) :: list()

Returns blur-related theme values.

This is a convenience function for the blur theme.

breakpoint(theme_config)

@spec breakpoint(map()) :: list()

Returns breakpoint-related theme values.

This is a convenience function for the breakpoint theme.

call_theme_getter(func, theme_config)

@spec call_theme_getter(Twm.Config.Theme.ThemeGetter.t() | function(), map()) ::
  list()

Calls a theme getter function with the provided theme configuration.

This function handles both ThemeGetter structs and regular functions for backwards compatibility.

Parameters

  • theme_getter - A ThemeGetter struct or regular function
  • theme_config - The theme configuration map

Examples

iex> theme_spacing = Twm.Config.Theme.from_theme(:spacing)
iex> config = %{spacing: ["1", "2", "4"]}
iex> Twm.Config.Theme.call_theme_getter(theme_spacing, config)
["1", "2", "4"]

color(theme_config)

@spec color(map()) :: list()

Returns color-related theme values.

This is a convenience function for the color theme.

container(theme_config)

@spec container(map()) :: list()

Returns container-related theme values.

This is a convenience function for the container theme.

drop_shadow(theme_config)

@spec drop_shadow(map()) :: list()

Returns drop-shadow-related theme values.

This is a convenience function for the drop-shadow theme.

ease(theme_config)

@spec ease(map()) :: list()

Returns ease-related theme values.

This is a convenience function for the ease theme.

font(theme_config)

@spec font(map()) :: list()

Returns font-related theme values.

This is a convenience function for the font theme.

font_weight(theme_config)

@spec font_weight(map()) :: list()

Returns font-weight-related theme values.

This is a convenience function for the font-weight theme.

from_theme(theme_key)

@spec from_theme(String.t() | atom()) :: Twm.Config.Theme.ThemeGetter.t()

Creates a theme getter function for the specified theme key.

This is the Elixir equivalent of the TypeScript fromTheme function. Returns a ThemeGetter struct that can be identified as a theme getter and called to extract theme values.

Parameters

  • theme_key - The theme key to extract from theme configuration (string or atom)

Returns

A ThemeGetter struct containing:

  • :key - The theme key
  • :getter_fn - Function that extracts values from theme config
  • :is_theme_getter - Always true to mark this as a theme getter

Examples

iex> theme_spacing = Twm.Config.Theme.from_theme("spacing")
iex> theme_spacing.is_theme_getter
true

iex> theme_color = Twm.Config.Theme.from_theme(:color)
iex> theme_color.key
:color

iex> theme_config = %{spacing: ["1", "2", "4", "8"]}
iex> theme_spacing = Twm.Config.Theme.from_theme("spacing")
iex> Twm.Config.Theme.call_theme_getter(theme_spacing, theme_config)
["1", "2", "4", "8"]

iex> theme_config = %{color: ["red", "blue"]}
iex> theme_missing = Twm.Config.Theme.from_theme("missing")
iex> Twm.Config.Theme.call_theme_getter(theme_missing, theme_config)
[]

inset_shadow(theme_config)

@spec inset_shadow(map()) :: list()

Returns inset-shadow-related theme values.

This is a convenience function for the inset-shadow theme.

leading(theme_config)

@spec leading(map()) :: list()

Returns leading-related theme values.

This is a convenience function for the leading theme.

perspective(theme_config)

@spec perspective(map()) :: list()

Returns perspective-related theme values.

This is a convenience function for the perspective theme.

radius(theme_config)

@spec radius(map()) :: list()

Returns radius-related theme values.

This is a convenience function for the radius theme.

shadow(theme_config)

@spec shadow(map()) :: list()

Returns shadow-related theme values.

This is a convenience function for the shadow theme.

spacing(theme_config)

@spec spacing(map()) :: list()

Returns spacing-related theme values.

This is a convenience function for the spacing theme.

text(theme_config)

@spec text(map()) :: list()

Returns text-related theme values.

This is a convenience function for the text theme.

text_shadow(theme_config)

@spec text_shadow(map()) :: list()

Returns text-shadow-related theme values.

This is a convenience function for the text-shadow theme.

theme_getter?(arg1)

@spec theme_getter?(any()) :: boolean()

Checks if a value is a theme getter.

Examples

iex> theme_spacing = Twm.Config.Theme.from_theme(:spacing)
iex> Twm.Config.Theme.theme_getter?(theme_spacing)
true

iex> regular_func = fn x -> x end
iex> Twm.Config.Theme.theme_getter?(regular_func)
false

tracking(theme_config)

@spec tracking(map()) :: list()

Returns tracking-related theme values.

This is a convenience function for the tracking theme.