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 1Tab 2
Tab 3
Disabled Tab
Tab 4Tab 5Content 1Content 2Content 3Content 4Content 4Content 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 1Tab 2Content 1Content 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.