UNPKG

@ariakit/react-core

Version:

Ariakit React core

64 lines (62 loc) 1.59 kB
"use client"; import { useFormControl } from "../__chunks/BRATOYGQ.js"; import { useFormContext } from "../__chunks/ICLJE26C.js"; import "../__chunks/DTXGDDAC.js"; import { useFocusable } from "../__chunks/US3TW2XI.js"; import "../__chunks/SWN3JYXT.js"; import "../__chunks/45YOMIF3.js"; import { createElement, createHook, forwardRef, memo } from "../__chunks/ILRXHV7V.js"; import { useEvent } from "../__chunks/K2XTQB3X.js"; import "../__chunks/YXGXYGQX.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 = `${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 };