UNPKG

@ariakit/react-core

Version:

Ariakit React core

70 lines (68 loc) 1.78 kB
"use client"; import { useFormControl } from "../__chunks/HMMAPSBX.js"; import { useFormContext } from "../__chunks/GSXI3IAI.js"; import "../__chunks/Y62RTBST.js"; import { useFocusable } from "../__chunks/OE2EFRVA.js"; import "../__chunks/SWN3JYXT.js"; import "../__chunks/5CPL3B7G.js"; import { createElement, createHook, forwardRef, memo } from "../__chunks/VOQWLFSQ.js"; import { useEvent } from "../__chunks/5GGHRIN3.js"; import "../__chunks/SK3NAZA3.js"; import { __objRest, __spreadProps, __spreadValues } from "../__chunks/3YLGPPWQ.js"; // src/form/form-input.tsx import { invariant } from "@ariakit/core/utils/misc"; var TagName = "input"; var useFormInput = createHook( function useFormInput2(_a) { var _b = _a, { store, name: nameProp } = _b, props = __objRest(_b, ["store", "name"]); 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 = __spreadProps(__spreadValues({ value }, props), { onChange }); props = useFocusable(props); props = useFormControl(__spreadValues({ store, name }, props)); return props; } ); var FormInput = memo( forwardRef(function FormInput2(props) { const htmlProps = useFormInput(props); return createElement(TagName, htmlProps); }) ); export { FormInput, useFormInput };