import { BADGE } from '@geometricpanda/storybook-addon-badges'; import type { Meta, StoryObj } from '@storybook/react'; import React from 'react'; import { Tabs } from '@components/components/Tabs/Tabs'; const exampleTabs = [ { key: 'tab1', name: 'Tab One', tooltip: 'Tooltip for Tab One', component:
This is the content for Tab One
, }, { key: 'tab2', name: 'Tab Two', tooltip: 'Tooltip for Tab Two', component:
This is the content for Tab Two
, }, { key: 'tab3', name: 'Tab Three', tooltip: 'Tooltip for Tab Three', component:
This is the content for Tab Three
, }, ]; const urlAwareTabs = [ { key: 'overview', name: 'Overview', tooltip: 'View the overview', component:
This is the overview content
, }, { key: 'details', name: 'Details', tooltip: 'View the details', component:
This is the details content
, }, { key: 'settings', name: 'Settings', tooltip: 'View the settings', component:
This is the settings content
, }, ]; const urlMap = { overview: '/overview', details: '/details', settings: '/settings', }; // Auto Docs const meta = { title: 'Components / Tabs', component: Tabs, // Display Properties parameters: { layout: 'centered', badges: [BADGE.BETA], docs: { subtitle: 'A component for rendering tabs where you can select and render content under them', }, }, // Component-level argTypes argTypes: { tabs: { description: 'The tabs you want to display', }, selectedTab: { description: 'A controlled pieces of state for which tab is selected. This is the key of the tab', }, onChange: { description: 'The handler called when any tab is clicked', }, urlMap: { description: 'A mapping of tab keys to URLs. When provided, the component will sync tab selection with the URL', }, onUrlChange: { description: 'A custom handler for URL changes. Defaults to window.history.replaceState', }, defaultTab: { description: 'The default tab to select when the URL does not match any tab', }, getCurrentUrl: { description: 'A custom function to get the current URL. Defaults to window.location.pathname', }, }, // Args for the story args: { tabs: exampleTabs, }, } satisfies Meta; export default meta; type Story = StoryObj; export const sandbox: Story = { tags: ['dev'], render: (props) => (
), }; const UrlAwareTabsDemo = () => { const [selectedTab, setSelectedTab] = React.useState('overview'); return (

Current URL: {window.location.pathname}

Selected Tab: {selectedTab}

); }; export const urlAware: Story = { tags: ['dev'], render: () => , };