Skip to content

Commit a2d3f74

Browse files
authored
fix toggleswitch color when checked #542 (#545)
* fix(toggleswitch): only add color when toggle is checked * chore(toggleswitch): make ToggleSwitch story interactive
1 parent cef730a commit a2d3f74

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/lib/components/ToggleSwitch/ToggleSwitch.stories.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Meta, Story } from '@storybook/react/types-6-0';
2+
import { useState } from 'react';
23
import theme from '../../theme/default';
34
import type { ToggleSwitchProps } from './ToggleSwitch';
45
import { ToggleSwitch } from './ToggleSwitch';
@@ -10,7 +11,15 @@ export default {
1011
component: ToggleSwitch,
1112
} as Meta;
1213

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+
};
1423

1524
export const DefaultToggleSwitch = Template.bind({});
1625
DefaultToggleSwitch.storyName = 'Toggle switch';

src/lib/components/ToggleSwitch/ToggleSwitch.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const ToggleSwitch: FC<ToggleSwitchProps> = ({
7171
className={classNames(
7272
theme.toggle.base,
7373
theme.toggle.checked[checked ? 'on' : 'off'],
74-
!disabled && theme.toggle.checked.color[color],
74+
!disabled && checked && theme.toggle.checked.color[color],
7575
)}
7676
/>
7777
<span

0 commit comments

Comments
 (0)