UNPKG

wix-style-react

Version:
128 lines (98 loc) 5.17 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 _BounceAnimationSt = require("./BounceAnimation.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; } } /** Bounce Animation*/ var BounceAnimation = /*#__PURE__*/function (_React$PureComponent) { (0, _inherits2["default"])(BounceAnimation, _React$PureComponent); var _super = _createSuper(BounceAnimation); function BounceAnimation(props) { var _this; (0, _classCallCheck2["default"])(this, BounceAnimation); _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"])(BounceAnimation, [{ 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; var animationSize = this.state.animationSize; return /*#__PURE__*/_react["default"].createElement(_Animate["default"], { dataHook: dataHook, delay: delay, animateClasses: (0, _BounceAnimationSt.st)(_BounceAnimationSt.classes.root, { active: active, loop: loop, size: animationSize }), onEnd: onEnd, onStart: onStart, ref: this.rootRef }, children); } }]); return BounceAnimation; }(_react["default"].PureComponent); BounceAnimation.displayName = 'Bounce'; BounceAnimation.propTypes = { /** Applied as data-hook HTML attribute that can be used in the tests */ dataHook: _propTypes["default"].string, /** The component which we would like to animate. */ 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]) }; BounceAnimation.defaultProps = {}; var _default = BounceAnimation; exports["default"] = _default;