UNPKG

react-animation-presets

Version:

Welcome to the React animation presets project. This project will give an overview of reusable animations used within Oberon projects.

151 lines (116 loc) 7.63 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _templateObject = _taggedTemplateLiteral(['\n position: relative;\n display: inline-block;\n overflow: hidden;\n width: 100%;\n margin: 0;\n'], ['\n position: relative;\n display: inline-block;\n overflow: hidden;\n width: 100%;\n margin: 0;\n']), _templateObject2 = _taggedTemplateLiteral(['\n position: absolute;\n display: block;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n margin: 0;\n background-color: ', ';\n'], ['\n position: absolute;\n display: block;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n margin: 0;\n background-color: ', ';\n']), _templateObject3 = _taggedTemplateLiteral(['\n from { transform: translate(-50%, -50%) rotate(0deg); }\n to { transform: translate(-50%, -50%) rotate(360deg); }\n'], ['\n from { transform: translate(-50%, -50%) rotate(0deg); }\n to { transform: translate(-50%, -50%) rotate(360deg); }\n']), _templateObject4 = _taggedTemplateLiteral(['\n position: absolute;\n top: 50%;\n left: 50%;\n width: 40px;\n height: 40px;\n margin: 0;\n padding: 0;\n border: 4px solid #fff;\n border-right: 4px solid transparent;\n border-radius: 50%;\n\n transform: translate(-50%, -50%);\n animation: ', ' 1s linear infinite;\n'], ['\n position: absolute;\n top: 50%;\n left: 50%;\n width: 40px;\n height: 40px;\n margin: 0;\n padding: 0;\n border: 4px solid #fff;\n border-right: 4px solid transparent;\n border-radius: 50%;\n\n transform: translate(-50%, -50%);\n animation: ', ' 1s linear infinite;\n']); var _gsap = require('gsap'); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _styledComponents = require('styled-components'); var _styledComponents2 = _interopRequireDefault(_styledComponents); var _Image = require('./layout/Image'); var _Image2 = _interopRequireDefault(_Image); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* * REQUIREMENTS: * - React * - Greensock Animation Platform (GSAP) * - Styled Components * * USAGE: * * props: * src: string = url of normal size image * src2x: string = url of retina size image * ratio: number = aspect ratio of image defaults to 16/9 * color: string = color of image mask, defaults to light grey (#EEEEEE) * onLoad: function = function to call when image has loaded * onError: function = function to call when image did not load * * <ImageLoader src='' src2x='' onLoad={onLoadHandler} onError={onErrorHandler} /> * */ var DEFAULTS = { ratio: 16 / 9, color: '#EEEEEE' }; var ImageLoad = function (_PureComponent) { _inherits(ImageLoad, _PureComponent); function ImageLoad() { var _ref; var _temp, _this, _ret; _classCallCheck(this, ImageLoad); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = ImageLoad.__proto__ || Object.getPrototypeOf(ImageLoad)).call.apply(_ref, [this].concat(args))), _this), _this.state = { isLoading: true }, _this.onImageLoad = function (e) { var onLoad = _this.props.onLoad; var imageWrapper = e.imageWrapper; if (imageWrapper) { _this.timeline = new _gsap.TimelineLite(); var delay = 0; _this.timeline.add(_gsap.TweenLite.fromTo(_this.mask, 0.6, { x: '0%' }, { x: '-100%', ease: _gsap.Circ.easeInOut }), delay); _this.timeline.add(_gsap.TweenLite.fromTo(imageWrapper, 1.2, { transformOrigin: 'right', scale: 1.2 }, { scale: 1, ease: _gsap.Circ.easeOut }), delay); } _this.setState({ isLoading: false }); onLoad && onLoad(); }, _this.onImageError = function (e) { var onError = _this.props.onError; _this.setState({ isLoading: false }); onError && onError(e); }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(ImageLoad, [{ key: 'render', value: function render() { var _this2 = this; var _props = this.props, src = _props.src, src2x = _props.src2x, alt = _props.alt, _props$ratio = _props.ratio, ratio = _props$ratio === undefined ? DEFAULTS.ratio : _props$ratio, _props$color = _props.color, color = _props$color === undefined ? DEFAULTS.color : _props$color; var isLoading = this.state.isLoading; return _react2.default.createElement( ImageLoader, null, _react2.default.createElement(_Image2.default, { src: src, src2x: src2x, ratio: ratio, alt: alt, onLoad: this.onImageLoad, onError: this.onImageError }), _react2.default.createElement(ImageMask, { innerRef: function innerRef(ref) { _this2.mask = ref; }, color: color }), isLoading && _react2.default.createElement(Loader, null) ); } }]); return ImageLoad; }(_react.PureComponent); var ImageLoader = _styledComponents2.default.figure(_templateObject); var ImageMask = _styledComponents2.default.figure(_templateObject2, function (_ref2) { var color = _ref2.color; return color; }); var LoaderAnimation = (0, _styledComponents.keyframes)(_templateObject3); var Loader = _styledComponents2.default.figure(_templateObject4, LoaderAnimation); exports.default = ImageLoad;