Introduce ContextualPath as dynamic path

This commit is contained in:
Manuel Cillero 2023-08-05 10:54:02 +02:00
parent fff8ab19aa
commit 25cb46e712
7 changed files with 74 additions and 19 deletions

View file

@ -7,15 +7,13 @@ new_handle!(COMPONENT_MEGAITEM);
type Label = OneComponent<L10n>;
type Content = OneComponent<Html>;
pub type MegaItemPath = fn(cx: &Context) -> &str;
#[derive(Default)]
pub enum MegaItemType {
#[default]
Void,
Label(Label),
Link(Label, MegaItemPath),
LinkBlank(Label, MegaItemPath),
Link(Label, ContextualPath),
LinkBlank(Label, ContextualPath),
Html(Content),
Submenu(Label, MegaMenu),
Separator,
@ -86,14 +84,14 @@ impl MegaItem {
}
}
pub fn link(label: L10n, path: MegaItemPath) -> Self {
pub fn link(label: L10n, path: ContextualPath) -> Self {
MegaItem {
item_type: MegaItemType::Link(Label::with(label), path),
..Default::default()
}
}
pub fn link_blank(label: L10n, path: MegaItemPath) -> Self {
pub fn link_blank(label: L10n, path: ContextualPath) -> Self {
MegaItem {
item_type: MegaItemType::LinkBlank(Label::with(label), path),
..Default::default()

View file

@ -2,7 +2,7 @@ use pagetop::prelude::*;
pub mod component {
mod item;
pub use item::{MegaItem, MegaItemPath, MegaItemType, COMPONENT_MEGAITEM};
pub use item::{MegaItem, MegaItemType, COMPONENT_MEGAITEM};
mod menu;
pub use menu::{MegaMenu, COMPONENT_MEGAMENU};
}