Skip to content

Commit 101852c

Browse files
(feat:toggle) add id, aria props
1 parent c1f13ba commit 101852c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

frontend/src/components/ToggleSwitch.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ type ToggleSwitchProps = {
88
disabled?: boolean;
99
size?: 'small' | 'medium' | 'large';
1010
labelPosition?: 'left' | 'right';
11+
id?: string;
12+
ariaLabel?: string;
1113
};
1214

1315
const ToggleSwitch: React.FC<ToggleSwitchProps> = ({
@@ -18,13 +20,15 @@ const ToggleSwitch: React.FC<ToggleSwitchProps> = ({
1820
disabled = false,
1921
size = 'medium',
2022
labelPosition = 'left',
23+
id,
24+
ariaLabel,
2125
}) => {
2226
// Size configurations
2327
const sizeConfig = {
2428
small: {
25-
box: 'h-6 w-10',
26-
toggle: 'h-4 w-4 left-1 top-1',
27-
translate: 'translate-x-4',
29+
box: 'h-5 w-9',
30+
toggle: 'h-4 w-4 left-0.5 top-0.5',
31+
translate: 'translate-x-full',
2832
},
2933
medium: {
3034
box: 'h-8 w-14',
@@ -58,14 +62,16 @@ const ToggleSwitch: React.FC<ToggleSwitchProps> = ({
5862
<div className="relative">
5963
<input
6064
type="checkbox"
65+
id={id}
6166
checked={checked}
6267
onChange={(e) => onChange(e.target.checked)}
6368
className="sr-only"
6469
disabled={disabled}
70+
aria-label={ariaLabel}
6571
/>
6672
<div
67-
className={`box block ${box} rounded-full ${
68-
checked ? 'bg-apple-green' : 'bg-silver dark:bg-charcoal-grey'
73+
className={`block ${box} rounded-full ${
74+
checked ? 'bg-north-texas-green' : 'bg-silver dark:bg-charcoal-grey'
6975
}`}
7076
></div>
7177
<div

0 commit comments

Comments
 (0)