Cinder.Theme (Cinder v0.3.0)

View Source

Theme management for Cinder table components.

Provides default themes and utilities for merging custom theme configurations. Also supports the new Spark DSL for defining modular themes.

Basic Usage

# Using built-in themes
theme = Cinder.Theme.merge("modern")

# Using application configuration for default theme
# config/config.exs
config :cinder, default_theme: "modern"

Advanced Usage (DSL-based themes)

defmodule MyApp.CustomTheme do
  use Cinder.Theme

  override Cinder.Components.Table do
    set :container_class, "my-custom-table-container"
    set :row_class, "my-custom-row hover:bg-blue-50"
  end
end

# Use in config
config :cinder, default_theme: MyApp.CustomTheme

# Or use directly
theme = Cinder.Theme.merge(MyApp.CustomTheme)

Configuration

You can set a default theme for all Cinder tables in your application configuration:

# config/config.exs
config :cinder, default_theme: "modern"

# Or use a custom theme module
config :cinder, default_theme: MyApp.CustomTheme

Individual tables can still override the configured default:

<Cinder.Table.table theme="dark" ...>
  <!-- This table uses "dark" theme, ignoring the configured default -->
</Cinder.Table.table>

Summary

Functions

Gets all available theme properties across all components.

Gets the complete default theme by merging all component defaults.

Returns the default theme configuration.

Gets the configured default theme from application configuration.

Merges a theme configuration with the default theme.

Returns a list of available theme presets.

Validates a theme configuration.

Types

theme()

@type theme() :: %{required(atom()) => String.t()}

Functions

all_theme_properties()

Gets all available theme properties across all components.

complete_default()

Gets the complete default theme by merging all component defaults.

default()

Returns the default theme configuration.

get_default_theme()

Gets the configured default theme from application configuration.

Returns the theme configured via config :cinder, default_theme: ... or falls back to "default" if no configuration is set.

Examples

# With configuration
Application.put_env(:cinder, :default_theme, "modern")
Cinder.Theme.get_default_theme()
#=> returns modern theme configuration

# Without configuration
Cinder.Theme.get_default_theme()
#=> returns "default" theme configuration

merge(theme_config)

Merges a theme configuration with the default theme.

Examples

iex> Cinder.Theme.merge("modern")
%{container_class: "bg-white shadow-lg rounded-xl border border-gray-100 overflow-hidden", ...}

iex> Cinder.Theme.merge(MyApp.CustomTheme)
%{container_class: "custom-container", ...}

presets()

Returns a list of available theme presets.

validate(theme_module)

Validates a theme configuration.

Returns :ok if the theme is valid, or {:error, reason} if invalid.