✨ Add new helper trait for components' classes
This commit is contained in:
parent
ed495121dd
commit
04286f1875
18 changed files with 294 additions and 341 deletions
|
|
@ -63,9 +63,8 @@ impl ComponentTrait for Button {
|
|||
}
|
||||
|
||||
fn setup_before_prepare(&mut self, _cx: &mut Context) {
|
||||
self.classes.alter_value(
|
||||
ClassesOp::AddFirst,
|
||||
[self.button_type.to_string(), self.font_size.to_string()].join(" "),
|
||||
self.prepend_classes(
|
||||
[self.button_type().to_string(), self.font_size().to_string()].join(" "),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -93,6 +92,17 @@ impl ComponentTrait for Button {
|
|||
}
|
||||
}
|
||||
|
||||
impl ComponentClasses for Button {
|
||||
fn alter_classes(&mut self, op: ClassesOp, classes: impl Into<String>) -> &mut Self {
|
||||
self.classes.alter_value(op, classes);
|
||||
self
|
||||
}
|
||||
|
||||
fn classes(&self) -> &OptionClasses {
|
||||
&self.classes
|
||||
}
|
||||
}
|
||||
|
||||
impl Button {
|
||||
pub fn link(href: impl Into<String>, html: L10n) -> Self {
|
||||
Button::default()
|
||||
|
|
@ -128,12 +138,6 @@ impl Button {
|
|||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_classes(&mut self, op: ClassesOp, classes: impl Into<String>) -> &mut Self {
|
||||
self.classes.alter_value(op, classes);
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_type(&mut self, button_type: ButtonType) -> &mut Self {
|
||||
self.button_type = button_type;
|
||||
|
|
@ -178,10 +182,6 @@ impl Button {
|
|||
|
||||
// Button GETTERS.
|
||||
|
||||
pub fn classes(&self) -> &OptionClasses {
|
||||
&self.classes
|
||||
}
|
||||
|
||||
pub fn button_type(&self) -> &ButtonType {
|
||||
&self.button_type
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue