🚧 Working on actions
This commit is contained in:
parent
e732244a2e
commit
d99a5aa586
23 changed files with 480 additions and 323 deletions
|
|
@ -9,6 +9,16 @@ impl PackageTrait for Bulmix {
|
|||
Some(&Bulmix)
|
||||
}
|
||||
|
||||
fn actions(&self) -> Vec<ActionBox> {
|
||||
actions![
|
||||
action::theme::BeforePrepare::<Icon>::new(&Self, before_prepare_icon),
|
||||
action::theme::BeforePrepare::<Button>::new(&Self, before_prepare_button),
|
||||
action::theme::BeforePrepare::<Heading>::new(&Self, before_prepare_heading),
|
||||
action::theme::BeforePrepare::<Paragraph>::new(&Self, before_prepare_paragraph),
|
||||
action::theme::RenderComponent::<Icon>::new(&Self, render_icon),
|
||||
]
|
||||
}
|
||||
|
||||
fn configure_service(&self, scfg: &mut service::web::ServiceConfig) {
|
||||
service_for_static_files!(scfg, bulmix => "/bulmix");
|
||||
}
|
||||
|
|
@ -38,63 +48,60 @@ impl ThemeTrait for Bulmix {
|
|||
StyleSheet::at("/bulmix/css/styles.css").with_version("0.0.1"),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn before_prepare_component(&self, component: &mut dyn ComponentTrait, _cx: &mut Context) {
|
||||
if let Some(i) = component.downcast_mut::<Icon>() {
|
||||
i.alter_classes(
|
||||
ClassesOp::Replace(i.font_size().to_string()),
|
||||
with_font(i.font_size()),
|
||||
);
|
||||
} else if let Some(b) = component.downcast_mut::<Button>() {
|
||||
b.alter_classes(ClassesOp::Replace("button__tap".to_owned()), "button");
|
||||
b.alter_classes(
|
||||
ClassesOp::Replace(b.style().to_string()),
|
||||
match b.style() {
|
||||
StyleBase::Default => "is-primary",
|
||||
StyleBase::Info => "is-info",
|
||||
StyleBase::Success => "is-success",
|
||||
StyleBase::Warning => "is-warning",
|
||||
StyleBase::Danger => "is-danger",
|
||||
StyleBase::Light => "is-light",
|
||||
StyleBase::Dark => "is-dark",
|
||||
StyleBase::Link => "is-text",
|
||||
},
|
||||
);
|
||||
b.alter_classes(
|
||||
ClassesOp::Replace(b.font_size().to_string()),
|
||||
with_font(b.font_size()),
|
||||
);
|
||||
} else if let Some(h) = component.downcast_mut::<Heading>() {
|
||||
match h.size() {
|
||||
HeadingSize::Subtitle => {
|
||||
h.alter_classes(ClassesOp::Replace(h.size().to_string()), "subtitle")
|
||||
}
|
||||
_ => h.alter_classes(ClassesOp::Add, "title"),
|
||||
};
|
||||
} else if let Some(p) = component.downcast_mut::<Paragraph>() {
|
||||
p.alter_classes(ClassesOp::Add, "block");
|
||||
p.alter_classes(
|
||||
ClassesOp::Replace(p.font_size().to_string()),
|
||||
with_font(p.font_size()),
|
||||
);
|
||||
}
|
||||
}
|
||||
fn before_prepare_icon(i: &mut Icon, _cx: &mut Context) {
|
||||
i.alter_classes(
|
||||
ClassesOp::Replace(i.font_size().to_string()),
|
||||
with_font(i.font_size()),
|
||||
);
|
||||
}
|
||||
|
||||
fn render_component(
|
||||
&self,
|
||||
component: &dyn ComponentTrait,
|
||||
_cx: &mut Context,
|
||||
) -> Option<Markup> {
|
||||
if let Some(i) = component.downcast_ref::<Icon>() {
|
||||
return match i.icon_name().get() {
|
||||
None => None,
|
||||
_ => Some(html! { span class="icon" { i class=[i.classes().get()] {} } }),
|
||||
};
|
||||
} else {
|
||||
None
|
||||
#[rustfmt::skip]
|
||||
fn before_prepare_button(b: &mut Button, _cx: &mut Context) {
|
||||
b.alter_classes(ClassesOp::Replace("button__tap".to_owned()), "button");
|
||||
b.alter_classes(
|
||||
ClassesOp::Replace(b.style().to_string()),
|
||||
match b.style() {
|
||||
StyleBase::Default => "is-primary",
|
||||
StyleBase::Info => "is-info",
|
||||
StyleBase::Success => "is-success",
|
||||
StyleBase::Warning => "is-warning",
|
||||
StyleBase::Danger => "is-danger",
|
||||
StyleBase::Light => "is-light",
|
||||
StyleBase::Dark => "is-dark",
|
||||
StyleBase::Link => "is-text",
|
||||
},
|
||||
);
|
||||
b.alter_classes(
|
||||
ClassesOp::Replace(b.font_size().to_string()),
|
||||
with_font(b.font_size()),
|
||||
);
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
fn before_prepare_heading(h: &mut Heading, _cx: &mut Context) {
|
||||
match h.size() {
|
||||
HeadingSize::Subtitle => {
|
||||
h.alter_classes(ClassesOp::Replace(h.size().to_string()), "subtitle")
|
||||
}
|
||||
}
|
||||
_ => h.alter_classes(ClassesOp::Add, "title"),
|
||||
};
|
||||
}
|
||||
|
||||
fn before_prepare_paragraph(p: &mut Paragraph, _cx: &mut Context) {
|
||||
p.alter_classes(ClassesOp::Add, "block");
|
||||
p.alter_classes(
|
||||
ClassesOp::Replace(p.font_size().to_string()),
|
||||
with_font(p.font_size()),
|
||||
);
|
||||
}
|
||||
|
||||
fn render_icon(i: &Icon, _cx: &mut Context) -> Option<Markup> {
|
||||
return match i.icon_name().get() {
|
||||
None => None,
|
||||
_ => Some(html! { span class="icon" { i class=[i.classes().get()] {} } }),
|
||||
};
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue