Add new components for page layout

This commit is contained in:
Manuel Cillero 2024-03-16 10:16:30 +01:00
parent b6b7d9687b
commit 36c931486d
9 changed files with 126 additions and 96 deletions

View file

@ -157,6 +157,12 @@ impl ToString for FontSize {
// *************************************************************************************************
mod layout;
pub use layout::Layout;
mod region;
pub use region::Region;
mod html;
pub use html::Html;

View file

@ -0,0 +1,58 @@
use crate::prelude::*;
#[derive(AutoDefault)]
pub struct Layout;
impl ComponentTrait for Layout {
fn new() -> Self {
Layout
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
PrepareMarkup::With(match cx.layout() {
"default" => Self::default_layout(cx),
"admin" => Self::admin_layout(cx),
_ => Self::default_layout(cx),
})
}
}
impl Layout {
fn default_layout(cx: &mut Context) -> Markup {
flex::Container::new()
.with_id("body__wrapper")
.with_direction(flex::Direction::Column(BreakPoint::None))
.with_items_align(flex::ItemAlign::Center)
.add_item(flex::Item::full(Region::named("header")).with_id("header"))
.add_item(flex::Item::full(Region::named("pagetop")).with_id("pagetop"))
.add_item(flex::Item::full(
flex::Container::new()
.with_id("content__wrapper")
.with_direction(flex::Direction::Row(BreakPoint::None))
.add_item(
flex::Item::with(Region::named("sidebar_left"))
.with_id("sidebar_left")
.with_grow(flex::ItemGrow::Is1),
)
.add_item(
flex::Item::with(Region::named("content"))
.with_id("content")
.with_grow(flex::ItemGrow::Is3),
)
.add_item(
flex::Item::with(Region::named("sidebar_right"))
.with_id("sidebar_right")
.with_grow(flex::ItemGrow::Is1),
),
))
.add_item(flex::Item::full(Region::named("footer")).with_id("footer"))
.render(cx)
}
fn admin_layout(cx: &mut Context) -> Markup {
Html::with(html! {
("admin")
})
.render(cx)
}
}

View file

@ -0,0 +1,37 @@
use crate::prelude::*;
#[derive(AutoDefault)]
pub struct Region(OptionId);
impl ComponentTrait for Region {
fn new() -> Self {
Region::default()
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
if let Some(name) = self.name().get() {
return PrepareMarkup::With(cx.prepare_region(name.as_str()));
}
PrepareMarkup::None
}
}
impl Region {
pub fn named(name: impl Into<String>) -> Self {
Region::new().with_name(name)
}
// Region BUILDER.
#[fn_builder]
pub fn alter_name(&mut self, name: impl Into<String>) -> &mut Self {
self.0.alter_value(name);
self
}
// Region GETTERS.
pub fn name(&self) -> &OptionId {
&self.0
}
}