@primer/react
Version:
An implementation of GitHub's Primer Design System using React
151 lines (144 loc) • 4.7 kB
JavaScript
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var reactCompilerRuntime = require('react-compiler-runtime');
var React = require('react');
var CheckboxOrRadioGroupCaption = require('../internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupCaption.js');
var CheckboxOrRadioGroupLabel = require('../internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupLabel.js');
var CheckboxOrRadioGroupValidation = require('../internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupValidation.js');
var Checkbox = require('../Checkbox/Checkbox.js');
var CheckboxGroupContext = require('./CheckboxGroupContext.js');
var jsxRuntime = require('react/jsx-runtime');
var useRenderForcingRef = require('../hooks/useRenderForcingRef.js');
var CheckboxOrRadioGroup = require('../internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroup.js');
var FormControl = require('../FormControl/FormControl.js');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
var React__default = /*#__PURE__*/_interopDefault(React);
const CheckboxGroup = t0 => {
const $ = reactCompilerRuntime.c(24);
let children;
let disabled;
let onChange;
let rest;
if ($[0] !== t0) {
({
children,
disabled,
onChange,
...rest
} = t0);
$[0] = t0;
$[1] = children;
$[2] = disabled;
$[3] = onChange;
$[4] = rest;
} else {
children = $[1];
disabled = $[2];
onChange = $[3];
rest = $[4];
}
let t1;
if ($[5] !== children) {
const formControlComponentChildren = React__default.default.Children.toArray(children).filter(_temp).map(_temp2).flat();
t1 = React__default.default.Children.toArray(formControlComponentChildren).filter(_temp3).map(_temp4).filter(Boolean);
$[5] = children;
$[6] = t1;
} else {
t1 = $[6];
}
const checkedCheckboxes = t1;
const [selectedCheckboxValues, setSelectedCheckboxValues] = useRenderForcingRef.useRenderForcingRef(checkedCheckboxes);
let t2;
if ($[7] !== selectedCheckboxValues || $[8] !== setSelectedCheckboxValues) {
t2 = e => {
const {
value,
checked
} = e.currentTarget;
if (checked) {
setSelectedCheckboxValues([...(selectedCheckboxValues.current || []), value]);
return;
}
setSelectedCheckboxValues((selectedCheckboxValues.current || []).filter(selectedValue => selectedValue !== value));
};
$[7] = selectedCheckboxValues;
$[8] = setSelectedCheckboxValues;
$[9] = t2;
} else {
t2 = $[9];
}
const updateSelectedCheckboxes = t2;
let t3;
if ($[10] !== onChange || $[11] !== selectedCheckboxValues || $[12] !== updateSelectedCheckboxes) {
t3 = e_0 => {
if (onChange) {
updateSelectedCheckboxes(e_0);
onChange(selectedCheckboxValues.current || [], e_0);
}
};
$[10] = onChange;
$[11] = selectedCheckboxValues;
$[12] = updateSelectedCheckboxes;
$[13] = t3;
} else {
t3 = $[13];
}
let t4;
if ($[14] !== disabled || $[15] !== t3) {
t4 = {
disabled,
onChange: t3
};
$[14] = disabled;
$[15] = t3;
$[16] = t4;
} else {
t4 = $[16];
}
let t5;
if ($[17] !== children || $[18] !== disabled || $[19] !== rest) {
t5 = /*#__PURE__*/jsxRuntime.jsx(CheckboxOrRadioGroup, {
disabled: disabled,
...rest,
children: children
});
$[17] = children;
$[18] = disabled;
$[19] = rest;
$[20] = t5;
} else {
t5 = $[20];
}
let t6;
if ($[21] !== t4 || $[22] !== t5) {
t6 = /*#__PURE__*/jsxRuntime.jsx(CheckboxGroupContext.CheckboxGroupContext.Provider, {
value: t4,
children: t5
});
$[21] = t4;
$[22] = t5;
$[23] = t6;
} else {
t6 = $[23];
}
return t6;
};
var CheckboxGroup$1 = Object.assign(CheckboxGroup, {
Caption: CheckboxOrRadioGroupCaption,
Label: CheckboxOrRadioGroupLabel,
Validation: CheckboxOrRadioGroupValidation
});
function _temp(child) {
return /*#__PURE__*/React__default.default.isValidElement(child) && child.type === FormControl;
}
function _temp2(formControlComponent) {
return /*#__PURE__*/React__default.default.isValidElement(formControlComponent) ? formControlComponent.props.children : [];
}
function _temp3(child_0) {
return /*#__PURE__*/React__default.default.isValidElement(child_0) && child_0.type === Checkbox;
}
function _temp4(checkbox) {
return /*#__PURE__*/React__default.default.isValidElement(checkbox) && (checkbox.props.checked || checkbox.props.defaultChecked) && checkbox.props.value;
}
exports.CheckboxGroupContext = CheckboxGroupContext.CheckboxGroupContext;
exports.default = CheckboxGroup$1;