Current section

Files

Jump to
m3e src m3e divider.gleam
Raw

src/m3e/divider.gleam

//// Divider is a thin line that separates content in lists or other containers.
////
//// 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 ---
/// Divider is a View Model for this component
///
/// ## Fields:
///
/// - inset: Whether the divider is indented with equal padding on both sides.
/// - inset_start: Whether the divider is indented with padding on the leading side.
/// - inset_end: Whether the divider is indented with padding on the trailing side.
/// - vertical: Whether the divider is vertically aligned with adjacent content.
///
pub opaque type Divider {
Divider(
inset: Inset,
inset_start: InsetStart,
inset_end: InsetEnd,
vertical: Vertical,
)
}
/// Inset is whether the divider is indented with equal padding on both sides.
///
pub type Inset {
IsInset
IsNotInset
}
/// InsetStart is whether the divider is indented with padding on the leading side.
///
pub type InsetStart {
IsInsetStart
IsNotInsetStart
}
/// InsetEnd is whether the divider is indented with padding on the trailing side.
///
pub type InsetEnd {
IsInsetEnd
IsNotInsetEnd
}
/// Vertical is whether the divider is vertically aligned with adjacent content.
///
pub type Vertical {
IsVertical
IsNotVertical
}
// --- Defaults ---
pub const default_inset: Inset = IsNotInset
pub const default_inset_start: InsetStart = IsNotInsetStart
pub const default_inset_end: InsetEnd = IsNotInsetEnd
pub const default_vertical: Vertical = IsNotVertical
// --- Configuration ---
/// Config is a public record for configuring this component.
///
pub type Config {
Config(
inset: Inset,
inset_start: InsetStart,
inset_end: InsetEnd,
vertical: Vertical,
)
}
/// default_config is the default configuration for this component.
///
pub fn default_config() -> Config {
Config(
inset: IsNotInset,
inset_start: IsNotInsetStart,
inset_end: IsNotInsetEnd,
vertical: IsNotVertical,
)
}
// --- Constructors ---
/// from_config creates a new Divider from the given configuration.
///
pub fn from_config(config: Config) -> Divider {
Divider(
inset: config.inset,
inset_start: config.inset_start,
inset_end: config.inset_end,
vertical: config.vertical,
)
}
/// new creates a new Divider with the default configuration.
///
pub fn new() -> Divider {
from_config(default_config())
}
// --- Setters ---
/// inset sets the value of inset for this Divider.
///
pub fn inset(record: Divider, inset: Inset) -> Divider {
Divider(..record, inset: inset)
}
/// inset_start sets the value of inset_start for this Divider.
///
pub fn inset_start(record: Divider, inset_start: InsetStart) -> Divider {
Divider(..record, inset_start: inset_start)
}
/// inset_end sets the value of inset_end for this Divider.
///
pub fn inset_end(record: Divider, inset_end: InsetEnd) -> Divider {
Divider(..record, inset_end: inset_end)
}
/// vertical sets the value of vertical for this Divider.
///
pub fn vertical(record: Divider, vertical: Vertical) -> Divider {
Divider(..record, vertical: vertical)
}
// --- Renderers ---
/// render creates a Lustre Element for a Divider
///
pub fn render(
model: Divider,
attributes: List(Attribute(msg)),
) -> Element(msg) {
element.element(
"m3e-divider",
list.flatten([
[
attr.boolean("inset", model.inset == IsInset),
attr.boolean("inset-start", model.inset_start == IsInsetStart),
attr.boolean("inset-end", model.inset_end == IsInsetEnd),
attr.boolean("vertical", model.vertical == IsVertical),
],
attributes,
])
|> list.filter(fn(a) { a != attribute.none() }),
[],
)
}
/// render_config creates a Lustre Element from a Divider Config
///
pub fn render_config(
c: Config,
attributes: List(Attribute(msg)),
) -> Element(msg) {
render(from_config(c), attributes)
}