datastar/ds_lustre
This module provides functions to add Datastar data attributes to html elements as shown here https://data-star.dev/reference/attribute_plugins
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/attribute_plugins#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.
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 $).
ds_lustre.data_bind("first_name")
<input data-bind="first_name" />
See https://data-star.dev/reference/attribute_plugins#data-bind
pub fn data_class(
key: String,
expression: String,
) -> Attribute(a)
Adds or removes a class.
The first value is the class name.
The second value is an expression. e.g. a signal $selected or a complex expression
See https://data-star.dev/reference/attribute_plugins#data-class
pub fn data_classes(
pairs: List(#(String, String)),
) -> Attribute(a)
Control multiple classes at once
See https://data-star.dev/reference/attribute_plugins#data-class
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/attribute_plugins#data-computed
pub fn data_custom_validity(expression: String) -> Attribute(a)
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.
See https://data-star.dev/reference/attribute_plugins#data-on
pub fn data_on_click(expression: String) -> Attribute(a)
Shorcut for data_on("click", _)
.
pub fn data_on_load(expression: String) -> Attribute(a)
Runs an expression when the element is loaded into the DOM.
See https://data-star.dev/reference/attribute_plugins#data-on-load
pub fn data_on_raf(expression: String) -> Attribute(a)
Runs an expression on every requestAnimationFrame event.
See https://data-star.dev/reference/attribute_plugins#data-on-raf
pub fn data_on_signal_change(expression: String) -> Attribute(a)
Runs an expression whenever a signal changes.
See https://data-star.dev/reference/attribute_plugins#data-on-signal-change
pub fn data_on_specific_signal_change(
signal: String,
expression: String,
) -> Attribute(a)
Runs an expression whenever a signal changes.
See https://data-star.dev/reference/attribute_plugins#data-on-signal-change
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_persist(signals: String) -> Attribute(a)
Persists signals in local storage
e.g.
<div data-persist></div>
See https://data-star.dev/reference/attribute_plugins#data-persist
pub fn data_ref(value: String) -> Attribute(a)
Creates a signal that is a reference to this DOM element.
See https://data-star.dev/reference/attribute_plugins#data-ref
pub fn data_replace_url(value: String) -> Attribute(a)
pub fn data_scroll_into_view() -> Attribute(a)
pub fn data_show(value: String) -> Attribute(a)
Show or hides an element based on an expression.
See https://data-star.dev/reference/attribute_plugins#data-show
pub fn data_signal(signal: String, value: String) -> Attribute(a)
Merges one signals into the existing signals.
See https://data-star.dev/reference/attribute_plugins#data-signals
pub fn data_signals(
signals: List(#(String, Json)),
) -> Attribute(a)
Merges one or more signals into the existing signals.
See https://data-star.dev/reference/attribute_plugins#data-signals
pub fn data_star_ignore() -> Attribute(a)
pub fn data_text(value: String) -> Attribute(a)
Binds the text content of an element to an expression.
e.g.
<div data-text="$foo"></div>
See https://data-star.dev/reference/attribute_plugins#data-text
pub fn data_view_transition(value: String) -> Attribute(a)