Tabs

A segmented control that switches between related subviews.

forms

Apple: Tab views

· Base UI: Tabs

Subviews

An event has a start and an end.

"use client"

import { Tabs, TabsList, TabsPanel, TabsTab } from "@applecn/ui/components/tabs"
import { Text } from "@applecn/ui/components/text"

export default function TabsBasic() {
  return (
    <Tabs defaultValue="event" className="w-full max-w-sm">
      <TabsList aria-label="Kind">
        <TabsTab value="event">Event</TabsTab>
        <TabsTab value="reminder">Reminder</TabsTab>
      </TabsList>
      <TabsPanel value="event">
        <Text color="label-2">An event has a start and an end.</Text>
      </TabsPanel>
      <TabsPanel value="reminder">
        <Text color="label-2">A reminder has a due date.</Text>
      </TabsPanel>
    </Tabs>
  )
}

Install

From the registry this site publishes, with dependencies resolved by the CLI.

npx shadcn@latest add https://applecn.vercel.app/r/tabs.json

Source

packages/ui/src/components/tabs.tsx

"use client"

import { Tabs as TabsPrimitive } from "@base-ui/react/tabs"
import { cn } from "cn"

import { SegmentedControlItem, SegmentedControlList } from "./segmented-control"

/**
 * Tab views: a segmented control that switches between closely related subviews (the Calendar
 * "New Event" sheet). For an app's top-level sections use `TabBar`.
 */
function Tabs({ className, ...props }: TabsPrimitive.Root.Props) {
  return (
    <TabsPrimitive.Root
      data-slot="tabs"
      className={cn("flex flex-col gap-4", className)}
      {...props}
    />
  )
}

const TabsList = SegmentedControlList
const TabsTab = SegmentedControlItem

function TabsPanel({ className, ...props }: TabsPrimitive.Panel.Props) {
  return (
    <TabsPrimitive.Panel
      data-slot="tabs-panel"
      className={cn("flex-1 type-body outline-none", className)}
      {...props}
    />
  )
}

export { Tabs, TabsList, TabsPanel, TabsTab }