Add new component SiteBranding

This commit is contained in:
Manuel Cillero 2023-08-01 20:29:36 +02:00
parent 117416a429
commit fff8ab19aa
6 changed files with 136 additions and 16 deletions

View file

@ -15,6 +15,8 @@ mod image;
pub use image::{Image, COMPONENT_IMAGE};
mod block;
pub use block::{Block, COMPONENT_BLOCK};
mod site_branding;
pub use site_branding::{SiteBranding, COMPONENT_BRANDING};
mod poweredby;
pub use poweredby::{PoweredBy, PoweredByLogo, COMPONENT_POWEREDBY};

View file

@ -10,7 +10,6 @@ pub struct Image {
id : IdentifierValue,
classes : Classes,
source : AttributeValue,
template : String,
}
impl ComponentTrait for Image {
@ -49,6 +48,10 @@ impl Image {
Image::new().with_source(source)
}
pub fn pagetop() -> Self {
Image::new().with_source("/minimal/pagetop-logo.svg")
}
// Image BUILDER.
#[fn_builder]
@ -81,12 +84,6 @@ impl Image {
self
}
#[fn_builder]
pub fn alter_template(&mut self, template: &str) -> &mut Self {
self.template = template.to_owned();
self
}
// Image GETTERS.
pub fn classes(&self) -> &Classes {
@ -96,8 +93,4 @@ impl Image {
pub fn source(&self) -> &AttributeValue {
&self.source
}
pub fn template(&self) -> &str {
self.template.as_str()
}
}

View file

@ -1,7 +1,7 @@
use crate::{Minimal, LOCALES_MINIMAL};
use pagetop::prelude::*;
use crate::{Minimal, LOCALES_MINIMAL};
new_handle!(COMPONENT_POWEREDBY);
#[derive(Default, Eq, PartialEq)]
@ -58,7 +58,6 @@ impl ComponentTrait for PoweredBy {
PoweredByLogo::Color => {
let logo_txt = L10n::t("pagetop_logo", &LOCALES_MINIMAL);
html! {
" "
span class="pagetop-logo" aria-label=[logo_txt.into_string(cx)] {
img src="/minimal/pagetop-logo.svg" alt=[logo_txt.into_string(cx)] {}
}
@ -80,7 +79,7 @@ impl ComponentTrait for PoweredBy {
@if let Some(c) = self.copyright() {
span class="copyright" { (c) "." } " "
}
span class="powered" { (credits.prepare(cx)) (logo) }
span class="powered" { (credits.prepare(cx)) " " (logo) }
}
})
}
@ -129,7 +128,6 @@ impl PoweredBy {
let logo_txt = L10n::t("pagetop_logo", &LOCALES_MINIMAL);
let logo_rgb = format!("rgb({},{},{})", r, g, b);
html! {
" "
span class="pagetop-logo" aria-label=[logo_txt.into_string(cx)] {
svg viewBox="0 0 1614 1614" xmlns="http://www.w3.org/2000/svg" role="img" {
path fill=(logo_rgb) d="M 1573,357 L 1415,357 C 1400,357 1388,369 1388,383 L 1388,410 1335,410 1335,357 C 1335,167 1181,13 992,13 L 621,13 C 432,13 278,167 278,357 L 278,410 225,410 225,383 C 225,369 213,357 198,357 L 40,357 C 25,357 13,369 13,383 L 13,648 C 13,662 25,674 40,674 L 198,674 C 213,674 225,662 225,648 L 225,621 278,621 278,1256 C 278,1446 432,1600 621,1600 L 992,1600 C 1181,1600 1335,1446 1335,1256 L 1335,621 1388,621 1388,648 C 1388,662 1400,674 1415,674 L 1573,674 C 1588,674 1600,662 1600,648 L 1600,383 C 1600,369 1588,357 1573,357 L 1573,357 1573,357 Z M 66,410 L 172,410 172,621 66,621 66,410 66,410 Z M 1282,357 L 1282,488 C 1247,485 1213,477 1181,464 L 1196,437 C 1203,425 1199,409 1186,401 1174,394 1158,398 1150,411 L 1133,440 C 1105,423 1079,401 1056,376 L 1075,361 C 1087,352 1089,335 1079,324 1070,313 1054,311 1042,320 L 1023,335 C 1000,301 981,263 967,221 L 1011,196 C 1023,189 1028,172 1021,160 1013,147 997,143 984,150 L 953,168 C 945,136 941,102 940,66 L 992,66 C 1152,66 1282,197 1282,357 L 1282,357 1282,357 Z M 621,66 L 674,66 674,225 648,225 C 633,225 621,237 621,251 621,266 633,278 648,278 L 674,278 674,357 648,357 C 633,357 621,369 621,383 621,398 633,410 648,410 L 674,410 674,489 648,489 C 633,489 621,501 621,516 621,530 633,542 648,542 L 664,542 C 651,582 626,623 600,662 583,653 563,648 542,648 469,648 410,707 410,780 410,787 411,794 412,801 388,805 361,806 331,806 L 331,357 C 331,197 461,66 621,66 L 621,66 621,66 Z M 621,780 C 621,824 586,859 542,859 498,859 463,824 463,780 463,736 498,701 542,701 586,701 621,736 621,780 L 621,780 621,780 Z M 225,463 L 278,463 278,569 225,569 225,463 225,463 Z M 992,1547 L 621,1547 C 461,1547 331,1416 331,1256 L 331,859 C 367,859 400,858 431,851 454,888 495,912 542,912 615,912 674,853 674,780 674,747 662,718 642,695 675,645 706,594 720,542 L 780,542 C 795,542 807,530 807,516 807,501 795,489 780,489 L 727,489 727,410 780,410 C 795,410 807,398 807,383 807,369 795,357 780,357 L 727,357 727,278 780,278 C 795,278 807,266 807,251 807,237 795,225 780,225 L 727,225 727,66 887,66 C 889,111 895,155 905,196 L 869,217 C 856,224 852,240 859,253 864,261 873,266 882,266 887,266 891,265 895,263 L 921,248 C 937,291 958,331 983,367 L 938,403 C 926,412 925,429 934,440 939,447 947,450 954,450 960,450 966,448 971,444 L 1016,408 C 1043,438 1074,465 1108,485 L 1084,527 C 1076,539 1081,555 1093,563 1098,565 1102,566 1107,566 1116,566 1125,561 1129,553 L 1155,509 C 1194,527 1237,538 1282,541 L 1282,1256 C 1282,1416 1152,1547 992,1547 L 992,1547 992,1547 Z M 1335,463 L 1388,463 1388,569 1335,569 1335,463 1335,463 Z M 1441,410 L 1547,410 1547,621 1441,621 1441,410 1441,410 Z" {}

View file

@ -0,0 +1,121 @@
use pagetop::prelude::*;
use crate::component::Image;
use crate::Minimal;
use crate::LOCALES_MINIMAL;
new_handle!(COMPONENT_BRANDING);
type SiteSlogan = OneComponent<L10n>;
type SiteLogo = OneComponent<Image>;
#[rustfmt::skip]
#[derive(Default)]
pub struct SiteBranding {
weight : Weight,
renderable: Renderable,
name : String,
slogan : SiteSlogan,
logo : SiteLogo,
}
impl ComponentTrait for SiteBranding {
fn new() -> Self {
SiteBranding {
name: config::SETTINGS.app.name.to_owned(),
..Default::default()
}
}
fn handle(&self) -> Handle {
COMPONENT_BRANDING
}
fn id(&self) -> Option<String> {
Some("site-branding".to_owned())
}
fn weight(&self) -> Weight {
self.weight
}
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn before_prepare_component(&mut self, cx: &mut Context) {
Minimal.load_assets(cx);
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
let title = L10n::t("site_home", &LOCALES_MINIMAL).prepare(cx);
let slogan = self.slogan().prepare(cx);
PrepareMarkup::With(html! {
div id=[self.id()] {
div class="site-branding-wrapper" {
div class="site-branding-logo" {
(self.logo().prepare(cx))
}
div class="site-branding-text" {
div class="site-branding-name" {
a href="/" title=(title) rel="home" { (self.name()) }
}
@if !slogan.is_empty() {
div class="site-branding-slogan" {
(slogan)
}
}
}
}
}
})
}
}
impl SiteBranding {
// SiteBranding BUILDER.
#[fn_builder]
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}
#[fn_builder]
pub fn alter_renderable(&mut self, check: IsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[fn_builder]
pub fn alter_name(&mut self, name: impl Into<String>) -> &mut Self {
self.name = name.into();
self
}
#[fn_builder]
pub fn alter_slogan(&mut self, slogan: L10n) -> &mut Self {
self.slogan = SiteSlogan::with(slogan);
self
}
#[fn_builder]
pub fn alter_logo(&mut self, logo: Image) -> &mut Self {
self.logo.set(logo);
self
}
// SiteBranding GETTERS.
pub fn name(&self) -> &String {
&self.name
}
pub fn slogan(&self) -> &SiteSlogan {
&self.slogan
}
pub fn logo(&self) -> &SiteLogo {
&self.logo
}
}

View file

@ -1,6 +1,9 @@
module_name = Minimal components
module_description = Minimal set of components for page composition.
# SiteBranding component.
site_home = Home
# PoweredBy component.
poweredby_pagetop = Powered by {$pagetop_link}
pagetop_logo = PageTop logo

View file

@ -1,6 +1,9 @@
module_name = Componentes Minimal
module_description = Conjunto mínimo de componentes para la composición de páginas.
# SiteBranding component.
site_home = Inicio
# PoweredBy component.
poweredby_pagetop = Funciona con {$pagetop_link}
pagetop_logo = Logotipo de PageTop