Implemented SwitchTableField

This commit is contained in:
Justin Edmund 2023-03-18 06:49:42 -07:00
parent b67c3bc8b5
commit 2bf578fec9
2 changed files with 47 additions and 0 deletions

View file

View file

@ -0,0 +1,47 @@
import { useEffect, useState } from 'react'
import Switch from '~components/Switch'
import TableField from '~components/TableField'
import './index.scss'
interface Props {
name: string
label: string
description?: string
value?: boolean
className?: string
imageAlt?: string
imageClass?: string
imageSrc?: string[]
}
const SwitchTableField = (props: Props) => {
const [value, setValue] = useState(false)
useEffect(() => {
if (props.value) setValue(props.value)
}, [props.value])
function onValueChange(value: boolean) {
setValue(value)
}
return (
<TableField
name={props.name}
className="SwitchField"
imageAlt={props.imageAlt}
imageClass={props.imageClass}
imageSrc={props.imageSrc}
label={props.label}
>
<Switch
name={props.name}
checked={value}
onCheckedChange={onValueChange}
/>
</TableField>
)
}
export default SwitchTableField