Tabs
Switch between panels on a page, or between routes. Comes in line, segmented, pills and button styles.
// Radix — @radix-ui/react-tabs
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@shavin/ui";States and navigation
as="states" (the default) switches panels on the page, built on Radix Tabs. as="navigation" renders links inside a nav, for moving between routes.
as="states"
March spending is $2,340, $160 under budget.
as="navigation"
const STATE_TABS = [
{ value: "overview", label: "Overview", content: <Text color="muted">March spending is $2,340, $160 under budget.</Text> },
{ value: "bills", label: "Bills", content: <Text color="muted">4 bills due this month. Rent is paid.</Text> },
{ value: "goals", label: "Goals", content: <Text color="muted">Summer trip fund is 62% of the way there.</Text> },
];
<Tabs as="states" items={STATE_TABS} />
const NAV_LINKS = [
{ value: "overview", href: "#overview", label: "Overview" },
{ value: "budgets", href: "#budgets", label: "Budgets" },
{ value: "reports", href: "#reports", label: "Reports" },
];
<Tabs as="navigation" value="overview" items={NAV_LINKS} />Active link and router links
In navigation mode a link is active when its item sets active, or when the value prop matches the item's value. Pass the current route segment as value. Links render as a plain a by default. Pass linkComponent={Link} from next/link (or your router's link) for client-side navigation. Items with external open in a new tab.
Next.js Link
import Link from "next/link";
const NAV_LINKS = [
{ value: "overview", href: "#overview", label: "Overview" },
{ value: "budgets", href: "#budgets", label: "Budgets" },
{ value: "reports", href: "#reports", label: "Reports" },
];
<Tabs as="navigation" linkComponent={Link} value="budgets" items={NAV_LINKS} />Variants
line (the default), segmented, pills and button. Both modes take the same variants.
States mode
Line
March spending is $2,340, $160 under budget.
Segmented
March spending is $2,340, $160 under budget.
Pills
March spending is $2,340, $160 under budget.
Button
March spending is $2,340, $160 under budget.
const STATE_TABS = [
{ value: "overview", label: "Overview", content: <Text color="muted">March spending is $2,340, $160 under budget.</Text> },
{ value: "bills", label: "Bills", content: <Text color="muted">4 bills due this month. Rent is paid.</Text> },
{ value: "goals", label: "Goals", content: <Text color="muted">Summer trip fund is 62% of the way there.</Text> },
];
<Tabs as="states" variant="line" items={STATE_TABS} />
<Tabs as="states" variant="segmented" items={STATE_TABS} />
<Tabs as="states" variant="pills" items={STATE_TABS} />
<Tabs as="states" variant="button" items={STATE_TABS} />Navigation mode
Line
Segmented
Pills
Button
const NAV_LINKS = [
{ value: "overview", href: "#overview", label: "Overview" },
{ value: "budgets", href: "#budgets", label: "Budgets" },
{ value: "reports", href: "#reports", label: "Reports" },
];
<Tabs as="navigation" variant="line" value="overview" items={NAV_LINKS} />
<Tabs as="navigation" variant="segmented" value="overview" items={NAV_LINKS} />
<Tabs as="navigation" variant="pills" value="overview" items={NAV_LINKS} />
<Tabs as="navigation" variant="button" value="overview" items={NAV_LINKS} />Vertical orientation
orientation="vertical" stacks the tabs, for sidebars and settings pages.
variant="line"
variant="segmented"
variant="pills"
variant="button"
const NAV_LINKS = [
{ value: "overview", href: "#overview", label: "Overview" },
{ value: "budgets", href: "#budgets", label: "Budgets" },
{ value: "reports", href: "#reports", label: "Reports" },
];
<Tabs as="navigation" variant="line" orientation="vertical" value="overview" items={NAV_LINKS} />
<Tabs as="navigation" variant="segmented" orientation="vertical" value="overview" items={NAV_LINKS} />
<Tabs as="navigation" variant="pills" orientation="vertical" value="overview" items={NAV_LINKS} />
<Tabs as="navigation" variant="button" orientation="vertical" value="overview" items={NAV_LINKS} />Sizes
size="md" is the default. size="sm" uses smaller text and padding.
size="sm"
size="md"
const NAV_LINKS = [
{ value: "overview", href: "#overview", label: "Overview" },
{ value: "budgets", href: "#budgets", label: "Budgets" },
{ value: "reports", href: "#reports", label: "Reports" },
];
<Tabs as="navigation" size="sm" value="overview" items={NAV_LINKS} />
<Tabs as="navigation" size="md" value="overview" items={NAV_LINKS} />Props
| Prop | Type | Default | Description |
|---|---|---|---|
| as | "states" | "navigation" | — | Mode: "states" for in-page stateful panels (default), "navigation" for URL routing links. |
| variant | TabVariant | — | Visual variant: "line" (default), "segmented", "pills", or "button". |
| orientation | "horizontal" | "vertical" | — | Layout orientation: "horizontal" (default) or "vertical". |
| size | "sm" | "md" | — | Component size: "sm" (small) or "md" (medium, default). |
| value | string | — | — |
| defaultValue | string | — | — |
| onValueChange | (value: string) => void | — | — |
| items | readonly TabItem[] | — | List of tab items. |
| tabs | readonly TabItem[] | — | Alias for items when passing data-driven tabs. |
| linkComponent | ElementType | — | Router component for as="navigation" mode (defaults to "a"). |
| children | ReactNode | — | — |
| className | string | — | — |