Current section

Files

Jump to
m3e src m3e heading.gleam
Raw

src/m3e/heading.gleam

//// Heading is a heading to a page or section.
////
//// This file was generated by m3e/generator
////
//// DO NOT EDIT
////
import gleam/list
import gleam/option.{type Option, None}
import lustre/attribute.{type Attribute}
import lustre/element.{type Element}
import m3e/attr
import m3e/heading_level.{type HeadingLevel}
import m3e/heading_size.{type HeadingSize}
import m3e/heading_variant.{type HeadingVariant}
// --- Types ---
/// Heading is a View Model for this component
///
/// ## Fields:
///
/// - emphasized: Whether the heading uses an emphasized typescale.
/// - level: The accessibility level of the heading.
/// - size: The size of the heading.
/// - variant: The appearance variant of the heading.
///
pub opaque type Heading {
Heading(
emphasized: Emphasized,
level: Option(HeadingLevel),
size: HeadingSize,
variant: HeadingVariant,
)
}
/// Emphasized is whether the heading uses an emphasized typescale.
///
pub type Emphasized {
IsEmphasized
IsNotEmphasized
}
// --- Defaults ---
pub const default_emphasized: Emphasized = IsNotEmphasized
pub const default_level: Option(HeadingLevel) = None
pub const default_size: HeadingSize = heading_size.Medium
pub const default_variant: HeadingVariant = heading_variant.Display
// --- Configuration ---
/// Config is a public record for configuring this component.
///
pub type Config {
Config(
emphasized: Emphasized,
level: Option(HeadingLevel),
size: HeadingSize,
variant: HeadingVariant,
)
}
/// default_config is the default configuration for this component.
///
pub fn default_config() -> Config {
Config(
emphasized: IsNotEmphasized,
level: None,
size: heading_size.Medium,
variant: heading_variant.Display,
)
}
// --- Constructors ---
/// from_config creates a new Heading from the given configuration.
///
pub fn from_config(config: Config) -> Heading {
Heading(
emphasized: config.emphasized,
level: config.level,
size: config.size,
variant: config.variant,
)
}
/// new creates a new Heading with the default configuration.
///
pub fn new() -> Heading {
from_config(default_config())
}
// --- Setters ---
/// emphasized sets the value of emphasized for this Heading.
///
pub fn emphasized(record: Heading, emphasized: Emphasized) -> Heading {
Heading(..record, emphasized: emphasized)
}
/// level sets the value of level for this Heading.
///
pub fn level(record: Heading, level: Option(HeadingLevel)) -> Heading {
Heading(..record, level: level)
}
/// size sets the value of size for this Heading.
///
pub fn size(record: Heading, size: HeadingSize) -> Heading {
Heading(..record, size: size)
}
/// variant sets the value of variant for this Heading.
///
pub fn variant(record: Heading, variant: HeadingVariant) -> Heading {
Heading(..record, variant: variant)
}
// --- Renderers ---
/// render creates a Lustre Element for a Heading
///
pub fn render(
model: Heading,
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
element.element(
"m3e-heading",
list.flatten([
[
attr.boolean("emphasized", model.emphasized == IsEmphasized),
attr.option(
model.level,
fn(_) { "level" },
heading_level.to_string,
default_level,
),
attr.with_default(
"size",
heading_size.to_string(model.size),
heading_size.to_string(default_size),
),
attr.with_default(
"variant",
heading_variant.to_string(model.variant),
heading_variant.to_string(default_variant),
),
],
attributes,
])
|> list.filter(fn(a) { a != attribute.none() }),
children,
)
}
/// render_config creates a Lustre Element from a Heading Config
///
pub fn render_config(
c: Config,
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
render(from_config(c), attributes, children)
}