Files
wdi-dashboard/node_modules/@chakra-ui/transition/dist/collapse.js
2024-08-16 15:06:52 +05:30

170 lines
5.2 KiB
JavaScript

'use client'
"use strict";
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
});
module.exports = __toCommonJS(collapse_exports);
var import_shared_utils = require("@chakra-ui/shared-utils");
var import_framer_motion = require("framer-motion");
var import_react = require("react");
// src/transition-utils.ts
var TRANSITION_EASINGS = {
ease: [0.25, 0.1, 0.25, 1],
easeIn: [0.4, 0, 1, 1],
easeOut: [0, 0, 0.2, 1],
easeInOut: [0.4, 0, 0.2, 1]
};
var TRANSITION_DEFAULTS = {
enter: {
duration: 0.2,
ease: TRANSITION_EASINGS.easeOut
},
exit: {
duration: 0.1,
ease: TRANSITION_EASINGS.easeIn
}
};
var withDelay = {
enter: (transition, delay) => ({
...transition,
delay: typeof delay === "number" ? delay : delay == null ? void 0 : delay["enter"]
}),
exit: (transition, delay) => ({
...transition,
delay: typeof delay === "number" ? delay : delay == null ? void 0 : delay["exit"]
})
};
// src/collapse.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var isNumeric = (value) => value != null && parseInt(value.toString(), 10) > 0;
var defaultTransitions = {
exit: {
height: { duration: 0.2, ease: TRANSITION_EASINGS.ease },
opacity: { duration: 0.3, ease: TRANSITION_EASINGS.ease }
},
enter: {
height: { duration: 0.3, ease: TRANSITION_EASINGS.ease },
opacity: { duration: 0.4, ease: TRANSITION_EASINGS.ease }
}
};
var variants = {
exit: ({
animateOpacity,
startingHeight,
transition,
transitionEnd,
delay
}) => {
var _a;
return {
...animateOpacity && { opacity: isNumeric(startingHeight) ? 1 : 0 },
height: startingHeight,
transitionEnd: transitionEnd == null ? void 0 : transitionEnd.exit,
transition: (_a = transition == null ? void 0 : transition.exit) != null ? _a : withDelay.exit(defaultTransitions.exit, delay)
};
},
enter: ({
animateOpacity,
endingHeight,
transition,
transitionEnd,
delay
}) => {
var _a;
return {
...animateOpacity && { opacity: 1 },
height: endingHeight,
transitionEnd: transitionEnd == null ? void 0 : transitionEnd.enter,
transition: (_a = transition == null ? void 0 : transition.enter) != null ? _a : withDelay.enter(defaultTransitions.enter, delay)
};
}
};
var Collapse = (0, import_react.forwardRef)(
(props, ref) => {
const {
in: isOpen,
unmountOnExit,
animateOpacity = true,
startingHeight = 0,
endingHeight = "auto",
style,
className,
transition,
transitionEnd,
...rest
} = props;
const [mounted, setMounted] = (0, import_react.useState)(false);
(0, import_react.useEffect)(() => {
const timeout = setTimeout(() => {
setMounted(true);
});
return () => clearTimeout(timeout);
}, []);
(0, import_shared_utils.warn)({
condition: Number(startingHeight) > 0 && !!unmountOnExit,
message: `startingHeight and unmountOnExit are mutually exclusive. You can't use them together`
});
const hasStartingHeight = parseFloat(startingHeight.toString()) > 0;
const custom = {
startingHeight,
endingHeight,
animateOpacity,
transition: !mounted ? { enter: { duration: 0 } } : transition,
transitionEnd: {
enter: transitionEnd == null ? void 0 : transitionEnd.enter,
exit: unmountOnExit ? transitionEnd == null ? void 0 : transitionEnd.exit : {
...transitionEnd == null ? void 0 : transitionEnd.exit,
display: hasStartingHeight ? "block" : "none"
}
}
};
const show = unmountOnExit ? isOpen : true;
const animate = isOpen || unmountOnExit ? "enter" : "exit";
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_framer_motion.AnimatePresence, { initial: false, custom, children: show && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_framer_motion.motion.div,
{
ref,
...rest,
className: (0, import_shared_utils.cx)("chakra-collapse", className),
style: {
overflow: "hidden",
display: "block",
...style
},
custom,
variants,
initial: unmountOnExit ? "exit" : false,
animate,
exit: "exit"
}
) });
}
);
Collapse.displayName = "Collapse";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
Collapse
});
//# sourceMappingURL=collapse.js.map