import { ChangeEvent, EventHandler, FC, useCallback, useEffect, useRef } from 'react'; import { FieldTypes } from '../../types/schema'; import { InputBinder } from '../../types/inputBinder'; import { FieldTypeInput } from './field-type-input'; import { useInput } from '../../hooks/useInput'; interface IValueProps { type: FieldTypes; bind: InputBinder; } const DICE_SIDES = [3, 4, 6, 8, 10, 12, 20, 100]; export const ValueField: FC = ({ type, bind }) => { const { value: diceCount, bind: bindDiceCount } = useInput(1); const { value: diceSides, bind: bindDiceSides } = useInput(''); const diceInputRef = useRef(null); switch (type) { case FieldTypes.dice: { const onChange = (handler: (arg: ChangeEvent) => void) => (e: ChangeEvent) => { handler(e) setTimeout(() => { if (!diceInputRef.current) return; e.target = diceInputRef.current; bind.onChange(e); }, 0) } return ( <> ); } case FieldTypes.type: return ( ) case FieldTypes.number: return ( ) case FieldTypes.text: return ( ) default: return <>; } }