Current section

Files

Jump to
m3e src m3e expansion_header.gleam
Raw

src/m3e/expansion_header.gleam

//// ExpansionHeader is a button used to toggle the expanded state of an expansion panel.
////
//// This file was generated by m3e/generator
////
//// DO NOT EDIT
////
import gleam/list
import lustre/attribute.{type Attribute}
import lustre/element.{type Element}
import m3e/attr
import m3e/expansion_toggle_direction.{type ExpansionToggleDirection}
import m3e/expansion_toggle_position.{type ExpansionTogglePosition}
// --- Types ---
/// ExpansionHeader is a View Model for this component
///
/// ## Fields:
///
/// - hide_toggle: Whether to hide the expansion toggle.
/// - toggle_direction: The direction of the expansion toggle.
/// - toggle_position: The position of the expansion toggle.
/// - disabled: Whether the element is disabled.
///
pub opaque type ExpansionHeader {
ExpansionHeader(
hide_toggle: HideToggle,
toggle_direction: ExpansionToggleDirection,
toggle_position: ExpansionTogglePosition,
disabled: Disabled,
)
}
/// HideToggle is whether to hide the expansion toggle.
///
pub type HideToggle {
IsHideToggle
IsNotHideToggle
}
/// Disabled is whether the element is disabled.
///
pub type Disabled {
IsDisabled
IsNotDisabled
}
// --- Defaults ---
pub const default_hide_toggle: HideToggle = IsNotHideToggle
pub const default_toggle_direction: ExpansionToggleDirection = expansion_toggle_direction.Vertical
pub const default_toggle_position: ExpansionTogglePosition = expansion_toggle_position.After
pub const default_disabled: Disabled = IsNotDisabled
/// Slots are used in child elements to insert content into this component
///
pub type Slot {
ToggleIcon
// Renders the icon of the expansion toggle.
}
// --- Configuration ---
/// Config is a public record for configuring this component.
///
pub type Config {
Config(
hide_toggle: HideToggle,
toggle_direction: ExpansionToggleDirection,
toggle_position: ExpansionTogglePosition,
disabled: Disabled,
)
}
/// default_config is the default configuration for this component.
///
pub fn default_config() -> Config {
Config(
hide_toggle: IsNotHideToggle,
toggle_direction: expansion_toggle_direction.Vertical,
toggle_position: expansion_toggle_position.After,
disabled: IsNotDisabled,
)
}
// --- Constructors ---
/// from_config creates a new ExpansionHeader from the given configuration.
///
pub fn from_config(config: Config) -> ExpansionHeader {
ExpansionHeader(
hide_toggle: config.hide_toggle,
toggle_direction: config.toggle_direction,
toggle_position: config.toggle_position,
disabled: config.disabled,
)
}
/// new creates a new ExpansionHeader with the default configuration.
///
pub fn new() -> ExpansionHeader {
from_config(default_config())
}
// --- Setters ---
/// hide_toggle sets the value of hide_toggle for this ExpansionHeader.
///
pub fn hide_toggle(
record: ExpansionHeader,
hide_toggle: HideToggle,
) -> ExpansionHeader {
ExpansionHeader(..record, hide_toggle: hide_toggle)
}
/// toggle_direction sets the value of toggle_direction for this ExpansionHeader.
///
pub fn toggle_direction(
record: ExpansionHeader,
toggle_direction: ExpansionToggleDirection,
) -> ExpansionHeader {
ExpansionHeader(..record, toggle_direction: toggle_direction)
}
/// toggle_position sets the value of toggle_position for this ExpansionHeader.
///
pub fn toggle_position(
record: ExpansionHeader,
toggle_position: ExpansionTogglePosition,
) -> ExpansionHeader {
ExpansionHeader(..record, toggle_position: toggle_position)
}
/// disabled sets the value of disabled for this ExpansionHeader.
///
pub fn disabled(
record: ExpansionHeader,
disabled: Disabled,
) -> ExpansionHeader {
ExpansionHeader(..record, disabled: disabled)
}
// --- Renderers ---
/// render creates a Lustre Element for a ExpansionHeader
///
pub fn render(
model: ExpansionHeader,
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
element.element(
"m3e-expansion-header",
list.flatten([
[
attr.boolean("hide-toggle", model.hide_toggle == IsHideToggle),
attr.with_default(
"toggle-direction",
expansion_toggle_direction.to_string(model.toggle_direction),
expansion_toggle_direction.to_string(default_toggle_direction),
),
attr.with_default(
"toggle-position",
expansion_toggle_position.to_string(model.toggle_position),
expansion_toggle_position.to_string(default_toggle_position),
),
attr.boolean("disabled", model.disabled == IsDisabled),
],
attributes,
])
|> list.filter(fn(a) { a != attribute.none() }),
children,
)
}
/// render_config creates a Lustre Element from a ExpansionHeader Config
///
pub fn render_config(
c: Config,
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
render(from_config(c), attributes, children)
}
/// slot returns a Lustre Attribute(msg) for the given slot name
///
pub fn slot(s: Slot) -> Attribute(msg) {
case s {
ToggleIcon -> attribute.attribute("slot", "toggle-icon")
}
}