'use client'; import React, { useRef, useImperativeHandle, forwardRef, type PropsWithChildren } from 'react'; import 'jb-input'; // eslint-disable-next-line no-duplicate-imports import type { JBInputWebComponent, JBInputEventType, SizeVariants } from 'jb-input'; import { type JBInputEvents, useJBInputEvents } from './events-hook.js'; import { type JBInputAttributes, useJBInputAttribute } from './attributes-hook.js'; import type { JBElementStandardProps } from 'jb-core/react'; import './module-declaration.js'; export { type JBInputEvents, useJBInputEvents, type JBInputAttributes, useJBInputAttribute, type JBInputEventType }; export type DirectProps = { label?: string, message?: string, placeholder?: string, size?: SizeVariants, name?: string, type?: string, inputmode?: string, error?: string, autocomplete?:string, value?: string | number | null, initialValue?: string | number | null, clearable?: boolean, } // eslint-disable-next-line react/display-name export const JBInput = forwardRef((props: Props, ref) => { const element = useRef(null); useImperativeHandle( ref, () => (element ? element.current : undefined), [element], ); const { onBeforeInput, onBlur, onChange, onChangeNative, onEnter, onFocus, onInput, onKeyDown, onKeyUp, size, autocomplete, clearable, disabled, error, initialValue, inputmode, label, message, name, placeholder, required, type, validationList, value, ...standardProps } = props; // props that directly set in jsx dom and need no process or property set const directProps: DirectProps = { label, message, name, placeholder, size, type, error, inputmode, autocomplete, clearable, initialValue: initialValue?.toString() ?? "", } const valueProps = value === undefined ? {} : { value: value?.toString() ?? "" }; const {onChange:internalOnchange} = useJBInputEvents(element, { onBeforeInput, onBlur, onChange, onChangeNative, onEnter, onFocus, onInput, onKeyDown, onKeyUp }); useJBInputAttribute(element, { disabled, required, validationList }); return ( {props.children} ); }); //used in derived jb-input react components like number input. export type BaseProps = PropsWithChildren> & JBInputEvents & JBInputAttributes & DirectProps; export type Props = BaseProps; JBInput.displayName = "JBInput";