Implemented SwitchTableField
This commit is contained in:
parent
b67c3bc8b5
commit
2bf578fec9
2 changed files with 47 additions and 0 deletions
0
components/SwitchTableField/index.scss
Normal file
0
components/SwitchTableField/index.scss
Normal file
47
components/SwitchTableField/index.tsx
Normal file
47
components/SwitchTableField/index.tsx
Normal 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
|
||||||
Loading…
Reference in a new issue