Skip to content

Commit ec0c41d

Browse files
author
Roman Snapko
authored
Add pill variant to ToggleSwitch component with Storybook stories (#2153)
<!-- Ensure the title clearly reflects what was changed. Provide a clear and concise description of the changes made. The PR should only contain the changes related to the issue, and no other unrelated changes. --> Fixes OPS-3925
1 parent 70f424d commit ec0c41d

2 files changed

Lines changed: 31 additions & 7 deletions

File tree

packages/ui-components/src/components/toggle-switch/toggle-switch.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Props = {
1515
onChange?: (value: string) => void;
1616
disabled?: boolean;
1717
className?: string;
18+
variant?: 'default' | 'pill';
1819
};
1920

2021
const ToggleSwitch = ({
@@ -23,6 +24,7 @@ const ToggleSwitch = ({
2324
onChange,
2425
disabled,
2526
className,
27+
variant = 'default',
2628
}: Props) => {
2729
const [selectedValue, setSelectedValue] = useState<string>(
2830
defaultValue ?? options[0].value,
@@ -42,7 +44,12 @@ const ToggleSwitch = ({
4244
value={selectedValue}
4345
onValueChange={handleValueChange}
4446
className={cn(
45-
'inline-flex bg-background border rounded-[4px] p-[1px] gap-[2px]',
47+
'inline-flex border gap-[2px]',
48+
{
49+
'bg-gray-100 dark:bg-gray-900 rounded-[40px] py-[6px] px-[8px] h-[54px]':
50+
variant === 'pill',
51+
'bg-background rounded-[4px] p-[1px]': variant !== 'pill',
52+
},
4653
className,
4754
)}
4855
variant="outline"
@@ -57,12 +64,12 @@ const ToggleSwitch = ({
5764
<ToggleGroupItem
5865
value={option.value}
5966
size="xs"
60-
className={cn(
61-
'w-[66px] px-2 py-1',
62-
'rounded text-sm font-normal transition-colors aria-checked:bg-gray-200 dark:aria-checked:bg-gray-800',
63-
'border-0',
64-
'rounded-[4px]',
65-
)}
67+
className={cn('text-sm transition-colors border-0', {
68+
'px-5 h-[42px] rounded-[40px] font-medium aria-checked:bg-primary-200 aria-checked:text-background':
69+
variant === 'pill',
70+
'w-[66px] px-2 py-1 rounded-[4px] font-normal aria-checked:bg-gray-200 dark:aria-checked:bg-gray-800':
71+
variant !== 'pill',
72+
})}
6673
>
6774
{option.label}
6875
</ToggleGroupItem>

packages/ui-components/src/stories/toggle-switch/toggle-switch.stories.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,21 @@ export const Disabled: Story = {
8787
},
8888
};
8989

90+
export const Pill: Story = {
91+
args: {
92+
options,
93+
variant: 'pill',
94+
onChange: action('onChange'),
95+
},
96+
};
97+
98+
export const PillDisabled: Story = {
99+
args: {
100+
options,
101+
variant: 'pill',
102+
disabled: true,
103+
onChange: action('onChange'),
104+
},
105+
};
106+
90107
export default meta;

0 commit comments

Comments
 (0)