2023-06-18 19:40:23 +08:00
|
|
|
use crate::components::SiteHeader;
|
2023-06-13 12:43:15 +08:00
|
|
|
use leptos::*;
|
|
|
|
use leptos_router::{use_location, use_navigate, Outlet};
|
|
|
|
use melt_ui::*;
|
|
|
|
|
|
|
|
#[component]
|
2023-08-29 09:11:22 +08:00
|
|
|
pub fn ComponentsPage() -> impl IntoView {
|
|
|
|
let navigate = use_navigate();
|
2023-10-11 21:12:45 +08:00
|
|
|
let selected = create_rw_signal({
|
|
|
|
let loaction = use_location();
|
|
|
|
let mut pathname = loaction.pathname.get_untracked();
|
2023-06-13 12:43:15 +08:00
|
|
|
|
2023-10-11 21:12:45 +08:00
|
|
|
if pathname.starts_with("/melt-ui/components/") {
|
|
|
|
pathname.drain(20..).collect()
|
|
|
|
} else {
|
|
|
|
String::new()
|
|
|
|
}
|
2023-06-13 12:43:15 +08:00
|
|
|
});
|
|
|
|
|
2023-08-29 09:11:22 +08:00
|
|
|
create_effect(move |value| {
|
2023-06-13 12:43:15 +08:00
|
|
|
let selected = selected.get();
|
|
|
|
if value.is_some() {
|
2023-08-29 09:11:22 +08:00
|
|
|
navigate(&format!("/components/{selected}"), Default::default());
|
2023-06-13 12:43:15 +08:00
|
|
|
}
|
|
|
|
selected
|
|
|
|
});
|
2023-08-29 09:11:22 +08:00
|
|
|
view! {
|
2023-10-16 21:15:43 +08:00
|
|
|
<Layout position=LayoutPosition::Absolute>
|
2023-10-08 09:28:13 +08:00
|
|
|
<SiteHeader/>
|
2023-10-16 21:15:43 +08:00
|
|
|
<Layout has_sider=true position=LayoutPosition::Absolute style="top: 54px;">
|
2023-06-18 19:40:23 +08:00
|
|
|
<LayoutSider>
|
2023-10-11 21:25:11 +08:00
|
|
|
<Menu value=selected>
|
2023-10-15 15:43:02 +08:00
|
|
|
{
|
|
|
|
gen_menu_data().into_view()
|
|
|
|
}
|
2023-06-18 19:40:23 +08:00
|
|
|
</Menu>
|
|
|
|
</LayoutSider>
|
2023-10-11 13:37:39 +08:00
|
|
|
<Layout style="padding: 8px 12px 28px; overflow-y: auto;">
|
2023-10-08 09:28:13 +08:00
|
|
|
<Outlet/>
|
2023-06-18 19:40:23 +08:00
|
|
|
</Layout>
|
|
|
|
</Layout>
|
|
|
|
</Layout>
|
2023-06-13 12:43:15 +08:00
|
|
|
}
|
|
|
|
}
|
2023-10-15 15:43:02 +08:00
|
|
|
|
|
|
|
struct MenuGroupOption {
|
|
|
|
label: String,
|
|
|
|
children: Vec<MenuItemOption>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoView for MenuGroupOption {
|
|
|
|
fn into_view(self) -> View {
|
|
|
|
let Self { label, children } = self;
|
|
|
|
view! {
|
|
|
|
<MenuGroup label>
|
|
|
|
{
|
|
|
|
children.into_iter().map(|v| v.into_view()).collect_view()
|
|
|
|
}
|
|
|
|
</MenuGroup>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct MenuItemOption {
|
|
|
|
label: String,
|
|
|
|
value: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl IntoView for MenuItemOption {
|
|
|
|
fn into_view(self) -> View {
|
|
|
|
let Self { label, value } = self;
|
|
|
|
view! {
|
|
|
|
<MenuItem key=value label/>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn gen_menu_data() -> Vec<MenuGroupOption> {
|
|
|
|
vec![
|
|
|
|
MenuGroupOption {
|
|
|
|
label: "Common Components".into(),
|
2023-10-16 15:10:55 +08:00
|
|
|
children: vec![
|
|
|
|
MenuItemOption {
|
|
|
|
value: "avatar".into(),
|
|
|
|
label: "Avatar".into(),
|
|
|
|
},
|
|
|
|
MenuItemOption {
|
|
|
|
value: "button".into(),
|
|
|
|
label: "Button".into(),
|
|
|
|
},
|
2023-10-16 22:04:34 +08:00
|
|
|
MenuItemOption {
|
|
|
|
value: "card".into(),
|
|
|
|
label: "Card".into(),
|
|
|
|
},
|
2023-10-17 11:11:39 +08:00
|
|
|
MenuItemOption {
|
|
|
|
value: "divider".into(),
|
|
|
|
label: "Divider".into(),
|
|
|
|
},
|
2023-10-16 15:10:55 +08:00
|
|
|
],
|
2023-10-15 15:43:02 +08:00
|
|
|
},
|
|
|
|
MenuGroupOption {
|
|
|
|
label: "Data Input Components".into(),
|
|
|
|
children: vec![
|
|
|
|
MenuItemOption {
|
|
|
|
value: "auto-complete".into(),
|
|
|
|
label: "Auto Complete".into(),
|
|
|
|
},
|
|
|
|
MenuItemOption {
|
|
|
|
value: "color-picker".into(),
|
|
|
|
label: "Color Picker".into(),
|
|
|
|
},
|
|
|
|
MenuItemOption {
|
|
|
|
value: "checkbox".into(),
|
|
|
|
label: "Checkbox".into(),
|
|
|
|
},
|
|
|
|
MenuItemOption {
|
|
|
|
value: "input".into(),
|
|
|
|
label: "Input".into(),
|
|
|
|
},
|
|
|
|
MenuItemOption {
|
|
|
|
value: "select".into(),
|
|
|
|
label: "Select".into(),
|
|
|
|
},
|
|
|
|
MenuItemOption {
|
|
|
|
value: "slider".into(),
|
|
|
|
label: "Slider".into(),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
MenuGroupOption {
|
|
|
|
label: "Data Display Components".into(),
|
|
|
|
children: vec![
|
|
|
|
MenuItemOption {
|
|
|
|
value: "image".into(),
|
|
|
|
label: "Image".into(),
|
|
|
|
},
|
|
|
|
MenuItemOption {
|
|
|
|
value: "table".into(),
|
|
|
|
label: "Table".into(),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
MenuGroupOption {
|
|
|
|
label: "Navigation Components".into(),
|
|
|
|
children: vec![
|
|
|
|
MenuItemOption {
|
|
|
|
value: "menu".into(),
|
|
|
|
label: "Menu".into(),
|
|
|
|
},
|
|
|
|
MenuItemOption {
|
|
|
|
value: "tabs".into(),
|
|
|
|
label: "Tabs".into(),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
MenuGroupOption {
|
|
|
|
label: "Feedback Components".into(),
|
|
|
|
children: vec![
|
|
|
|
MenuItemOption {
|
|
|
|
value: "alert".into(),
|
|
|
|
label: "Alert".into(),
|
|
|
|
},
|
2023-10-16 20:56:14 +08:00
|
|
|
MenuItemOption {
|
|
|
|
value: "badge".into(),
|
|
|
|
label: "Badge".into(),
|
|
|
|
},
|
2023-10-15 15:43:02 +08:00
|
|
|
MenuItemOption {
|
|
|
|
value: "modal".into(),
|
|
|
|
label: "Modal".into(),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
MenuGroupOption {
|
|
|
|
label: "Layout Components".into(),
|
|
|
|
children: vec![
|
|
|
|
MenuItemOption {
|
|
|
|
value: "grid".into(),
|
|
|
|
label: "Grid".into(),
|
|
|
|
},
|
|
|
|
MenuItemOption {
|
|
|
|
value: "space".into(),
|
|
|
|
label: "Space".into(),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
MenuGroupOption {
|
|
|
|
label: "Mobile Components".into(),
|
|
|
|
children: vec![
|
|
|
|
MenuItemOption {
|
|
|
|
value: "nav-bar".into(),
|
|
|
|
label: "Nav Bar".into(),
|
|
|
|
},
|
|
|
|
MenuItemOption {
|
|
|
|
value: "tabbar".into(),
|
|
|
|
label: "Tabbar".into(),
|
|
|
|
},
|
|
|
|
MenuItemOption {
|
|
|
|
value: "toast".into(),
|
|
|
|
label: "Toast".into(),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]
|
|
|
|
}
|