Co-authored-by: Sharang Parnerkar <parnerkarsharang@gmail.com> Reviewed-on: #6
45 lines
1.1 KiB
Rust
45 lines
1.1 KiB
Rust
use crate::app::Route;
|
|
use dioxus::prelude::*;
|
|
|
|
/// A single tab item for the sub-navigation bar.
|
|
///
|
|
/// # Fields
|
|
///
|
|
/// * `label` - Display text for the tab
|
|
/// * `route` - Route to navigate to when clicked
|
|
#[derive(Clone, PartialEq)]
|
|
pub struct SubNavItem {
|
|
pub label: &'static str,
|
|
pub route: Route,
|
|
}
|
|
|
|
/// Horizontal tab navigation bar used inside nested shell layouts.
|
|
///
|
|
/// Highlights the active tab based on the current route.
|
|
///
|
|
/// # Arguments
|
|
///
|
|
/// * `items` - List of tab items to render
|
|
#[component]
|
|
pub fn SubNav(items: Vec<SubNavItem>) -> Element {
|
|
let current_route = use_route::<Route>();
|
|
|
|
rsx! {
|
|
nav { class: "sub-nav",
|
|
for item in &items {
|
|
{
|
|
let is_active = item.route == current_route;
|
|
let class = if is_active {
|
|
"sub-nav-item sub-nav-item--active"
|
|
} else {
|
|
"sub-nav-item"
|
|
};
|
|
rsx! {
|
|
Link { class: "{class}", to: item.route.clone(), "{item.label}" }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|