LiveStyle.ShorthandBehavior behaviour (LiveStyle v0.13.1)

View Source

Behaviour and dispatch for shorthand expansion.

LiveStyle supports three built-in behaviors for handling CSS shorthand properties:

You can also provide a custom module that implements this behaviour.

Configuration

# Using atom shortcuts
config :live_style,
  shorthand_behavior: :accept_shorthands

# Using module directly
config :live_style,
  shorthand_behavior: LiveStyle.ShorthandBehavior.FlattenShorthands

# Custom behavior with options
config :live_style,
  shorthand_behavior: {MyCustomBehavior, strict: true}

Implementing a Custom Behavior

To implement a custom behavior, create a module that implements the LiveStyle.ShorthandBehavior behaviour. Property keys are CSS strings (e.g., "margin-top", "background-color").

defmodule MyCustomBehavior do
  @behaviour LiveStyle.ShorthandBehavior

  @impl true
  def expand_declaration(css_property, value) do
    # Return list of {css_property_string, value} tuples
    [{css_property, value}]
  end

  @impl true
  def expand_shorthand_conditions(css_property, conditions) do
    # Return list of {css_property_string, conditions_map} tuples
    [{css_property, conditions}]
  end
end

Summary

Functions

Returns the configured behavior module and options.

Returns just the configured behavior module.

Expands a declaration using the configured behavior.

Expands shorthand conditions using the configured behavior.

Callbacks

expand_declaration(t, any)

@callback expand_declaration(String.t(), any()) :: [{String.t(), any()}]

expand_shorthand_conditions(t, keyword)

@callback expand_shorthand_conditions(
  String.t(),
  keyword()
) :: [{String.t(), any()}]

Functions

backend()

Returns the configured behavior module and options.

Returns a tuple of {module, opts}.

backend_module()

Returns just the configured behavior module.

expand_declaration(css_property, value)

Expands a declaration using the configured behavior.

Takes a CSS property string (e.g., "margin", "background-color") and value. Returns a list of {css_property_string, value} tuples.

expand_shorthand_conditions(css_property, conditions)

Expands shorthand conditions using the configured behavior.

Takes a CSS property string and a conditions map. Returns a list of {css_property_string, conditions_map} tuples.