UNPKG

wix-style-react

Version:
127 lines (105 loc) 5.7 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import React from 'react'; import PropTypes from 'prop-types'; import { st, classes } from './SkeletonRectangle.st.css'; import { DEFAULT_HEIGHT, DEFAULT_WIDTH } from './constants'; import { DEFAULT_SKIN, SKIN_COLOR } from '../SkeletonGroup/constants'; import Box from '../Box'; import { SkeletonGroupContext } from '../SkeletonGroup'; /** SkeletonRectangle */ var SkeletonRectangle = /*#__PURE__*/function (_React$PureComponent) { _inherits(SkeletonRectangle, _React$PureComponent); var _super = _createSuper(SkeletonRectangle); function SkeletonRectangle() { var _this; _classCallCheck(this, SkeletonRectangle); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _defineProperty(_assertThisInitialized(_this), "state", {}); return _this; } _createClass(SkeletonRectangle, [{ key: "render", value: function render() { var _this$props = this.props, dataHook = _this$props.dataHook, className = _this$props.className, height = _this$props.height, width = _this$props.width, margin = _this$props.margin, marginLeft = _this$props.marginLeft, marginRight = _this$props.marginRight, marginTop = _this$props.marginTop, marginBottom = _this$props.marginBottom; return /*#__PURE__*/React.createElement(SkeletonGroupContext.Consumer, null, function (context) { var skin = context && context.skin || DEFAULT_SKIN; return /*#__PURE__*/React.createElement("div", { "data-hook": dataHook, className: className, "data-height": height, "data-width": width, "data-skin": skin }, /*#__PURE__*/React.createElement(Box, { height: height, width: width, margin: margin, marginLeft: marginLeft, marginRight: marginRight, marginTop: marginTop, marginBottom: marginBottom, backgroundColor: SKIN_COLOR[skin], className: st(classes.root, { skin: skin }) })); }); } }]); return SkeletonRectangle; }(React.PureComponent); SkeletonRectangle.displayName = 'SkeletonRectangle'; SkeletonRectangle.propTypes = { /** Applied as data-hook HTML attribute that can be used in the tests */ dataHook: PropTypes.string, /** A css class to be applied to the component's root element */ className: PropTypes.string, /** Sets the width of the box (pixels) */ width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), /** Sets the height of the box (pixels) */ height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), /** Sets margin on all sides. * Accepts a numeric value (multiplied by spacing unit), predefined spacing value (tiny, small, etc.) * a spacing token (SP1, SP2, etc.) or a string of space-separated values ("3px 3px") */ margin: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), /** Sets margin on the top. * Accepts a numeric value (multiplied by spacing unit), predefined spacing value (tiny, small, etc.) * a spacing token (SP1, SP2, etc.) or a string of space-separated values ("3px 3px") */ marginTop: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), /** Sets margin on the right. * Accepts a numeric value (multiplied by spacing unit), predefined spacing value (tiny, small, etc.) * a spacing token (SP1, SP2, etc.) or a string of space-separated values ("3px 3px") */ marginRight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), /** Sets margin on the bottom. * Accepts a numeric value (multiplied by spacing unit), predefined spacing value (tiny, small, etc.) * a spacing token (SP1, SP2, etc.) or a string of space-separated values ("3px 3px") */ marginBottom: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), /** Sets margin on the left. * Accepts a numeric value (multiplied by spacing unit), predefined spacing value (tiny, small, etc.) * a spacing token (SP1, SP2, etc.) or a string of space-separated values ("3px 3px") */ marginLeft: PropTypes.oneOfType([PropTypes.string, PropTypes.number]) }; SkeletonRectangle.defaultProps = { height: DEFAULT_HEIGHT, width: DEFAULT_WIDTH }; export default SkeletonRectangle;