Implement InputTableField
This commit is contained in:
parent
0418c01bc4
commit
ece5e2434c
2 changed files with 53 additions and 0 deletions
4
components/InputTableField/index.scss
Normal file
4
components/InputTableField/index.scss
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
.InputField.TableField .Input {
|
||||
text-align: right;
|
||||
width: $unit-8x;
|
||||
}
|
||||
49
components/InputTableField/index.tsx
Normal file
49
components/InputTableField/index.tsx
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { useEffect, useState } from 'react'
|
||||
import Input from '~components/Input'
|
||||
import TableField from '~components/TableField'
|
||||
|
||||
import './index.scss'
|
||||
|
||||
interface Props {
|
||||
name: string
|
||||
label: string
|
||||
description?: string
|
||||
value?: number
|
||||
className?: string
|
||||
imageAlt?: string
|
||||
imageClass?: string
|
||||
imageSrc?: string[]
|
||||
}
|
||||
|
||||
const InputTableField = (props: Props) => {
|
||||
const [value, setValue] = useState(0)
|
||||
|
||||
useEffect(() => {
|
||||
if (props.value) setValue(props.value)
|
||||
}, [props.value])
|
||||
|
||||
function onInputChange(event: React.ChangeEvent<HTMLInputElement>) {
|
||||
setValue(parseInt(event.currentTarget?.value))
|
||||
}
|
||||
|
||||
return (
|
||||
<TableField
|
||||
name={props.name}
|
||||
className="InputField"
|
||||
imageAlt={props.imageAlt}
|
||||
imageClass={props.imageClass}
|
||||
imageSrc={props.imageSrc}
|
||||
label={props.label}
|
||||
>
|
||||
<Input
|
||||
className="Bound"
|
||||
type="number"
|
||||
value={`${value}`}
|
||||
step={1}
|
||||
onChange={onInputChange}
|
||||
/>
|
||||
</TableField>
|
||||
)
|
||||
}
|
||||
|
||||
export default InputTableField
|
||||
Loading…
Reference in a new issue