Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,232 Bytes
6294700 d2a6779 6294700 d2a6779 6294700 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import classNames from "classnames";
import { useState } from "react";
import { useUpdateEffect } from "react-use";
interface Props {
label: string;
checked: boolean;
onChange: (checked: boolean) => void;
}
export const Toggle: React.FC<Props> = ({ label, onChange, checked }) => {
const [checkedState, setCheckedState] = useState(checked);
useUpdateEffect(() => onChange(checkedState), [checkedState]);
return (
<div className="w-full flex items-center justify-start gap-2.5">
<label className="text-slate-400 text-sm font-medium capitalize">
{label}:
</label>
<div
className={classNames(
"w-[52px] h-[24px] rounded-full p-[4px] relative cursor-pointer",
{
"bg-red-700": !checkedState,
"bg-green-500": checkedState,
}
)}
onClick={() => setCheckedState(!checkedState)}
>
<div
className={classNames(
"rounded-full h-[16px] w-[16px] bg-slate-50 shadow-xl absolute top-[4px] transition-all duration-200",
{
"left-[4px]": !checkedState,
"left-[31px]": checkedState,
}
)}
/>
</div>
</div>
);
};
|