♻️ Major code restructuring

This commit is contained in:
Manuel Cillero 2024-02-09 14:05:38 +01:00
parent a96e203bb3
commit fa66d628a0
221 changed files with 228 additions and 315 deletions

View file

@ -0,0 +1,79 @@
use crate::prelude::*;
use crate::BaseHandle;
use super::Group;
#[rustfmt::skip]
#[derive(BaseHandle, SmartDefault)]
pub struct Megamenu {
id : OptionId,
weight : Weight,
renderable: Renderable,
groups : TypedComponents<Group>,
}
impl ComponentTrait for Megamenu {
fn new() -> Self {
Megamenu::default()
}
fn id(&self) -> Option<String> {
self.id.get()
}
fn weight(&self) -> Weight {
self.weight
}
fn is_renderable(&self, cx: &Context) -> bool {
(self.renderable.check)(cx)
}
fn prepare_component(&self, cx: &mut Context) -> PrepareMarkup {
PrepareMarkup::With(html! {
div id=[self.id()] class="pt-menu__groups" {
(self.groups().render(cx))
}
})
}
}
impl Megamenu {
// Megamenu BUILDER.
#[fn_with]
pub fn alter_id(&mut self, id: impl Into<String>) -> &mut Self {
self.id.alter_value(id);
self
}
#[fn_with]
pub fn alter_weight(&mut self, value: Weight) -> &mut Self {
self.weight = value;
self
}
#[fn_with]
pub fn alter_renderable(&mut self, check: FnIsRenderable) -> &mut Self {
self.renderable.check = check;
self
}
#[rustfmt::skip]
pub fn add_group(mut self, group: Group) -> Self {
self.groups.alter_value(ArcTypedOp::Add(ArcTypedComponent::new(group)));
self
}
#[fn_with]
pub fn alter_groups(&mut self, op: ArcTypedOp<Group>) -> &mut Self {
self.groups.alter_value(op);
self
}
// Megamenu GETTERS.
pub fn groups(&self) -> &TypedComponents<Group> {
&self.groups
}
}