@yamada-ui/transitions
Version:
Yamada UI transitions components
160 lines (159 loc) • 4.85 kB
JavaScript
"use client"
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/collapse.tsx
var collapse_exports = {};
__export(collapse_exports, {
Collapse: () => Collapse,
collapseProps: () => collapseProps
});
module.exports = __toCommonJS(collapse_exports);
var import_core = require("@yamada-ui/core");
var import_motion = require("@yamada-ui/motion");
var import_utils = require("@yamada-ui/utils");
var import_react = require("react");
var import_jsx_runtime = require("react/jsx-runtime");
var isNumeric = (value) => value != null && parseFloat(value.toString()) > 0;
var variants = {
enter: ({
animationOpacity,
delay,
duration,
endingHeight: height,
enter,
transition,
transitionEnd
} = {}) => ({
...animationOpacity ? { opacity: 1 } : {},
height,
transition: (0, import_motion.transitionEnter)(transition == null ? void 0 : transition.enter)(delay, duration),
transitionEnd: transitionEnd == null ? void 0 : transitionEnd.enter,
...enter
}),
exit: ({
animationOpacity,
delay,
duration,
exit,
startingHeight: height,
transition,
transitionEnd
} = {}) => ({
...animationOpacity ? { opacity: isNumeric(height) ? 1 : 0 } : {},
height,
transition: (0, import_motion.transitionExit)(transition == null ? void 0 : transition.exit)(delay, duration),
transitionEnd: transitionEnd == null ? void 0 : transitionEnd.exit,
...exit
})
};
var collapseProps = {
animate: "enter",
exit: "exit",
initial: "exit",
variants
};
var Collapse = (0, import_motion.motionForwardRef)((props, ref) => {
const [style, mergedProps] = (0, import_core.useComponentStyle)("Collapse", props);
const {
className,
animationOpacity,
delay,
duration,
endingHeight,
isOpen,
open = isOpen,
startingHeight,
transition: transitionProp,
transitionEnd,
unmountOnExit,
__css,
...rest
} = (0, import_core.omitThemeProps)(mergedProps);
const [mounted, setMounted] = (0, import_react.useState)(false);
const animate = open || unmountOnExit ? "enter" : "exit";
const resolvedOpen = unmountOnExit ? open : true;
const transition = (0, import_react.useMemo)(() => {
if (!mounted) {
return { enter: { duration: 0 } };
} else if (transitionProp) {
return transitionProp;
} else {
return {
enter: {
height: {
duration: duration != null ? duration : 0.3,
ease: import_motion.MOTION_TRANSITION_EASINGS.ease
},
opacity: {
duration: duration != null ? duration : 0.4,
ease: import_motion.MOTION_TRANSITION_EASINGS.ease
}
},
exit: {
height: {
duration: duration != null ? duration : 0.3,
ease: import_motion.MOTION_TRANSITION_EASINGS.ease
},
opacity: {
duration: duration != null ? duration : 0.4,
ease: import_motion.MOTION_TRANSITION_EASINGS.ease
}
}
};
}
}, [mounted, duration, transitionProp]);
const custom = {
animationOpacity,
delay,
duration,
endingHeight,
startingHeight,
transition,
transitionEnd
};
const css = {
...style,
...__css
};
(0, import_react.useEffect)(() => {
if ((0, import_utils.createdDom)()) setMounted(true);
}, []);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_motion.AnimatePresence, { custom, initial: false, children: resolvedOpen ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_motion.motion.div,
{
ref,
className: (0, import_utils.cx)("ui-collapse", className),
...rest,
...collapseProps,
style: { overflow: "hidden", ...rest.style },
animate,
custom,
initial: unmountOnExit ? "exit" : false,
__css: css
}
) : null });
});
Collapse.displayName = "Collapse";
Collapse.__ui__ = "Collapse";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Collapse,
collapseProps
});
//# sourceMappingURL=collapse.js.map