mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-25 13:57:11 +02:00
First public commit
This commit is contained in:
commit
e05cd62e53
228 changed files with 17717 additions and 0 deletions
43
components/switch.tsx
Normal file
43
components/switch.tsx
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { Switch as HeadlessSwitch } from "@headlessui/react";
|
||||
import clsx from "clsx";
|
||||
import * as React from "react";
|
||||
|
||||
export interface SwitchProps {
|
||||
checked?: boolean;
|
||||
onChange: (checked: boolean) => void;
|
||||
srDescription?: string;
|
||||
}
|
||||
|
||||
const Switch: React.VoidFunctionComponent<SwitchProps> = ({
|
||||
checked = false,
|
||||
onChange,
|
||||
srDescription,
|
||||
}) => {
|
||||
return (
|
||||
<HeadlessSwitch
|
||||
checked={checked}
|
||||
onChange={onChange}
|
||||
className={clsx(
|
||||
"relative inline-flex flex-shrink-0 h-6 w-10 border-2 border-transparent rounded-full cursor-pointer transition-colors ease-in-out duration-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75",
|
||||
{
|
||||
"bg-gray-200": !checked,
|
||||
"bg-green-500": checked,
|
||||
},
|
||||
)}
|
||||
>
|
||||
{srDescription ? <span className="sr-only">{srDescription}</span> : null}
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={clsx(
|
||||
"pointer-events-none inline-block h-5 w-5 rounded-full bg-white shadow-lg transform ring-0 transition ease-in-out duration-200",
|
||||
{
|
||||
"translate-x-4": checked,
|
||||
"translate-x-0": !checked,
|
||||
},
|
||||
)}
|
||||
/>
|
||||
</HeadlessSwitch>
|
||||
);
|
||||
};
|
||||
|
||||
export default Switch;
|
Loading…
Add table
Add a link
Reference in a new issue