update
This commit is contained in:
parent
b1c6ab8b7d
commit
f7668c5c54
3 changed files with 26 additions and 6 deletions
|
@ -86,9 +86,15 @@ pub async fn render_page(
|
||||||
pub trait UIWidget: Render {
|
pub trait UIWidget: Render {
|
||||||
/// Indicating if the widget supports inheriting classes
|
/// Indicating if the widget supports inheriting classes
|
||||||
fn can_inherit(&self) -> bool;
|
fn can_inherit(&self) -> bool;
|
||||||
|
|
||||||
/// Returning the base classes for this widget
|
/// Returning the base classes for this widget
|
||||||
|
///
|
||||||
|
/// Base here means all classes defining the current widget
|
||||||
fn base_class(&self) -> Vec<String>;
|
fn base_class(&self) -> Vec<String>;
|
||||||
|
|
||||||
|
/// Return own base classes and all classes below the tree
|
||||||
fn extended_class(&self) -> Vec<String>;
|
fn extended_class(&self) -> Vec<String>;
|
||||||
|
|
||||||
/// Render the widget with additional classes
|
/// Render the widget with additional classes
|
||||||
fn render_with_class(&self, class: &str) -> Markup;
|
fn render_with_class(&self, class: &str) -> Markup;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,16 @@ impl Render for DivWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl DivWidget {
|
||||||
|
pub fn extended_class_(&self) -> Vec<String> {
|
||||||
|
let mut c = self.base_class();
|
||||||
|
for e in &self.0 {
|
||||||
|
c.extend_from_slice(&e.extended_class());
|
||||||
|
}
|
||||||
|
c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl UIWidget for DivWidget {
|
impl UIWidget for DivWidget {
|
||||||
fn can_inherit(&self) -> bool {
|
fn can_inherit(&self) -> bool {
|
||||||
false
|
false
|
||||||
|
@ -81,11 +91,11 @@ impl UIWidget for DivWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extended_class(&self) -> Vec<String> {
|
fn extended_class(&self) -> Vec<String> {
|
||||||
let mut c = self.base_class();
|
if self.1 {
|
||||||
for e in &self.0 {
|
self.extended_class_()
|
||||||
c.extend_from_slice(&e.extended_class());
|
} else {
|
||||||
|
vec![]
|
||||||
}
|
}
|
||||||
c
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_with_class(&self, _: &str) -> Markup {
|
fn render_with_class(&self, _: &str) -> Markup {
|
||||||
|
@ -104,7 +114,11 @@ impl UIWidget for DivWidget {
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join(" ");
|
.join(" ");
|
||||||
|
|
||||||
PreEscaped(format!("<div {attrs}> {} </a>", inner.0))
|
PreEscaped(format!(
|
||||||
|
"<div class='{}' {attrs}> {} </a>",
|
||||||
|
self.extended_class_().join(" "),
|
||||||
|
inner.0
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ impl HTMXAttributes for LinkWidget {}
|
||||||
|
|
||||||
impl Render for LinkWidget {
|
impl Render for LinkWidget {
|
||||||
fn render(&self) -> Markup {
|
fn render(&self) -> Markup {
|
||||||
self.render_with_class("")
|
self.render_with_class(&self.extended_class().join(" "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue