UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

122 lines (119 loc) 3.01 kB
import { c } from 'react-compiler-runtime'; import { createContext } from 'react'; import CheckboxOrRadioGroupCaption from '../internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupCaption.js'; import CheckboxOrRadioGroupLabel from '../internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupLabel.js'; import CheckboxOrRadioGroupValidation from '../internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupValidation.js'; import { jsx } from 'react/jsx-runtime'; import { useRenderForcingRef } from '../hooks/useRenderForcingRef.js'; import CheckboxOrRadioGroup from '../internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroup.js'; const RadioGroupContext = /*#__PURE__*/createContext(null); const RadioGroup = t0 => { const $ = c(23); let children; let disabled; let name; let onChange; let rest; if ($[0] !== t0) { ({ children, disabled, onChange, name, ...rest } = t0); $[0] = t0; $[1] = children; $[2] = disabled; $[3] = name; $[4] = onChange; $[5] = rest; } else { children = $[1]; disabled = $[2]; name = $[3]; onChange = $[4]; rest = $[5]; } const [selectedRadioValue, setSelectedRadioValue] = useRenderForcingRef(null); let t1; if ($[6] !== setSelectedRadioValue) { t1 = e => { const { value, checked } = e.currentTarget; if (checked) { setSelectedRadioValue(value); return; } }; $[6] = setSelectedRadioValue; $[7] = t1; } else { t1 = $[7]; } const updateSelectedCheckboxes = t1; let t2; if ($[8] !== onChange || $[9] !== selectedRadioValue || $[10] !== updateSelectedCheckboxes) { t2 = e_0 => { if (onChange) { updateSelectedCheckboxes(e_0); onChange(selectedRadioValue.current, e_0); } }; $[8] = onChange; $[9] = selectedRadioValue; $[10] = updateSelectedCheckboxes; $[11] = t2; } else { t2 = $[11]; } let t3; if ($[12] !== disabled || $[13] !== name || $[14] !== t2) { t3 = { disabled, name, onChange: t2 }; $[12] = disabled; $[13] = name; $[14] = t2; $[15] = t3; } else { t3 = $[15]; } let t4; if ($[16] !== children || $[17] !== disabled || $[18] !== rest) { t4 = /*#__PURE__*/jsx(CheckboxOrRadioGroup, { disabled: disabled, ...rest, children: children }); $[16] = children; $[17] = disabled; $[18] = rest; $[19] = t4; } else { t4 = $[19]; } let t5; if ($[20] !== t3 || $[21] !== t4) { t5 = /*#__PURE__*/jsx(RadioGroupContext.Provider, { value: t3, children: t4 }); $[20] = t3; $[21] = t4; $[22] = t5; } else { t5 = $[22]; } return t5; }; var RadioGroup$1 = Object.assign(RadioGroup, { Caption: CheckboxOrRadioGroupCaption, Label: CheckboxOrRadioGroupLabel, Validation: CheckboxOrRadioGroupValidation }); export { RadioGroupContext, RadioGroup$1 as default };