Current section

Files

Jump to
m3e src m3e expandable_list_item.gleam
Raw

src/m3e/expandable_list_item.gleam

//// ExpandableListItem is an item in a list that can be expanded to show more items.
////
//// 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
// --- Types ---
/// ExpandableListItem is a View Model for this component
///
/// ## Fields:
///
/// - disabled: Whether the element is disabled.
/// - open: Whether the item is expanded.
///
pub opaque type ExpandableListItem {
ExpandableListItem(disabled: Disabled, open: Open)
}
/// Disabled is whether the element is disabled.
///
pub type Disabled {
IsDisabled
IsNotDisabled
}
/// Open is whether the item is expanded.
///
pub type Open {
IsOpen
IsNotOpen
}
// --- Defaults ---
pub const default_disabled: Disabled = IsNotDisabled
pub const default_open: Open = IsNotOpen
/// Slots are used in child elements to insert content into this component
///
pub type Slot {
Leading
// Renders the leading content of the list item.
Overline
// Renders the overline of the list item.
SupportingText
// Renders the supporting text of the list item.
ToggleIcon
// Renders a custom icon for the expand/collapse toggle.
Items
// Container for child list items displayed when expanded.
Trailing
// This component does not expose the base trailing slot.
}
// --- Configuration ---
/// Config is a public record for configuring this component.
///
pub type Config {
Config(disabled: Disabled, open: Open)
}
/// default_config is the default configuration for this component.
///
pub fn default_config() -> Config {
Config(disabled: IsNotDisabled, open: IsNotOpen)
}
// --- Constructors ---
/// from_config creates a new ExpandableListItem from the given configuration.
///
pub fn from_config(config: Config) -> ExpandableListItem {
ExpandableListItem(disabled: config.disabled, open: config.open)
}
/// new creates a new ExpandableListItem with the default configuration.
///
pub fn new() -> ExpandableListItem {
from_config(default_config())
}
// --- Setters ---
/// disabled sets the value of disabled for this ExpandableListItem.
///
pub fn disabled(
record: ExpandableListItem,
disabled: Disabled,
) -> ExpandableListItem {
ExpandableListItem(..record, disabled: disabled)
}
/// open sets the value of open for this ExpandableListItem.
///
pub fn open(record: ExpandableListItem, open: Open) -> ExpandableListItem {
ExpandableListItem(..record, open: open)
}
// --- Renderers ---
/// render creates a Lustre Element for a ExpandableListItem
///
pub fn render(
model: ExpandableListItem,
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
element.element(
"m3e-expandable-list-item",
list.flatten([
[
attr.boolean("disabled", model.disabled == IsDisabled),
attr.boolean("open", model.open == IsOpen),
],
attributes,
])
|> list.filter(fn(a) { a != attribute.none() }),
children,
)
}
/// render_config creates a Lustre Element from a ExpandableListItem 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 {
Leading -> attribute.attribute("slot", "leading")
Overline -> attribute.attribute("slot", "overline")
SupportingText -> attribute.attribute("slot", "supporting-text")
ToggleIcon -> attribute.attribute("slot", "toggle-icon")
Items -> attribute.attribute("slot", "items")
Trailing -> attribute.attribute("slot", "trailing")
}
}