Bottom navigation
Mobile tab bar. 3 lengths × 2 themes.
import * as React from "react";
import { BottomNav, BottomNavItem } from "@/components/ui/bottom-nav";
import { House, Search, Star, User } from "@/components/ui/icons";
export default function Example() {
const [tab, setTab] = React.useState("shop");
const go = (id: string) => (e: React.MouseEvent) => { e.preventDefault(); setTab(id); };
return (
<div style={{ width: 360, maxWidth: "100%" }}>
<BottomNav>
<BottomNavItem href="#shop" icon={<House />} active={tab === "shop"} onClick={go("shop")}>Shop</BottomNavItem>
<BottomNavItem href="#search" icon={<Search />} active={tab === "search"} onClick={go("search")}>Search</BottomNavItem>
<BottomNavItem href="#saved" icon={<Star />} active={tab === "saved"} onClick={go("saved")}>Saved</BottomNavItem>
<BottomNavItem href="#me" icon={<User />} active={tab === "me"} onClick={go("me")}>Me</BottomNavItem>
</BottomNav>
</div>
);
}
Installation
$ npx uix-ui@latest add bottom-navThis copies the file into components/ui/bottom-nav.tsx in your project. npx shadcn@latest add @uix/bottom-nav works too.
Usage
import { BottomNav, BottomNavItem } from "@/components/ui/bottom-nav";
<div style={{ width: 360, maxWidth: "100%" }}>
<BottomNav>
<BottomNavItem href="#shop" icon={<House />} active={tab === "shop"} onClick={go("shop")}>Shop</BottomNavItem>
<BottomNavItem href="#search" icon={<Search />} active={tab === "search"} onClick={go("search")}>Search</BottomNavItem>
<BottomNavItem href="#saved" icon={<Star />} active={tab === "saved"} onClick={go("saved")}>Saved</BottomNavItem>
<BottomNavItem href="#me" icon={<User />} active={tab === "me"} onClick={go("me")}>Me</BottomNavItem>
</BottomNav>
</div>
Props
Bottom navigation props
| Prop | Type | Default | Description |
|---|---|---|---|
theme | light | dark | "light" |
BottomNavItemProps
| Prop | Type | Default | Description |
|---|---|---|---|
icon | React.ReactNode | – | Icon above the label. |
active | boolean | false | Marks the current tab. |
Everything else is passed to the root element, so className, aria-* and event handlers work as usual.
Dependencies
Installed for you by the CLI.
class-variance-authorityclsxtailwind-merge
lib/utils.ts
This file exports 2 parts: BottomNav, BottomNavItem. Use only the ones you need.