2
0
Files
bot/apps/builder/components/shared/SwitchWithLabel.tsx

45 lines
1023 B
TypeScript
Raw Normal View History

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
moreInfoContent?: string
2022-01-06 16:54:23 +01:00
onCheckChange: (isChecked: boolean) => void
} & SwitchProps
export const SwitchWithLabel = ({
label,
initialValue,
moreInfoContent,
2022-01-06 16:54:23 +01:00
onCheckChange,
...switchProps
2022-01-06 16:54:23 +01:00
}: SwitchWithLabelProps) => {
const [isChecked, setIsChecked] = useState(initialValue)
const handleChange = () => {
setIsChecked(!isChecked)
onCheckChange(!isChecked)
}
return (
<FormControl as={HStack} justifyContent="space-between">
<FormLabel mb="0">
{label}
{moreInfoContent && (
<>
&nbsp;<MoreInfoTooltip>{moreInfoContent}</MoreInfoTooltip>
</>
)}
</FormLabel>
<Switch isChecked={isChecked} onChange={handleChange} {...switchProps} />
</FormControl>
2022-01-06 16:54:23 +01:00
)
}