@catho/quantum
Version:
Catho react components
142 lines (141 loc) • 9.97 kB
JavaScript
"use strict";
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _propTypes = _interopRequireDefault(require("prop-types"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _shared = require("../shared");
var _theme = require("../shared/theme");
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["disabled", "error", "children", "label", "onChange", "value", "theme", "required", "inline"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
var radioSize = '24px';
var RadioMark = _styledComponents["default"].span.withConfig({
displayName: "Radio__RadioMark",
componentId: "sc-1dy6exu-0"
})(["border-radius:50%;box-sizing:border-box;flex:0 0 auto;height:", ";position:relative;top:6px;width:", ";", " &:after{border-radius:50%;content:'';display:none;height:60%;left:20%;position:absolute;top:20%;width:60%;background-color:", ";}"], radioSize, radioSize, function (_ref) {
var _ref$theme = _ref.theme,
_ref$theme$colors$neu = _ref$theme.colors.neutral,
white = _ref$theme$colors$neu[0],
gray = _ref$theme$colors$neu[500],
xsmall = _ref$theme.spacing.xsmall;
return "\n background-color: ".concat(white, ";\n border: 2px solid ").concat(gray, ";\n margin-right: ").concat(xsmall, "px;\n ");
}, function (_ref2) {
var primary = _ref2.theme.colors.primary[700];
return primary;
});
var RadioLabel = (0, _styledComponents["default"])(_shared.Label).withConfig({
displayName: "Radio__RadioLabel",
componentId: "sc-1dy6exu-1"
})(["align-items:baseline;display:flex;cursor:pointer;user-select:none;", "{&:checked{~ ", "{", "}}&:focus{~ ", "{", "}}}", " &:hover,&:focus{", "{", "}}", " ", " ", ":checked:disabled ~ ", "{", "}"], _shared.HiddenInput, RadioMark, function (_ref3) {
var primary = _ref3.theme.colors.primary[700];
return "\n border-color: ".concat(primary, ";\n &:after {\n background-color: ").concat(primary, ";\n display: block;\n }\n ");
}, RadioMark, function (_ref4) {
var theme = _ref4.theme;
var primary = theme.colors.primary[700];
return "\n border-color: ".concat(primary, ";\n ").concat((0, _shared.shadow)(5, primary)({
theme: theme
}), "\n ");
}, function (_ref5) {
var inline = _ref5.inline,
medium = _ref5.theme.spacing.medium;
return inline && "\n display: inline-flex;\n margin-right: ".concat(medium, "px;\n\n &:last-child {\n margin-right: 0;\n }");
}, RadioMark, function (_ref6) {
var theme = _ref6.theme;
var primary = theme.colors.primary[700];
return "\n border-color: ".concat(primary, ";\n ").concat((0, _shared.shadow)(5, primary)({
theme: theme
}), "\n ");
}, function (_ref7) {
var theme = _ref7.theme,
error = _ref7.error;
var errorColor = theme.colors.error[700];
return error && "\n ".concat(_shared.HiddenInput, " {\n &:checked {\n ~ ").concat(RadioMark, " {\n border-color: ").concat(errorColor, ";\n &:after {\n background-color: ").concat(errorColor, ";\n display: block;\n }\n }\n }\n &:focus {\n ~ ").concat(RadioMark, " {\n border-color: ").concat(errorColor, ";\n ").concat((0, _shared.shadow)(5, errorColor)({
theme: theme
}), "\n }\n }\n }\n\n ").concat(RadioMark, " {\n border-color: ").concat(errorColor, ";\n }\n\n &:hover, &:focus {\n ").concat(RadioMark, " {\n border-color: ").concat(errorColor, ";\n ").concat((0, _shared.shadow)(5, errorColor)({
theme: theme
}), "\n }\n }\n ");
}, function (_ref8) {
var disabled = _ref8.disabled,
_ref8$theme$colors = _ref8.theme.colors,
_ref8$theme$colors$ne = _ref8$theme$colors.neutral,
neutral500 = _ref8$theme$colors$ne[500],
neutral300 = _ref8$theme$colors$ne[300],
errorColor = _ref8$theme$colors.error[500];
return disabled && "\n color: ".concat(neutral500, ";\n\n &:hover {\n cursor: not-allowed;\n }\n\n ").concat(_shared.HiddenInput, " {\n &:disabled {\n ~ ").concat(RadioMark, " {\n background-color: ").concat(neutral300, ";\n }\n }\n\n &:checked {\n ~ ").concat(RadioMark, " {\n border-color: ").concat(errorColor, ";\n &:after {\n background-color: ").concat(errorColor, ";\n display: block;\n }\n }\n }\n\n &:checked:disabled {\n background-color: ").concat(neutral500, ";\n border-color: ").concat(neutral500, ";\n ~ ").concat(RadioMark, ":after {\n background-color: ").concat(neutral500, ";\n }\n }\n\n &:focus {\n ~ ").concat(RadioMark, " {\n border-color: ").concat(neutral500, ";\n box-shadow: none;\n }\n }\n }\n\n &:hover, &:focus {\n ").concat(RadioMark, " {\n border-color: ").concat(neutral500, ";\n box-shadow: none;\n }\n }\n ");
}, _shared.HiddenInput, RadioMark, function (_ref9) {
var _ref9$theme$colors$ne = _ref9.theme.colors.neutral,
white = _ref9$theme$colors$ne[0],
black = _ref9$theme$colors$ne[500];
return "\n background-color: ".concat(black, ";\n border-color: ").concat(black, ";\n box-shadow: inset 0 0 0 3.5px ").concat(white, ";\n ");
});
var Radio = function Radio(_ref10) {
var _ref10$disabled = _ref10.disabled,
disabled = _ref10$disabled === void 0 ? false : _ref10$disabled,
_ref10$error = _ref10.error,
error = _ref10$error === void 0 ? false : _ref10$error,
_ref10$children = _ref10.children,
children = _ref10$children === void 0 ? undefined : _ref10$children,
_ref10$label = _ref10.label,
label = _ref10$label === void 0 ? undefined : _ref10$label,
_ref10$onChange = _ref10.onChange,
_onChange = _ref10$onChange === void 0 ? function () {} : _ref10$onChange,
value = _ref10.value,
_ref10$theme = _ref10.theme,
theme = _ref10$theme === void 0 ? {
colors: _theme.colors,
spacing: _theme.spacing
} : _ref10$theme,
_ref10$required = _ref10.required,
required = _ref10$required === void 0 ? false : _ref10$required,
_ref10$inline = _ref10.inline,
inline = _ref10$inline === void 0 ? false : _ref10$inline,
rest = _objectWithoutProperties(_ref10, _excluded);
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(RadioLabel, {
inline: inline,
error: error,
disabled: disabled,
theme: theme,
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_shared.HiddenInput, _objectSpread({
type: "radio",
disabled: disabled,
onChange: function onChange(e) {
return _onChange({
value: value,
label: label
}, e);
},
value: value,
required: required
}, rest)), /*#__PURE__*/(0, _jsxRuntime.jsx)(RadioMark, {
theme: theme
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
children: children || label
})]
});
};
Radio.displayName = 'RadioGroup.Radio';
Radio.propTypes = {
disabled: _propTypes["default"].bool,
error: _propTypes["default"].bool,
inline: _propTypes["default"].bool,
children: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].node]),
label: _propTypes["default"].string,
value: _propTypes["default"].string.isRequired,
onChange: _propTypes["default"].func,
theme: _propTypes["default"].shape({
colors: _propTypes["default"].object,
spacing: _propTypes["default"].object
}),
required: _propTypes["default"].bool
};
var _default = exports["default"] = Radio;