import { fn } from '@storybook/test'; import { Button, Tooltip, Slot, Fill, SlotFillProvider } from '@wordpress/components'; import { wordpress, more, link } from '@wordpress/icons'; import { useState } from 'react'; import { Tabs } from '..'; import { Icon } from '../../icon'; import type { Meta, StoryFn } from '@storybook/react'; const meta: Meta< typeof Tabs > = { title: 'Tabs', id: 'components-tabs', component: Tabs, subcomponents: { 'Tabs.TabList': Tabs.TabList, 'Tabs.Tab': Tabs.Tab, 'Tabs.TabPanel': Tabs.TabPanel, }, parameters: { actions: { argTypesRegex: '^on.*' }, controls: { expanded: true }, docs: { canvas: { sourceState: 'shown' } }, }, args: { onActiveTabIdChange: fn(), onSelect: fn(), }, }; export default meta; const Template: StoryFn< typeof Tabs > = ( props ) => { return ( Tab 1 Tab 2 Tab 3

Selected tab: Tab 1

Selected tab: Tab 2

Selected tab: Tab 3

This tabpanel has its focusable prop set to false, so it won't get a tab stop.
Instead, the [Tab] key will move focus to the first focusable element within the panel.

); }; const CompactTemplate: StoryFn< typeof Tabs > = ( props ) => { return ( Tab 1 Tab 2 Tab 3

Selected tab: Tab 1

Selected tab: Tab 2

Selected tab: Tab 3

This tabpanel has its focusable prop set to false, so it won't get a tab stop.
Instead, the [Tab] key will move focus to the first focusable element within the panel.

); }; export const Default = Template.bind( {} ); export const Compact = CompactTemplate.bind( {} ); export const SizeAndOverflowPlayground: StoryFn< typeof Tabs > = ( props ) => { const [ fullWidth, setFullWidth ] = useState( false ); return (

This story helps understand how the TabList component behaves under different conditions. The container below (with the dotted red border) can be horizontally resized, and it has a bit of padding to be out of the way of the TabList.

The button will toggle between full width (adding width: 100%) and the default width.

Try the following:

Label with multiple words Short Hippopotomonstrosesquippedaliophobia Tab 4 Tab 5

Selected tab: Tab 1

(Label with multiple words)

Selected tab: Tab 2

(Short)

Selected tab: Tab 3

(Hippopotomonstrosesquippedaliophobia)

Selected tab: Tab 4

Selected tab: Tab 5

); }; SizeAndOverflowPlayground.args = { defaultTabId: 'tab4', }; const VerticalTemplate: StoryFn< typeof Tabs > = ( props ) => { return ( Tab 1 Tab 2 Tab 3 ); }; export const Vertical = VerticalTemplate.bind( {} ); const DisabledTabTemplate: StoryFn< typeof Tabs > = ( props ) => { return ( Tab 1 Tab 2 Tab 3

Selected tab: Tab 1

Selected tab: Tab 2

Selected tab: Tab 3

); }; export const DisabledTab = DisabledTabTemplate.bind( {} ); const WithTabIconsAndTooltipsTemplate: StoryFn< typeof Tabs > = ( props ) => { return ( { [ { id: 'tab1', label: 'Tab one', icon: wordpress, }, { id: 'tab2', label: 'Tab two', icon: link, }, { id: 'tab3', label: 'Tab three', icon: more, }, ].map( ( { id, label, icon } ) => ( ) ) }

Selected tab: Tab 1

Selected tab: Tab 2

Selected tab: Tab 3

); }; export const WithTabIconsAndTooltips = WithTabIconsAndTooltipsTemplate.bind( {} ); export const ManualActivation = Template.bind( {} ); ManualActivation.args = { selectOnMove: false, }; const UsingSlotFillTemplate: StoryFn< typeof Tabs > = ( props ) => { return ( Tab 1 Tab 2 Tab 3

Selected tab: Tab 1

Selected tab: Tab 2

Selected tab: Tab 3

other stuff

other stuff

this is fun!

other stuff

); }; export const UsingSlotFill = UsingSlotFillTemplate.bind( {} ); UsingSlotFill.storyName = 'Using SlotFill'; const CloseButtonTemplate: StoryFn< typeof Tabs > = ( props ) => { const [ isOpen, setIsOpen ] = useState( true ); return ( <> { isOpen ? (
Tab 1 Tab 2 Tab 3

Selected tab: Tab 1

Selected tab: Tab 2

Selected tab: Tab 3

) : ( ) } ); }; export const InsertCustomElements = CloseButtonTemplate.bind( {} );