@chakra-xui/transition
Version:
Common transition components for Chakra xui
83 lines (79 loc) • 2.45 kB
JavaScript
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import { cx, mergeWith, __DEV__ } from "@chakra-xui/utils";
import { AnimatePresence, motion } from "framer-motion";
import * as React from "react";
import { EASINGS } from "./__utils";
var transitions = {
enter: {
duration: 0.2,
ease: EASINGS.easeOut
},
exit: {
duration: 0.1,
ease: EASINGS.easeIn
}
};
var variants = {
initial: props => ({
opacity: 0,
x: props.offsetX,
y: props.offsetY,
transition: transitions.exit
}),
exit: props => _extends({
opacity: 0,
transition: transitions.exit
}, props.reverse && {
x: props.offsetX,
y: props.offsetY
}, !props.reverse && {
transitionEnd: {
x: props.offsetX,
y: props.offsetY
}
}),
enter: {
opacity: 1,
x: 0,
y: 0,
transition: transitions.enter
}
};
export var slideFadeConfig = {
initial: "initial",
animate: "enter",
exit: "exit",
variants
};
export var SlideFade = /*#__PURE__*/React.forwardRef((props, ref) => {
var {
unmountOnExit,
in: isOpen,
reverse = true,
className,
offsetX = 0,
offsetY = 8
} = props,
rest = _objectWithoutPropertiesLoose(props, ["unmountOnExit", "in", "reverse", "className", "offsetX", "offsetY"]);
var shouldExpand = unmountOnExit ? isOpen && unmountOnExit : true;
var custom = {
offsetX,
offsetY,
reverse
};
var motionProps = mergeWith(slideFadeConfig, {
custom,
animate: isOpen || unmountOnExit ? "enter" : "exit"
});
return /*#__PURE__*/React.createElement(AnimatePresence, {
custom: custom
}, shouldExpand && /*#__PURE__*/React.createElement(motion.div, _extends({
ref: ref,
className: cx("chakra-offset-slide", className)
}, motionProps, rest)));
});
if (__DEV__) {
SlideFade.displayName = "SlideFade";
}
//# sourceMappingURL=slide-fade.js.map