Current section

Files

Jump to
m3e src m3e search_bar.gleam
Raw

src/m3e/search_bar.gleam

//// SearchBar is a bar that provides a prominent entry point for search.
////
//// 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 ---
/// SearchBar is a View Model for this component
///
/// ## Fields:
///
/// - clearable: Whether the bar presents a button used to clear the search term.
/// - clear_label: The accessible label given to the button used to clear the search term.
///
pub opaque type SearchBar {
SearchBar(clearable: Clearable, clear_label: String)
}
/// Clearable is whether the bar presents a button used to clear the search term.
///
pub type Clearable {
IsClearable
IsNotClearable
}
// --- Defaults ---
pub const default_clearable: Clearable = IsNotClearable
pub const default_clear_label: String = "Clear"
/// Slots are used in child elements to insert content into this component
///
pub type Slot {
Leading
// Renders content before the input of the bar.
Input
// Renders the input of the bar.
Trailing
// Renders content after the input of the bar.
}
// --- Configuration ---
/// Config is a public record for configuring this component.
///
pub type Config {
Config(clearable: Clearable, clear_label: String)
}
/// default_config is the default configuration for this component.
///
pub fn default_config() -> Config {
Config(clearable: IsNotClearable, clear_label: "Clear")
}
// --- Constructors ---
/// from_config creates a new SearchBar from the given configuration.
///
pub fn from_config(config: Config) -> SearchBar {
SearchBar(clearable: config.clearable, clear_label: config.clear_label)
}
/// new creates a new SearchBar with the default configuration.
///
pub fn new() -> SearchBar {
from_config(default_config())
}
// --- Setters ---
/// clearable sets the value of clearable for this SearchBar.
///
pub fn clearable(record: SearchBar, clearable: Clearable) -> SearchBar {
SearchBar(..record, clearable: clearable)
}
/// clear_label sets the value of clear_label for this SearchBar.
///
pub fn clear_label(record: SearchBar, clear_label: String) -> SearchBar {
SearchBar(..record, clear_label: clear_label)
}
// --- Renderers ---
/// render creates a Lustre Element for a SearchBar
///
pub fn render(
model: SearchBar,
attributes: List(Attribute(msg)),
children: List(Element(msg)),
) -> Element(msg) {
element.element(
"m3e-search-bar",
list.flatten([
[
attr.boolean("clearable", model.clearable == IsClearable),
attr.with_default("clear-label", model.clear_label, default_clear_label),
],
attributes,
])
|> list.filter(fn(a) { a != attribute.none() }),
children,
)
}
/// render_config creates a Lustre Element from a SearchBar 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 {
Leading -> attribute.attribute("slot", "leading")
Input -> attribute.attribute("slot", "input")
Trailing -> attribute.attribute("slot", "trailing")
}
}