Current section

Files

Jump to
m3e src m3e textarea_autosize.gleam
Raw

src/m3e/textarea_autosize.gleam

//// TextareaAutosize is a non-visual element used to automatically resize a `textarea` to fit its content.
////
//// This file was generated by m3e/generator
////
//// DO NOT EDIT
////
import gleam/float
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
// --- Types ---
/// TextareaAutosize is a View Model for this component
///
/// ## Fields:
///
/// - disabled: Whether auto-sizing is disabled.
/// - for: The identifier of the interactive control to which this element is attached.
/// - max_rows: The maximum amount of rows in the `textarea`.
/// - min_rows: The minimum amount of rows in the `textarea`.
///
pub opaque type TextareaAutosize {
TextareaAutosize(
disabled: Disabled,
for: Option(String),
max_rows: Float,
min_rows: Float,
)
}
/// Disabled is whether auto-sizing is disabled.
///
pub type Disabled {
IsDisabled
IsNotDisabled
}
// --- Defaults ---
pub const default_disabled: Disabled = IsNotDisabled
pub const default_for: Option(String) = None
pub const default_max_rows: Float = 0.0
pub const default_min_rows: Float = 0.0
// --- Configuration ---
/// Config is a public record for configuring this component.
///
pub type Config {
Config(
disabled: Disabled,
for: Option(String),
max_rows: Float,
min_rows: Float,
)
}
/// default_config is the default configuration for this component.
///
pub fn default_config() -> Config {
Config(disabled: IsNotDisabled, for: None, max_rows: 0.0, min_rows: 0.0)
}
// --- Constructors ---
/// from_config creates a new TextareaAutosize from the given configuration.
///
pub fn from_config(config: Config) -> TextareaAutosize {
TextareaAutosize(
disabled: config.disabled,
for: config.for,
max_rows: config.max_rows,
min_rows: config.min_rows,
)
}
/// new creates a new TextareaAutosize with the default configuration.
///
pub fn new() -> TextareaAutosize {
from_config(default_config())
}
// --- Setters ---
/// disabled sets the value of disabled for this TextareaAutosize.
///
pub fn disabled(
record: TextareaAutosize,
disabled: Disabled,
) -> TextareaAutosize {
TextareaAutosize(..record, disabled: disabled)
}
/// for sets the value of for for this TextareaAutosize.
///
pub fn for(record: TextareaAutosize, for: Option(String)) -> TextareaAutosize {
TextareaAutosize(..record, for: for)
}
/// max_rows sets the value of max_rows for this TextareaAutosize.
///
pub fn max_rows(record: TextareaAutosize, max_rows: Float) -> TextareaAutosize {
TextareaAutosize(..record, max_rows: max_rows)
}
/// min_rows sets the value of min_rows for this TextareaAutosize.
///
pub fn min_rows(record: TextareaAutosize, min_rows: Float) -> TextareaAutosize {
TextareaAutosize(..record, min_rows: min_rows)
}
// --- Renderers ---
/// render creates a Lustre Element for a TextareaAutosize
///
pub fn render(
model: TextareaAutosize,
attributes: List(Attribute(msg)),
) -> Element(msg) {
element.element(
"m3e-textarea-autosize",
list.flatten([
[
attr.boolean("disabled", model.disabled == IsDisabled),
attr.option(model.for, fn(_) { "for" }, function.identity, default_for),
attr.with_default(
"max-rows",
float.to_string(model.max_rows),
float.to_string(default_max_rows),
),
attr.with_default(
"min-rows",
float.to_string(model.min_rows),
float.to_string(default_min_rows),
),
],
attributes,
])
|> list.filter(fn(a) { a != attribute.none() }),
[],
)
}
/// render_config creates a Lustre Element from a TextareaAutosize Config
///
pub fn render_config(
c: Config,
attributes: List(Attribute(msg)),
) -> Element(msg) {
render(from_config(c), attributes)
}