plushie/widget/build
Shared helpers for widget builder modules.
Values
pub fn apply_default_a11y(
props: dict.Dict(String, node.PropValue),
a11y_opt: option.Option(a11y.A11y),
role: String,
label_from_key: option.Option(String),
) -> dict.Dict(String, node.PropValue)
Apply default a11y props to a node’s prop dict when no explicit a11y is set.
role is the default role string, label_from_key is an optional prop key
to derive the label from (e.g. “label”, “placeholder”, “content”).
pub fn apply_default_a11y_props(
props: dict.Dict(String, node.PropValue),
a11y_opt: option.Option(a11y.A11y),
role: String,
label_from_key: option.Option(String),
extra_props: List(#(String, node.PropValue)),
) -> dict.Dict(String, node.PropValue)
Apply default a11y props plus widget-specific defaults.
pub fn merge_animated(
props: dict.Dict(String, node.PropValue),
animated: dict.Dict(String, node.PropValue),
) -> dict.Dict(String, node.PropValue)
Merge animated prop overrides into a props dict. Animated values take precedence over statically-encoded values for the same key.
pub fn put_animated(
props: dict.Dict(String, node.PropValue),
key: String,
animation: node.PropValue,
) -> dict.Dict(String, node.PropValue)
Insert a pre-encoded animation descriptor (Transition, Spring, or
Sequence) as a prop value. The animation must already be encoded via
its module’s encode function.
pub fn put_optional(
props: dict.Dict(String, node.PropValue),
key: String,
value: option.Option(a),
encoder: fn(a) -> node.PropValue,
) -> dict.Dict(String, node.PropValue)
Insert a prop only if the Option is Some.
pub fn put_optional_bool(
props: dict.Dict(String, node.PropValue),
key: String,
value: option.Option(Bool),
) -> dict.Dict(String, node.PropValue)
Insert an optional bool prop.
pub fn put_optional_float(
props: dict.Dict(String, node.PropValue),
key: String,
value: option.Option(Float),
) -> dict.Dict(String, node.PropValue)
Insert an optional float prop.
pub fn put_optional_int(
props: dict.Dict(String, node.PropValue),
key: String,
value: option.Option(Int),
) -> dict.Dict(String, node.PropValue)
Insert an optional int prop.
pub fn put_optional_string(
props: dict.Dict(String, node.PropValue),
key: String,
value: option.Option(String),
) -> dict.Dict(String, node.PropValue)
Insert an optional string prop.
pub fn put_string(
props: dict.Dict(String, node.PropValue),
key: String,
value: String,
) -> dict.Dict(String, node.PropValue)
Insert a string prop.
pub fn validate_pair_children(
id: String,
kind: String,
children: List(node.Node),
) -> Nil
Validate that a widget has exactly 2 children. Panics with a descriptive message if the constraint is violated.
pub fn validate_single_child(
id: String,
kind: String,
children: List(node.Node),
) -> Nil
Validate that a widget has at most one child. Panics with a descriptive message if the constraint is violated.