LiveStyle.ShorthandBehavior behaviour (LiveStyle v0.13.0)
View SourceBehaviour and dispatch for shorthand expansion.
LiveStyle supports three built-in behaviors for handling CSS shorthand properties:
LiveStyle.ShorthandBehavior.AcceptShorthands(default) - Keeps shorthand properties with nil resetsLiveStyle.ShorthandBehavior.FlattenShorthands- Expands shorthands to their longhand equivalentsLiveStyle.ShorthandBehavior.ForbidShorthands- Forbids disallowed shorthand properties at compile time
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
Functions
Returns the configured behavior module and options.
Returns a tuple of {module, opts}.
Returns just the configured behavior module.
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.
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.