feat(style): compose generated class states
Add CssClass/CssClasses with/with_if helpers so nested partial view data can compose generated CSS constants without ad hoc class strings. req: style/003 req: component/003
This commit is contained in:
@@ -186,6 +186,14 @@ impl CssClass {
|
||||
pub const fn as_str(self) -> &'static str {
|
||||
self.name
|
||||
}
|
||||
|
||||
pub fn with(self, class: CssClass) -> CssClasses {
|
||||
CssClasses::from([self, class])
|
||||
}
|
||||
|
||||
pub fn with_if(self, condition: bool, class: CssClass) -> CssClasses {
|
||||
CssClasses::from(self).with_if(condition, class)
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<str> for CssClass {
|
||||
@@ -315,6 +323,22 @@ impl CssClasses {
|
||||
pub fn as_str(&self) -> &str {
|
||||
&self.names
|
||||
}
|
||||
|
||||
pub fn with(mut self, class: CssClass) -> Self {
|
||||
if !self.names.is_empty() {
|
||||
self.names.push(' ');
|
||||
}
|
||||
self.names.push_str(class.as_str());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_if(self, condition: bool, class: CssClass) -> Self {
|
||||
if condition {
|
||||
self.with(class)
|
||||
} else {
|
||||
self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<CssClass> for CssClasses {
|
||||
|
||||
Reference in New Issue
Block a user