Files
DABEEO-DETECTION-APPLICATION/web-app/app/shared/components/switch/Switch.stories.tsx

133 lines
3.0 KiB
TypeScript

import type { Meta, StoryObj } from '@storybook/react'
import { useState } from 'react'
import { Switch } from './Switch'
const meta = {
title: 'Components/Switch',
component: Switch,
argTypes: {
isDisabled: {
control: 'boolean',
},
isReadOnly: {
control: 'boolean',
},
},
} satisfies Meta<typeof Switch>
export default meta
type Story = StoryObj<typeof meta>
export const Default: Story = {
args: {
children: '알림 설정',
},
}
export const Selected: Story = {
render: function Render() {
const [isSelected, setIsSelected] = useState(true)
return (
<Switch isSelected={isSelected} onChange={setIsSelected}>
</Switch>
)
},
}
export const Unselected: Story = {
render: function Render() {
const [isSelected, setIsSelected] = useState(false)
return (
<Switch isSelected={isSelected} onChange={setIsSelected}>
</Switch>
)
},
}
export const Disabled: Story = {
args: {
isDisabled: true,
children: '비활성화된 스위치',
},
}
export const DisabledSelected: Story = {
args: {
isDisabled: true,
isSelected: true,
children: '비활성화됨 (켜짐)',
},
}
export const ReadOnly: Story = {
args: {
isReadOnly: true,
isSelected: true,
children: '읽기 전용',
},
}
export const WithoutLabel: Story = {
args: {},
}
export const Controlled: Story = {
render: function Render() {
const [isSelected, setIsSelected] = useState(false)
return (
<div className="space-y-4">
<Switch isSelected={isSelected} onChange={setIsSelected}>
</Switch>
<p className="text-sm text-gray-600">: {isSelected ? '켜짐' : '꺼짐'}</p>
</div>
)
},
}
export const MultipleSettings: Story = {
render: function Render() {
const [settings, setSettings] = useState({
notifications: true,
darkMode: false,
autoSave: true,
})
const handleChange = (key: keyof typeof settings) => (isSelected: boolean) => {
setSettings((prev) => ({ ...prev, [key]: isSelected }))
}
return (
<div className="space-y-4">
<Switch isSelected={settings.notifications} onChange={handleChange('notifications')}>
</Switch>
<Switch isSelected={settings.darkMode} onChange={handleChange('darkMode')}>
</Switch>
<Switch isSelected={settings.autoSave} onChange={handleChange('autoSave')}>
</Switch>
</div>
)
},
}
export const AllStates: Story = {
render: () => (
<div className="space-y-4">
<Switch> ()</Switch>
<Switch isSelected> ()</Switch>
<Switch isDisabled> ()</Switch>
<Switch isDisabled isSelected>
()
</Switch>
<Switch isReadOnly isSelected>
</Switch>
</div>
),
}