|
| 1 | +import type {Meta} from '@storybook/react-vite' |
| 2 | +import {action} from 'storybook/actions' |
| 3 | +import React from 'react' |
| 4 | +import {Tabs, TabList, Tab, TabPanel} from './Tabs' |
| 5 | +import Flash from '../../Flash' |
| 6 | + |
| 7 | +const meta = { |
| 8 | + title: 'Experimental/Components/Tabs/Features', |
| 9 | + component: Tabs, |
| 10 | +} satisfies Meta<typeof Tabs> |
| 11 | + |
| 12 | +export default meta |
| 13 | + |
| 14 | +export const Uncontrolled = () => ( |
| 15 | + <Tabs |
| 16 | + defaultValue="one" |
| 17 | + onValueChange={({value}) => { |
| 18 | + action('onValueChange')({value}) |
| 19 | + }} |
| 20 | + > |
| 21 | + <TabList aria-label="Tabs"> |
| 22 | + <Tab value="one">One</Tab> |
| 23 | + <Tab value="two">Two</Tab> |
| 24 | + <Tab value="three">Three</Tab> |
| 25 | + </TabList> |
| 26 | + <TabPanel value="one">Panel one</TabPanel> |
| 27 | + <TabPanel value="two">Panel two</TabPanel> |
| 28 | + <TabPanel value="three">Panel three</TabPanel> |
| 29 | + </Tabs> |
| 30 | +) |
| 31 | + |
| 32 | +export const Controlled = () => { |
| 33 | + const [value, setValue] = React.useState('one') |
| 34 | + return ( |
| 35 | + <> |
| 36 | + <Tabs |
| 37 | + value={value} |
| 38 | + onValueChange={({value}) => { |
| 39 | + action('onValueChange')({value}) |
| 40 | + setValue(value) |
| 41 | + }} |
| 42 | + > |
| 43 | + <TabList aria-label="Tabs"> |
| 44 | + <Tab value="one">One</Tab> |
| 45 | + <Tab value="two">Two</Tab> |
| 46 | + <Tab value="three">Three</Tab> |
| 47 | + </TabList> |
| 48 | + <TabPanel value="one">Panel one</TabPanel> |
| 49 | + <TabPanel value="two">Panel two</TabPanel> |
| 50 | + <TabPanel value="three">Panel three</TabPanel> |
| 51 | + </Tabs> |
| 52 | + <button |
| 53 | + type="button" |
| 54 | + onClick={() => { |
| 55 | + setValue('three') |
| 56 | + }} |
| 57 | + > |
| 58 | + Activate panel three |
| 59 | + </button> |
| 60 | + </> |
| 61 | + ) |
| 62 | +} |
| 63 | + |
| 64 | +export const Vertical = () => ( |
| 65 | + <> |
| 66 | + <Flash style={{marginBottom: '16px'}}> |
| 67 | + This example shows the `Tabs` component with `aria-orientation` set to `vertical`, which changes the keyboard |
| 68 | + navigation to Up/Down arrows. |
| 69 | + </Flash> |
| 70 | + <div |
| 71 | + style={{ |
| 72 | + display: 'grid', |
| 73 | + gridTemplateColumns: 'auto 1fr', |
| 74 | + }} |
| 75 | + > |
| 76 | + <Tabs |
| 77 | + defaultValue="one" |
| 78 | + onValueChange={({value}) => { |
| 79 | + action('onValueChange')({value}) |
| 80 | + }} |
| 81 | + > |
| 82 | + <TabList |
| 83 | + aria-orientation="vertical" |
| 84 | + style={{ |
| 85 | + display: 'flex', |
| 86 | + flexDirection: 'column', |
| 87 | + }} |
| 88 | + aria-label="Tabs" |
| 89 | + > |
| 90 | + <Tab value="one">One</Tab> |
| 91 | + <Tab value="two">Two</Tab> |
| 92 | + <Tab value="three">Three</Tab> |
| 93 | + </TabList> |
| 94 | + <TabPanel value="one">Panel one</TabPanel> |
| 95 | + <TabPanel value="two">Panel two</TabPanel> |
| 96 | + <TabPanel value="three">Panel three</TabPanel> |
| 97 | + </Tabs> |
| 98 | + </div> |
| 99 | + </> |
| 100 | +) |
0 commit comments