💄 Define context styles for base components

This commit is contained in:
Manuel Cillero 2024-03-03 20:23:58 +01:00
parent e2090b2c81
commit c54390d3d9
5 changed files with 303 additions and 289 deletions

View file

@ -17,7 +17,7 @@ pub struct Button {
weight : Weight,
renderable : Renderable,
classes : OptionClasses,
style : ButtonStyle,
style : StyleBase,
font_size : FontSize,
left_icon : OptionComponent<Icon>,
right_icon : OptionComponent<Icon>,
@ -44,7 +44,14 @@ impl ComponentTrait for Button {
}
fn setup_before_prepare(&mut self, _cx: &mut Context) {
self.prepend_classes([self.style().to_string(), self.font_size().to_string()].join(" "));
self.prepend_classes(
[
"button__tap".to_string(),
self.style().to_string(),
self.font_size().to_string(),
]
.join(" "),
);
}
#[rustfmt::skip]
@ -64,7 +71,7 @@ impl ComponentTrait for Button {
target=[target]
{
(self.left_icon().render(cx))
" " span { (self.html().escaped(cx.langid())) } " "
span { (self.html().escaped(cx.langid())) }
(self.right_icon().render(cx))
}
})
@ -97,7 +104,7 @@ impl Button {
}
#[fn_builder]
pub fn alter_style(&mut self, style: ButtonStyle) -> &mut Self {
pub fn alter_style(&mut self, style: StyleBase) -> &mut Self {
self.style = style;
self
}
@ -140,7 +147,7 @@ impl Button {
// Button GETTERS.
pub fn style(&self) -> &ButtonStyle {
pub fn style(&self) -> &StyleBase {
&self.style
}

View file

@ -24,7 +24,7 @@ pub struct ActionButton {
renderable : Renderable,
classes : OptionClasses,
button_type: ActionButtonType,
style : ButtonStyle,
style : StyleBase,
font_size : FontSize,
left_icon : OptionComponent<Icon>,
right_icon : OptionComponent<Icon>,
@ -48,7 +48,14 @@ impl ComponentTrait for ActionButton {
}
fn setup_before_prepare(&mut self, _cx: &mut Context) {
self.prepend_classes([self.style().to_string(), self.font_size().to_string()].join(" "));
self.prepend_classes(
[
"button__tap".to_string(),
self.style().to_string(),
self.font_size().to_string(),
]
.join(" "),
);
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
@ -64,7 +71,7 @@ impl ComponentTrait for ActionButton {
disabled=[self.disabled().get()]
{
(self.left_icon().render(cx))
" " (self.value().escaped(cx.langid())) " "
span { (self.value().escaped(cx.langid())) }
(self.right_icon().render(cx))
}
})
@ -75,7 +82,7 @@ impl ActionButton {
pub fn submit() -> Self {
ActionButton {
button_type: ActionButtonType::Submit,
style: ButtonStyle::Default,
style: StyleBase::Default,
value: OptionTranslated::new(L10n::l("button_submit")),
..Default::default()
}
@ -84,7 +91,7 @@ impl ActionButton {
pub fn reset() -> Self {
ActionButton {
button_type: ActionButtonType::Reset,
style: ButtonStyle::Info,
style: StyleBase::Info,
value: OptionTranslated::new(L10n::l("button_reset")),
..Default::default()
}
@ -105,7 +112,7 @@ impl ActionButton {
}
#[fn_builder]
pub fn alter_style(&mut self, style: ButtonStyle) -> &mut Self {
pub fn alter_style(&mut self, style: StyleBase) -> &mut Self {
self.style = style;
self
}
@ -164,7 +171,7 @@ impl ActionButton {
&self.button_type
}
pub fn style(&self) -> &ButtonStyle {
pub fn style(&self) -> &StyleBase {
&self.style
}