Skip to content

Commit 9078414

Browse files
authored
feat: Refactor SwitchInput component to accept a className prop (#15)
1 parent 43884f8 commit 9078414

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/Components/SwitchInput/SwitchInput.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import { useState, useEffect, ReactNode } from 'react';
22
import { Switch } from '@headlessui/react';
33
import classNames from 'classnames';
4+
import { twMerge } from 'tailwind-merge';
45

56
type Props = {
67
label: string;
78
initialValue?: boolean;
89
help?: ReactNode;
910
disabled?: boolean;
11+
className?: string;
1012
onChange?: (status: boolean) => void;
1113
};
1214

13-
const SwitchInput = ({ initialValue = false, label, help, disabled = false, onChange }: Props) => {
15+
const SwitchInput = ({
16+
initialValue = false,
17+
label,
18+
help,
19+
disabled = false,
20+
className,
21+
onChange,
22+
}: Props) => {
1423
const [enabled, setState] = useState(initialValue);
1524

1625
// Reset the state when the initialValue changes
@@ -27,7 +36,7 @@ const SwitchInput = ({ initialValue = false, label, help, disabled = false, onCh
2736
};
2837

2938
return (
30-
<Switch.Group as="div" className="relative flex items-start">
39+
<Switch.Group as="div" className={twMerge('relative flex items-start mb-4', className)}>
3140
<Switch
3241
checked={enabled}
3342
disabled={disabled}

0 commit comments

Comments
 (0)