Current section
Files
Jump to
Current section
Files
src/m3e/fab_menu_item.gleam
//// FabMenuItem is an item of a floating action button (FAB) menu.
////
//// This file was generated by m3e/generator
////
//// DO NOT EDIT
////
import gleam/function
import gleam/list
import gleam/option.{type Option, None}
import lustre/attribute.{type Attribute}
import lustre/element.{type Element}
import m3e/attr
import m3e/link_target.{type LinkTarget}
// --- Types ---
/// FabMenuItem is a View Model for this component
///
/// ## Fields:
///
/// - disabled: Whether the element is disabled.
/// - download: A value indicating whether the `target` of the link button will be downloaded, optionally specifying the new name of the file.
/// - href: The URL to which the link button points.
/// - rel: The relationship between the `target` of the link button and the document.
/// - target: The target of the link button.
///
pub opaque type FabMenuItem {
FabMenuItem(
disabled: Disabled,
download: Option(String),
href: String,
rel: String,
target: Option(LinkTarget),
)
}
/// Disabled is whether the element is disabled.
///
pub type Disabled {
IsDisabled
IsNotDisabled
}
// --- Defaults ---
pub const default_disabled: Disabled = IsNotDisabled
pub const default_download: Option(String) = None
pub const default_href: String = ""
pub const default_rel: String = ""
pub const default_target: Option(LinkTarget) = None
/// Slots are used in child elements to insert content into this component
///
pub type Slot {
Icon
// Renders an icon before the items's label.
}
// --- Configuration ---
/// Config is a public record for configuring this component.
///
pub type Config {
Config(
disabled: Disabled,
download: Option(String),
href: String,
rel: String,
target: Option(LinkTarget),
)
}
/// default_config is the default configuration for this component.
///
pub fn default_config() -> Config {
Config(
disabled: IsNotDisabled,
download: None,
href: "",
rel: "",
target: None,
)
}
// --- Constructors ---
/// from_config creates a new FabMenuItem from the given configuration.
///
pub fn from_config(config: Config) -> FabMenuItem {
FabMenuItem(
disabled: config.disabled,
download: config.download,
href: config.href,
rel: config.rel,
target: config.target,
)
}
/// new creates a new FabMenuItem with the default configuration.
///
pub fn new() -> FabMenuItem {
from_config(default_config())
}
// --- Setters ---
/// disabled sets the value of disabled for this FabMenuItem.
///
pub fn disabled(record: FabMenuItem, disabled: Disabled) -> FabMenuItem {
FabMenuItem(..record, disabled: disabled)
}
/// download sets the value of download for this FabMenuItem.
///
pub fn download(record: FabMenuItem, download: Option(String)) -> FabMenuItem {
FabMenuItem(..record, download: download)
}
/// href sets the value of href for this FabMenuItem.
///
pub fn href(record: FabMenuItem, href: String) -> FabMenuItem {
FabMenuItem(..record, href: href)
}
/// rel sets the value of rel for this FabMenuItem.
///
pub fn rel(record: FabMenuItem, rel: String) -> FabMenuItem {
FabMenuItem(..record, rel: rel)
}
/// target sets the value of target for this FabMenuItem.
///
pub fn target(record: FabMenuItem, target: Option(LinkTarget)) -> FabMenuItem {
FabMenuItem(..record, target: target)
}
// --- Renderers ---
/// render creates a Lustre Element for a FabMenuItem
///
pub fn render(
model: FabMenuItem,
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
element.element(
"m3e-menu-item",
list.flatten([
[
attr.boolean("disabled", model.disabled == IsDisabled),
attr.option(
model.download,
fn(_) { "download" },
function.identity,
default_download,
),
attr.with_default("href", model.href, default_href),
attr.with_default("rel", model.rel, default_rel),
attr.option(
model.target,
fn(_) { "target" },
link_target.to_string,
default_target,
),
],
attributes,
])
|> list.filter(fn(a) { a != attribute.none() }),
children,
)
}
/// render_config creates a Lustre Element from a FabMenuItem 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")
}
}