💄 Improve block component capabilities
This commit is contained in:
parent
36a89ac571
commit
f467aaa330
10 changed files with 290 additions and 147 deletions
|
|
@ -15,7 +15,17 @@ pub(crate) fn add_base_assets(cx: &mut Context) {
|
|||
StyleSheet::at("/base/css/root.css")
|
||||
.with_version("0.0.1")
|
||||
.with_weight(weight),
|
||||
)).alter(ContextOp::AddStyleSheet(
|
||||
StyleSheet::at("/base/css/looks.css")
|
||||
.with_version("0.0.1")
|
||||
.with_weight(weight),
|
||||
))
|
||||
.alter(ContextOp::AddStyleSheet(
|
||||
StyleSheet::at("/base/css/buttons.css")
|
||||
.with_version("0.0.2")
|
||||
.with_weight(weight),
|
||||
));
|
||||
|
||||
if let Some(true) = cx.get_param::<bool>(PARAM_BASE_INCLUDE_ICONS) {
|
||||
cx.alter(ContextOp::AddStyleSheet(
|
||||
StyleSheet::at("/base/css/icons.min.css")
|
||||
|
|
@ -23,6 +33,7 @@ pub(crate) fn add_base_assets(cx: &mut Context) {
|
|||
.with_weight(weight),
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(true) = cx.get_param::<bool>(PARAM_BASE_INCLUDE_FLEX_ASSETS) {
|
||||
cx.alter(ContextOp::AddStyleSheet(
|
||||
StyleSheet::at("/base/css/flex.css")
|
||||
|
|
@ -30,6 +41,7 @@ pub(crate) fn add_base_assets(cx: &mut Context) {
|
|||
.with_weight(weight),
|
||||
));
|
||||
}
|
||||
|
||||
if let Some(true) = cx.get_param::<bool>(PARAM_BASE_INCLUDE_MENU_ASSETS) {
|
||||
cx.alter(ContextOp::AddStyleSheet(
|
||||
StyleSheet::at("/base/css/menu.css")
|
||||
|
|
@ -42,16 +54,6 @@ pub(crate) fn add_base_assets(cx: &mut Context) {
|
|||
.with_weight(weight),
|
||||
));
|
||||
}
|
||||
cx.alter(ContextOp::AddStyleSheet(
|
||||
StyleSheet::at("/base/css/looks.css")
|
||||
.with_version("0.0.1")
|
||||
.with_weight(weight),
|
||||
))
|
||||
.alter(ContextOp::AddStyleSheet(
|
||||
StyleSheet::at("/base/css/buttons.css")
|
||||
.with_version("0.0.2")
|
||||
.with_weight(weight),
|
||||
));
|
||||
}
|
||||
|
||||
// *************************************************************************************************
|
||||
|
|
@ -92,10 +94,10 @@ impl ToString for BreakPoint {
|
|||
pub enum StyleBase {
|
||||
#[default]
|
||||
Default,
|
||||
Success,
|
||||
Danger,
|
||||
Warning,
|
||||
Info,
|
||||
Success,
|
||||
Warning,
|
||||
Danger,
|
||||
Light,
|
||||
Dark,
|
||||
Link,
|
||||
|
|
@ -106,10 +108,10 @@ impl ToString for StyleBase {
|
|||
fn to_string(&self) -> String {
|
||||
String::from(match self {
|
||||
StyleBase::Default => "style__default",
|
||||
StyleBase::Success => "style__success",
|
||||
StyleBase::Danger => "style__danger",
|
||||
StyleBase::Warning => "style__warning",
|
||||
StyleBase::Info => "style__info",
|
||||
StyleBase::Success => "style__success",
|
||||
StyleBase::Warning => "style__warning",
|
||||
StyleBase::Danger => "style__danger",
|
||||
StyleBase::Light => "style__light",
|
||||
StyleBase::Dark => "style__dark",
|
||||
StyleBase::Link => "style__link",
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ pub struct Block {
|
|||
weight : Weight,
|
||||
renderable: Renderable,
|
||||
classes : OptionClasses,
|
||||
style : StyleBase,
|
||||
title : OptionTranslated,
|
||||
mixed : MixedComponents,
|
||||
}
|
||||
|
|
@ -29,23 +30,29 @@ impl ComponentTrait for Block {
|
|||
}
|
||||
|
||||
fn setup_before_prepare(&mut self, _cx: &mut Context) {
|
||||
self.alter_classes(ClassesOp::Prepend, "block__container");
|
||||
self.alter_classes(
|
||||
ClassesOp::Prepend,
|
||||
[String::from("block__container"), self.style().to_string()].join(" "),
|
||||
);
|
||||
}
|
||||
|
||||
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
|
||||
let block_body = self.components().render(cx);
|
||||
if !block_body.is_empty() {
|
||||
let id = cx.required_id::<Block>(self.id());
|
||||
return PrepareMarkup::With(html! {
|
||||
div id=(id) class=[self.classes().get()] {
|
||||
@if let Some(title) = self.title().using(cx.langid()) {
|
||||
h2 class="block__title" { (title) }
|
||||
}
|
||||
div class="block__body" { (block_body) }
|
||||
}
|
||||
});
|
||||
|
||||
if block_body.is_empty() {
|
||||
return PrepareMarkup::None;
|
||||
}
|
||||
PrepareMarkup::None
|
||||
|
||||
let id = cx.required_id::<Block>(self.id());
|
||||
|
||||
PrepareMarkup::With(html! {
|
||||
div id=(id) class=[self.classes().get()] {
|
||||
@if let Some(title) = self.title().using(cx.langid()) {
|
||||
h2 class="block__title" { (title) }
|
||||
}
|
||||
div class="block__content" { (block_body) }
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -70,6 +77,12 @@ impl Block {
|
|||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_style(&mut self, style: StyleBase) -> &mut Self {
|
||||
self.style = style;
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_title(&mut self, title: L10n) -> &mut Self {
|
||||
self.title.alter_value(title);
|
||||
|
|
@ -90,6 +103,10 @@ impl Block {
|
|||
|
||||
// Block GETTERS.
|
||||
|
||||
pub fn style(&self) -> &StyleBase {
|
||||
&self.style
|
||||
}
|
||||
|
||||
pub fn title(&self) -> &OptionTranslated {
|
||||
&self.title
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ impl ComponentTrait for Button {
|
|||
self.alter_classes(
|
||||
ClassesOp::Prepend,
|
||||
[
|
||||
"button__tap".to_string(),
|
||||
String::from("button__tap"),
|
||||
self.style().to_string(),
|
||||
self.font_size().to_string(),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ impl ComponentTrait for ActionButton {
|
|||
self.alter_classes(
|
||||
ClassesOp::Prepend,
|
||||
[
|
||||
"button__tap".to_string(),
|
||||
String::from("button__tap"),
|
||||
self.style().to_string(),
|
||||
self.font_size().to_string(),
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue