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

[Popup][base-ui] Use context-based transition API #39326

Merged
merged 35 commits into from
Dec 22, 2023

Conversation

michaldudak
Copy link
Member

@michaldudak michaldudak commented Oct 5, 2023

Adding new transition components and hooks and using them in the Popup component.

In contrast to the current implementation, this does not require the popup child to be a function. Because of this, it'll be possible to provide custom transition component using the slots prop.

Related issue: #38280

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak
@mui-bot
Copy link

mui-bot commented Oct 5, 2023

Netlify deploy preview

@material-ui/unstyled: parsed: +1.76% , gzip: +1.50%

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against cf5d49f

@michaldudak michaldudak added component: Popper The React component. See <Popup> for the latest version. package: base-ui Specific to @mui/base proof of concept Studying and/or experimenting with a to be validated approach labels Oct 6, 2023
};
}

export function useTransitionableElement(requestEnter: boolean) {
Copy link
Member

@siriwatknp siriwatknp Oct 11, 2023

Choose a reason for hiding this comment

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

Based on the usage in Popup.tsx, shouldn't this be a Transition component that contains the transition provider?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, could be as well. I wasn't focusing that much on the implementation as I wanted to check how would it feel to use it (from a developer's perspective). Do you have any remarks about that (especially in comparison to our current solution)?

Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

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

This is a significant improvement from the previous implementation 🎉

I left a couple of questions regarding naming and making the useTransition hook higher level, but overall I think this is the right direction.

Another thing we should consider is how our implementation interacts with the most common animation libraries like Framer Motion, React Spring, or tailwindcss-animate. For example, it seems to work good with React Spring, but I find it a little weird that the whole Popup is the one wrapped transitions rather than just the content. If there's anything we can do to make these libraries first-class citizens, we should.

As a side note, I like this implementation more than Radix's and React Aria's, which add a data- attribute for the transition state. Exposing that state through a hook gives more flexibility to work with whatever styling or animation solution is used.

};
}

export function useTransitionableElement(requestEnter: boolean) {
Copy link
Member

Choose a reason for hiding this comment

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

As an implementation detail, I think a reducer would be better for keeping the state if we go this route.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried it in 9339c3f, but I'm not sure it's better. There's more to reason about and the code is much longer.
What do you think?

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 better with a reducer as the hasEntered and inTransition are heavily related. With the reducer, it will be harder for them to become unsynced. It's a personal preference, though, and if there are not many changes to the hook in the future, my fear of them becoming unsynced by mistake is low and coverable by tests. I'll leave the decision to you 🤗

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak
…ntext

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak
@michaldudak
Copy link
Member Author

For example, it seems to work good with React Spring, but I find it a little weird that the whole Popup is the one wrapped transitions rather than just the content.

I added a React-spring example where it's not needed to wrap the whole Popup - the transition is defined as a child.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 31, 2023

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak
…ntext
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 1, 2023

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak
@michaldudak
Copy link
Member Author

I added the CssAnimation and CssTransition components so it's not necessary to deal with low-level events.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 7, 2023

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak
…ntext

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak
…ntext
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Nov 29, 2023

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak
…ntext

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak
…ntext

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak
…ntext

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Dec 13, 2023
@michaldudak michaldudak marked this pull request as ready for review December 13, 2023 11:03
@michaldudak
Copy link
Member Author

@samuelsycamore, I'd appreciate your review of the docs.

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak
@michaldudak michaldudak removed the proof of concept Studying and/or experimenting with a to be validated approach label Dec 13, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Co-authored-by: Diego Andai <diego@mui.com>
Signed-off-by: Michał Dudak <michal.dudak@gmail.com>
michaldudak and others added 7 commits December 20, 2023 13:00

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Co-authored-by: Sam Sycamore <71297412+samuelsycamore@users.noreply.github.com>
Signed-off-by: Michał Dudak <michal.dudak@gmail.com>

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak
…ntext

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak

Verified

This commit was signed with the committer’s verified signature.
michaldudak Michał Dudak
Copy link
Member

@DiegoAndai DiegoAndai left a comment

Choose a reason for hiding this comment

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

This API is (IMO) what Base UI is all about: extracting the core logic into reusable hooks that work with all the styling solutions available.

And the CssAnimation and CssTransition components are the cherry on top 🍒

Great work 🎉

@michaldudak michaldudak merged commit 84a4d37 into mui:master Dec 22, 2023
@michaldudak michaldudak deleted the poc/transition-context branch December 22, 2023 15:03
mnajdova pushed a commit to mnajdova/material-ui that referenced this pull request Jan 9, 2024
Signed-off-by: Michał Dudak <michal.dudak@gmail.com>
Co-authored-by: Diego Andai <diego@mui.com>
Co-authored-by: Sam Sycamore <71297412+samuelsycamore@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: Popper The React component. See <Popup> for the latest version. package: base-ui Specific to @mui/base
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants