@catho/quantum
Version:
Catho react components
161 lines (160 loc) • 6.51 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 _shared = require("../shared");
var _subComponents = require("./sub-components");
var _jsxRuntime = require("react/jsx-runtime");
var _excluded = ["type", "as", "width", "height", "size", "theme"];
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 Skeleton = function Skeleton(_ref) {
var _ref$type = _ref.type,
type = _ref$type === void 0 ? 'rect' : _ref$type,
_ref$as = _ref.as,
as = _ref$as === void 0 ? 'div' : _ref$as,
_ref$width = _ref.width,
width = _ref$width === void 0 ? '100%' : _ref$width,
_ref$height = _ref.height,
height = _ref$height === void 0 ? '14px' : _ref$height,
_ref$size = _ref.size,
size = _ref$size === void 0 ? 'medium' : _ref$size,
_ref$theme = _ref.theme,
theme = _ref$theme === void 0 ? _shared.theme : _ref$theme,
props = _objectWithoutProperties(_ref, _excluded);
switch (type) {
case 'circle':
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_subComponents.Circle, _objectSpread({
as: as,
width: width,
height: height,
size: size,
theme: theme
}, props));
case 'text':
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_subComponents.Text, _objectSpread({
as: as,
width: width,
height: height,
size: size,
theme: theme
}, props));
case 'button':
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_subComponents.Button, _objectSpread({
as: as,
width: width,
height: height,
size: size,
theme: theme
}, props));
case 'tag':
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_subComponents.Tag, _objectSpread({
as: as,
width: width,
height: height,
size: size,
theme: theme
}, props));
default:
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_subComponents.Rect, _objectSpread({
as: as,
width: width,
height: height,
size: size,
theme: theme
}, props));
}
};
Skeleton.propTypes = {
/** Sets the component behavior */
type: _propTypes["default"].oneOf(['rect', 'circle', 'text', 'button', 'tag']),
as: _propTypes["default"].oneOf(['div', 'span']),
width: _propTypes["default"].string,
height: _propTypes["default"].string,
/** Will affect only types that not uses the prop `size` */
size: _propTypes["default"].oneOf(['xsmall', 'small', 'medium', 'large']),
/** Used only for themification. */
theme: _propTypes["default"].shape({
spacing: _propTypes["default"].object,
baseFontSize: _propTypes["default"].number
})
};
Skeleton.Rect = function (_ref2) {
var theme = _ref2.theme,
width = _ref2.width,
height = _ref2.height,
as = _ref2.as;
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Skeleton, {
theme: theme,
width: width,
height: height,
as: as
});
};
Skeleton.Circle = function (_ref3) {
var theme = _ref3.theme,
width = _ref3.width,
height = _ref3.height,
as = _ref3.as;
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Skeleton, {
theme: theme,
width: width,
height: height,
as: as,
type: "circle"
});
};
Skeleton.Text = function (_ref4) {
var theme = _ref4.theme,
width = _ref4.width,
height = _ref4.height,
_ref4$as = _ref4.as,
as = _ref4$as === void 0 ? 'span' : _ref4$as;
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Skeleton, {
theme: theme,
width: width,
height: height,
as: as,
type: "text"
});
};
Skeleton.Button = function (_ref5) {
var theme = _ref5.theme,
size = _ref5.size,
width = _ref5.width,
height = _ref5.height,
as = _ref5.as;
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Skeleton, {
theme: theme,
width: width,
height: height,
as: as,
size: size,
type: "button"
});
};
Skeleton.Tag = function (_ref6) {
var theme = _ref6.theme,
size = _ref6.size,
width = _ref6.width,
height = _ref6.height,
as = _ref6.as;
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Skeleton, {
theme: theme,
width: width,
height: height,
as: as,
size: size,
type: "tag"
});
};
var _default = exports["default"] = Skeleton;