Current section

Files

Jump to
m3e src m3e input_chip_set.gleam
Raw

src/m3e/input_chip_set.gleam

//// InputChipSet is a container that transforms user input into a cohesive set of interactive chips, supporting entry, editing, and removal of discrete values.
////
//// 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 ---
/// InputChipSet is a View Model for this component
///
/// ## Fields:
///
/// - disabled: Whether the element is disabled.
/// - name: The name that identifies the element when submitting the associated form.
/// - required: Whether a value is required for the element.
/// - vertical: Whether the element is oriented vertically.
///
pub opaque type InputChipSet {
InputChipSet(
disabled: Disabled,
name: String,
required: Required,
vertical: Vertical,
)
}
/// Disabled is whether the element is disabled.
///
pub type Disabled {
IsDisabled
IsNotDisabled
}
/// Required is whether a value is required for the element.
///
pub type Required {
IsRequired
IsNotRequired
}
/// Vertical is whether the element is oriented vertically.
///
pub type Vertical {
IsVertical
IsNotVertical
}
// --- Defaults ---
pub const default_disabled: Disabled = IsNotDisabled
pub const default_name: String = ""
pub const default_required: Required = IsNotRequired
pub const default_vertical: Vertical = IsNotVertical
/// Slots are used in child elements to insert content into this component
///
pub type Slot {
Input
// Renders the input element used to add new chips to the set.
}
// --- Configuration ---
/// Config is a public record for configuring this component.
///
pub type Config {
Config(
disabled: Disabled,
name: String,
required: Required,
vertical: Vertical,
)
}
/// default_config is the default configuration for this component.
///
pub fn default_config() -> Config {
Config(
disabled: IsNotDisabled,
name: "",
required: IsNotRequired,
vertical: IsNotVertical,
)
}
// --- Constructors ---
/// from_config creates a new InputChipSet from the given configuration.
///
pub fn from_config(config: Config) -> InputChipSet {
InputChipSet(
disabled: config.disabled,
name: config.name,
required: config.required,
vertical: config.vertical,
)
}
/// new creates a new InputChipSet with the default configuration.
///
pub fn new() -> InputChipSet {
from_config(default_config())
}
// --- Setters ---
/// disabled sets the value of disabled for this InputChipSet.
///
pub fn disabled(record: InputChipSet, disabled: Disabled) -> InputChipSet {
InputChipSet(..record, disabled: disabled)
}
/// name sets the value of name for this InputChipSet.
///
pub fn name(record: InputChipSet, name: String) -> InputChipSet {
InputChipSet(..record, name: name)
}
/// required sets the value of required for this InputChipSet.
///
pub fn required(record: InputChipSet, required: Required) -> InputChipSet {
InputChipSet(..record, required: required)
}
/// vertical sets the value of vertical for this InputChipSet.
///
pub fn vertical(record: InputChipSet, vertical: Vertical) -> InputChipSet {
InputChipSet(..record, vertical: vertical)
}
// --- Renderers ---
/// render creates a Lustre Element for a InputChipSet
///
pub fn render(
model: InputChipSet,
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
element.element(
"m3e-input-chip-set",
list.flatten([
[
attr.boolean("disabled", model.disabled == IsDisabled),
attr.with_default("name", model.name, default_name),
attr.boolean("required", model.required == IsRequired),
attr.boolean("vertical", model.vertical == IsVertical),
],
attributes,
])
|> list.filter(fn(a) { a != attribute.none() }),
children,
)
}
/// render_config creates a Lustre Element from a InputChipSet 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 {
Input -> attribute.attribute("slot", "input")
}
}