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

46 lines
1.0 KiB
TypeScript
Raw Normal View History

2022-05-24 14:25:15 -07:00
import { 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 = {
2022-01-10 08:05:03 +01:00
id: string
2022-01-06 16:54:23 +01:00
label: string
initialValue: boolean
moreInfoContent?: string
2022-01-06 16:54:23 +01:00
onCheckChange: (isChecked: boolean) => void
} & SwitchProps
export const SwitchWithLabel = ({
2022-01-10 08:05:03 +01:00
id,
2022-01-06 16:54:23 +01:00
label,
initialValue,
moreInfoContent,
2022-01-06 16:54:23 +01:00
onCheckChange,
...props
}: SwitchWithLabelProps) => {
const [isChecked, setIsChecked] = useState(initialValue)
const handleChange = () => {
setIsChecked(!isChecked)
onCheckChange(!isChecked)
}
return (
<HStack justifyContent="space-between">
<HStack>
<FormLabel htmlFor={id} mb="0" mr="0">
{label}
</FormLabel>
{moreInfoContent && (
2022-05-24 14:25:15 -07:00
<MoreInfoTooltip>{moreInfoContent}</MoreInfoTooltip>
)}
</HStack>
2022-01-10 08:05:03 +01:00
<Switch
isChecked={isChecked}
onChange={handleChange}
id={id}
{...props}
/>
2022-01-06 16:54:23 +01:00
</HStack>
)
}