File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
src/lib/components/ToggleSwitch Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 1
1
import type { Meta , Story } from '@storybook/react/types-6-0' ;
2
+ import { useState } from 'react' ;
2
3
import theme from '../../theme/default' ;
3
4
import type { ToggleSwitchProps } from './ToggleSwitch' ;
4
5
import { ToggleSwitch } from './ToggleSwitch' ;
@@ -10,7 +11,15 @@ export default {
10
11
component : ToggleSwitch ,
11
12
} as Meta ;
12
13
13
- const Template : Story < ToggleSwitchProps > = ( args ) => < ToggleSwitch { ...args } /> ;
14
+ const Template : Story < ToggleSwitchProps > = ( { checked, onChange, ...args } ) => {
15
+ const [ switchChecked , setSwitchChecked ] = useState ( checked ) ;
16
+
17
+ const handleChange = ( ) => {
18
+ setSwitchChecked ( ( currentCheck ) => ! currentCheck ) ;
19
+ } ;
20
+
21
+ return < ToggleSwitch checked = { switchChecked } onChange = { handleChange } { ...args } /> ;
22
+ } ;
14
23
15
24
export const DefaultToggleSwitch = Template . bind ( { } ) ;
16
25
DefaultToggleSwitch . storyName = 'Toggle switch' ;
Original file line number Diff line number Diff line change @@ -71,7 +71,7 @@ export const ToggleSwitch: FC<ToggleSwitchProps> = ({
71
71
className = { classNames (
72
72
theme . toggle . base ,
73
73
theme . toggle . checked [ checked ? 'on' : 'off' ] ,
74
- ! disabled && theme . toggle . checked . color [ color ] ,
74
+ ! disabled && checked && theme . toggle . checked . color [ color ] ,
75
75
) }
76
76
/>
77
77
< span
You can’t perform that action at this time.
0 commit comments