pub enum AttributeValue {
Text(String),
Signal(Signal<String>),
Event(NativeEventHandler),
Dynamic(String),
Css(Css),
}Expand description
Represents the value of an HTML attribute.
Attributes can be static text, reactive signals, event handlers, dynamic expressions, or CSS class references.
Variants§
Text(String)
A static string value.
Signal(Signal<String>)
A dynamic signal-backed value.
Event(NativeEventHandler)
An event handler callback.
Dynamic(String)
A dynamic expression value of any type (for component props).
Css(Css)
A CSS class reference created by the class! macro.
Implementations§
Source§impl AttributeValue
Implementation of attribute value factory methods for reactive and merged values.
impl AttributeValue
Implementation of attribute value factory methods for reactive and merged values.
Sourcepub fn reactive<F>(compute: F) -> Self
pub fn reactive<F>(compute: F) -> Self
Creates a reactive attribute Self for conditional attribute values.
This function replaces the inline Signal::create(...) + subscribe_attr(...)
boilerplate that was previously generated by the html! macro for every
attribute value containing an if condition.
§Arguments
Fn() -> String + 'static- A closure that computes the current attribute value. Called on initial render and whenever any signal changes.
§Returns
Self- ASelf::Signalbacked by aSignal<String>that reactively re-evaluates the attribute value on signal updates.
Sourcepub fn merge_class(values: &[Self]) -> Self
pub fn merge_class(values: &[Self]) -> Self
Merges multiple class attribute values into a single Self.
Each input value is adapted into a Self via IntoReactiveValue.
Css values are injected into the DOM and their names are collected.
All non-empty class names are joined with spaces into a final Text attribute.
If any value is signal-backed, the result becomes a reactive Signal attribute
that re-evaluates when any constituent signal changes.
§Arguments
&[Self]- The class attribute values to merge.
§Returns
Self- A merged attribute value containing space-separated class names.
Sourcepub fn merge_style(values: &[Self]) -> Self
pub fn merge_style(values: &[Self]) -> Self
Merges multiple style attribute values into a single Self.
Each input value is expected to be a style string (Text) or a reactive
Signal<String> producing a style string. All non-empty style strings are
joined with spaces into a final combined style attribute.
If any value is signal-backed, the result becomes a reactive Signal attribute.
§Arguments
&[Self]- The style attribute values to merge.
§Returns
Self- A merged attribute value containing the combined CSS style string.
Trait Implementations§
Source§impl Clone for AttributeValue
impl Clone for AttributeValue
Source§fn clone(&self) -> AttributeValue
fn clone(&self) -> AttributeValue
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AttributeValue
impl Debug for AttributeValue
Source§impl From<&'static Css> for AttributeValue
Converts a reference to a CSS class into an attribute value by cloning.
impl From<&'static Css> for AttributeValue
Converts a reference to a CSS class into an attribute value by cloning.
Source§impl From<&str> for AttributeValue
Converts a string slice into a text attribute value.
impl From<&str> for AttributeValue
Converts a string slice into a text attribute value.
Source§impl<T> From<AttrValueAdapter<T>> for AttributeValuewhere
T: Into<AttributeValue>,
Adapts any type that implements Into<AttributeValue> into an AttributeValue.
impl<T> From<AttrValueAdapter<T>> for AttributeValuewhere
T: Into<AttributeValue>,
Adapts any type that implements Into<AttributeValue> into an AttributeValue.
This is the fallback path for non-closure attribute values (strings, signals, CSS classes, etc.).
Source§fn from(adapter: AttrValueAdapter<T>) -> Self
fn from(adapter: AttrValueAdapter<T>) -> Self
Converts the wrapped value into an AttributeValue.
§Returns
AttributeValue- The reactive attribute value.
Source§impl<F> From<CallbackNamedAdapter<F>> for AttributeValue
Converts a named callback adapter into an AttributeValue.
impl<F> From<CallbackNamedAdapter<F>> for AttributeValue
Converts a named callback adapter into an AttributeValue.
Source§fn from(adapter: CallbackNamedAdapter<F>) -> Self
fn from(adapter: CallbackNamedAdapter<F>) -> Self
Converts the wrapped closure with custom name into a callback AttributeValue.
§Returns
AttributeValue- An event attribute value with the custom name.
Source§impl From<Css> for AttributeValue
Converts a CSS class reference into an attribute value.
impl From<Css> for AttributeValue
Converts a CSS class reference into an attribute value.
Source§impl<F> From<EventNamedAdapter<F>> for AttributeValue
Converts an event with a specific event name into an AttributeValue.
impl<F> From<EventNamedAdapter<F>> for AttributeValue
Converts an event with a specific event name into an AttributeValue.
Source§fn from(adapter: EventNamedAdapter<F>) -> Self
fn from(adapter: EventNamedAdapter<F>) -> Self
Converts the wrapped closure with event name into an event AttributeValue.
§Returns
AttributeValue- AnAttributeValue::Eventwrapping the handler.
Source§impl From<EventNamedAdapter<NativeEventHandler>> for AttributeValue
Converts an event named adapter with NativeEventHandler into an AttributeValue.
impl From<EventNamedAdapter<NativeEventHandler>> for AttributeValue
Converts an event named adapter with NativeEventHandler into an AttributeValue.
Source§fn from(adapter: EventNamedAdapter<NativeEventHandler>) -> Self
fn from(adapter: EventNamedAdapter<NativeEventHandler>) -> Self
Converts the wrapped handler with event name into an event AttributeValue.
§Returns
AttributeValue- AnAttributeValue::Eventwrapping the handler.
Source§impl From<EventNamedAdapter<Option<Rc<dyn Fn(Event)>>>> for AttributeValue
Converts an event named adapter with optional shared closure into an AttributeValue.
impl From<EventNamedAdapter<Option<Rc<dyn Fn(Event)>>>> for AttributeValue
Converts an event named adapter with optional shared closure into an AttributeValue.
Some(callback) becomes AttributeValue::Event by wrapping the shared closure
into a NativeEventHandler with the adapter’s event name, and None becomes
AttributeValue::Text(String::new()).
Source§impl<F> From<F> for AttributeValue
Converts a closure into a callback attribute value.
impl<F> From<F> for AttributeValue
Converts a closure into a callback attribute value.
Source§impl From<NativeEventHandler> for AttributeValue
Converts an owned event handler into a callback attribute value.
impl From<NativeEventHandler> for AttributeValue
Converts an owned event handler into a callback attribute value.
Re-wraps the handler with a generic “callback” event name so that
subsequent EventAdapter::into_attribute calls can override it with
the correct DOM event type.
Source§fn from(handler: NativeEventHandler) -> Self
fn from(handler: NativeEventHandler) -> Self
Converts this event handler into an AttributeValue::Event.
§Returns
AttributeValue- An event attribute value with a generic callback event name.
Source§impl From<Option<NativeEventHandler>> for AttributeValue
Converts an optional event handler into a callback attribute value.
impl From<Option<NativeEventHandler>> for AttributeValue
Converts an optional event handler into a callback attribute value.
Re-wraps a Some handler with a generic “callback” event name so that
subsequent EventAdapter::into_attribute calls can override it with
the correct DOM event type.
Source§impl From<Option<Signal<String>>> for AttributeValue
Converts an optional string signal into a reactive or empty attribute value.
impl From<Option<Signal<String>>> for AttributeValue
Converts an optional string signal into a reactive or empty attribute value.
Some(signal) becomes AttributeValue::Signal, None becomes
AttributeValue::Text(String::new()). This supports component props
that use Option<Signal<String>> for optional reactive attributes.
Source§impl From<Signal<String>> for AttributeValue
Converts a string signal into a reactive attribute value.
impl From<Signal<String>> for AttributeValue
Converts a string signal into a reactive attribute value.
Source§impl From<Signal<bool>> for AttributeValue
Converts a mutable bool signal into a reactive attribute value.
impl From<Signal<bool>> for AttributeValue
Converts a mutable bool signal into a reactive attribute value.
The signal is mapped to a Signal<String> that yields "true" or "false",
enabling boolean attributes like checked to reactively update the DOM.
Source§impl From<String> for AttributeValue
Converts a static String into a text attribute value.
impl From<String> for AttributeValue
Converts a static String into a text attribute value.
Source§impl From<bool> for AttributeValue
Converts a bool into a dynamic attribute value.
impl From<bool> for AttributeValue
Converts a bool into a dynamic attribute value.
Stored as AttributeValue::Dynamic("true"/"false") so components can
extract the original boolean via try_get_typed_prop.
Source§impl From<f64> for AttributeValue
Converts an f64 into a dynamic attribute value.
impl From<f64> for AttributeValue
Converts an f64 into a dynamic attribute value.
Stored as AttributeValue::Dynamic so components can extract the
original float via try_get_typed_prop.
Source§impl From<i32> for AttributeValue
Converts an i32 into a dynamic attribute value.
impl From<i32> for AttributeValue
Converts an i32 into a dynamic attribute value.
Stored as AttributeValue::Dynamic so components can extract the
original integer via try_get_typed_prop.
Source§impl PartialEq for AttributeValue
Visual equality comparison for attribute values.
impl PartialEq for AttributeValue
Visual equality comparison for attribute values.
Compares values by their visual output rather than identity. Signal
values are compared by their current resolved string; when both signals
share the same inner pointer, they are always considered unequal
because the signal may have mutated between VDOM snapshots and .get()
would return the same current value for both, masking the change.
Event values are always considered equal (re-binding is handled by the
handler registry), and Css values are compared by class name.