Skip to content

Commit 064455f

Browse files
authored
feat(navbar): floating variant, link highlight and animated mobile menu (#70)
1 parent 77dd0f4 commit 064455f

5 files changed

Lines changed: 495 additions & 204 deletions

File tree

‎content/docs/components/navigation/navbar.mdx‎

Lines changed: 81 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -69,22 +69,25 @@ export function SiteNav() {
6969

7070
## Props
7171

72-
| Prop | Type | Required | Description |
73-
| --------------- | --------------------------------- | -------- | -------------------------------------------------------------- |
74-
| `logo` | `React.ReactNode` | No | Logo element (renders before nav links) |
75-
| `links` | `NavLink[]` | No | Navigation links |
76-
| `locales` | `Locale[]` | No | Available locales for language selector |
77-
| `value` | `string` | No | Selected locale code — pass this to control the component |
78-
| `defaultValue` | `string` | No | Initial locale code when uncontrolled (default: `"en"`) |
79-
| `onValueChange` | `(code: string) => void` | No | Callback when locale changes |
80-
| `cta` | `{ label: string; href: string }` | No | CTA button |
81-
| `showGitHub` | `boolean` | No | Show GitHub icon button |
82-
| `githubUrl` | `string` | No | GitHub repository URL |
83-
| `sticky` | `boolean` | No | Make navbar sticky at top (default: `true`) |
84-
| `showFlags` | `boolean` | No | Show flags in language selector (default: `true`) |
85-
| `maxHeight` | `number \| string` | No | Max height of the scrolling language menu (default: `"15rem"`) |
86-
| `linkComponent` | `React.ElementType` | No | Component used for internal links (default: `"a"`) |
87-
| `className` | `string` | No | Additional CSS classes |
72+
| Prop | Type | Required | Description |
73+
| --------------- | --------------------------------- | -------- | ---------------------------------------------------------------- |
74+
| `logo` | `React.ReactNode` | No | Logo element (renders before nav links) |
75+
| `links` | `NavLink[]` | No | Navigation links |
76+
| `activeHref` | `string` | No | `href` of the current page — gets `aria-current` and a highlight |
77+
| `locales` | `Locale[]` | No | Available locales for language selector |
78+
| `value` | `string` | No | Selected locale code — pass this to control the component |
79+
| `defaultValue` | `string` | No | Initial locale code when uncontrolled (default: first locale) |
80+
| `onValueChange` | `(code: string) => void` | No | Callback when locale changes |
81+
| `cta` | `{ label: string; href: string }` | No | CTA button |
82+
| `showGitHub` | `boolean` | No | Show GitHub icon button |
83+
| `githubUrl` | `string` | No | GitHub repository URL |
84+
| `sticky` | `boolean` | No | Make navbar sticky at top (default: `true`) |
85+
| `variant` | `"default" \| "floating"` | No | Full-width bar or inset floating card (default: `"default"`) |
86+
| `showFlags` | `boolean` | No | Show flags in language selector (default: `true`) |
87+
| `maxHeight` | `number \| string` | No | Max height of the scrolling language menu (default: `"15rem"`) |
88+
| `linkComponent` | `React.ElementType` | No | Component used for internal links (default: `"a"`) |
89+
| `classNames` | `NavBarClassNames` | No | Per-part class overrides (see below) |
90+
| `className` | `string` | No | Additional CSS classes |
8891

8992
Any other prop is spread onto the underlying `<nav>` element, and the ref is
9093
forwarded to it.
@@ -101,6 +104,35 @@ import Link from "next/link";
101104
<NavBar links={links} linkComponent={Link} />;
102105
```
103106

107+
### Styling parts
108+
109+
`classNames` merges extra classes into each part with `cn`, so your classes win
110+
over the defaults:
111+
112+
| Key | Part |
113+
| ----------------- | --------------------------------------------------------- |
114+
| `root` | The `<nav>` element (same as `className`) |
115+
| `container` | The bar itself — the full-width row, or the floating card |
116+
| `links` | The desktop link group |
117+
| `link` | Each link, on desktop and in the mobile menu |
118+
| `actions` | The desktop group with the language menu, GitHub and CTA |
119+
| `cta` | The call-to-action button |
120+
| `languageTrigger` | The language menu triggers |
121+
| `languageContent` | The language menu panel |
122+
| `languageItem` | Each language option |
123+
| `mobileMenu` | The mobile menu panel |
124+
125+
```tsx
126+
<NavBar
127+
links={links}
128+
classNames={{
129+
container: "max-w-4xl",
130+
cta: "rounded-full",
131+
link: "text-base",
132+
}}
133+
/>
134+
```
135+
104136
### NavLink Object
105137

106138
| Property | Type | Description |
@@ -221,6 +253,32 @@ export function AppNavBar() {
221253
}
222254
```
223255

256+
### Floating
257+
258+
An inset, rounded bar that floats above the page — pair it with `activeHref` to
259+
highlight the current page:
260+
261+
```tsx
262+
"use client";
263+
264+
import { NavBar } from "@/components/ui/navbar";
265+
266+
export default function App() {
267+
return (
268+
<NavBar
269+
variant="floating"
270+
logo={<span className="font-bold">MyApp</span>}
271+
links={[
272+
{ label: "Home", href: "/" },
273+
{ label: "Docs", href: "/docs" },
274+
]}
275+
activeHref="/docs"
276+
cta={{ label: "Get Started", href: "/signup" }}
277+
/>
278+
);
279+
}
280+
```
281+
224282
### Non-sticky
225283

226284
```tsx
@@ -268,17 +326,21 @@ never scrolls the page. Pass `maxHeight` to set how tall the menu gets.
268326
- **Sticky/non-sticky** — toggle top-of-page stickiness
269327
- **Keyboard accessible** — arrow keys, Home / End, Enter, and Escape navigation
270328
- **ARIA labels** — `aria-expanded`, `aria-haspopup`, `aria-selected`, and roving focus over the options
271-
- **Dark mode** — built with Tailwind CSS, dark-mode compatible
272-
- **Next.js Link** — uses `next/link` for client-side navigation
329+
- **Themeable** — styled with shadcn/ui tokens, so it follows your theme and dark mode
330+
- **Two variants** — full-width bar or floating inset card
331+
- **Animated** — hover highlight that glides between links, animated mobile menu and language menu; honors `prefers-reduced-motion`
332+
- **Router-agnostic** — pass `next/link` (or any link) through `linkComponent`
273333

274334
## Dependencies
275335

336+
- `motion` — animations
337+
- `lucide-react` — icons
338+
276339
Peer dependencies:
277340

278341
- `react` >= 18
279342
- `react-dom` >= 18
280343
- `tailwindcss` >= 3
281-
- `next` >= 13 (uses `next/link`)
282344

283345
## Credits
284346

‎src/registry/components/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export { PhoneInput, COUNTRIES } from "./phone-input";
1919
export type { PhoneInputProps, PhoneInputClassNames, Country } from "./phone-input";
2020

2121
export { NavBar } from "./navbar";
22-
export type { NavBarProps, NavLink } from "./navbar";
22+
export type { NavBarProps, NavBarClassNames, NavLink } from "./navbar";
2323

2424
export { TranslationWidget } from "./translation-widget";
2525
export type { TranslationWidgetProps } from "./translation-widget";

0 commit comments

Comments
 (0)