UNPKG

@ariakit/react-core

Version:

Ariakit React core

79 lines (77 loc) 2.04 kB
"use client"; import { useRadio } from "../__chunks/D7BWB6V7.js"; import "../__chunks/NJV4AM4M.js"; import { useFormControl } from "../__chunks/BRATOYGQ.js"; import { useFormContext } from "../__chunks/ICLJE26C.js"; import "../__chunks/FIT2LC3L.js"; import "../__chunks/5VQZOHHZ.js"; import "../__chunks/DTXGDDAC.js"; import "../__chunks/72IB6YNO.js"; import "../__chunks/WJ7PHYH7.js"; import "../__chunks/US3TW2XI.js"; import "../__chunks/SWN3JYXT.js"; import "../__chunks/Q3KUZPD7.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-radio.tsx import { invariant } from "@ariakit/core/utils/misc"; var TagName = "input"; var useFormRadio = createHook( function useFormRadio2({ store, name: nameProp, value, ...props }) { 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 = { ...props, checked, onChange }; props = useRadio({ value, ...props }); props = useFormControl({ 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 };