-
Notifications
You must be signed in to change notification settings - Fork 361
feat(animations): tasteful motion refresh with reduced-motion support #3375
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
base: master
Are you sure you want to change the base?
Changes from all commits
3bafe61
8e58e40
ab961eb
97ae8b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| @import "~@vibe/style/dist/mixins"; | ||
| @import "~@vibe/style/dist/mixins/motion"; | ||
|
|
||
| .contentWrapper { | ||
| outline: 0; | ||
|
|
@@ -53,121 +54,147 @@ | |
| } | ||
|
|
||
| // Animations | ||
| // | ||
| // Two flavors driven by Dialog's `animationType` prop: | ||
| // - opacity-and-slide: fade + 16px translate from origin (default for popovers) | ||
| // - expand: scale-from-origin + fade (used by Tooltip, Menu submenus) | ||
| // | ||
| // Both are gated on `prefers-reduced-motion: no-preference`. Reduced-motion | ||
| // users get the popover at rest immediately with no transition. | ||
|
|
||
| $translate-minus-px: calc(var(--space-16) * -1); | ||
|
|
||
| .opacitySlideAppear { | ||
| opacity: 0; | ||
| @include motion-safe { | ||
| opacity: 0; | ||
|
|
||
| &.top { | ||
| transform: translateY(var(--space-16)); | ||
| } | ||
| &.top { | ||
| transform: translateY(var(--space-16)); | ||
| } | ||
|
|
||
| &.right { | ||
| transform: translateX($translate-minus-px); | ||
| } | ||
| &.right { | ||
| transform: translateX($translate-minus-px); | ||
| } | ||
|
|
||
| &.bottom { | ||
| transform: translateY($translate-minus-px); | ||
| } | ||
| &.bottom { | ||
| transform: translateY($translate-minus-px); | ||
| } | ||
|
|
||
| &.left { | ||
| transform: translateX(var(--space-16)); | ||
| &.left { | ||
| transform: translateX(var(--space-16)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .opacitySlideAppearActive { | ||
| transition: opacity 0.2s ease, transform 0.2s ease-out; | ||
| opacity: 1; | ||
| pointer-events: none; | ||
|
|
||
| &.top, | ||
| &.bottom { | ||
| transform: translateY(0); | ||
| } | ||
| @include motion-safe { | ||
| transition: opacity var(--motion-productive-long) var(--motion-timing-enter), | ||
| transform var(--motion-productive-long) var(--motion-timing-enter); | ||
| opacity: 1; | ||
|
|
||
| &.right, | ||
| &.left { | ||
| transform: translateX(0); | ||
| &.top, | ||
| &.bottom { | ||
| transform: translateY(0); | ||
| } | ||
|
|
||
| &.right, | ||
| &.left { | ||
| transform: translateX(0); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .expandAppear, | ||
| .expandExit { | ||
| transition: transform 0.1s $expand-animation-timing; | ||
| &.top, | ||
| &.topStart, | ||
| &.topEnd { | ||
| transform-origin: bottom center; | ||
| transform: scale(0.8); | ||
| &.edgeBottom { | ||
| transform-origin: bottom left; | ||
| } | ||
| &.edgeTop { | ||
| transform-origin: bottom right; | ||
| @include motion-safe { | ||
| transition: transform var(--motion-productive-long) var(--motion-timing-enter), | ||
| opacity var(--motion-productive-long) var(--motion-timing-enter); | ||
| opacity: 0; | ||
|
Comment on lines
+111
to
+114
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. Dialogcontent timeout mismatch DialogContent’s CSS now uses --motion-productive-long (150ms) for expand transitions, but
DialogContent.tsx still ends the transition after timeout={showDelay} (default 100ms). This
removes the active transition classes early, truncating the animation and making the new token
timing not actually take effect.
Agent Prompt
|
||
|
|
||
| &.top, | ||
| &.topStart, | ||
| &.topEnd { | ||
| transform-origin: bottom center; | ||
| transform: scale(0.92); | ||
| &.edgeBottom { | ||
| transform-origin: bottom left; | ||
| } | ||
| &.edgeTop { | ||
| transform-origin: bottom right; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| &.right, | ||
| &.rightStart, | ||
| &.rightEnd { | ||
| transform-origin: left; | ||
| transform: scale(0.8); | ||
| &.edgeBottom { | ||
| transform-origin: top left; | ||
| } | ||
| &.edgeTop { | ||
| transform-origin: bottom left; | ||
| &.right, | ||
| &.rightStart, | ||
| &.rightEnd { | ||
| transform-origin: left; | ||
| transform: scale(0.92); | ||
| &.edgeBottom { | ||
| transform-origin: top left; | ||
| } | ||
| &.edgeTop { | ||
| transform-origin: bottom left; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| &.bottom, | ||
| &.bottomStart, | ||
| &.bottomEnd { | ||
| transform-origin: top; | ||
| transform: scale(0.8); | ||
| &.edgeBottom { | ||
| transform-origin: top left; | ||
| &.bottom, | ||
| &.bottomStart, | ||
| &.bottomEnd { | ||
| transform-origin: top; | ||
| transform: scale(0.92); | ||
| &.edgeBottom { | ||
| transform-origin: top left; | ||
| } | ||
| &.edgeTop { | ||
| transform-origin: top right; | ||
| } | ||
| } | ||
| &.edgeTop { | ||
| transform-origin: top right; | ||
| } | ||
| } | ||
|
|
||
| &.left, | ||
| &.leftStart, | ||
| &.leftEnd { | ||
| transform-origin: right; | ||
| transform: scale(0.8); | ||
| &.edgeBottom { | ||
| transform-origin: top right; | ||
| } | ||
| &.edgeTop { | ||
| transform-origin: bottom right; | ||
| &.left, | ||
| &.leftStart, | ||
| &.leftEnd { | ||
| transform-origin: right; | ||
| transform: scale(0.92); | ||
| &.edgeBottom { | ||
| transform-origin: top right; | ||
| } | ||
| &.edgeTop { | ||
| transform-origin: bottom right; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| .expandExit { | ||
| transition: transform 0.1s $expand-animation-timing; | ||
| @include motion-safe { | ||
| transition: transform var(--motion-productive-medium) var(--motion-timing-exit), | ||
| opacity var(--motion-productive-medium) var(--motion-timing-exit); | ||
| } | ||
| } | ||
|
|
||
| .expandAppearActive { | ||
| transition: transform 0.1s $expand-animation-timing; | ||
| pointer-events: none; | ||
|
|
||
| &.top, | ||
| &.topStart, | ||
| &.topEnd, | ||
| &.bottom, | ||
| &.bottomStart, | ||
| &.bottomEnd, | ||
| &.right, | ||
| &.rightStart, | ||
| &.rightEnd, | ||
| &.left, | ||
| &.leftStart, | ||
| &.leftEnd { | ||
| transform: scale(1); | ||
| @include motion-safe { | ||
| transition: transform var(--motion-productive-long) var(--motion-timing-enter), | ||
| opacity var(--motion-productive-long) var(--motion-timing-enter); | ||
| opacity: 1; | ||
|
|
||
| &.top, | ||
| &.topStart, | ||
| &.topEnd, | ||
| &.bottom, | ||
| &.bottomStart, | ||
| &.bottomEnd, | ||
| &.right, | ||
| &.rightStart, | ||
| &.rightEnd, | ||
| &.left, | ||
| &.leftStart, | ||
| &.leftEnd { | ||
| transform: scale(1); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| @import "~@vibe/style/dist/mixins"; | ||
| @import "~@vibe/style/dist/mixins/motion"; | ||
|
|
||
| // Submenu open/close animation. Mirrors the `expand` variant in DialogContent — | ||
| // fade + scale-from-origin keyed off the floating-ui placement so the submenu | ||
| // grows out of the parent menu item's edge. | ||
| // | ||
| // Uses CSS animations instead of transitions because CSSTransition+mountOnEnter | ||
| // can skip the "from" frame when the class swap lands in a single paint — | ||
| // keyframes fire reliably on a freshly mounted element. | ||
|
|
||
| @keyframes submenuExpandIn { | ||
| from { | ||
| opacity: 0; | ||
| transform: scale(0.92); | ||
| } | ||
| to { | ||
| opacity: 1; | ||
| transform: scale(1); | ||
| } | ||
| } | ||
|
|
||
| @keyframes submenuExpandOut { | ||
| from { | ||
| opacity: 1; | ||
| transform: scale(1); | ||
| } | ||
| to { | ||
| opacity: 0; | ||
| transform: scale(0.92); | ||
| } | ||
| } | ||
|
|
||
| .rightStart { | ||
| transform-origin: top left; | ||
| } | ||
|
|
||
| .rightEnd { | ||
| transform-origin: bottom left; | ||
| } | ||
|
|
||
| .leftStart { | ||
| transform-origin: top right; | ||
| } | ||
|
|
||
| .leftEnd { | ||
| transform-origin: bottom right; | ||
| } | ||
|
|
||
| .appearActive, | ||
| .enterActive { | ||
| @include motion-safe { | ||
| animation: submenuExpandIn var(--motion-productive-long) var(--motion-timing-enter) forwards; | ||
| } | ||
| } | ||
|
|
||
| .exitActive { | ||
| @include motion-safe { | ||
| animation: submenuExpandOut var(--motion-productive-medium) var(--motion-timing-exit) forwards; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,12 @@ | ||
| import React, { useMemo, useRef } from "react"; | ||
| import { CSSTransition } from "react-transition-group"; | ||
| import { camelCase } from "es-toolkit"; | ||
| import { DialogContentContainer } from "@vibe/dialog"; | ||
| import { useFloating, flip, type Placement } from "@floating-ui/react-dom"; | ||
| import { type MenuChild } from "../../../Menu/MenuConstants"; | ||
| import { type MenuItemSubMenuProps } from "./MenuItemSubMenu.types"; | ||
| import { useIsomorphicLayoutEffect } from "@vibe/shared"; | ||
| import { useIsomorphicLayoutEffect, getStyle } from "@vibe/shared"; | ||
| import styles from "./MenuItemSubMenu.module.scss"; | ||
|
|
||
| const DEFAULT_FALLBACK_PLACEMENTS: Placement[] = ["right-end", "left-start", "left-end"]; | ||
|
|
||
|
|
@@ -16,6 +19,7 @@ const MenuItemSubMenu = ({ | |
| submenuPosition | ||
| }: MenuItemSubMenuProps) => { | ||
| const childRef = useRef<HTMLDivElement>(null); | ||
| const transitionRef = useRef<HTMLDivElement>(null); | ||
|
|
||
| useIsomorphicLayoutEffect(() => { | ||
| if (!autoFocusOnMount || !open || !childRef?.current) { | ||
|
|
@@ -49,24 +53,36 @@ const MenuItemSubMenu = ({ | |
| return null; | ||
| } | ||
|
|
||
| const placementClassName = getStyle(styles, camelCase(actualPlacement)); | ||
|
|
||
| return ( | ||
| <div | ||
| style={{ ...floatingStyles, visibility: open ? "visible" : "hidden" }} | ||
| ref={refs.setFloating} | ||
| data-popper-placement={actualPlacement} | ||
| > | ||
| {subMenu && open && ( | ||
| <DialogContentContainer> | ||
| {React.cloneElement(subMenu, { | ||
| ...subMenu?.props, | ||
| isVisible: open, | ||
| isSubMenu: true, | ||
| onClose, | ||
| ref: childRef, | ||
| useDocumentEventListeners: !autoFocusOnMount | ||
| })} | ||
| </DialogContentContainer> | ||
| )} | ||
| <div style={floatingStyles} ref={refs.setFloating} data-popper-placement={actualPlacement}> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. menuitemsubmenu root lacks data-vibe The updated root element for MenuItemSubMenu does not include the required [data-vibe] attribute. This breaks the standard component identification/instrumentation requirement. Agent Prompt
|
||
| <CSSTransition | ||
| in={open} | ||
| appear | ||
| mountOnEnter | ||
| unmountOnExit | ||
| nodeRef={transitionRef} | ||
| timeout={{ appear: 150, enter: 150, exit: 100 }} | ||
| classNames={{ | ||
| appearActive: styles.appearActive, | ||
| enterActive: styles.enterActive, | ||
| exitActive: styles.exitActive | ||
| }} | ||
|
Comment on lines
+60
to
+71
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Submenu enter flash risk MenuItemSubMenu’s CSSTransition only provides *Active classNames (no appear/enter base classes), so the submenu can mount at its resting (visible) styles for a paint and then snap to the keyframe from state when enterActive is applied, producing a visible flash on open. DialogContent avoids this by mapping an explicit appear class that sets the initial hidden/scale state before the active transition begins. Agent Prompt
|
||
| > | ||
| <div ref={transitionRef} className={placementClassName}> | ||
| <DialogContentContainer> | ||
| {React.cloneElement(subMenu, { | ||
| ...subMenu?.props, | ||
| isVisible: open, | ||
| isSubMenu: true, | ||
| onClose, | ||
| ref: childRef, | ||
| useDocumentEventListeners: !autoFocusOnMount | ||
| })} | ||
| </DialogContentContainer> | ||
| </div> | ||
| </CSSTransition> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
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.
1. Reduced-motion blocks clicks
🐞 Bug≡ CorrectnessAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools