Current section
Files
Jump to
Current section
Files
src/m3e/button_segment.gleam
//// ButtonSegment is a option that can be selected within a segmented button.
////
//// 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 ---
/// ButtonSegment is a View Model for this component
///
/// ## Fields:
///
/// - checked: Whether the element is checked.
/// - disabled: Whether the element is disabled.
/// - value: A string representing the value of the segment.
///
pub opaque type ButtonSegment {
ButtonSegment(checked: Checked, disabled: Disabled, value: String)
}
/// Checked is whether the element is checked.
///
pub type Checked {
IsChecked
IsNotChecked
}
/// Disabled is whether the element is disabled.
///
pub type Disabled {
IsDisabled
IsNotDisabled
}
// --- Defaults ---
pub const default_checked: Checked = IsNotChecked
pub const default_disabled: Disabled = IsNotDisabled
pub const default_value: String = "on"
/// Slots are used in child elements to insert content into this component
///
pub type Slot {
Icon
// Renders an icon before the option's label.
}
// --- Configuration ---
/// Config is a public record for configuring this component.
///
pub type Config {
Config(checked: Checked, disabled: Disabled, value: String)
}
/// default_config is the default configuration for this component.
///
pub fn default_config() -> Config {
Config(checked: IsNotChecked, disabled: IsNotDisabled, value: "on")
}
// --- Constructors ---
/// from_config creates a new ButtonSegment from the given configuration.
///
pub fn from_config(config: Config) -> ButtonSegment {
ButtonSegment(
checked: config.checked,
disabled: config.disabled,
value: config.value,
)
}
/// new creates a new ButtonSegment with the default configuration.
///
pub fn new() -> ButtonSegment {
from_config(default_config())
}
// --- Setters ---
/// checked sets the value of checked for this ButtonSegment.
///
pub fn checked(record: ButtonSegment, checked: Checked) -> ButtonSegment {
ButtonSegment(..record, checked: checked)
}
/// disabled sets the value of disabled for this ButtonSegment.
///
pub fn disabled(record: ButtonSegment, disabled: Disabled) -> ButtonSegment {
ButtonSegment(..record, disabled: disabled)
}
/// value sets the value of value for this ButtonSegment.
///
pub fn value(record: ButtonSegment, value: String) -> ButtonSegment {
ButtonSegment(..record, value: value)
}
// --- Renderers ---
/// render creates a Lustre Element for a ButtonSegment
///
pub fn render(
model: ButtonSegment,
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
element.element(
"m3e-button-segment",
list.flatten([
[
attr.boolean("checked", model.checked == IsChecked),
attr.boolean("disabled", model.disabled == IsDisabled),
attr.with_default("value", model.value, default_value),
],
attributes,
])
|> list.filter(fn(a) { a != attribute.none() }),
children,
)
}
/// render_config creates a Lustre Element from a ButtonSegment 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")
}
}