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(motion): Refactor scale, migrate to new variant structure #33341

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pixel-perfectionist
Copy link
Member

Previous Behavior

New Behavior

  • Refactored Scale component to adopt a new createScalePresence function for defining motion parameters.
  • Introduced new motion variant types ScaleVariantParams_unstable and ScaleRuntimeParams_unstable to enhance type safety and flexibility.
  • Added ScaleSnappy and ScaleRelaxed components using the refactored variant structure.

Key Changes:

  • Refactored Scale.ts to utilize the new createScalePresence approach.

  • Created new reusable atoms (scaleAtom, opacityAtom) for motion logic.

  • Defined new TypeScript types for scale variant parameters.

  • Simplified and improved motion logic with better defaults.

  • Fixes #33112

Copy link

📊 Bundle size report

✅ No changes found

Copy link

Pull request demo site: URL

export const createScalePresence: PresenceMotionFnCreator<ScaleVariantParams_unstable, ScaleRuntimeParams_unstable> =
({
enterDuration = motionTokens.durationGentle,
enterEasing = motionTokens.curveEasyEaseMax,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
enterEasing = motionTokens.curveEasyEaseMax,
enterEasing = motionTokens.curveDecelerateMax,

Somehow this value was changed in the diff, but it hasn't changed in the spec. The Scale variants all use decelerate max for enter and accelerate max for exit.

@@ -0,0 +1,20 @@
// eslint-disable-next-line @typescript-eslint/naming-convention
export type ScaleVariantParams_unstable = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good choice to mark these as unstable in the naming convention, since there is more design work that needs to be done.

scaleAtom({
duration: exitDuration,
easing: exitEasing,
}),
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like the exit scale atom is exactly the same as the enter, rather than scaling in reverse.

easing: string;
}): AtomMotion => ({
keyframes: [
{ transform: `scale3d(${fromScale}, ${fromScale}, 1)`, visibility: 'visible' },
Copy link
Collaborator

Choose a reason for hiding this comment

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

The previous implementation used both visibility of hidden and visible between enter and exit transitions. I haven't tested this new code yet, but I wonder if it functions as expected.

easing: exitEasing,
}),
]
: []),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I understand the thinking behind this refactoring and the functional style, and the motivations are fine. But with the resulting code, it's debatable as to whether the readability has become better or worse. The ternary spread is clever and functional, but it's verbose and not straightforward to understand like a simple imperative if.

@robertpenner
Copy link
Collaborator

robertpenner commented Nov 25, 2024

There are 2 independent changes happening in this PR:

  1. Refactoring away from createPresenceComponentVariant.
  1. Refactoring from merged keyframes to atom factories.

The code for 1) is good, and it's what is described in the ticket.
The code for 2) needs further work, and can be separated into another PR.

@robertpenner
Copy link
Collaborator

robertpenner commented Nov 25, 2024

Also, note that the previous migration for Fade included a bit of Storybook work:

Update Fade's variant customization example in Storybook.

This needs to be done for Scale's Storybook example as well:
https://react.fluentui.dev/?path=/docs/motion-components-preview-scale--docs#customization

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.

[Scale] Migrate to new variant structure
3 participants