Tabs
Shows one of several views of the same thing at a time, with their names in a row to switch between them.
import { Tabs } from '@sypnia/ui/react'
Views of a table
Use the arrow keys once a tab has the focus.
Rows
Columns
Access rules
API
1,204 rows. The newest order was placed 4 minutes ago.
Code
import { KeyValue, Tabs } from '@sypnia/ui/react';
// Arrow keys move between tabs; Tab goes into the panel.
export default function Basic() {
return (
<Tabs label="Table orders" items={[
{ id: 'rows', label: 'Rows', icon: 'table', content: <p className="sy-text--sm sy-text--soft">1,204 rows. The newest order was placed 4 minutes ago.</p> },
{ id: 'columns', label: 'Columns', content: <KeyValue items={[['id', 'number, primary key'], ['customer_id', 'number'], ['total', 'number'], ['status', 'text']]} /> },
{ id: 'rules', label: 'Access rules', icon: 'shield', content: <p className="sy-text--sm sy-text--soft">2 rules. Customers see only their own orders.</p> },
{ id: 'api', label: 'API', content: <p className="sy-text--sm sy-machine">GET https://storefront.sypnia.app/orders</p> },
]} />
);
} Opened from outside, with counts
The button under the tabs opens «Failed».
All 1.2K
Pending 18
Failed 3
18 orders are waiting for payment.
Code
import { useState } from 'react';
import { Button, Count, Tabs } from '@sypnia/ui/react';
// The app decides which tab is open, for example from the address of the page.
export default function Controlled() {
const [tab, setTab] = useState('pending');
return (
<div className="sy-stack">
<Tabs label="Orders by state" selected={tab} onChange={setTab} items={[
{ id: 'all', label: <>All <Count value={1204} /></>, content: <p className="sy-text--sm sy-text--soft">Every order, newest first.</p> },
{ id: 'pending', label: <>Pending <Count value={18} tone="warn" /></>, content: <p className="sy-text--sm sy-text--soft">18 orders are waiting for payment.</p> },
{ id: 'failed', label: <>Failed <Count value={3} tone="fail" /></>, content: <p className="sy-text--sm sy-text--soft">3 payments were rejected by the bank.</p> },
]} />
<div><Button size="sm" onClick={() => setTab('failed')}>Go to the failed ones</Button></div>
</div>
);
} A tab that is not available
It stays in its place, greyed.
General
Team
Billing
Delete
Name, region and plan.
Code
import { Tabs } from '@sypnia/ui/react';
// A tab that is not available stays visible, greyed, and the arrow keys skip it.
export default function Disabled() {
return (
<Tabs label="Project settings" items={[
{ id: 'general', label: 'General', content: <p className="sy-text--sm sy-text--soft">Name, region and plan.</p> },
{ id: 'team', label: 'Team', content: <p className="sy-text--sm sy-text--soft">4 members.</p> },
{ id: 'billing', label: 'Billing', disabled: true },
{ id: 'danger', label: 'Delete', content: <p className="sy-text--sm sy-text--soft">Delete the project and everything in it.</p> },
]} />
);
} Skeleton
The real piece and its skeleton: the same box, so nothing moves when the data arrives.
Rows
Columns
Access
Code
import { Tabs, TabsSkeleton } from '@sypnia/ui/react';
// The tabs and their skeleton: the same row, so the content under them does not move.
export default function Skeleton() {
return (
<div className="sy-grid">
<Tabs label="Table orders" items={[{ id: 'rows', label: 'Rows' }, { id: 'columns', label: 'Columns' }, { id: 'policies', label: 'Access' }]} />
<TabsSkeleton items={3} />
</div>
);
} When to use it
Use it when
- One thing has several sides: the rows, columns, rules and API of a table.
- The views are alike in importance and the person moves between them often.
- Two to six tabs with short names. A Count beside a name says how much is behind it.
Do not use it when
- The options change how the same content is shown or filtered: SegmentedControl.
- They are steps to follow in order: Stepper.
- They lead to different pages of the app: that is navigation.
- There are so many that they would not fit: use a NativeSelect or split the page.
For everyone
- The row is one Tab stop. Arrow keys move between tabs and open them as they move; Home and End go to the ends; disabled tabs are skipped.
- Each tab says whether it is selected and is tied to its panel, which is reached with Tab.
- On phones the tabs sit two by two as buttons; nothing scrolls sideways.
- The selected tab has a lit dot and stronger text, not colour alone.
Props
| Tabs | Type | Default |
|---|---|---|
itemsrequired | TabItem[] | |
labelrequired | string | |
onChange | ((id: string) => void) | |
selected | string |