UNPKG

@baseplate-dev/ui-components

Version:

Shared UI component library

18 lines 1.27 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { get, useFormState } from 'react-hook-form'; import { cn, mergeRefs } from '#src/utils/index.js'; import { FormControl, FormDescription, FormItem, FormLabel, FormMessage, } from '../form-item/form-item.js'; import { Input } from '../input/input.js'; function InputField({ label, description, error, onChange, register, className, ref, ...props }) { return (_jsxs(FormItem, { error: error, className: cn('flex flex-col gap-1.5', className), children: [_jsx(FormLabel, { children: label }), _jsx(FormControl, { children: _jsx(Input, { onChange: onChange && ((e) => { onChange(e.target.value); }), ref: mergeRefs(ref, register?.ref), ...props, ...register }) }), _jsx(FormDescription, { children: description }), _jsx(FormMessage, {})] })); } function InputFieldController({ control, name, registerOptions, ...rest }) { const { errors } = useFormState({ control, name }); const error = get(errors, name); return (_jsx(InputField, { register: control.register(name, registerOptions), error: error?.message, ...rest })); } export { InputField, InputFieldController }; //# sourceMappingURL=input-field.js.map