Skip to content

Commit

Permalink
animationを付与
Browse files Browse the repository at this point in the history
  • Loading branch information
k35o committed Sep 21, 2024
1 parent 977fbeb commit 7c4cb54
Showing 1 changed file with 48 additions and 21 deletions.
69 changes: 48 additions & 21 deletions src/components/dropdown-menu/dropdown-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
useMenuTrigger,
} from './hooks';
import clsx from 'clsx';
import { AnimatePresence, motion, Variants } from 'framer-motion';

const Root: FC<PropsWithChildren<{ placement?: Placement }>> = ({
children,
Expand All @@ -57,6 +58,7 @@ const Root: FC<PropsWithChildren<{ placement?: Placement }>> = ({
padding: 8,
}),
],
transform: false,
});

const listNavigation = useListNavigation(context, {
Expand Down Expand Up @@ -119,6 +121,22 @@ const Root: FC<PropsWithChildren<{ placement?: Placement }>> = ({
);
};

const contentMotionVariants = {
closed: {
scale: 0,
transition: {
delay: 0.15,
},
},
open: {
scale: 1,
transition: {
type: 'spring',
duration: 0.2,
},
},
} satisfies Variants;

const Content: FC<PropsWithChildren> = ({ children }) => {
const {
id,
Expand All @@ -133,28 +151,37 @@ const Content: FC<PropsWithChildren> = ({ children }) => {

return (
<FloatingList elementsRef={itemElementsRef}>
{isOpen && (
<FloatingPortal>
<FloatingFocusManager context={context} modal={false}>
<div
ref={setContentRef}
style={contentStyles}
{...contentProps}
>
<section
ref={ref}
id={id}
role="menu"
aria-orientation="vertical"
className="flex min-w-40 flex-col rounded-xl border border-borderSecondary bg-bgBase py-2 shadow-xl"
tabIndex={-1}
<AnimatePresence>
{isOpen && (
<FloatingPortal>
<FloatingFocusManager context={context} modal={false}>
<div
ref={setContentRef}
style={contentStyles}
{...contentProps}
>
{children}
</section>
</div>
</FloatingFocusManager>
</FloatingPortal>
)}
<motion.div
animate={isOpen ? 'open' : 'closed'}
initial="closed"
exit="closed"
variants={contentMotionVariants}
>
<section
ref={ref}
id={id}
role="menu"
aria-orientation="vertical"
className="flex min-w-40 flex-col rounded-xl border border-borderSecondary bg-bgBase py-2 shadow-xl"
tabIndex={-1}
>
{children}
</section>
</motion.div>
</div>
</FloatingFocusManager>
</FloatingPortal>
)}
</AnimatePresence>
</FloatingList>
);
};
Expand Down

0 comments on commit 7c4cb54

Please sign in to comment.