/* eslint-disable no-alert */ import { useCallback, useState } from 'react' import { type Meta, type StoryFn, type StoryObj } from '@storybook/react' import { noop } from '~/src/utils/function' import { isFunction } from '~/src/utils/type' import { Center } from '~/src/components/Center' import { Text } from '~/src/components/Text' import { TabAction, TabActions, TabContent, TabItem, TabItems, TabList, Tabs, } from './Tabs' import { type TabActionProps, type TabListProps, type TabsProps, } from './Tabs.types' type TabsCompositionProps = TabsProps & TabListProps & TabActionProps function TabsComposition({ activationMode, defaultValue, value, size, onValueChange, }: TabsCompositionProps) { const [currentValue, setCurrentValue] = useState(value ?? defaultValue) const handleValueChange = useCallback( (_value: typeof value) => { setCurrentValue(_value) if (isFunction(onValueChange)) { onValueChange(_value as string) } }, [onValueChange] ) return (
Tab1 Tab2 LongLongLabelTab Sub1 { window.alert('Hi!') }} > Sub2
Tab1 content
Tab2 content
LongLongLabelTab content
) } const meta: Meta = { component: TabsComposition, argTypes: { size: { control: { type: 'radio', }, options: ['s', 'm', 'l'], }, onValueChange: { action: 'clicked', }, }, } export default meta const Template: StoryFn = TabsComposition export const Composition: StoryObj = { render: Template, args: { size: 'm', onValueChange: noop, defaultValue: undefined, activationMode: 'automatic', value: 'One', }, } export const UnControlled: StoryObj = { render: Template, args: { size: 'm', onValueChange: noop, defaultValue: 'One', activationMode: 'automatic', }, }