From 255fb393a9503e10e49e15eb63edb2f0bdf3a8d1 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Sun, 19 Nov 2023 00:44:04 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=BD=EF=B8=8F=20Apply=20latest=20change?= =?UTF-8?q?s=20to=20the=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagetop-homedemo/src/lib.rs | 4 +-- pagetop/src/base/component/branding.rs | 11 ++++---- pagetop/src/base/component/button.rs | 18 ++++++------ pagetop/src/base/component/form/button.rs | 2 +- pagetop/src/base/component/heading.rs | 2 +- pagetop/src/base/component/menu/item.rs | 34 +++++++++++++++++++++++ 6 files changed, 53 insertions(+), 18 deletions(-) diff --git a/pagetop-homedemo/src/lib.rs b/pagetop-homedemo/src/lib.rs index 58b46f2f..849d0d56 100644 --- a/pagetop-homedemo/src/lib.rs +++ b/pagetop-homedemo/src/lib.rs @@ -75,13 +75,13 @@ fn hello_world() -> Wrapper { L10n::t("hello_code", &LOCALES_HOMEDEMO), ) .with_target(ButtonTarget::Blank) - .with_left_icon(Icon::with("git")) + .with_left_icon(Some(Icon::with("git"))) .with_classes(ClassesOp::Add, "code-link") .with_font_size(FontSize::Medium), ) .add_component( Button::link("#welcome", L10n::t("hello_welcome", &LOCALES_HOMEDEMO)) - .with_left_icon(Icon::with("arrow-down-circle-fill")) + .with_left_icon(Some(Icon::with("arrow-down-circle-fill"))) .with_classes(ClassesOp::Add, "welcome-link") .with_font_size(FontSize::Medium), ), diff --git a/pagetop/src/base/component/branding.rs b/pagetop/src/base/component/branding.rs index f14430d0..7fb6d664 100644 --- a/pagetop/src/base/component/branding.rs +++ b/pagetop/src/base/component/branding.rs @@ -34,12 +34,13 @@ impl ComponentTrait for Branding { } fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { + let logo = self.logo().render(cx); let title = L10n::l("site_home").using(cx.langid()); PrepareMarkup::With(html! { div id=[self.id()] class="pt-branding" { div class="pt-branding__wrapper" { - div class="pt-branding__logo" { - (self.logo().render(cx)) + @if !logo.is_empty() { + div class="pt-branding__logo" { (logo) } } div class="pt-branding__text" { div class="pt-branding__name" { @@ -93,8 +94,8 @@ impl Branding { } #[fn_builder] - pub fn alter_logo(&mut self, logo: Image) -> &mut Self { - self.logo.set(logo); + pub fn alter_logo(&mut self, logo: Option) -> &mut Self { + self.logo.alter_value(logo); self } @@ -114,7 +115,7 @@ impl Branding { &self.slogan } - pub fn logo(&self) -> &ArcTypedComponent { + pub fn logo(&self) -> &OptionComponent { &self.logo } diff --git a/pagetop/src/base/component/button.rs b/pagetop/src/base/component/button.rs index 82486b17..e5ccbced 100644 --- a/pagetop/src/base/component/button.rs +++ b/pagetop/src/base/component/button.rs @@ -38,8 +38,8 @@ pub struct Button { font_size : FontSize, href : OptionString, html : OptionTranslated, - left_icon : ButtonIcon, - right_icon : ButtonIcon, + left_icon : OptionComponent, + right_icon : OptionComponent, target : ButtonTarget, } @@ -85,7 +85,7 @@ impl ComponentTrait for Button { target=[target] { (self.left_icon().render(cx)) - " " span { (self.html().escaped(cx.langid()).unwrap_or_default()) } " " + " " span { (self.html().escaped(cx.langid())) } " " (self.right_icon().render(cx)) } }) @@ -163,14 +163,14 @@ impl Button { } #[fn_builder] - pub fn alter_left_icon(&mut self, icon: Icon) -> &mut Self { - self.left_icon.set(icon); + pub fn alter_left_icon(&mut self, icon: Option) -> &mut Self { + self.left_icon.alter_value(icon); self } #[fn_builder] - pub fn alter_right_icon(&mut self, icon: Icon) -> &mut Self { - self.right_icon.set(icon); + pub fn alter_right_icon(&mut self, icon: Option) -> &mut Self { + self.right_icon.alter_value(icon); self } @@ -198,11 +198,11 @@ impl Button { &self.html } - pub fn left_icon(&self) -> &ButtonIcon { + pub fn left_icon(&self) -> &OptionComponent { &self.left_icon } - pub fn right_icon(&self) -> &ButtonIcon { + pub fn right_icon(&self) -> &OptionComponent { &self.right_icon } diff --git a/pagetop/src/base/component/form/button.rs b/pagetop/src/base/component/form/button.rs index b4db4788..e0df5e88 100644 --- a/pagetop/src/base/component/form/button.rs +++ b/pagetop/src/base/component/form/button.rs @@ -67,7 +67,7 @@ impl ComponentTrait for Button { autofocus=[self.autofocus().get()] disabled=[self.disabled().get()] { - (self.value().escaped(cx.langid()).unwrap_or_default()) + (self.value().escaped(cx.langid())) } }) } diff --git a/pagetop/src/base/component/heading.rs b/pagetop/src/base/component/heading.rs index 1883f084..83bedc97 100644 --- a/pagetop/src/base/component/heading.rs +++ b/pagetop/src/base/component/heading.rs @@ -77,7 +77,7 @@ impl ComponentTrait for Heading { fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { let id = self.id(); let classes = self.classes().get(); - let text = self.text().escaped(cx.langid()).unwrap_or_default(); + let text = self.text().escaped(cx.langid()); PrepareMarkup::With(html! { @match &self.heading_type() { HeadingType::H1 => h1 id=[id] class=[classes] { (text) }, HeadingType::H2 => h2 id=[id] class=[classes] { (text) }, diff --git a/pagetop/src/base/component/menu/item.rs b/pagetop/src/base/component/menu/item.rs index ff50696a..ec3edf02 100644 --- a/pagetop/src/base/component/menu/item.rs +++ b/pagetop/src/base/component/menu/item.rs @@ -28,6 +28,8 @@ pub struct Item { renderable : Renderable, item_type : ItemType, description: OptionTranslated, + left_icon : OptionComponent, + right_icon : OptionComponent, } impl_handle!(COMPONENT_BASE_MENU_ITEM for Item); @@ -47,26 +49,36 @@ impl ComponentTrait for Item { fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup { let description = self.description.using(cx.langid()); + + let left_icon = self.left_icon().render(cx); + let right_icon = self.right_icon().render(cx); + match self.item_type() { ItemType::Void => PrepareMarkup::None, ItemType::Label(label) => PrepareMarkup::With(html! { li class="pt-menu__label" { span title=[description] { + (left_icon) (label.escaped(cx.langid())) + (right_icon) } } }), ItemType::Link(label, path) => PrepareMarkup::With(html! { li class="pt-menu__link" { a href=(path(cx)) title=[description] { + (left_icon) (label.escaped(cx.langid())) + (right_icon) } } }), ItemType::LinkBlank(label, path) => PrepareMarkup::With(html! { li class="pt-menu__link" { a href=(path(cx)) title=[description] target="_blank" { + (left_icon) (label.escaped(cx.langid())) + (right_icon) } } }), @@ -78,6 +90,7 @@ impl ComponentTrait for Item { ItemType::Submenu(label, submenu) => PrepareMarkup::With(html! { li class="pt-menu__children" { a href="#" title=[description] { + (left_icon) (label.escaped(cx.langid())) i class="pt-menu__icon bi-chevron-down" {} } div class="pt-menu__subs" { @@ -88,6 +101,7 @@ impl ComponentTrait for Item { ItemType::Megamenu(label, megamenu) => PrepareMarkup::With(html! { li class="pt-menu__children" { a href="#" title=[description] { + (left_icon) (label.escaped(cx.langid())) i class="pt-menu__icon bi-chevron-down" {} } div class="pt-menu__subs pt-menu__mega" { @@ -162,6 +176,18 @@ impl Item { self } + #[fn_builder] + pub fn alter_left_icon(&mut self, icon: Option) -> &mut Self { + self.left_icon.alter_value(icon); + self + } + + #[fn_builder] + pub fn alter_right_icon(&mut self, icon: Option) -> &mut Self { + self.right_icon.alter_value(icon); + self + } + // Item GETTERS. pub fn item_type(&self) -> &ItemType { @@ -171,4 +197,12 @@ impl Item { pub fn description(&self) -> &OptionTranslated { &self.description } + + pub fn left_icon(&self) -> &OptionComponent { + &self.left_icon + } + + pub fn right_icon(&self) -> &OptionComponent { + &self.right_icon + } }