UNPKG

wix-style-react

Version:
107 lines (93 loc) 4.01 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; 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 './Skeleton.st.css'; import { dataHooks } from './constants'; import deprecationLog from '../utils/deprecationLog'; /** * Skeleton is a “placeholder” component. * Used for filling up screen usually for when some async operation is ongoing. */ var Skeleton = /*#__PURE__*/function (_React$PureComponent) { _inherits(Skeleton, _React$PureComponent); var _super = _createSuper(Skeleton); function Skeleton() { _classCallCheck(this, Skeleton); return _super.apply(this, arguments); } _createClass(Skeleton, [{ key: "componentDidMount", value: function componentDidMount() { deprecationLog("Using \"<Skeleton/>\" is deprecated. we advise you use <SkeletonGroup/> instead."); } }, { key: "render", value: function render() { var _this$props = this.props, dataHook = _this$props.dataHook, content = _this$props.content, alignment = _this$props.alignment, spacing = _this$props.spacing, className = _this$props.className; return /*#__PURE__*/React.createElement("div", { "data-hook": dataHook, "data-alignment": alignment, "data-spacing": spacing, className: st(classes.root, { alignment: alignment, spacing: spacing }, className) }, content.map(function (_ref, key) { var type = _ref.type, size = _ref.size; return /*#__PURE__*/React.createElement("div", { key: key, "data-hook": dataHooks.line, className: st(classes.line, { alignment: alignment, spacing: spacing }) }, /*#__PURE__*/React.createElement("div", { "data-hook": dataHooks.chunk, "data-type": type, "data-size": size, className: st(classes.chunk, { size: size }) })); })); } }]); return Skeleton; }(React.PureComponent); Skeleton.displayName = 'Skeleton'; Skeleton.propTypes = { /** Applied as data-hook HTML attribute that can be used in the tests */ dataHook: PropTypes.string, /** A single CSS class name to be appended to the root element. */ className: PropTypes.string, /** The type of the skeleton */ content: PropTypes.arrayOf(PropTypes.shape({ type: PropTypes.oneOf(['line']).isRequired, size: PropTypes.oneOf(['small', 'medium', 'large', 'full']).isRequired })).isRequired, /** The position of the indicating progress line */ alignment: PropTypes.oneOf(['start', 'middle']), /** The space between the first and second lines */ spacing: PropTypes.oneOf(['small', 'medium', 'large']) }; Skeleton.defaultProps = { alignment: 'start', spacing: 'medium', content: [{ type: 'line', size: 'small' }] }; export default Skeleton;