UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

1 lines 4.92 kB
{"version":3,"file":"slide.cjs","names":["slideVariants: Variants","createTransition","createComponent","slideStyle","useValue","AnimatePresence","motion"],"sources":["../../../../src/components/slide/slide.tsx"],"sourcesContent":["\"use client\"\n\nimport type { Variants } from \"motion/react\"\nimport type { ThemeProps } from \"../../core\"\nimport type {\n HTMLMotionProps,\n MotionTransitionVariants,\n WithTransitionProps,\n} from \"../motion\"\nimport type { SlideStyle } from \"./slide.style\"\nimport { AnimatePresence } from \"motion/react\"\nimport { useMemo } from \"react\"\nimport { createComponent } from \"../../core\"\nimport { useValue } from \"../../hooks/use-value\"\nimport { createTransition, motion } from \"../motion\"\nimport { slideStyle } from \"./slide.style\"\n\nconst getAnimationProps = (placement: SlideProps[\"placement\"]) => {\n switch (placement) {\n case \"block-start\":\n return { enter: { x: 0, y: 0 }, exit: { x: 0, y: \"-100%\" } }\n case \"inline-end\":\n return { enter: { x: 0, y: 0 }, exit: { x: \"100%\", y: 0 } }\n case \"block-end\":\n return { enter: { x: 0, y: 0 }, exit: { x: 0, y: \"100%\" } }\n case \"inline-start\":\n return { enter: { x: 0, y: 0 }, exit: { x: \"-100%\", y: 0 } }\n default:\n return {}\n }\n}\nexport const slideVariants: Variants = {\n enter: ({\n delay,\n duration,\n enter,\n placement,\n transition,\n transitionEnd,\n } = {}) => ({\n ...getAnimationProps(placement).enter,\n transition: createTransition.enter(transition?.enter)(delay, duration),\n transitionEnd: transitionEnd?.enter,\n ...enter,\n }),\n exit: ({\n delay,\n duration,\n exit,\n placement,\n transition,\n transitionEnd,\n } = {}) => ({\n ...getAnimationProps(placement).exit,\n transition: createTransition.exit(transition?.exit)(delay, duration),\n transitionEnd: transitionEnd?.exit,\n ...exit,\n }),\n} satisfies MotionTransitionVariants\n\nexport interface SlideProps\n extends WithTransitionProps<HTMLMotionProps>,\n ThemeProps<SlideStyle> {}\n\nconst {\n PropsContext: SlidePropsContext,\n usePropsContext: useSlidePropsContext,\n withContext,\n} = createComponent<SlideProps, SlideStyle>(\"slide\", slideStyle)\n\nexport { SlidePropsContext, useSlidePropsContext }\n\n/**\n * `Slide` is a component that shows or hides an element from the corners of the page.\n *\n * @see https://yamada-ui.com/docs/components/slide\n */\nexport const Slide = withContext<\"div\", SlideProps, \"placement\">(\n ({\n delay,\n duration = { enter: 0.4, exit: 0.3 },\n open: openProp,\n placement: placementProp,\n transition,\n transitionEnd,\n unmountOnExit,\n ...rest\n }) => {\n const animate = openProp || unmountOnExit ? \"enter\" : \"exit\"\n const open = unmountOnExit ? openProp && unmountOnExit : true\n const placement = useValue(placementProp)\n\n const custom = useMemo(\n () => ({\n delay,\n duration,\n placement,\n transition,\n transitionEnd,\n }),\n [delay, duration, placement, transition, transitionEnd],\n )\n\n return (\n <AnimatePresence custom={custom}>\n {open ? (\n <motion.div\n animate={animate}\n custom={custom}\n exit=\"exit\"\n initial=\"exit\"\n variants={slideVariants}\n {...rest}\n />\n ) : null}\n </AnimatePresence>\n )\n },\n { transferProps: [\"placement\"] },\n)()\n"],"mappings":";;;;;;;;;;;;;;;;;AAiBA,MAAM,qBAAqB,cAAuC;AAChE,SAAQ,WAAR;EACE,KAAK,cACH,QAAO;GAAE,OAAO;IAAE,GAAG;IAAG,GAAG;IAAG;GAAE,MAAM;IAAE,GAAG;IAAG,GAAG;IAAS;GAAE;EAC9D,KAAK,aACH,QAAO;GAAE,OAAO;IAAE,GAAG;IAAG,GAAG;IAAG;GAAE,MAAM;IAAE,GAAG;IAAQ,GAAG;IAAG;GAAE;EAC7D,KAAK,YACH,QAAO;GAAE,OAAO;IAAE,GAAG;IAAG,GAAG;IAAG;GAAE,MAAM;IAAE,GAAG;IAAG,GAAG;IAAQ;GAAE;EAC7D,KAAK,eACH,QAAO;GAAE,OAAO;IAAE,GAAG;IAAG,GAAG;IAAG;GAAE,MAAM;IAAE,GAAG;IAAS,GAAG;IAAG;GAAE;EAC9D,QACE,QAAO,E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