pub struct RespoElement<T>{
pub name: Rc<str>,
pub attributes: HashMap<Rc<str>, String>,
pub style: RespoStyle,
pub children: Vec<(RespoIndexKey, RespoNode<T>)>,
/* private fields */
}Expand description
internal abstraction for an element
Fields§
§name: Rc<str>tagName
attributes: HashMap<Rc<str>, String>§style: RespoStyleinlines styles, partially typed.
there’s also a macro called static_styles for inserting CSS rules
children: Vec<(RespoIndexKey, RespoNode<T>)>each child as a key like a string, by default generated from index, they are used in diffing, so it’s better to be distinct, although not required to be.
Implementations§
Source§impl<T> RespoElement<T>
impl<T> RespoElement<T>
pub fn named(name: &str) -> Self
pub fn to_node(self) -> RespoNode<T>
Sourcepub fn style(self, more: RespoStyle) -> Self
pub fn style(self, more: RespoStyle) -> Self
attach styles
element.style(respo_style().margin(10))Sourcepub fn modify_style<U>(self, builder: U) -> Selfwhere
U: Fn(&mut RespoStyle),
pub fn modify_style<U>(self, builder: U) -> Selfwhere
U: Fn(&mut RespoStyle),
imparative way of updating style
element.modify_style(|s| {
if data > 1 {
s.color(CssColor::Red);
}
});Sourcepub fn maybe_attr<U, V>(self, property: U, value: Option<V>) -> Self
pub fn maybe_attr<U, V>(self, property: U, value: Option<V>) -> Self
set an attribute on element, but using None indicates noting
pub fn on_click<U>(self, handler: U) -> Self
pub fn on_input<U>(self, handler: U) -> Self
Sourcepub fn on_keydown<U>(self, handler: U) -> Self
pub fn on_keydown<U>(self, handler: U) -> Self
handle keydown event
Sourcepub fn on_named_event<U>(self, name: &str, handler: U) -> Self
pub fn on_named_event<U>(self, name: &str, handler: U) -> Self
attach a listener by event name(only a small set of events are supported)
Sourcepub fn children<U>(self, more: U) -> Selfwhere
U: IntoIterator<Item = RespoNode<T>>,
pub fn children<U>(self, more: U) -> Selfwhere
U: IntoIterator<Item = RespoNode<T>>,
add children elements, index key are generated from index number
Sourcepub fn children_indexed<U>(self, more: U) -> Self
pub fn children_indexed<U>(self, more: U) -> Self
add children elements, with index keys specified
Sourcepub fn elements<U>(self, mode: U) -> Selfwhere
U: IntoIterator<Item = RespoElement<T>>,
pub fn elements<U>(self, mode: U) -> Selfwhere
U: IntoIterator<Item = RespoElement<T>>,
add elements. if any component is involved, use self.children([]) instead
Sourcepub fn maybe_class<U>(self, name: Option<U>) -> Self
pub fn maybe_class<U>(self, name: Option<U>) -> Self
attach an optional class name for adding styles
Sourcepub fn toggle_class<U>(self, name: U, on: bool) -> Self
pub fn toggle_class<U>(self, name: U, on: bool) -> Self
attach a class name, controlled by a boolean
Sourcepub fn class_list<U>(self, names: &[U]) -> Self
pub fn class_list<U>(self, names: &[U]) -> Self
attach a list of class names for adding styles
Sourcepub fn inner_text<U>(self, content: U) -> Self
pub fn inner_text<U>(self, content: U) -> Self
writes innerText
Sourcepub fn inner_html<U>(self, content: U) -> Self
pub fn inner_html<U>(self, content: U) -> Self
writes innerHTML
Trait Implementations§
Source§impl<T> Clone for RespoElement<T>
impl<T> Clone for RespoElement<T>
Source§fn clone(&self) -> RespoElement<T>
fn clone(&self) -> RespoElement<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more