Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add animate support to popovers, add custom origin middleware and animate from reference origin #1194

Merged
merged 3 commits into from Dec 13, 2023

Conversation

robinpyon
Copy link
Contributor

@robinpyon robinpyon commented Dec 13, 2023

Description

This PR adds animate support for Popover components.

In addition to fading in, animated popovers will now also slightly scale from the reference element's origin, giving the appearance of popovers very slightly 'growing out'. Since this is a popover prop, it's also possible to apply this animation on <MenuButton> components too (via the popover prop) too.

This is done via a custom origin middleware which calculates this transform origin offset from both the shifted position and final (not user supplied) floating placement.

This middleware is also applied to <Tooltip> components too.

Currently, there's no optionality around animation here – opting in means you get both opacity + scale transitions, though we may want to provide more fine-grained control in future.

Screenflick.Movie.60.mp4

Copy link

vercel bot commented Dec 13, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
sanity-ui-workshop ✅ Ready (Inspect) Visit Preview Dec 13, 2023 10:35am
1 Ignored Deployment
Name Status Preview Updated (UTC)
sanity-ui-storybook ⬜️ Ignored (Inspect) Dec 13, 2023 10:35am

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separated this out into its own component, to match popoverCard.tsx

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -105,9 +115,9 @@ export const PopoverCard = memo(
)

return (
<Root
<MotionCard
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we're not conditionally creating this motion component – we're always leveraging motion(Card) even if you don't opt into animate.

Given that we're not rendering these motion elements as wrappers, it felt simpler to just conditionally attach motion props as needed rather than conditionally define this component. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine – there might be a tiny perf hit, but nothing compared to perf issues already caused by styled-components

@robinpyon robinpyon marked this pull request as ready for review December 13, 2023 10:43
Copy link
Member

@mariuslundgard mariuslundgard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful – thank you for this!

@robinpyon robinpyon merged commit 9ee54ba into beta Dec 13, 2023
13 checks passed
@robinpyon robinpyon deleted the feat/animated-popovers branch December 13, 2023 12:59
robinpyon added a commit that referenced this pull request Jan 16, 2024
…nd animate from reference origin (#1194)

* refactor: add clarifying comments

* feat: animate tooltips + popovers from reference origin, add custom framer-motion middleware

* chore(storybook): add animated menu button story
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants