2022-09-12 16:34:56 +00:00
|
|
|
import { Switch } from '@headlessui/react'
|
|
|
|
import clsx from 'clsx'
|
|
|
|
import React from 'react'
|
2022-10-03 13:41:39 +00:00
|
|
|
import { Tooltip } from 'web/components/tooltip'
|
2022-09-12 16:34:56 +00:00
|
|
|
|
|
|
|
export const SwitchSetting = (props: {
|
|
|
|
checked: boolean
|
|
|
|
onChange: (checked: boolean) => void
|
|
|
|
label: string
|
2022-10-03 13:41:39 +00:00
|
|
|
disabled: boolean
|
2022-09-12 16:34:56 +00:00
|
|
|
}) => {
|
2022-10-03 13:41:39 +00:00
|
|
|
const { checked, onChange, label, disabled } = props
|
2022-09-12 16:34:56 +00:00
|
|
|
return (
|
|
|
|
<Switch.Group as="div" className="flex items-center">
|
2022-10-03 13:41:39 +00:00
|
|
|
<Tooltip
|
|
|
|
text={
|
|
|
|
disabled
|
|
|
|
? `You are opted out of all ${label} notifications. Go to the Opt Out section to undo this setting.`
|
|
|
|
: ''
|
|
|
|
}
|
2022-09-12 16:34:56 +00:00
|
|
|
>
|
2022-10-03 13:41:39 +00:00
|
|
|
<Switch
|
|
|
|
checked={checked}
|
|
|
|
onChange={onChange}
|
2022-09-12 16:34:56 +00:00
|
|
|
className={clsx(
|
2022-10-03 13:41:39 +00:00
|
|
|
checked ? 'bg-indigo-600' : 'bg-gray-200',
|
|
|
|
'relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2',
|
|
|
|
disabled ? 'cursor-not-allowed opacity-50' : ''
|
2022-09-12 16:34:56 +00:00
|
|
|
)}
|
2022-10-03 13:41:39 +00:00
|
|
|
disabled={disabled}
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
aria-hidden="true"
|
|
|
|
className={clsx(
|
|
|
|
checked ? 'translate-x-5' : 'translate-x-0',
|
|
|
|
'pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out'
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</Switch>
|
|
|
|
</Tooltip>
|
2022-09-12 16:34:56 +00:00
|
|
|
<Switch.Label as="span" className="ml-3">
|
2022-10-03 13:41:39 +00:00
|
|
|
<span
|
|
|
|
className={clsx(
|
|
|
|
'text-sm font-medium text-gray-900',
|
|
|
|
disabled ? 'cursor-not-allowed opacity-50' : ''
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{label}
|
|
|
|
</span>
|
2022-09-12 16:34:56 +00:00
|
|
|
</Switch.Label>
|
|
|
|
</Switch.Group>
|
|
|
|
)
|
|
|
|
}
|