import React, { ChangeEventHandler, FocusEventHandler, MouseEventHandler, useImperativeHandle, useRef, } from "react" import InputHeader, { InputHeaderProps } from "../../fundamentals/input-header" import clsx from "clsx" import InputError from "../../atoms/input-error" import MinusIcon from "../../fundamentals/icons/minus-icon" import PlusIcon from "../../fundamentals/icons/plus-icon" export type InputProps = Omit, "prefix"> & InputHeaderProps & { small?: boolean label?: string deletable?: boolean onDelete?: MouseEventHandler onChange?: ChangeEventHandler onFocus?: FocusEventHandler errors?: { [x: string]: unknown } prefix?: React.ReactNode suffix?: React.ReactNode props?: React.HTMLAttributes } const InputField = React.forwardRef( ( { small, placeholder, label, name, required, deletable, onDelete, onChange, onFocus, tooltipContent, tooltip, prefix, suffix, errors, props, className, ...fieldProps }: InputProps, ref ) => { const inputRef = useRef(null) useImperativeHandle( ref, () => inputRef.current ) const onNumberIncrement = () => { inputRef.current?.stepUp() if (onChange) { inputRef.current?.dispatchEvent( new InputEvent("change", { view: window, bubbles: true, cancelable: false, }) ) } } const onNumberDecrement = () => { inputRef.current?.stepDown() if (onChange) { inputRef.current?.dispatchEvent( new InputEvent("change", { view: window, bubbles: true, cancelable: false, }) ) } } return (
{label && ( )}
{prefix ? ( {prefix} ) : null} {suffix ? ( {suffix} ) : null} {deletable && ( )} {fieldProps.type === "number" && (
)}
) } ) InputField.displayName = "InputField" export default InputField