yew_nav_link/lib.rs
1// SPDX-FileCopyrightText: 2024-2026 RAprogramm <andrey.rozanov-vl@gmail.com>
2// SPDX-License-Identifier: MIT
3
4//! # yew-nav-link
5//!
6//! Navigation link component for [Yew](https://yew.rs) with automatic active
7//! state detection.
8//!
9//! [](https://crates.io/crates/yew-nav-link)
10//! [](https://docs.rs/yew-nav-link)
11//! [](https://github.com/RAprogramm/yew-nav-link/blob/main/LICENSE)
12//!
13//! ## Overview
14//!
15//! `yew-nav-link` provides a [`NavLink`] component that wraps Yew Router's
16//! `Link` with automatic active state management. When the target route matches
17//! the current URL, an `active` CSS class is applied.
18//!
19//! ## Quick Start
20//!
21//! ```toml
22//! [dependencies]
23//! yew-nav-link = "0.9"
24//! ```
25//!
26//! ## Component Syntax
27//!
28//! ```rust
29//! use yew::prelude::*;
30//! use yew_nav_link::NavLink;
31//! use yew_router::prelude::*;
32//!
33//! #[derive(Clone, PartialEq, Debug, Routable)]
34//! enum Route {
35//! #[at("/")]
36//! Home,
37//! #[at("/about")]
38//! About
39//! }
40//!
41//! #[component]
42//! fn Navigation() -> Html {
43//! html! {
44//! <nav>
45//! <NavLink<Route> to={Route::Home}>{ "Home" }</NavLink<Route>>
46//! <NavLink<Route> to={Route::About}>{ "About" }</NavLink<Route>>
47//! </nav>
48//! }
49//! }
50//! ```
51//!
52//! ## Function Syntax
53//!
54//! For text-only links, use [`nav_link()`] with explicit [`Match`] mode:
55//!
56//! ```rust
57//! use yew::prelude::*;
58//! use yew_nav_link::{Match, nav_link};
59//! use yew_router::prelude::*;
60//!
61//! # #[derive(Clone, PartialEq, Debug, Routable)]
62//! # enum Route {
63//! # #[at("/")]
64//! # Home,
65//! # #[at("/docs")]
66//! # Docs,
67//! # }
68//! #[component]
69//! fn Menu() -> Html {
70//! html! {
71//! <nav>
72//! { nav_link(Route::Home, "Home", Match::Exact) }
73//! { nav_link(Route::Docs, "Docs", Match::Partial) }
74//! </nav>
75//! }
76//! }
77//! ```
78//!
79//! ## Partial Matching
80//!
81//! Use `partial` prop to keep parent links active on nested routes:
82//!
83//! ```rust
84//! use yew::prelude::*;
85//! use yew_nav_link::NavLink;
86//! use yew_router::prelude::*;
87//!
88//! # #[derive(Clone, PartialEq, Debug, Routable)]
89//! # enum Route {
90//! # #[at("/docs")]
91//! # Docs,
92//! # #[at("/docs/api")]
93//! # DocsApi,
94//! # }
95//! #[component]
96//! fn Navigation() -> Html {
97//! html! {
98//! <nav>
99//! // Active on /docs, /docs/api, /docs/*
100//! <NavLink<Route> to={Route::Docs} partial=true>{ "Docs" }</NavLink<Route>>
101//! </nav>
102//! }
103//! }
104//! ```
105//!
106//! ## CSS Classes
107//!
108//! | Class | Condition |
109//! |-------|-----------|
110//! | `nav-link` | Always |
111//! | `active` | Route matches |
112//!
113//! Compatible with Bootstrap, Tailwind, and other CSS frameworks.
114//!
115//! ## Requirements
116//!
117//! - Yew 0.23+
118//! - yew-router 0.20+
119
120/// HTML attribute builders for navigation components.
121pub mod attrs;
122
123/// Reusable navigation UI components (badges, dropdowns, tabs, pagination).
124pub mod components;
125
126/// Error types returned by navigation operations.
127pub mod errors;
128
129/// Reactive hooks for route and navigation state.
130pub mod hooks;
131
132/// Core navigation primitives (lists, items, dividers).
133pub mod nav;
134
135/// [`NavLink`] component and [`Match`] strategy for active state detection.
136pub mod active_link;
137
138/// Path, URL, query string, and keyboard navigation utilities.
139pub mod utils;
140
141pub use active_link::{Match, NavLink, NavLinkProps, nav_link};
142pub use attrs::{NavItemAttrs, NavLinkAttrs, NavListAttrs};
143pub use components::{
144 NavBadge, NavBadgeProps, NavDropdown, NavDropdownDivider, NavDropdownItem, NavDropdownProps,
145 NavHeader, NavHeaderProps, NavIcon, NavIconProps, NavIconSize, NavLinkWithIcon,
146 NavLinkWithIconProps, NavTab, NavTabPanel, NavTabPanelProps, NavTabProps, NavTabs,
147 NavTabsProps, NavText, NavTextProps, PageItem, PageItemProps, PageLink, PageLinkProps,
148 Pagination, PaginationProps
149};
150pub use errors::{NavError, NavResult};
151pub use hooks::{
152 BreadcrumbItem, BreadcrumbLabelProvider, Navigation, use_breadcrumbs, use_is_active,
153 use_is_exact_active, use_is_partial_active, use_navigation, use_query_params, use_route_info
154};
155pub use nav::{NavDivider, NavDividerProps, NavItem, NavItemProps, NavList, NavListProps};
156pub use utils::{is_absolute, join_paths, normalize_path};