import React, { useState } from 'react' import { type Meta, type StoryObj } from '@storybook/react' import { Button } from '~components/Button' import { Text } from '~components/Text' import { Tab, TabList, TabPanel, Tabs, type Key } from '../index' const meta = { title: 'Components/Tabs', component: Tabs, args: { children: ( <> Tab 1 Tab 2 Tab 3 Disabled Tab Tab 4 Tab 5 Content 1 Content 2 Content 3 Content 4 Content 4 Content 5 ), }, } satisfies Meta export default meta type Story = StoryObj export const Playground: Story = { parameters: { chromatic: { disable: false }, docs: { canvas: { sourceState: 'shown', }, }, }, args: { defaultSelectedKey: 'one', onSelectionChange: (key): void => console.log('Tab changed to ', key), }, } export const Controlled: Story = { render: () => { const [selectedKey, setSelectedKey] = useState(0) return ( <> Tab 1 Tab 2 Content 1 Content 2 ) }, } /** * When a tab is selected via user interaction, `TabList` scrolls the selected tab * into view within its horizontal strip. It deliberately does *not* do this on * mount — so when `Tabs` render below the fold, landing on the page does not scroll * the tabs into view or jump the page. * * This story pushes the `Tabs` below the fold with a full-viewport spacer. On load * the page stays at the top. Scroll down and select a tab — only then does the * selected tab scroll into view within the strip. */ export const BelowTheFold: Story = { render: () => (
Scroll down — the tabs are rendered below the fold.
{Array.from({ length: 8 }, (_, i) => ( Lorem {i + 1} ))} {Array.from({ length: 8 }, (_, i) => ( Lorem ipsum dolor sit amet, consectetur adipiscing elit — panel {i + 1}. ))}
), }