UNPKG

wix-style-react

Version:
142 lines (110 loc) 5.58 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")); var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _PulseAnimationSt = require("./PulseAnimation.st.css"); var _Animate = _interopRequireDefault(require("../Animate")); var _constants = require("./constants"); var _utils = require("../Animate/utils"); function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(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; } } /** PulseAnimation*/ var PulseAnimation = /*#__PURE__*/function (_React$PureComponent) { (0, _inherits2["default"])(PulseAnimation, _React$PureComponent); var _super = _createSuper(PulseAnimation); function PulseAnimation(props) { var _this; (0, _classCallCheck2["default"])(this, PulseAnimation); _this = _super.call(this, props); (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_getAnimationSize", function () { var childWidth = _this.rootRef.current.offsetWidth; var _childWidthRange$medi = _constants.childWidthRange.medium, from = _childWidthRange$medi.from, to = _childWidthRange$medi.to; return (0, _utils.isValueInRange)(childWidth, from, to) ? _constants.childSize.medium : _constants.childSize.small; }); _this.state = { animationSize: undefined }; _this.rootRef = /*#__PURE__*/_react["default"].createRef(); return _this; } (0, _createClass2["default"])(PulseAnimation, [{ key: "componentDidMount", value: function componentDidMount() { var animationSize = this._getAnimationSize(); this.setState({ animationSize: animationSize }); } }, { key: "render", value: function render() { var _this$props = this.props, dataHook = _this$props.dataHook, active = _this$props.active, onEnd = _this$props.onEnd, onStart = _this$props.onStart, loop = _this$props.loop, children = _this$props.children, delay = _this$props.delay, color = _this$props.color, borderRadius = _this$props.borderRadius; var animationSize = this.state.animationSize; return /*#__PURE__*/_react["default"].createElement(_Animate["default"], { dataHook: dataHook, animateClasses: (0, _PulseAnimationSt.st)(_PulseAnimationSt.classes.root, { active: active, loop: loop, size: animationSize, color: color }), animateInlineStyle: { borderRadius: borderRadius }, onEnd: onEnd, onStart: onStart, delay: delay, ref: this.rootRef }, children); } }]); return PulseAnimation; }(_react["default"].PureComponent); PulseAnimation.displayName = 'PulseAnimation'; PulseAnimation.propTypes = { /** Applied as data-hook HTML attribute that can be used in the tests */ dataHook: _propTypes["default"].string, /** Node to animate (one child node) */ children: _propTypes["default"].node.isRequired, /** Triggers the animation transition */ active: _propTypes["default"].bool, /** A callback fired immediately after the animation starts. */ onStart: _propTypes["default"].func, /** A callback fired immediately after the animation ends. */ onEnd: _propTypes["default"].func, /** When set to true, the child component animate repetitively until stopped by other event*/ loop: _propTypes["default"].bool, /** Set a delay before the animation execution. When provided a number- sets this as `ms`.*/ delay: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]), /** The color of the animation */ color: _propTypes["default"].oneOf(['B10', 'R10', 'P10', 'G10']).isRequired, /** Sets the border-radius css property of the animation */ borderRadius: _propTypes["default"].string }; PulseAnimation.defaultProps = { loop: true }; var _default = PulseAnimation; exports["default"] = _default;