Current section

Files

Jump to
m3e src m3e linear_progress_indicator.gleam
Raw

src/m3e/linear_progress_indicator.gleam

//// LinearProgressIndicator is a horizontal bar for indicating progress and activity.
////
//// This file was generated by m3e/generator
////
//// DO NOT EDIT
////
import gleam/float
import gleam/list
import lustre/attribute.{type Attribute}
import lustre/element.{type Element}
import m3e/attr
import m3e/linear_progress_mode.{type LinearProgressMode}
import m3e/progress_indicator_variant.{type ProgressIndicatorVariant}
// --- Types ---
/// LinearProgressIndicator is a View Model for this component
///
/// ## Fields:
///
/// - buffer_value: A fractional value, between 0 and `max`, indicating buffer progress.
/// - max: The maximum progress value.
/// - mode: The mode of the progress bar.
/// - value: A fractional value, between 0 and `max`, indicating progress.
/// - variant: The appearance of the indicator.
///
pub opaque type LinearProgressIndicator {
LinearProgressIndicator(
buffer_value: Float,
max: Float,
mode: LinearProgressMode,
value: Float,
variant: ProgressIndicatorVariant,
)
}
// --- Defaults ---
pub const default_buffer_value: Float = 0.0
pub const default_max: Float = 100.0
pub const default_mode: LinearProgressMode = linear_progress_mode.Determinate
pub const default_value: Float = 0.0
pub const default_variant: ProgressIndicatorVariant = progress_indicator_variant.Flat
// --- Configuration ---
/// Config is a public record for configuring this component.
///
pub type Config {
Config(
buffer_value: Float,
max: Float,
mode: LinearProgressMode,
value: Float,
variant: ProgressIndicatorVariant,
)
}
/// default_config is the default configuration for this component.
///
pub fn default_config() -> Config {
Config(
buffer_value: 0.0,
max: 100.0,
mode: linear_progress_mode.Determinate,
value: 0.0,
variant: progress_indicator_variant.Flat,
)
}
// --- Constructors ---
/// from_config creates a new LinearProgressIndicator from the given configuration.
///
pub fn from_config(config: Config) -> LinearProgressIndicator {
LinearProgressIndicator(
buffer_value: config.buffer_value,
max: config.max,
mode: config.mode,
value: config.value,
variant: config.variant,
)
}
/// new creates a new LinearProgressIndicator with the default configuration.
///
pub fn new() -> LinearProgressIndicator {
from_config(default_config())
}
// --- Setters ---
/// buffer_value sets the value of buffer_value for this LinearProgressIndicator.
///
pub fn buffer_value(
record: LinearProgressIndicator,
buffer_value: Float,
) -> LinearProgressIndicator {
LinearProgressIndicator(..record, buffer_value: buffer_value)
}
/// max sets the value of max for this LinearProgressIndicator.
///
pub fn max(
record: LinearProgressIndicator,
max: Float,
) -> LinearProgressIndicator {
LinearProgressIndicator(..record, max: max)
}
/// mode sets the value of mode for this LinearProgressIndicator.
///
pub fn mode(
record: LinearProgressIndicator,
mode: LinearProgressMode,
) -> LinearProgressIndicator {
LinearProgressIndicator(..record, mode: mode)
}
/// value sets the value of value for this LinearProgressIndicator.
///
pub fn value(
record: LinearProgressIndicator,
value: Float,
) -> LinearProgressIndicator {
LinearProgressIndicator(..record, value: value)
}
/// variant sets the value of variant for this LinearProgressIndicator.
///
pub fn variant(
record: LinearProgressIndicator,
variant: ProgressIndicatorVariant,
) -> LinearProgressIndicator {
LinearProgressIndicator(..record, variant: variant)
}
// --- Renderers ---
/// render creates a Lustre Element for a LinearProgressIndicator
///
pub fn render(
model: LinearProgressIndicator,
attributes: List(Attribute(msg)),
) -> Element(msg) {
element.element(
"m3e-linear-progress-indicator",
list.flatten([
[
attr.with_default(
"buffer-value",
float.to_string(model.buffer_value),
float.to_string(default_buffer_value),
),
attr.with_default(
"max",
float.to_string(model.max),
float.to_string(default_max),
),
attr.with_default(
"mode",
linear_progress_mode.to_string(model.mode),
linear_progress_mode.to_string(default_mode),
),
attr.with_default(
"value",
float.to_string(model.value),
float.to_string(default_value),
),
attr.with_default(
"variant",
progress_indicator_variant.to_string(model.variant),
progress_indicator_variant.to_string(default_variant),
),
],
attributes,
])
|> list.filter(fn(a) { a != attribute.none() }),
[],
)
}
/// render_config creates a Lustre Element from a LinearProgressIndicator Config
///
pub fn render_config(
c: Config,
attributes: List(Attribute(msg)),
) -> Element(msg) {
render(from_config(c), attributes)
}