Current section
Files
Jump to
Current section
Files
src/m3e/menu_item_checkbox.gleam
//// MenuItemCheckbox is an item of a menu which supports a checkable state.
////
//// 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 ---
/// MenuItemCheckbox is a View Model for this component
///
/// ## Fields:
///
/// - disabled: Whether the element is disabled.
/// - checked: Whether the element is checked.
///
pub opaque type MenuItemCheckbox {
MenuItemCheckbox(disabled: Disabled, checked: Checked)
}
/// Disabled is whether the element is disabled.
///
pub type Disabled {
IsDisabled
IsNotDisabled
}
/// Checked is whether the element is checked.
///
pub type Checked {
IsChecked
IsNotChecked
}
// --- Defaults ---
pub const default_disabled: Disabled = IsNotDisabled
pub const default_checked: Checked = IsNotChecked
/// Slots are used in child elements to insert content into this component
///
pub type Slot {
Icon
// Renders an icon before the items's label.
TrailingIcon
// Renders an icon after the item's label.
}
// --- Configuration ---
/// Config is a public record for configuring this component.
///
pub type Config {
Config(disabled: Disabled, checked: Checked)
}
/// default_config is the default configuration for this component.
///
pub fn default_config() -> Config {
Config(disabled: IsNotDisabled, checked: IsNotChecked)
}
// --- Constructors ---
/// from_config creates a new MenuItemCheckbox from the given configuration.
///
pub fn from_config(config: Config) -> MenuItemCheckbox {
MenuItemCheckbox(disabled: config.disabled, checked: config.checked)
}
/// new creates a new MenuItemCheckbox with the default configuration.
///
pub fn new() -> MenuItemCheckbox {
from_config(default_config())
}
// --- Setters ---
/// disabled sets the value of disabled for this MenuItemCheckbox.
///
pub fn disabled(
record: MenuItemCheckbox,
disabled: Disabled,
) -> MenuItemCheckbox {
MenuItemCheckbox(..record, disabled: disabled)
}
/// checked sets the value of checked for this MenuItemCheckbox.
///
pub fn checked(record: MenuItemCheckbox, checked: Checked) -> MenuItemCheckbox {
MenuItemCheckbox(..record, checked: checked)
}
// --- Renderers ---
/// render creates a Lustre Element for a MenuItemCheckbox
///
pub fn render(
model: MenuItemCheckbox,
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
element.element(
"m3e-menu-item-checkbox",
list.flatten([
[
attr.boolean("disabled", model.disabled == IsDisabled),
attr.boolean("checked", model.checked == IsChecked),
],
attributes,
])
|> list.filter(fn(a) { a != attribute.none() }),
children,
)
}
/// render_config creates a Lustre Element from a MenuItemCheckbox 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 {
Icon -> attribute.attribute("slot", "icon")
TrailingIcon -> attribute.attribute("slot", "trailing-icon")
}
}