Current section

Files

Jump to
m3e src m3e toc_item.gleam
Raw

src/m3e/toc_item.gleam

//// TocItem is an item in a table of contents.
////
//// 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 ---
/// TocItem is a View Model for this component
///
/// ## Fields:
///
/// - disabled: A value indicating whether the element is disabled.
/// - selected: Whether the element is selected.
///
pub opaque type TocItem {
TocItem(disabled: Disabled, selected: Selected)
}
/// Disabled is a value indicating whether the element is disabled.
///
pub type Disabled {
IsDisabled
IsNotDisabled
}
/// Selected is whether the element is selected.
///
pub type Selected {
IsSelected
IsNotSelected
}
// --- Defaults ---
pub const default_disabled: Disabled = IsNotDisabled
pub const default_selected: Selected = IsNotSelected
// --- Configuration ---
/// Config is a public record for configuring this component.
///
pub type Config {
Config(disabled: Disabled, selected: Selected)
}
/// default_config is the default configuration for this component.
///
pub fn default_config() -> Config {
Config(disabled: IsNotDisabled, selected: IsNotSelected)
}
// --- Constructors ---
/// from_config creates a new TocItem from the given configuration.
///
pub fn from_config(config: Config) -> TocItem {
TocItem(disabled: config.disabled, selected: config.selected)
}
/// new creates a new TocItem with the default configuration.
///
pub fn new() -> TocItem {
from_config(default_config())
}
// --- Setters ---
/// disabled sets the value of disabled for this TocItem.
///
pub fn disabled(record: TocItem, disabled: Disabled) -> TocItem {
TocItem(..record, disabled: disabled)
}
/// selected sets the value of selected for this TocItem.
///
pub fn selected(record: TocItem, selected: Selected) -> TocItem {
TocItem(..record, selected: selected)
}
// --- Renderers ---
/// render creates a Lustre Element for a TocItem
///
pub fn render(
model: TocItem,
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
element.element(
"m3e-toc-item",
list.flatten([
[
attr.boolean("disabled", model.disabled == IsDisabled),
attr.boolean("selected", model.selected == IsSelected),
],
attributes,
])
|> list.filter(fn(a) { a != attribute.none() }),
children,
)
}
/// render_config creates a Lustre Element from a TocItem Config
///
pub fn render_config(
c: Config,
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
render(from_config(c), attributes, children)
}