Current section

Files

Jump to
m3e src m3e segmented_button.gleam
Raw

src/m3e/segmented_button.gleam

//// SegmentedButton is a button that allows a user to select from a limited set of options.
////
//// This file was generated:
//// By: m3e/generator version 0.1.0
//// At: 2026-05-05T14:38:23+10:00
////
//// DO NOT EDIT
////
import gleam/list
import lustre/attribute.{type Attribute}
import lustre/element.{type Element}
import m3e/attr
// --- Types ---
/// SegmentedButton is a View Model for this component
///
/// ## Fields:
///
/// - disabled: Whether the element is disabled.
/// - hide_selection_indicator: Whether to hide the selection indicator.
/// - multi: Whether multiple options can be selected.
/// - name: The name that identifies the element when submitting the associated form.
///
pub opaque type SegmentedButton {
SegmentedButton(
disabled: Disabled,
hide_selection_indicator: HideSelectionIndicator,
multi: Multi,
name: String,
)
}
/// Disabled is whether the element is disabled.
///
pub type Disabled {
IsDisabled
IsNotDisabled
}
/// HideSelectionIndicator is whether to hide the selection indicator.
///
pub type HideSelectionIndicator {
IsHideSelectionIndicator
IsNotHideSelectionIndicator
}
/// Multi is whether multiple options can be selected.
///
pub type Multi {
IsMulti
IsNotMulti
}
// --- Defaults ---
pub const default_disabled: Disabled = IsNotDisabled
pub const default_hide_selection_indicator: HideSelectionIndicator = IsNotHideSelectionIndicator
pub const default_multi: Multi = IsNotMulti
pub const default_name: String = ""
// --- Configuration ---
/// Config is a public record for configuring this component.
///
pub type Config {
Config(
disabled: Disabled,
hide_selection_indicator: HideSelectionIndicator,
multi: Multi,
name: String,
)
}
/// default_config is the default configuration for this component.
///
pub fn default_config() -> Config {
Config(
disabled: IsNotDisabled,
hide_selection_indicator: IsNotHideSelectionIndicator,
multi: IsNotMulti,
name: "",
)
}
// --- Constructors ---
/// from_config creates a new SegmentedButton from the given configuration.
///
pub fn from_config(config: Config) -> SegmentedButton {
SegmentedButton(
disabled: config.disabled,
hide_selection_indicator: config.hide_selection_indicator,
multi: config.multi,
name: config.name,
)
}
/// new creates a new SegmentedButton with the default configuration.
///
pub fn new() -> SegmentedButton {
from_config(default_config())
}
// --- Setters ---
/// disabled sets the value of disabled for this SegmentedButton.
///
pub fn disabled(record: SegmentedButton, disabled: Disabled) -> SegmentedButton {
SegmentedButton(..record, disabled: disabled)
}
/// hide_selection_indicator sets the value of hide_selection_indicator for this SegmentedButton.
///
pub fn hide_selection_indicator(
record: SegmentedButton,
hide_selection_indicator: HideSelectionIndicator,
) -> SegmentedButton {
SegmentedButton(..record, hide_selection_indicator: hide_selection_indicator)
}
/// multi sets the value of multi for this SegmentedButton.
///
pub fn multi(record: SegmentedButton, multi: Multi) -> SegmentedButton {
SegmentedButton(..record, multi: multi)
}
/// name sets the value of name for this SegmentedButton.
///
pub fn name(record: SegmentedButton, name: String) -> SegmentedButton {
SegmentedButton(..record, name: name)
}
// --- Renderers ---
/// render creates a Lustre Element for a SegmentedButton
///
pub fn render(
model: SegmentedButton,
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
element.element(
"m3e-segmented-button",
list.flatten([
[
attr.boolean("disabled", model.disabled == IsDisabled),
attr.boolean(
"hide-selection-indicator",
model.hide_selection_indicator == IsHideSelectionIndicator,
),
attr.boolean("multi", model.multi == IsMulti),
attr.with_default("name", model.name, default_name),
],
attributes,
])
|> list.filter(fn(a) { a != attribute.none() }),
children,
)
}
/// render_config creates a Lustre Element from a SegmentedButton Config
///
pub fn render_config(
c: Config,
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
render(from_config(c), attributes, children)
}