Skip to content

Commit 795b30b

Browse files
petrapazkresimir-coko
authored andcommitted
3610 - refactor switch
1 parent 3149b13 commit 795b30b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

client/src/components/Switch/Switch.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import {Switch as ShadcnSwitch} from '@/components/ui/switch';
2-
import * as React from 'react';
2+
import {ComponentPropsWithoutRef, ElementRef, ReactNode, forwardRef} from 'react';
33
import {twMerge} from 'tailwind-merge';
44

5-
interface BaseSwitchProps extends Omit<
6-
React.ComponentPropsWithoutRef<typeof ShadcnSwitch>,
7-
'checked' | 'onCheckedChange'
8-
> {
5+
interface BaseSwitchProps extends Omit<ComponentPropsWithoutRef<typeof ShadcnSwitch>, 'checked' | 'onCheckedChange'> {
96
variant?: VariantType;
107
checked?: boolean;
118
onCheckedChange?: (checked: boolean) => void;
129
}
1310

1411
interface LabeledSwitchProps extends BaseSwitchProps {
15-
label: React.ReactNode;
16-
description?: React.ReactNode;
12+
label: ReactNode;
13+
description?: ReactNode;
1714
alignment?: AlignmentType;
1815
}
1916

@@ -52,8 +49,8 @@ const wrapperStyles: Record<VariantType, string> = {
5249
};
5350

5451
interface TextBlockProps {
55-
label: React.ReactNode;
56-
description?: React.ReactNode;
52+
label: ReactNode;
53+
description?: ReactNode;
5754
variant: VariantType;
5855
}
5956

@@ -78,7 +75,7 @@ function TextBlock({description, label, variant}: TextBlockProps) {
7875
);
7976
}
8077

81-
const Switch = React.forwardRef<React.ElementRef<typeof ShadcnSwitch>, SwitchPropsType>(
78+
const Switch = forwardRef<ElementRef<typeof ShadcnSwitch>, SwitchPropsType>(
8279
(
8380
{
8481
alignment = 'start',
@@ -124,6 +121,7 @@ const Switch = React.forwardRef<React.ElementRef<typeof ShadcnSwitch>, SwitchPro
124121
}
125122

126123
const isBoxVariant = variant === 'box';
124+
127125
const wrapperClasses = twMerge(
128126
wrapperStyles[variant],
129127
isBoxVariant && checked ? 'bg-surface-brand-secondary border-stroke-brand-secondary' : ''

0 commit comments

Comments
 (0)