2022-06-24 23:38:39 +00:00
|
|
|
/* This example requires Tailwind CSS v2.0+ */
|
|
|
|
import { Switch } from '@headlessui/react'
|
|
|
|
import clsx from 'clsx'
|
|
|
|
|
|
|
|
export default function ShortToggle(props: {
|
2022-10-03 15:36:49 +00:00
|
|
|
on: boolean
|
|
|
|
setOn: (enabled: boolean) => void
|
|
|
|
disabled?: boolean
|
2022-08-26 02:42:40 +00:00
|
|
|
onChange?: (enabled: boolean) => void
|
2022-06-24 23:38:39 +00:00
|
|
|
}) {
|
2022-10-03 15:36:49 +00:00
|
|
|
const { on, setOn, disabled } = props
|
2022-06-24 23:38:39 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Switch
|
2022-10-03 15:36:49 +00:00
|
|
|
disabled={disabled}
|
|
|
|
checked={on}
|
2022-08-26 02:42:40 +00:00
|
|
|
onChange={(e: boolean) => {
|
2022-10-03 15:36:49 +00:00
|
|
|
setOn(e)
|
2022-08-26 02:42:40 +00:00
|
|
|
if (props.onChange) {
|
|
|
|
props.onChange(e)
|
|
|
|
}
|
|
|
|
}}
|
2022-10-03 15:36:49 +00:00
|
|
|
className={clsx(
|
|
|
|
'group relative inline-flex h-5 w-10 flex-shrink-0 items-center justify-center rounded-full focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2',
|
|
|
|
!disabled ? 'cursor-pointer' : 'cursor-not-allowed opacity-50'
|
|
|
|
)}
|
2022-06-24 23:38:39 +00:00
|
|
|
>
|
|
|
|
<span className="sr-only">Use setting</span>
|
|
|
|
<span
|
|
|
|
aria-hidden="true"
|
|
|
|
className="pointer-events-none absolute h-full w-full rounded-md bg-white"
|
|
|
|
/>
|
|
|
|
<span
|
|
|
|
aria-hidden="true"
|
|
|
|
className={clsx(
|
2022-10-03 15:36:49 +00:00
|
|
|
on ? 'bg-indigo-600' : 'bg-gray-200',
|
2022-06-24 23:38:39 +00:00
|
|
|
'pointer-events-none absolute mx-auto h-4 w-9 rounded-full transition-colors duration-200 ease-in-out'
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<span
|
|
|
|
aria-hidden="true"
|
|
|
|
className={clsx(
|
2022-10-03 15:36:49 +00:00
|
|
|
on ? 'translate-x-5' : 'translate-x-0',
|
2022-06-24 23:38:39 +00:00
|
|
|
'pointer-events-none absolute left-0 inline-block h-5 w-5 transform rounded-full border border-gray-200 bg-white shadow ring-0 transition-transform duration-200 ease-in-out'
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</Switch>
|
|
|
|
)
|
|
|
|
}
|