datastar/ds_lustre
This module provides functions to add Datastar data attributes to html elements as shown here https://data-star.dev/reference/attributes
Functions
pub fn data_attr(key: String, expression: String) -> Attribute(a)
Sets the value of any HTML attribute to an expression, and keeps it in sync.
See https://data-star.dev/reference/attributes#data-attr.
e.g.
div([ds_lustre.data_attr("title", "$foo")], [])
<div data-attr-title="$foo"></div>
pub fn data_attrs(pairs: List(#(String, String))) -> Attribute(a)
Similar to data_attr but sets multiple attrs at once.
See https://data-star.dev/reference/attributes#data-attr
e.g.
<div data-attr="{title: $foo, disabled: $bar}"></div>
pub fn data_bind(value: String) -> Attribute(a)
Creates a signal and sets up two-way data binding. This takes the name of a signal (without the $).
See https://data-star.dev/reference/attributes#data-bind
ds_lustre.data_bind("first_name")
<input data-bind="first_name" />
pub fn data_class(
key: String,
expression: String,
) -> Attribute(a)
Adds or removes a class.
See https://data-star.dev/reference/attributes#data-class
The first value is the class name.
The second value is an expression. e.g. a signal $selected or a complex expression
pub fn data_classes(
pairs: List(#(String, String)),
) -> Attribute(a)
Control multiple classes at once
pub fn data_computed(key: String, value: String) -> Attribute(a)
Creates a signal that is computed based on an expression.
See https://data-star.dev/reference/attributes#data-computed
pub fn data_indicator(signal: String) -> Attribute(a)
pub fn data_on(event: String, expression: String) -> Attribute(a)
Attaches an event listener to an element.
pub fn data_on_click(expression: String) -> Attribute(a)
Shorcut for data_on("click", _).
pub fn data_on_submit(expression: String) -> Attribute(a)
Shorcut for data_on("submit", _).
This prevents the default submission behavior of forms.
pub fn data_ref(value: String) -> Attribute(a)
Creates a signal that is a reference to this DOM element.
pub fn data_show(value: String) -> Attribute(a)
Show or hides an element based on an expression.
pub fn data_signal(signal: String, value: String) -> Attribute(a)
Patches one signals into the existing signals.
pub fn data_signals(
signals: List(#(String, Json)),
) -> Attribute(a)
Merges one or more signals into the existing signals.
pub fn data_text(value: String) -> Attribute(a)
Binds the text content of an element to an expression.
See https://data-star.dev/reference/attributes#data-text
e.g.
<div data-text="$foo"></div>