UNPKG

@ariakit/react-core

Version:

Ariakit React core

83 lines (81 loc) 2.24 kB
"use client"; import { useRadio } from "../__chunks/SQZLCNLX.js"; import "../__chunks/BGBYET7R.js"; import { useFormControl } from "../__chunks/HMMAPSBX.js"; import { useFormContext } from "../__chunks/GSXI3IAI.js"; import "../__chunks/SBSPVDDI.js"; import "../__chunks/5VQZOHHZ.js"; import "../__chunks/Y62RTBST.js"; import "../__chunks/APTFW6PT.js"; import "../__chunks/2W3RN7C5.js"; import "../__chunks/OE2EFRVA.js"; import "../__chunks/SWN3JYXT.js"; import "../__chunks/RTNCFSKZ.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-radio.tsx import { invariant } from "@ariakit/core/utils/misc"; var TagName = "input"; var useFormRadio = createHook( function useFormRadio2(_a) { var _b = _a, { store, name: nameProp, value } = _b, props = __objRest(_b, ["store", "name", "value"]); const context = useFormContext(); store = store || context; invariant( store, process.env.NODE_ENV !== "production" && "FormRadio 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, value); }); const checkedProp = props.checked; const checked = store.useState( () => checkedProp != null ? checkedProp : (store == null ? void 0 : store.getValue(name)) === value ); props = __spreadProps(__spreadValues({}, props), { checked, onChange }); props = useRadio(__spreadValues({ value }, props)); props = useFormControl(__spreadValues({ store, name, "aria-labelledby": void 0 }, props)); return props; } ); var FormRadio = memo( forwardRef(function FormRadio2(props) { const htmlProps = useFormRadio(props); return createElement(TagName, htmlProps); }) ); export { FormRadio, useFormRadio };