UNPKG

@pantheon-systems/design-toolkit-react

Version:
39 lines (36 loc) 2.13 kB
import _defineProperty from '@babel/runtime/helpers/defineProperty'; import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties'; import { useFormState, RadioGroup } from 'informed'; import PropTypes from 'prop-types'; import React from 'react'; import CardGridTemplate from '../../Templates/CardGridTemplate.js'; import { jsx } from 'react/jsx-runtime'; var _excluded = ["children", "field"]; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } var CardSelectGroup = function CardSelectGroup(_ref) { var children = _ref.children, field = _ref.field, rest = _objectWithoutProperties(_ref, _excluded); var formState = useFormState(); var fieldValue = formState.values[field]; var childrenWithFieldValue = React.Children.map(children, function (child) { return /*#__PURE__*/React.cloneElement(child, { fieldValue: fieldValue }); }); return /*#__PURE__*/jsx(RadioGroup, _objectSpread(_objectSpread({ field: field }, rest), {}, { children: /*#__PURE__*/jsx(CardGridTemplate, { children: childrenWithFieldValue }) })); }; CardSelectGroup.propTypes = { children: PropTypes.node.isRequired, field: PropTypes.string.isRequired }; var CardSelectGroup$1 = CardSelectGroup; export { CardSelectGroup$1 as default }; //# sourceMappingURL=CardSelectGroup.js.map