-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Animate: refactor to TypeScript #49243
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that there shouldn't be runtime changes in this file
|
||
// Create a new type that and distributes the `Pick` operator separately to | ||
// every individual type of a union, thus preserving that same union. | ||
type DistributiveTypeAndOptions< T extends { type?: any } > = T extends any |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chad1008 does this look familiar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I rewrote this file to be more verbose, but in a way that allows us to get rid of the Appear
helper and to use the Story.args
syntax which works well with Storybook controls.
In short, I opted for more verbosity in exchange of more straightforward code.
className: getAnimateClassName( { | ||
type, | ||
...options, | ||
} as GetAnimateOptions ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This typecast is not ideal, but there wasn't an easy way around it. Given that the Animate
component doesn't seem to be currently used in Gutenberg, I thought I wouldn't spend too long on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough 👍
Size Change: +2 B (0%) Total Size: 1.34 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking and working great to me 🚀
* ); | ||
* ``` | ||
*/ | ||
export function Animate( { type, options = {}, children }: AnimateProps ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It felt odd that we're allowing Animate
to not have any type
, but I guess that this is by design. After all, if we want to not animate, we would just omit this component from the tree.
Anyway, this was like that before, and I've confirmed that the distributive conditional type support that use case correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also felt odd to me, but then I saw that the Default Storybook example explicitly mentions that the lack of type
prop means no animation 🤷
className: getAnimateClassName( { | ||
type, | ||
...options, | ||
} as GetAnimateOptions ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough 👍
What?
Refactor the
Animate
component to TypeScriptWhy?
Part of #35744
How?
Animate
componentReviewing commit-by-commit may help.
Testing Instructions
trunk