UNPKG

infinity-forge

Version:
36 lines 1.98 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Animation = Animation; var jsx_runtime_1 = require("react/jsx-runtime"); var react_1 = require("react"); var react_2 = require("motion/react"); var type_animation_1 = require("./type-animation.js"); function Animation(_a) { var children = _a.children, type = _a.type, _b = _a.element, element = _b === void 0 ? 'div' : _b, _c = _a.duration, duration = _c === void 0 ? 0.7 : _c, _d = _a.delay, delay = _d === void 0 ? 0 : _d, _e = _a.easing, easing = _e === void 0 ? 'easeInOut' : _e, _f = _a.offset, offset = _f === void 0 ? {} : _f, _g = _a.customAnimate, customAnimate = _g === void 0 ? {} : _g, _h = _a.once, once = _h === void 0 ? false : _h; var ref = (0, react_1.useRef)(null); var isInView = (0, react_2.useInView)(ref); var Element = react_2.motion[element]; var _j = (0, react_1.useState)(false), hasAnimated = _j[0], setHasAnimated = _j[1]; (0, react_1.useEffect)(function () { if (isInView && !hasAnimated) { setHasAnimated(true); } }, [isInView, hasAnimated]); var initialAnimation = __assign(__assign({}, type_animation_1.types[type]), offset); var shouldAnimate = once ? hasAnimated : isInView; var animate = shouldAnimate ? __assign({ opacity: 1, x: 0, y: 0 }, customAnimate) : initialAnimation; return ((0, jsx_runtime_1.jsx)(Element, { ref: ref, initial: initialAnimation, animate: animate, transition: { duration: duration, delay: delay, ease: easing }, children: children })); } //# sourceMappingURL=index.js.map