UNPKG

@ariakit/react-core

Version:

Ariakit React core

65 lines (63 loc) 1.63 kB
"use client"; import { useFormControl } from "../__chunks/ZNASNLV3.js"; import { useFormContext } from "../__chunks/AOHIIJHJ.js"; import "../__chunks/4WQSNMEM.js"; import { useFocusable } from "../__chunks/3F6D4KUU.js"; import "../__chunks/SWN3JYXT.js"; import "../__chunks/SOQQIDO4.js"; import "../__chunks/CTVD4XJH.js"; import { createElement, createHook, forwardRef, memo } from "../__chunks/L4OUMOCQ.js"; import { useEvent } from "../__chunks/W2TDKEPX.js"; import "../__chunks/AZVQSWGA.js"; // src/form/form-input.tsx import { invariant } from "@ariakit/core/utils/misc"; var TagName = "input"; var useFormInput = createHook( function useFormInput2({ store, name: nameProp, ...props }) { const context = useFormContext(); store = store || context; invariant( store, process.env.NODE_ENV !== "production" && "FormInput must be wrapped in a Form component." ); const name = String(nameProp); const onChangeProp = props.onChange; const onChange = useEvent((event) => { onChangeProp == null ? void 0 : onChangeProp(event); if (event.defaultPrevented) return; store == null ? void 0 : store.setValue(name, event.target.value); }); const value = store.useValue(name); props = { value, ...props, onChange }; props = useFocusable(props); props = useFormControl({ store, name, ...props }); return props; } ); var FormInput = memo( forwardRef(function FormInput2(props) { const htmlProps = useFormInput(props); return createElement(TagName, htmlProps); }) ); export { FormInput, useFormInput };