feat(inputs): ✨ Add text options
This commit is contained in:
30
apps/builder/components/shared/SwitchWithLabel.tsx
Normal file
30
apps/builder/components/shared/SwitchWithLabel.tsx
Normal file
@ -0,0 +1,30 @@
|
||||
import { FormLabel, HStack, Switch, SwitchProps } from '@chakra-ui/react'
|
||||
import React, { useState } from 'react'
|
||||
|
||||
type SwitchWithLabelProps = {
|
||||
label: string
|
||||
initialValue: boolean
|
||||
onCheckChange: (isChecked: boolean) => void
|
||||
} & SwitchProps
|
||||
|
||||
export const SwitchWithLabel = ({
|
||||
label,
|
||||
initialValue,
|
||||
onCheckChange,
|
||||
...props
|
||||
}: SwitchWithLabelProps) => {
|
||||
const [isChecked, setIsChecked] = useState(initialValue)
|
||||
|
||||
const handleChange = () => {
|
||||
setIsChecked(!isChecked)
|
||||
onCheckChange(!isChecked)
|
||||
}
|
||||
return (
|
||||
<HStack justifyContent="space-between">
|
||||
<FormLabel htmlFor={props.id} mb="0">
|
||||
{label}
|
||||
</FormLabel>
|
||||
<Switch isChecked={isChecked} onChange={handleChange} {...props} />
|
||||
</HStack>
|
||||
)
|
||||
}
|
Reference in New Issue
Block a user