@primer/react
Version:
An implementation of GitHub's Primer Design System using React
126 lines (120 loc) • 3.42 kB
JavaScript
var reactCompilerRuntime = require('react-compiler-runtime');
var React = require('react');
var RadioGroup = require('../RadioGroup/RadioGroup.js');
var clsx = require('clsx');
var shared_module = require('../Checkbox/shared.module.css.js');
var Radio_module = require('./Radio.module.css.js');
var BoxWithFallback = require('../internal/components/BoxWithFallback.js');
var jsxRuntime = require('react/jsx-runtime');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
var React__default = /*#__PURE__*/_interopDefault(React);
/**
* An accessible, native radio component for selecting one option from a list.
*/
const Radio = /*#__PURE__*/React__default.default.forwardRef((t0, ref) => {
const $ = reactCompilerRuntime.c(26);
let checked;
let className;
let disabled;
let nameProp;
let onChange;
let required;
let rest;
let t1;
let value;
if ($[0] !== t0) {
({
checked,
disabled,
name: nameProp,
onChange,
required,
value,
className,
"aria-hidden": t1,
...rest
} = t0);
$[0] = t0;
$[1] = checked;
$[2] = className;
$[3] = disabled;
$[4] = nameProp;
$[5] = onChange;
$[6] = required;
$[7] = rest;
$[8] = t1;
$[9] = value;
} else {
checked = $[1];
className = $[2];
disabled = $[3];
nameProp = $[4];
onChange = $[5];
required = $[6];
rest = $[7];
t1 = $[8];
value = $[9];
}
const ariaHidden = t1 === undefined ? false : t1;
const radioGroupContext = React.useContext(RadioGroup.RadioGroupContext);
let t2;
if ($[10] !== onChange || $[11] !== radioGroupContext) {
t2 = e => {
(radioGroupContext === null || radioGroupContext === void 0 ? void 0 : radioGroupContext.onChange) && radioGroupContext.onChange(e);
onChange && onChange(e);
};
$[10] = onChange;
$[11] = radioGroupContext;
$[12] = t2;
} else {
t2 = $[12];
}
const handleOnChange = t2;
const name = nameProp || (radioGroupContext === null || radioGroupContext === void 0 ? void 0 : radioGroupContext.name);
if (!name && !ariaHidden) {
console.warn("A radio input must have a `name` attribute. Pass `name` as a prop directly to each Radio, or nest them in a `RadioGroup` component with a `name` prop");
}
const t3 = checked ? "true" : "false";
let t4;
if ($[13] !== className) {
t4 = clsx.clsx(className, shared_module.Input, Radio_module.Radio);
$[13] = className;
$[14] = t4;
} else {
t4 = $[14];
}
let t5;
if ($[15] !== checked || $[16] !== disabled || $[17] !== handleOnChange || $[18] !== name || $[19] !== ref || $[20] !== required || $[21] !== rest || $[22] !== t3 || $[23] !== t4 || $[24] !== value) {
t5 = /*#__PURE__*/jsxRuntime.jsx(BoxWithFallback.BoxWithFallback, {
as: "input",
type: "radio",
value: value,
name: name,
ref: ref,
disabled: disabled,
checked: checked,
"aria-checked": t3,
required: required,
onChange: handleOnChange,
className: t4,
...rest
});
$[15] = checked;
$[16] = disabled;
$[17] = handleOnChange;
$[18] = name;
$[19] = ref;
$[20] = required;
$[21] = rest;
$[22] = t3;
$[23] = t4;
$[24] = value;
$[25] = t5;
} else {
t5 = $[25];
}
return t5;
});
Radio.displayName = 'Radio';
module.exports = Radio;
;