You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
788 B
34 lines
788 B
import React from 'react';
|
|
|
|
import { Switch } from '@headlessui/react';
|
|
|
|
interface ToggleSwitchProps {
|
|
active: boolean;
|
|
toggle?: Function;
|
|
}
|
|
|
|
const ToggleSwitch = (props: ToggleSwitchProps) => {
|
|
const [active, setActive] = React.useState(false);
|
|
|
|
React.useEffect(() => {
|
|
setActive(props.active);
|
|
}, []);
|
|
|
|
return (
|
|
<Switch
|
|
checked={active}
|
|
onChange={setActive}
|
|
className={`w-12 h-6 flex items-center bg-gray-300 rounded-full p-1 duration-300 ease-in-out my-auto ${
|
|
active ? 'bg-green-400' : null
|
|
}`}
|
|
>
|
|
<span
|
|
className={`bg-white w-4 h-4 rounded-full shadow-md transform duration-300 ease-in-out ${
|
|
active ? 'translate-x-6' : null
|
|
}`}
|
|
></span>
|
|
</Switch>
|
|
);
|
|
};
|
|
|
|
export default ToggleSwitch;
|
|
|