UNPKG

vcc-ui

Version:

A React library for building user interfaces at Volvo Cars

87 lines (86 loc) 3.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RadioGroup = exports.RadioContext = void 0; var _propTypes = require("prop-types"); var _react = _interopRequireWildcard(require("react")); var _block = require("../block"); var _message = require("../message"); var _view = require("../view"); function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } const labelStyle = _ref => { let { isValid } = _ref; return _ref2 => { let { theme } = _ref2; return { color: isValid ? theme.color.foreground.secondary : theme.color.foreground.alert, fontSize: 16, letterSpacing: '0.02em', fontFamily: theme.fontTypes.NOVUM, fontWeight: 300 }; }; }; const RadioContext = exports.RadioContext = /*#__PURE__*/(0, _react.createContext)({}); /** * @deprecated Use `import { RadioGroup } from '@volvo-cars/react-forms'` instead. See [Radio](https://developer.volvocars.com/design-system/web/?path=/docs/components-forms-radio--docs) */ const RadioGroup = _ref3 => { let { name, legend, isValid = true, value, onChange, errorMessage, description, children } = _ref3; const styleProps = { isValid }; const context = { name, isValid, value, onChange }; const messages = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, !errorMessage ? null : /*#__PURE__*/_react.default.createElement(_message.Message, { type: "error" }, errorMessage), !description ? null : /*#__PURE__*/_react.default.createElement(_message.Message, null, description)); return /*#__PURE__*/_react.default.createElement(_view.View, { spacing: 0.5 }, /*#__PURE__*/_react.default.createElement(_block.Block, { as: "legend", extend: labelStyle(styleProps) }, legend), /*#__PURE__*/_react.default.createElement(RadioContext.Provider, { value: context }, children), messages); }; exports.RadioGroup = RadioGroup; RadioGroup.propTypes = { name: _propTypes.string, /** Renders a legend. */ legend: _propTypes.string, /** Renders a description text underneath the input. */ description: _propTypes.string, /** Renders a red error message for validation underneath the input. */ errorMessage: _propTypes.string, /** onChange handler. Triggers on every keyboard and generally * is here where you change the value of the `value` property */ onChange: _propTypes.func.isRequired, /** Value of the textInput. This should be stored in the * state of the parent component */ value: _propTypes.string, /** Renders the input as valid or invalid */ isValid: _propTypes.bool, /** A JSX node */ // @ts-ignore children: _propTypes.node };