Synertech Web/ui v0.57.5 Site Storybook

Documentation / Navigation & actions

Tabs

Client@synertech/uiOpen in Storybook

Tabs to switch between several views of the same context without leaving the page. The component is composed: Tabs holds the state, TabsList lines up the TabsTriggers, and each TabsContent shows when its value is the active tab’s.

Uncontrolled with defaultValue (set it, otherwise no tab is active at first), controlled with value + onValueChange. Four styles (underline, pills, enclosed, soft), six colours, three sizes, horizontal or vertical. An inactive panel is unmounted, unless forceMount keeps it hidden in the DOM.

From the keyboard, one tab is in the tab order: the arrow keys, Home and End move from one to the next, skipping disabled tabs, and the tab they land on is selected. The arrows follow the layout (up and down when vertical) and the reading direction. Each panel is named by its tab (aria-labelledby). Client component ("use client").

Examples

Basic usage

The default underline; defaultValue names the tab open at first.

Open in a tab
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@synertech/ui";

export function Basic() {
  return (
    <Tabs defaultValue="apercu">
      <TabsList>
        <TabsTrigger value="apercu">Aperçu</TabsTrigger>
        <TabsTrigger value="activite">Activité</TabsTrigger>
        <TabsTrigger value="parametres">Paramètres</TabsTrigger>
      </TabsList>
      <TabsContent value="apercu">Résumé du projet et indicateurs clés.</TabsContent>
      <TabsContent value="activite">Les dernières modifications de l’équipe.</TabsContent>
      <TabsContent value="parametres">Nom, visibilité et membres du projet.</TabsContent>
    </Tabs>
  );
}

Styles and colours

variant changes the shape of the active tab, color its hue.

Open in a tab
import { Tabs, TabsList, TabsTrigger } from "@synertech/ui";

export function Variants() {
  return (
    <div className="space-y-6">
      {(["pills", "enclosed", "soft"] as const).map((variant) => (
        <Tabs key={variant} defaultValue="mois" variant={variant} color="primary" size="sm">
          <TabsList gap={variant === "enclosed" ? "none" : "sm"}>
            <TabsTrigger value="semaine">Semaine</TabsTrigger>
            <TabsTrigger value="mois">Mois</TabsTrigger>
            <TabsTrigger value="annee">Année</TabsTrigger>
          </TabsList>
        </Tabs>
      ))}
    </div>
  );
}

Icons, counter and disabled tab

icon and endIcon frame the label; disabled makes a tab unreachable.

Open in a tab
import { Badge, Tabs, TabsContent, TabsList, TabsTrigger } from "@synertech/ui";

const UserIcon = () => (
  <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2} aria-hidden="true">
    <path
      strokeLinecap="round"
      strokeLinejoin="round"
      d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"
    />
  </svg>
);

export function WithIcons() {
  return (
    <Tabs defaultValue="profil" variant="pills" fullWidth>
      <TabsList>
        <TabsTrigger value="profil" icon={<UserIcon />}>
          Profil
        </TabsTrigger>
        <TabsTrigger
          value="messages"
          endIcon={
            <Badge size="sm" color="error">
              4
            </Badge>
          }
        >
          Messages
        </TabsTrigger>
        <TabsTrigger value="equipe" disabled>
          Équipe
        </TabsTrigger>
      </TabsList>
      <TabsContent value="profil">Vos informations personnelles.</TabsContent>
      <TabsContent value="messages">Quatre messages non lus.</TabsContent>
    </Tabs>
  );
}

Vertical tabs

orientation="vertical" puts the list to the left of the panels, like a settings page.

Open in a tab
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@synertech/ui";

export function Vertical() {
  return (
    <Tabs defaultValue="general" orientation="vertical" variant="soft">
      <TabsList>
        <TabsTrigger value="general">Général</TabsTrigger>
        <TabsTrigger value="securite">Sécurité</TabsTrigger>
        <TabsTrigger value="notifications">Notifications</TabsTrigger>
      </TabsList>
      <TabsContent value="general" className="mt-0">
        Langue, fuseau horaire et format des dates.
      </TabsContent>
      <TabsContent value="securite" className="mt-0">
        Mot de passe et double authentification.
      </TabsContent>
      <TabsContent value="notifications" className="mt-0">
        E-mails et alertes dans l’application.
      </TabsContent>
    </Tabs>
  );
}

Controlled mode

value and onValueChange let the application switch tabs, here from a link.

Open in a tab
import { useState } from "react";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@synertech/ui";

export function Controlled() {
  const [tab, setTab] = useState("commande");

  return (
    <Tabs value={tab} onValueChange={setTab}>
      <TabsList>
        <TabsTrigger value="commande">Commande</TabsTrigger>
        <TabsTrigger value="livraison">Livraison</TabsTrigger>
      </TabsList>
      <TabsContent value="commande">
        3 articles, 128,40 €.{" "}
        <button
          type="button"
          className="text-blue-600 underline"
          onClick={() => setTab("livraison")}
        >
          Choisir la livraison
        </button>
      </TabsContent>
      <TabsContent value="livraison">Livraison prévue sous 48 h.</TabsContent>
    </Tabs>
  );
}

API reference

Components

Tabs

ComponentClient
import { Tabs } from "@synertech/ui";

Props — TabsProps

PropTypeDefaultDescription
children• ReactNode —
className string —
color TabsColor "default"
defaultValue string ""
fullWidth boolean false
onValueChange (value: string) => void —
orientation TabsOrientation "horizontal"
size TabsSize "md"
value string —
variant TabsVariant "underline"

TabsContent

ComponentClient
import { TabsContent } from "@synertech/ui";

Props — TabsContentProps

PropTypeDefaultDescription
children• ReactNode —
value• string —
className string —
forceMount boolean false

TabsList

ComponentClient
import { TabsList } from "@synertech/ui";

Props — TabsListProps

PropTypeDefaultDescription
children• ReactNode —
bgColor string —
className string —
gap "none" | "sm" | "md" | "lg" "none"

TabsTrigger

ComponentClient
import { TabsTrigger } from "@synertech/ui";

Props — TabsTriggerProps

PropTypeDefaultDescription
children• ReactNode —
value• string —
activeClassName string —
className string —
disabled boolean false
endIcon ReactNode —
icon ReactNode —
inactiveClassName string —

Types

type TabsColor = "default" | "primary" | "secondary" | "success" | "warning" | "error"
type TabsOrientation = "horizontal" | "vertical"
type TabsSize = "sm" | "md" | "lg"
type TabsVariant = "underline" | "pills" | "enclosed" | "soft"