@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
121 lines (117 loc) • 3.35 kB
JavaScript
"use client";
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
const require_create_component = require('../../core/components/create-component.cjs');
const require_factory = require('../motion/factory.cjs');
const require_transition = require('../motion/transition.cjs');
const require_hooks_use_value_index = require('../../hooks/use-value/index.cjs');
const require_slide_style = require('./slide.style.cjs');
let react = require("react");
react = require_rolldown_runtime.__toESM(react);
let react_jsx_runtime = require("react/jsx-runtime");
react_jsx_runtime = require_rolldown_runtime.__toESM(react_jsx_runtime);
let motion_react = require("motion/react");
motion_react = require_rolldown_runtime.__toESM(motion_react);
//#region src/components/slide/slide.tsx
const getAnimationProps = (placement) => {
switch (placement) {
case "block-start": return {
enter: {
x: 0,
y: 0
},
exit: {
x: 0,
y: "-100%"
}
};
case "inline-end": return {
enter: {
x: 0,
y: 0
},
exit: {
x: "100%",
y: 0
}
};
case "block-end": return {
enter: {
x: 0,
y: 0
},
exit: {
x: 0,
y: "100%"
}
};
case "inline-start": return {
enter: {
x: 0,
y: 0
},
exit: {
x: "-100%",
y: 0
}
};
default: return {};
}
};
const slideVariants = {
enter: ({ delay, duration, enter, placement, transition, transitionEnd } = {}) => ({
...getAnimationProps(placement).enter,
transition: require_transition.createTransition.enter(transition?.enter)(delay, duration),
transitionEnd: transitionEnd?.enter,
...enter
}),
exit: ({ delay, duration, exit, placement, transition, transitionEnd } = {}) => ({
...getAnimationProps(placement).exit,
transition: require_transition.createTransition.exit(transition?.exit)(delay, duration),
transitionEnd: transitionEnd?.exit,
...exit
})
};
const { PropsContext: SlidePropsContext, usePropsContext: useSlidePropsContext, withContext } = require_create_component.createComponent("slide", require_slide_style.slideStyle);
/**
* `Slide` is a component that shows or hides an element from the corners of the page.
*
* @see https://yamada-ui.com/docs/components/slide
*/
const Slide = withContext(({ delay, duration = {
enter: .4,
exit: .3
}, open: openProp, placement: placementProp, transition, transitionEnd, unmountOnExit,...rest }) => {
const animate = openProp || unmountOnExit ? "enter" : "exit";
const open = unmountOnExit ? openProp && unmountOnExit : true;
const placement = require_hooks_use_value_index.useValue(placementProp);
const custom = (0, react.useMemo)(() => ({
delay,
duration,
placement,
transition,
transitionEnd
}), [
delay,
duration,
placement,
transition,
transitionEnd
]);
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(motion_react.AnimatePresence, {
custom,
children: open ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_factory.motion.div, {
animate,
custom,
exit: "exit",
initial: "exit",
variants: slideVariants,
...rest
}) : null
});
}, { transferProps: ["placement"] })();
//#endregion
exports.Slide = Slide;
exports.SlidePropsContext = SlidePropsContext;
exports.slideVariants = slideVariants;
exports.useSlidePropsContext = useSlidePropsContext;
//# sourceMappingURL=slide.cjs.map