2022-11-14 11:02:30 +01:00
|
|
|
import {
|
|
|
|
FormControl,
|
|
|
|
FormLabel,
|
|
|
|
HStack,
|
|
|
|
Switch,
|
|
|
|
SwitchProps,
|
|
|
|
} from '@chakra-ui/react'
|
2022-01-06 16:54:23 +01:00
|
|
|
import React, { useState } from 'react'
|
2022-05-24 14:25:15 -07:00
|
|
|
import { MoreInfoTooltip } from './MoreInfoTooltip'
|
2022-01-06 16:54:23 +01:00
|
|
|
|
|
|
|
type SwitchWithLabelProps = {
|
|
|
|
label: string
|
|
|
|
initialValue: boolean
|
2022-03-10 12:05:34 +01:00
|
|
|
moreInfoContent?: string
|
2022-01-06 16:54:23 +01:00
|
|
|
onCheckChange: (isChecked: boolean) => void
|
|
|
|
} & SwitchProps
|
|
|
|
|
|
|
|
export const SwitchWithLabel = ({
|
|
|
|
label,
|
|
|
|
initialValue,
|
2022-03-10 12:05:34 +01:00
|
|
|
moreInfoContent,
|
2022-01-06 16:54:23 +01:00
|
|
|
onCheckChange,
|
2022-11-14 11:02:30 +01:00
|
|
|
...switchProps
|
2022-01-06 16:54:23 +01:00
|
|
|
}: SwitchWithLabelProps) => {
|
|
|
|
const [isChecked, setIsChecked] = useState(initialValue)
|
|
|
|
|
|
|
|
const handleChange = () => {
|
|
|
|
setIsChecked(!isChecked)
|
|
|
|
onCheckChange(!isChecked)
|
|
|
|
}
|
|
|
|
return (
|
2022-11-14 11:02:30 +01:00
|
|
|
<FormControl as={HStack} justifyContent="space-between">
|
|
|
|
<FormLabel mb="0">
|
|
|
|
{label}
|
2022-03-10 12:05:34 +01:00
|
|
|
{moreInfoContent && (
|
2022-11-14 11:02:30 +01:00
|
|
|
<>
|
|
|
|
<MoreInfoTooltip>{moreInfoContent}</MoreInfoTooltip>
|
|
|
|
</>
|
2022-03-10 12:05:34 +01:00
|
|
|
)}
|
2022-11-14 11:02:30 +01:00
|
|
|
</FormLabel>
|
|
|
|
<Switch isChecked={isChecked} onChange={handleChange} {...switchProps} />
|
|
|
|
</FormControl>
|
2022-01-06 16:54:23 +01:00
|
|
|
)
|
|
|
|
}
|