Skip to main content

euv_core/vdom/attribute/
trait.rs

1use crate::*;
2
3/// Trait for types that can be converted into a reactive string value.
4///
5/// This allows both static strings and signals to be used interchangeably
6/// in HTML attributes.
7pub trait IntoReactiveValue {
8    /// Converts this value into an `AttributeValue`, wrapping signals
9    /// for reactive updates or converting static values to text.
10    fn into_reactive_value(self) -> AttributeValue;
11}
12
13/// Trait for converting a value into a string for reactive attribute updates.
14///
15/// Used by the `html!` macro when an attribute value contains an `if` condition.
16/// The result is stored in a `Signal<String>` that re-evaluates whenever any
17/// signal changes — mirroring the DOM-level `DynamicNode` mechanism.
18///
19/// Implementations are provided for `String`, `&str`, `CssClass`, `bool`,
20/// numeric types, and `Signal<T>` (which resolves the signal first).
21pub trait IntoReactiveString {
22    /// Converts this value into its string representation for attribute storage.
23    fn into_reactive_string(self) -> String;
24}
25
26/// Trait for types that can be converted into a callback attribute value.
27///
28/// This allows closures to be passed as custom component props.
29pub trait IntoCallbackAttribute {
30    /// Converts this value into an `AttributeValue`, wrapping the callback
31    /// for use as a component prop.
32    fn into_callback_attribute(self) -> AttributeValue;
33}