Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A blazing fast type-checked HTML macro crate.

## Features

- Type checking for element names/attributes, including extensible support for custom frameworks like [htmx](https://htmx.org/) and [Alpine.js](https://alpinejs.dev/)
- Type checking for element names/attributes, including extensible support for custom frameworks like [htmx](https://htmx.org/), [Alpine.js](https://alpinejs.dev/), and [DataStar](https://data-star.dev/)
- `#![no_std]` support
- [Extremely fast](https://github.com/askama-rs/template-benchmark#benchmark-results),
using lazy rendering to minimize allocation
Expand Down
1 change: 1 addition & 0 deletions hypertext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ actix-web = ["alloc", "dep:actix-web"]
alloc = ["dep:html-escape", "dep:itoa", "dep:ryu"]
alpine = []
axum = ["alloc", "dep:axum-core"]
datastar = []
default = ["alloc"]
htmx = []
hyperscript = []
Expand Down
99 changes: 99 additions & 0 deletions hypertext/src/validation/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,102 @@ pub trait AlpineJsAttributes: GlobalAttributes {

#[cfg(feature = "alpine")]
impl<T: GlobalAttributes> AlpineJsAttributes for T {}

/// Attributes for use with [DataStar](https://data-star.dev/).
#[cfg(feature = "datastar")]
pub trait DataStarAttributes: GlobalAttributes {
/// Sets the value of any HTML attribute to an expression
const data_attr: AttributeNamespace = AttributeNamespace;

/// Creates a signal and sets up two-way data binding
const data_bind: AttributeNamespace = AttributeNamespace;

/// Adds or removes a class based on an expression
const data_class: AttributeNamespace = AttributeNamespace;

/// Creates a computed signal based on an expression
const data_computed: AttributeNamespace = AttributeNamespace;

/// Executes an expression when any signals in it change
const data_effect: Attribute = Attribute;

/// Tells Datastar to ignore an element and its descendants
const data_ignore: Attribute = Attribute;

/// Tells PatchElements watcher to skip processing an element when morphing
const data_ignore_morph: Attribute = Attribute;

/// Creates a signal that is `true` while a fetch request is in flight
const data_indicator: AttributeNamespace = AttributeNamespace;

/// Runs an expression when the attribute is initialized
const data_init: Attribute = Attribute;

/// Sets text content to a reactive JSON stringified version of signals
const data_json_signals: Attribute = Attribute;

/// Attaches an event listener to an element
const data_on: AttributeNamespace = AttributeNamespace;

/// Runs an expression when the element intersects with the viewport
const data_on_intersect: Attribute = Attribute;

/// Runs an expression at a regular interval
const data_on_interval: Attribute = Attribute;

/// Runs an expression whenever any signals are patched
const data_on_signal_patch: Attribute = Attribute;

/// Filters which signals to watch when using data-on-signal-patch
const data_on_signal_patch_filter: Attribute = Attribute;

/// Preserves the value of an attribute when morphing DOM elements
const data_preserve_attr: Attribute = Attribute;

/// Creates a new signal that is a re ference to the element
const data_ref: AttributeNamespace = AttributeNamespace;

/// Shows or hides an element based on an expression
const data_show: Attribute = Attribute;

/// Patches one or more signals into the existing signals
const data_signals: AttributeNamespace = AttributeNamespace;

/// Sets the value of inline CSS styles based on an expression
const data_style: AttributeNamespace = AttributeNamespace;

/// Binds the text content of an element to an expression
const data_text: Attribute = Attribute;

// Pro Attributes

/// Allows you to animate element attributes over time
const data_animate: AttributeNamespace = AttributeNamespace;

/// Adds custom validity to an element using an expression
const data_custom_validity: Attribute = Attribute;

/// Runs an expression on every requestAnimationFrame event
const data_on_raf: Attribute = Attribute;

/// Runs an expression whenever an element's dimensions change
const data_on_resize: Attribute = Attribute;

/// Persists signals in local storage
const data_persist: AttributeNamespace = AttributeNamespace;

/// Syncs query string params to signal values
const data_query_string: Attribute = Attribute;

/// Replaces the URL in the browser without reloading the page
const data_replace_url: Attribute = Attribute;

/// Scrolls the element into view
const data_scroll_into_view: Attribute = Attribute;

/// Sets the view-transition-name style attribute explicitly
const data_view_transition: Attribute = Attribute;
}

#[cfg(feature = "datastar")]
impl<T: GlobalAttributes> DataStarAttributes for T {}