Commit 4b7cd36761c for woocommerce
commit 4b7cd36761c33320d57719964165bdfe96055aa0
Author: Mike Jolley <mike.jolley@me.com>
Date: Thu Nov 26 12:58:23 2026 +0000
Add motion rules and shared helpers for Cart and Checkout (#70851)
* Add Cart and Checkout motion rules and lint rule
* Add shared motion mixins and keyframes
* Move existing transitions onto motion helpers
* Add a skill for Cart and Checkout motion
* Add changelog entry for motion foundation
* Describe techniques, not implementations, in the motion skill
Drop the patterns and helper references, which described how the
reference PR implemented each area. The skill now covers techniques,
constraints, traps and verification, and lists helpers as they land.
* Scope the motion skill and rules to all blocks
Motion starts with Cart and Checkout, but product blocks and others
may adopt it later, so rename the skill to woocommerce-blocks-motion
and word the rules for any block.
* Point the motion skill at motion.md for the rules
Move the general rules the skill repeated into motion.md and have the
skill reference it, keeping only the workflow, techniques, traps and
checklist.
* Simplify motion helpers and rewrite docs in plain English
Share one transition-list function between the motion-state, motion-hold
and motion-move helpers, drop parameters nothing overrides, and stop the
lint rule accepting a raw prefers-reduced-motion query. Rewrite the rules,
skill and comments in Simplified Technical English. The compiled CSS is
unchanged.
* Clarify motion rules gaps found by the first skill run
Keep motion changes small (no dependency or markup churn), give the
snackbar distances, fix the dropdown fade easing, and allow shared
components to replace their own motion everywhere.
* Keep pricing behaviour out of the motion rules
How a cart line total is calculated while a quantity saves is not a
motion rule.
* Move the motion skill into the Motion guide
The techniques, traps, and test steps are useful to everyone, so they
live in motion.md. AGENTS.md links to the guide under Block Development
instead of listing a skill.
* Reduce the Motion guide to its core rules
Merge the general and numbered rules into one short list of named
rules, drop niche and not yet built rules, and drop guidance that was
only for agents. Code comments no longer cite rule numbers.
* Drop the traps from the Motion guide
The shared helpers handle these, and new motion should reuse them.
* Update the Motion guide summary in AGENTS.md
* Add the first-load list stagger rule and first-time test to the Motion guide
* Add the selection rule to the Motion guide
* Use no-preference and sibling-index() in the motion mixins
motion-safe now uses @media (prefers-reduced-motion: no-preference), which
older browsers also understand. Stagger steps come from sibling-index()
through a registered --wc-motion-index, with nth-child as the fallback.
* Reject transition all anywhere in a transition item
The pattern only matched "all" at the start of a comma-separated item, so "var(--wpds-motion-duration-md) ease all" passed. Match "all" as a whole token anywhere in the value instead.
* Allow motion-state() outside motion-safe only for fade and colour properties
The motion-safe rule exempted any motion-state() call, so motion-state(transform) emitted an unguarded transform transition. Check each argument against the fade properties. motion-hold() stays exempt because step-end never animates, and Sass variables pass so motion-transition can forward its $state.
* Check the values of Sass variables in motion-state()
A variable now passes only when it is a parameter of the enclosing mixin, or is declared in the same file with only fade or colour properties. Unresolvable variables fail.
* Check the $state argument of motion-transition in the motion lint
The $state list runs with reduced motion, so named or positional $state arguments outside motion-safe may list only fade and colour properties. Variables resolve as in motion-state().
* Check literal motion times per animation item
The loop exemption looked for infinite anywhere in the value, so a finite animation listed next to a looping one could use a literal time. Check each comma-separated item, exempt only the looping ones, and cover vendor-prefixed properties.
* Check vendor-prefixed motion properties in the motion lint
-webkit-animation and -webkit-transition move things like the unprefixed properties, but the rule skipped them.
* Resolve Sass variables where the motion lint reads them
The motion lint now uses only the assignments before the use, as Sass does, and applies `!default` only when the variable has no value yet. Before, a later assignment or a `!default` could make a movement transition pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Check literal motion times inside nested functions
The duration regex only looked one level into parentheses, so `calc( var( … ) + 100ms )` passed. The motion lint now checks each item's tokens at any depth, and the config keeps only the `all` check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Handle flow-control assignments and any whitespace in the motion lint
An assignment in an earlier `@if`, `@else` or loop can replace a variable, so the lint now treats it as another possible value that must also fade. Animation and transition items now split on any whitespace, so multiline and tab-separated values are read correctly.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Resolve Sass variables in the motion lint as Sass does, with tests
The motion lint now applies `!default` to `null` values, keeps a first assignment inside `@if` local, ignores assignments in nested rules, reads `@each` loop bindings, and treats every assignment around a mixin as a value it can read when included. The cases from review run as Jest tests, so the test config no longer skips the stylelint plugin tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Simplify the motion lint and remove unused motion helpers
The motion lint now accepts a Sass variable only when it is a parameter of the enclosing mixin that the mixin does not assign, instead of working out Sass scoping. It splits lists with `postcss.list.comma`. The unused `motion-spinner-swap` mixin, its keyframes, `$wc-scale-pulse-peak` and the `$hold` parameter are gone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Make clear that motion is checked by hand
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
diff --git a/AGENTS.md b/AGENTS.md
index b73d3500b44..7194cd239cc 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -302,6 +302,10 @@ See [the theme CLI README](tools/theme-cli/README.md) and the selected theme's R
## Block Development
+### Motion
+
+Before adding or changing motion (transitions, animations, layout changes) in blocks or the components they share, read the [Motion guide](plugins/woocommerce/client/blocks/docs/contributors/motion.md). It has the rules, tokens, helpers, techniques, and how to test motion.
+
### Block Styling
Prefer Core Block Supports. For explicit style generation, use `wp_style_engine_get_styles()`. Avoid new `StyleAttributesUtils` usages; migrate existing ones when touched, preserving rendered styles.
diff --git a/plugins/woocommerce/changelog/add-cart-checkout-motion-foundation b/plugins/woocommerce/changelog/add-cart-checkout-motion-foundation
new file mode 100644
index 00000000000..ff9d76535d2
--- /dev/null
+++ b/plugins/woocommerce/changelog/add-cart-checkout-motion-foundation
@@ -0,0 +1,4 @@
+Significance: patch
+Type: tweak
+
+Use consistent motion timing in the Cart and Checkout blocks, and keep the loading spinner still when reduced motion is preferred.
diff --git a/plugins/woocommerce/client/blocks/.stylelintrc.json b/plugins/woocommerce/client/blocks/.stylelintrc.json
index 275eb527ebf..d7da814473e 100644
--- a/plugins/woocommerce/client/blocks/.stylelintrc.json
+++ b/plugins/woocommerce/client/blocks/.stylelintrc.json
@@ -1,7 +1,8 @@
{
"extends": "@wordpress/stylelint-config/scss-stylistic",
"plugins": [
- "@wordpress/theme/stylelint-plugins/no-token-fallback-values"
+ "@wordpress/theme/stylelint-plugins/no-token-fallback-values",
+ "./bin/stylelint-plugins/motion.js"
],
"reportNeedlessDisables": true,
"rules": {
@@ -24,5 +25,29 @@
true,
{ "ignoreFunctions": [ "calc", "var" ] }
]
- }
+ },
+ "overrides": [
+ {
+ "files": [
+ "assets/js/blocks/{cart,checkout,cart-checkout-shared,order-confirmation}/**/*.scss",
+ "assets/js/base/components/{button,notice-banner,loading-mask,rolling-price,cart-checkout,skeleton,quantity-selector}/**/*.scss",
+ "packages/public-api/blocks-components/**/*.scss",
+ "assets/css/abstracts/_mixins.scss",
+ "assets/css/abstracts/_motion.scss"
+ ],
+ "rules": {
+ "woocommerce/motion-safe": true,
+ "declaration-property-value-disallowed-list": [
+ {
+ "/^(-(webkit|moz|ms|o)-)?transition/": [
+ "/(^|[\\s,])all(?![\\w-])/i"
+ ]
+ },
+ {
+ "message": "List transitioned properties instead of \"all\". See docs/contributors/motion.md."
+ }
+ ]
+ }
+ }
+ ]
}
diff --git a/plugins/woocommerce/client/blocks/assets/css/abstracts/_mixins.scss b/plugins/woocommerce/client/blocks/assets/css/abstracts/_mixins.scss
index ac3a2dc8c8e..1530db6eefa 100644
--- a/plugins/woocommerce/client/blocks/assets/css/abstracts/_mixins.scss
+++ b/plugins/woocommerce/client/blocks/assets/css/abstracts/_mixins.scss
@@ -4,6 +4,8 @@
@use "sass:meta";
@use "sass:string";
+@import "motion";
+
$fontSizes: (
"smaller": 0.75,
"small": 0.875,
@@ -55,12 +57,6 @@ $fontSizes: (
@mixin spinner-animation() {
@keyframes spinner__animation {
0% {
- animation-timing-function: cubic-bezier(
- 0.5856,
- 0.0703,
- 0.4143,
- 0.9297
- );
transform: rotate(0deg);
}
100% {
@@ -119,11 +115,10 @@ $fontSizes: (
);
transform: translateX(-100%);
@include loading-animation();
- animation: loading__animation 1.5s ease-in-out infinite;
- }
- @media screen and (prefers-reduced-motion: reduce) {
- animation: none;
+ @include motion-safe {
+ animation: loading__animation 1.5s ease-in-out infinite;
+ }
}
}
@@ -366,10 +361,8 @@ $fontSizes: (
color-mix(in srgb, currentColor 5%, transparent) 50%,
transparent 100%
);
- animation: wc-skeleton-shimmer 1.25s infinite;
-
- @media (prefers-reduced-motion: reduce) {
- animation: none;
+ @include motion-safe {
+ animation: wc-skeleton-shimmer 1.25s infinite;
}
}
@@ -381,18 +374,10 @@ $fontSizes: (
}
@mixin skeleton-animation-fade() {
- transition: background-color 0.2s ease;
+ transition: motion-state(background-color);
&::after {
- transition: background-color 0.2s ease;
- }
-
- @media (prefers-reduced-motion: reduce) {
- transition: background-color 0.2s ease;
-
- &::after {
- transition: background-color 0.2s ease;
- }
+ transition: motion-state(background-color);
}
}
diff --git a/plugins/woocommerce/client/blocks/assets/css/abstracts/_motion.scss b/plugins/woocommerce/client/blocks/assets/css/abstracts/_motion.scss
new file mode 100644
index 00000000000..2eec0dc807c
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/assets/css/abstracts/_motion.scss
@@ -0,0 +1,143 @@
+// Motion helpers for WooCommerce blocks. See docs/contributors/motion.md.
+// Each helper writes the state change (color, opacity: 200ms, subtle) so that it always runs. It adds movement only
+// inside `motion-safe`, so movement stops with reduced motion. The shared keyframes are in `assets/css/style.scss`.
+@use "sass:list";
+@use "sass:selector";
+
+// Woo motion constants that WPDS does not have.
+$wc-scale-press: 0.97;
+$wc-scale-icon-from: 0.8;
+$wc-blur-icon: 4px;
+
+// Rows after this number share the last stagger step, so long lists do not wait.
+$wc-stagger-cap: 7;
+
+@mixin motion-safe() {
+ @media (prefers-reduced-motion: no-preference) {
+ @content;
+ }
+}
+
+@function motion-duration($step) {
+ @return var(--wpds-motion-duration-#{$step});
+}
+
+@function motion-easing($name) {
+ @return var(--wpds-motion-easing-#{$name});
+}
+
+// A comma-separated transition list: each property with the same duration and timing function.
+@function -motion-list($properties, $duration, $timing) {
+ $list: ();
+ @each $property in $properties {
+ $list: list.append($list, $property $duration $timing, $separator: comma);
+ }
+ @return $list;
+}
+
+// State changes: 200ms, subtle, both ways.
+@function motion-state($properties...) {
+ @return -motion-list($properties, motion-duration(md), motion-easing(subtle));
+}
+
+// Keeps each property at its old value until a 200ms fade ends, for example `visibility` while an element fades out.
+@function motion-hold($properties...) {
+ @return -motion-list($properties, motion-duration(md), step-end);
+}
+
+// Movement: `lg` for movement in, `md` for movement out or in place, `sm` for the press.
+@function motion-move($properties, $duration: lg, $easing: expressive) {
+ @return -motion-list($properties, motion-duration($duration), motion-easing($easing));
+}
+
+// Transitions $state as a state change. When motion is allowed, also transitions $move as movement over $duration.
+// Empty lists are not written.
+@mixin motion-transition($state: (), $move: (), $duration: lg, $easing: expressive) {
+ @if list.length($state) > 0 {
+ transition: motion-state($state...);
+ }
+ @if list.length($move) > 0 {
+ @include motion-safe {
+ transition: motion-move($move, $duration, $easing), motion-state($state...);
+ }
+ }
+}
+
+// Dims the element to half opacity while it matches $states, for example `".is-disabled"`. The transition is on the
+// element, not on the state, so the element also fades back. @content adds declarations to the dimmed state.
+@mixin motion-dim($states) {
+ transition: motion-state(opacity);
+
+ @at-root #{selector.append(&, $states)} {
+ opacity: 0.5;
+ @content;
+ }
+}
+
+// Fades content in when it mounts: 200ms, subtle. Runs with reduced motion.
+@mixin motion-fade-in($delay: null) {
+ animation: wc-fade-in motion-duration(md) motion-easing(subtle) $delay backwards;
+}
+
+// Fades content out and keeps it hidden until it unmounts.
+@mixin motion-fade-out() {
+ animation: wc-fade-out motion-duration(md) motion-easing(subtle) forwards;
+}
+
+// Content that appears. It fades in. When motion is allowed, it also plays $keyframes over $duration.
+@mixin motion-enter($keyframes: wc-rise, $duration: lg, $delay: null) {
+ @include motion-fade-in($delay);
+ @include motion-safe {
+ animation:
+ wc-fade-in motion-duration(md) motion-easing(subtle) $delay backwards,
+ $keyframes motion-duration($duration) motion-easing(expressive) $delay backwards;
+ }
+}
+
+// Content that goes. It fades out. When motion is allowed, it also plays $keyframes. It keeps the end state until it
+// unmounts.
+@mixin motion-exit($keyframes) {
+ @include motion-fade-out;
+ @include motion-safe {
+ animation:
+ wc-fade-out motion-duration(md) motion-easing(subtle) forwards,
+ $keyframes motion-duration(md) motion-easing(expressive) forwards;
+ }
+}
+
+// Sets --wc-motion-index on sibling rows. Rows after $wc-stagger-cap share the last index. `--wc-motion-index` is
+// registered as an integer in `assets/css/style.scss`, so `sibling-index()` counts the row, not the child that reads
+// it. Browsers without `sibling-index()` use `nth-child`. The `@supports` tests use a literal time, not `var()`.
+@mixin motion-stagger-index() {
+ @supports (animation-delay: calc(sibling-index() * 1s)) {
+ --wc-motion-index: min(sibling-index() - 1, #{$wc-stagger-cap - 1});
+ }
+
+ @supports not (animation-delay: calc(sibling-index() * 1s)) {
+ @for $i from 1 to $wc-stagger-cap {
+ &:nth-child(#{$i}) {
+ --wc-motion-index: #{$i - 1};
+ }
+ }
+ &:nth-child(n + #{$wc-stagger-cap}) {
+ --wc-motion-index: #{$wc-stagger-cap - 1};
+ }
+ }
+}
+
+// The delay for a row: its index, plus $extra steps, times 50ms.
+@function motion-stagger-delay($extra: 0) {
+ @return calc((var(--wc-motion-index) + #{$extra}) * var(--wpds-motion-duration-xs));
+}
+
+// Sibling rows enter in sequence, 50ms apart.
+@mixin motion-stagger($keyframes: wc-rise) {
+ @include motion-stagger-index;
+ @include motion-enter($keyframes, $delay: motion-stagger-delay());
+
+ // When a section enters as one unit, its rows enter with it and do not stagger. The motion that moves the section
+ // sets one of these attributes.
+ :where([data-wc-entering], [data-wc-swapping]) & {
+ animation: none;
+ }
+}
diff --git a/plugins/woocommerce/client/blocks/assets/css/style.scss b/plugins/woocommerce/client/blocks/assets/css/style.scss
index e62c4574fe2..000577876ba 100644
--- a/plugins/woocommerce/client/blocks/assets/css/style.scss
+++ b/plugins/woocommerce/client/blocks/assets/css/style.scss
@@ -2,6 +2,50 @@
--wc-separator-color: color-mix(in srgb, currentColor 20%, transparent);
}
+// The stagger step of a row. Registered as an integer, so a `sibling-index()` value is counted on the row that sets it,
+// and its children inherit that number. See `motion-stagger-index`.
+@property --wc-motion-index {
+ syntax: "<integer>";
+ inherits: true;
+ initial-value: 0;
+}
+
+// Shared motion keyframes. Use them through the motion mixins. Fades and movement are separate keyframes, so opacity
+// always uses the state change timing. Movement uses `translate`, `scale`, and `filter`, so it combines with the
+// resting `transform` of an element.
+@keyframes wc-fade-in {
+ from {
+ opacity: 0;
+ }
+}
+
+@keyframes wc-fade-out {
+ to {
+ opacity: 0;
+ }
+}
+
+@keyframes wc-rise {
+ from {
+ translate: 0 4px;
+ }
+}
+
+// Icons and small items grow in with scale and blur.
+@keyframes wc-grow {
+ from {
+ scale: $wc-scale-icon-from;
+ filter: blur($wc-blur-icon);
+ }
+}
+
+@keyframes wc-shrink {
+ to {
+ scale: $wc-scale-icon-from;
+ filter: blur($wc-blur-icon);
+ }
+}
+
body.wc-modal--open {
overflow: hidden;
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/components/button/style.scss b/plugins/woocommerce/client/blocks/assets/js/base/components/button/style.scss
index 2920e0f753a..e2a4296160f 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/components/button/style.scss
+++ b/plugins/woocommerce/client/blocks/assets/js/base/components/button/style.scss
@@ -41,7 +41,7 @@
height: auto;
justify-content: center;
position: relative;
- transition: box-shadow 0.1s linear;
+ transition: motion-state(box-shadow);
&:not(:where(.wp-block-woocommerce-cart *, .wp-block-woocommerce-checkout *)) {
@include button-appearance;
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/cart-line-items-table/style.scss b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/cart-line-items-table/style.scss
index 9a0d911455b..6609e22f335 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/cart-line-items-table/style.scss
+++ b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/cart-line-items-table/style.scss
@@ -125,10 +125,8 @@ table.wc-block-cart-items {
line-height: 1.4;
}
- &.is-disabled {
- opacity: 0.5;
+ @include motion-dim(".is-disabled") {
pointer-events: none;
- transition: opacity 200ms ease;
}
}
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/password-strength-meter/style.scss b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/password-strength-meter/style.scss
index aa17e62157a..b1d49b377fe 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/password-strength-meter/style.scss
+++ b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/password-strength-meter/style.scss
@@ -34,11 +34,11 @@
&::-webkit-meter-suboptimum-value {
background: none;
background-color: currentColor;
- transition: 0.2s ease;
border-radius: calc($gap-smaller / 2);
border: 0;
height: $gap-smaller;
vertical-align: middle;
+ transition: motion-state(background-color);
}
&:-moz-meter-optimum::-moz-meter-bar,
@@ -46,11 +46,11 @@
&:-moz-meter-sub-sub-optimum::-moz-meter-bar {
background: none;
background-color: currentColor;
- transition: 0.2s ease;
border-radius: calc($gap-smaller / 2);
border: 0;
height: $gap-smaller;
vertical-align: middle;
+ transition: motion-state(background-color);
}
}
.wc-block-components-password-strength__result {
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/components/notice-banner/style.scss b/plugins/woocommerce/client/blocks/assets/js/base/components/notice-banner/style.scss
index 973be039abf..c40557df0d7 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/components/notice-banner/style.scss
+++ b/plugins/woocommerce/client/blocks/assets/js/base/components/notice-banner/style.scss
@@ -66,7 +66,7 @@
opacity: 0.7;
text-decoration-line: underline;
text-underline-position: under;
- transition: all 0.2s ease-in-out;
+ transition: motion-state(opacity);
&:hover,
&:focus,
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/cart-checkout-shared/payment-methods/style-legacy.scss b/plugins/woocommerce/client/blocks/assets/js/blocks/cart-checkout-shared/payment-methods/style-legacy.scss
index 8dcdd587915..563162536f4 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/cart-checkout-shared/payment-methods/style-legacy.scss
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/cart-checkout-shared/payment-methods/style-legacy.scss
@@ -73,16 +73,12 @@
top: 0;
transform-origin: top left;
color: $gray-700;
- transition: transform 200ms ease;
margin: 0 0 0 #{$gap + 1px};
overflow: hidden;
text-overflow: ellipsis;
max-width: calc(100% - #{$gap + $gap-smaller});
cursor: text;
-
- @media screen and (prefers-reduced-motion: reduce) {
- transition: none;
- }
+ @include motion-transition($move: transform, $duration: md, $easing: balanced);
}
&.wc-inline-card-element {
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/checkout/address-wrapper/style.scss b/plugins/woocommerce/client/blocks/assets/js/blocks/checkout/address-wrapper/style.scss
index ab314982ea9..395a370f2f2 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/checkout/address-wrapper/style.scss
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/checkout/address-wrapper/style.scss
@@ -7,9 +7,20 @@
}
&.is-animated {
- .wc-block-components-address-card-wrapper,
- .wc-block-components-address-form-wrapper {
- transition: all 300ms ease-in-out;
+ .wc-block-components-address-card-wrapper {
+ transition: motion-state(opacity);
+ }
+
+ &.is-editing {
+ // The card covers the form while it fades out. `step-end` keeps it
+ // visible until the fade ends. Then it hides it from assistive technology.
+ .wc-block-components-address-card-wrapper {
+ transition: motion-state(opacity), motion-hold(visibility);
+ }
+
+ .wc-block-components-address-form-wrapper {
+ @include motion-fade-in;
+ }
}
}
diff --git a/plugins/woocommerce/client/blocks/bin/stylelint-plugins/motion.js b/plugins/woocommerce/client/blocks/bin/stylelint-plugins/motion.js
new file mode 100644
index 00000000000..0c63f48a8be
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/bin/stylelint-plugins/motion.js
@@ -0,0 +1,278 @@
+/**
+ * `woocommerce/motion-safe`: a `transition*` or `animation*` declaration (other than `none`) must be inside
+ * `@include motion-safe` or `@keyframes`. Transitions that only fade or change color, including `motion-state()` of
+ * those properties and `motion-hold()`, and the shared fade animations, can be anywhere, because they do not move
+ * anything. The `$state` of `@include motion-transition` follows the same rule, because it runs with reduced motion.
+ * Times in these declarations must use duration tokens, except in an item that loops (`infinite`).
+ * See docs/contributors/motion.md.
+ */
+const { list } = require( 'postcss' );
+const stylelint = require( 'stylelint' );
+
+const {
+ createPlugin,
+ utils: { report, ruleMessages, validateOptions },
+} = stylelint;
+
+const ruleName = 'woocommerce/motion-safe';
+
+const messages = ruleMessages( ruleName, {
+ rejected: ( prop ) =>
+ `Use a motion mixin, or put "${ prop }" in \`@include motion-safe { … }\`, so that it obeys reduced motion. Only transitions of opacity and colors can be outside it.`,
+ rejectedState: () =>
+ 'The `$state` of `motion-transition` runs with reduced motion, so it can list only opacity and colors. Pass movement as `$move`.',
+ rejectedTime: ( time ) =>
+ `Use a WPDS motion duration token instead of "${ time }". Only loops (\`infinite\`) can use literal times.`,
+} );
+
+const VENDOR_PREFIXES = [ '-webkit-', '-moz-', '-ms-', '-o-' ];
+
+// `-webkit-animation` moves things just like `animation`, so check it the same way.
+const unprefixed = ( prop ) => {
+ const prefix = VENDOR_PREFIXES.find( ( p ) => prop.startsWith( p ) );
+ return prefix ? prop.slice( prefix.length ) : prop;
+};
+
+const FADE_PROPERTIES = new Set( [
+ 'opacity',
+ 'color',
+ 'background-color',
+ 'border-color',
+ 'border-top-color',
+ 'border-right-color',
+ 'border-bottom-color',
+ 'border-left-color',
+ 'border-block-color',
+ 'border-block-start-color',
+ 'border-block-end-color',
+ 'border-inline-color',
+ 'border-inline-start-color',
+ 'border-inline-end-color',
+ 'outline-color',
+ 'box-shadow',
+ 'fill',
+ 'stroke',
+ 'text-decoration-color',
+ '-webkit-text-fill-color',
+] );
+
+// Splits a comma-separated value. Commas inside parentheses, such as in `cubic-bezier( … )`, do not split it.
+const splitList = ( value ) => list.comma( value ).filter( Boolean );
+
+const FADE_KEYFRAMES = new Set( [ 'wc-fade-in', 'wc-fade-out' ] );
+
+// Helpers from `_motion.scss`. `motion-hold()` jumps at the end (`step-end`), so it never animates any property.
+// `motion-state()` animates, so each property must fade or change colour.
+const isFadeFunction = ( item, decl ) => {
+ if ( ! item.endsWith( ')' ) ) {
+ return false;
+ }
+ if ( item.startsWith( 'motion-hold(' ) ) {
+ return true;
+ }
+ if ( ! item.startsWith( 'motion-state(' ) ) {
+ return false;
+ }
+ return splitList( item.slice( 'motion-state('.length, -1 ) ).every(
+ ( property ) => isFadeProperty( property, decl )
+ );
+};
+
+// The names of the parameters of a `@mixin`, for example `$state` and `$move` in `motion-transition($state: (), …)`.
+const mixinParameters = ( { params } ) => {
+ const open = params.indexOf( '(' );
+ if ( open === -1 || ! params.endsWith( ')' ) ) {
+ return [];
+ }
+ return splitList( params.slice( open + 1, -1 ) ).map( ( parameter ) =>
+ parameter.split( ':' )[ 0 ].replace( '...', '' ).trim()
+ );
+};
+
+// The items of a Sass list value, for example `opacity` and `color` in `(opacity, color)`.
+const listTokens = ( value ) =>
+ [ ...value ]
+ .map( ( character ) =>
+ '(),'.includes( character ) || character.trim() === ''
+ ? ' '
+ : character
+ )
+ .join( '' )
+ .split( ' ' )
+ .filter( Boolean );
+
+// Whether `item` assigns the Sass variable `name`, directly or as an `@each` or `@for` loop variable.
+const assigns = ( item, name ) =>
+ ( item.type === 'decl' && item.prop === name ) ||
+ ( item.type === 'atrule' &&
+ [ 'each', 'for' ].includes( item.name ) &&
+ item.params
+ .split( /\s+(?:in|from)\s+/ )[ 0 ]
+ .split( ',' )
+ .map( ( variable ) => variable.trim() )
+ .includes( name ) );
+
+// A property that only fades or changes colour, or a parameter of the enclosing mixin that the mixin does not assign,
+// such as the `$state` that `motion-transition` forwards. Other Sass variables fail, because the lint does not work out
+// their value: list the properties instead.
+const isFadeProperty = ( property, node ) => {
+ if ( ! property.startsWith( '$' ) ) {
+ return FADE_PROPERTIES.has( property.toLowerCase() );
+ }
+ const name = property.replace( '...', '' );
+ let mixin = node.parent;
+ while ( mixin && ! ( mixin.type === 'atrule' && mixin.name === 'mixin' ) ) {
+ mixin = mixin.parent;
+ }
+ if ( ! mixin || ! mixinParameters( mixin ).includes( name ) ) {
+ return false;
+ }
+ let isAssigned = false;
+ mixin.walk( ( item ) => {
+ isAssigned = assigns( item, name );
+ return ! isAssigned;
+ } );
+ return ! isAssigned;
+};
+
+// A `transition` or `transition-property` that only fades or changes color, or an `animation` that only fades.
+const isFadeOnly = ( prop, decl ) => {
+ const { value } = decl;
+ if ( prop === 'animation' || prop === 'animation-name' ) {
+ return splitList( value ).every( ( item ) =>
+ item.split( /\s+/ ).some( ( token ) => FADE_KEYFRAMES.has( token ) )
+ );
+ }
+ if ( prop !== 'transition' && prop !== 'transition-property' ) {
+ return false;
+ }
+ return splitList( value ).every(
+ ( item ) =>
+ isFadeFunction( item, decl ) ||
+ FADE_PROPERTIES.has( item.split( /\s+/ )[ 0 ].toLowerCase() )
+ );
+};
+
+// `@media … prefers-reduced-motion` is not a guard: it can also match `reduce`. Use `motion-safe`.
+const isGuard = ( { type, name, params } ) =>
+ type === 'atrule' &&
+ ( name.endsWith( 'keyframes' ) ||
+ ( name === 'include' && params.startsWith( 'motion-safe' ) ) );
+
+const isGuarded = ( node ) => {
+ for ( let parent = node.parent; parent; parent = parent.parent ) {
+ if ( isGuard( parent ) ) {
+ return true;
+ }
+ }
+ return false;
+};
+
+// The `$state` argument of `@include motion-transition( … )`, named or first positional, or null when there is none.
+const motionTransitionState = ( { params } ) => {
+ const name = 'motion-transition';
+ const rest = params.slice( name.length ).trim();
+ if ( ! params.startsWith( name ) || ! rest.startsWith( '(' ) ) {
+ return null;
+ }
+ const args = splitList( rest.slice( 1, -1 ) );
+ for ( const arg of args ) {
+ const colon = arg.indexOf( ':' );
+ if ( colon !== -1 && arg.slice( 0, colon ).trim() === '$state' ) {
+ return arg.slice( colon + 1 ).trim();
+ }
+ }
+ const first = args[ 0 ];
+ const colon = first ? first.indexOf( ':' ) : -1;
+ const isNamed =
+ colon !== -1 &&
+ first.startsWith( '$' ) &&
+ ! first.slice( 0, colon ).trim().includes( ' ' );
+ return first && ! isNamed ? first : null;
+};
+
+// A non-zero time such as `100ms`, `.2s` or `-1s`. Durations and delays must use tokens.
+const LITERAL_TIME = /^[+-]?[\d.]*[1-9][\d.]*m?s$/i;
+
+// The first literal time in `value`, at any depth, such as in `calc( var( … ) + 100ms )`. An item that loops
+// (`infinite`) can use literal times.
+const literalTime = ( value ) => {
+ for ( const item of splitList( value ) ) {
+ const tokens = item.split( /[\s(),*/]+/ );
+ if ( ! tokens.includes( 'infinite' ) ) {
+ const time = tokens.find( ( token ) => LITERAL_TIME.test( token ) );
+ if ( time ) {
+ return time;
+ }
+ }
+ }
+ return null;
+};
+
+const ruleFunction = ( primary ) => ( root, result ) => {
+ if (
+ ! validateOptions( result, ruleName, {
+ actual: primary,
+ possible: [ true ],
+ } )
+ ) {
+ return;
+ }
+ root.walkDecls( ( decl ) => {
+ const prop = unprefixed( decl.prop.toLowerCase() );
+ if (
+ ! prop.startsWith( 'transition' ) &&
+ ! prop.startsWith( 'animation' )
+ ) {
+ return;
+ }
+ const time = literalTime( decl.value );
+ if ( time ) {
+ report( {
+ message: messages.rejectedTime( time ),
+ node: decl,
+ word: time,
+ result,
+ ruleName,
+ } );
+ }
+ if (
+ decl.value.trim() === 'none' ||
+ isFadeOnly( prop, decl ) ||
+ isGuarded( decl )
+ ) {
+ return;
+ }
+ report( {
+ message: messages.rejected( decl.prop ),
+ node: decl,
+ word: decl.prop,
+ result,
+ ruleName,
+ } );
+ } );
+ root.walkAtRules( 'include', ( include ) => {
+ const state = motionTransitionState( include );
+ if (
+ state === null ||
+ isGuarded( include ) ||
+ listTokens( state ).every( ( token ) =>
+ isFadeProperty( token, include )
+ )
+ ) {
+ return;
+ }
+ report( {
+ message: messages.rejectedState(),
+ node: include,
+ word: '$state',
+ result,
+ ruleName,
+ } );
+ } );
+};
+
+ruleFunction.ruleName = ruleName;
+ruleFunction.messages = messages;
+
+module.exports = createPlugin( ruleName, ruleFunction );
diff --git a/plugins/woocommerce/client/blocks/bin/stylelint-plugins/test/motion.js b/plugins/woocommerce/client/blocks/bin/stylelint-plugins/test/motion.js
new file mode 100644
index 00000000000..0e2c6ad7de5
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/bin/stylelint-plugins/test/motion.js
@@ -0,0 +1,184 @@
+/**
+ * External dependencies
+ */
+const path = require( 'path' );
+
+// Stylelint does not load in the jsdom environment of the tests, so the rule runs on its own, with the parts of the
+// stylelint API that it uses.
+const mockReports = [];
+jest.mock( 'stylelint', () => ( {
+ createPlugin: ( ruleName, rule ) => ( { ruleName, rule } ),
+ utils: {
+ report: ( problem ) => mockReports.push( problem ),
+ ruleMessages: ( ruleName, messages ) => messages,
+ validateOptions: () => true,
+ },
+} ) );
+
+/**
+ * Internal dependencies
+ */
+const { rule } = require( '../motion' );
+
+// The SCSS syntax that the WordPress stylelint config uses.
+const scss = require(
+ require.resolve( 'postcss-scss', {
+ paths: [
+ path.dirname(
+ require.resolve( '@wordpress/stylelint-config/package.json' )
+ ),
+ ],
+ } )
+);
+
+const lint = ( code ) => {
+ mockReports.length = 0;
+ rule( true )( scss.parse( code ), {} );
+ return mockReports.map( ( { message } ) => message );
+};
+
+const guarded = ( declaration ) =>
+ `.a {\n\t@include motion-safe {\n\t\t${ declaration };\n\t}\n}`;
+
+const fade = ( state ) => `.a { transition: motion-state(${ state }); }`;
+
+describe( 'woocommerce/motion-safe', () => {
+ describe( 'movement outside motion-safe', () => {
+ it.each( [
+ [ 'a fade', '.a { transition: opacity var(--d); }' ],
+ [
+ 'a guarded transform',
+ guarded( 'transition: transform var(--d)' ),
+ ],
+ [
+ 'a single-line fade animation',
+ '.a { animation: wc-fade-in var(--d); }',
+ ],
+ [
+ 'a tab-separated fade animation',
+ '.a { animation: wc-fade-in\tvar(--d); }',
+ ],
+ [
+ 'a multiline fade animation',
+ '.a {\n\tanimation:\n\t\twc-fade-in\n\t\tvar(--d);\n}',
+ ],
+ [
+ 'a multiline fade transition',
+ '.a {\n\ttransition:\n\t\topacity\n\t\tvar(--d);\n}',
+ ],
+ ] )( 'allows %s', ( _, code ) => {
+ expect( lint( code ) ).toEqual( [] );
+ } );
+
+ it.each( [
+ [
+ 'an unguarded transform',
+ '.a { transition: transform var(--d); }',
+ ],
+ [
+ 'an unguarded prefixed animation',
+ '.a { -webkit-animation: wc-rise var(--d); }',
+ ],
+ [
+ 'a multiline transform',
+ '.a {\n\ttransition:\n\t\ttransform\n\t\tvar(--d);\n}',
+ ],
+ ] )( 'rejects %s', ( _, code ) => {
+ expect( lint( code ) ).toHaveLength( 1 );
+ } );
+ } );
+
+ describe( 'literal times', () => {
+ it.each( [
+ [ 'a token', guarded( 'transition-duration: var(--d)' ) ],
+ [
+ 'a calc of tokens',
+ guarded( 'transition-duration: calc(var(--d) * 2)' ),
+ ],
+ [ 'zero times', guarded( 'transition-delay: 0s, 0ms' ) ],
+ [
+ 'a loop',
+ guarded( 'animation: wc-shimmer 1.5s infinite linear' ),
+ ],
+ [
+ 'numbers in cubic-bezier',
+ guarded(
+ 'transition: transform var(--d) cubic-bezier(0.4, 0, 0.2, 1)'
+ ),
+ ],
+ ] )( 'allows %s', ( _, code ) => {
+ expect( lint( code ) ).toEqual( [] );
+ } );
+
+ it.each( [
+ [ 'a bare time', guarded( 'transition-duration: 100ms' ) ],
+ [
+ 'a time inside calc',
+ guarded( 'transition-duration: calc(var(--d) + 100ms)' ),
+ ],
+ [
+ 'a time inside calc without spaces',
+ guarded( 'transition-duration: calc(var(--d)+100ms)' ),
+ ],
+ [
+ 'a fallback inside var',
+ guarded( 'transition-duration: var(--d, .2s)' ),
+ ],
+ [ 'a negative delay', guarded( 'transition-delay: -100ms' ) ],
+ [
+ 'a finite item next to a loop',
+ guarded(
+ 'animation: wc-fade-in 123ms, wc-shimmer 1.5s infinite'
+ ),
+ ],
+ [
+ 'a prefixed time',
+ guarded( '-webkit-transition-duration: 100ms' ),
+ ],
+ ] )( 'rejects %s', ( _, code ) => {
+ expect( lint( code ) ).toHaveLength( 1 );
+ } );
+ } );
+
+ describe( 'Sass variables in motion-state() and motion-transition', () => {
+ it.each( [
+ [
+ 'a mixin parameter',
+ '@mixin m($state: ()) { transition: motion-state($state); }',
+ ],
+ [
+ 'a mixin parameter forwarded to motion-transition',
+ '@mixin m($state: ()) { @include motion-transition($state: $state); }',
+ ],
+ [
+ 'a mixin parameter in a nested rule',
+ '@mixin m($state: ()) { .a { transition: motion-state($state...); } }',
+ ],
+ ] )( 'allows %s', ( _, code ) => {
+ expect( lint( code ) ).toEqual( [] );
+ } );
+
+ it.each( [
+ [ 'a root variable', `$state: opacity;\n${ fade( '$state' ) }` ],
+ [
+ 'a root variable in motion-transition',
+ '$state: opacity;\n.a { @include motion-transition($state: $state); }',
+ ],
+ [ 'an unknown variable', fade( '$nope' ) ],
+ [
+ 'a variable that is not a parameter of the mixin',
+ '$state: opacity;\n@mixin m { transition: motion-state($state); }',
+ ],
+ [
+ 'a mixin parameter that the mixin assigns',
+ '@mixin m($state: ()) { $state: transform; transition: motion-state($state); }',
+ ],
+ [
+ 'a mixin parameter that a loop rebinds',
+ '@mixin m($state: ()) { @each $state in transform { .a { transition: motion-state($state); } } }',
+ ],
+ ] )( 'rejects %s', ( _, code ) => {
+ expect( lint( code ) ).toHaveLength( 1 );
+ } );
+ } );
+} );
diff --git a/plugins/woocommerce/client/blocks/docs/contributors/README.md b/plugins/woocommerce/client/blocks/docs/contributors/README.md
index f761965050d..8790ffa3a89 100644
--- a/plugins/woocommerce/client/blocks/docs/contributors/README.md
+++ b/plugins/woocommerce/client/blocks/docs/contributors/README.md
@@ -32,6 +32,10 @@ The [Block Script Assets](block-assets.md) document elucidates how Block Script
Our [JavaScript Build System](javascript-build-system.md) guide offers a detailed explanation of how JavaScript files are built. This is a crucial read for understanding the behind-the-scenes operations of your code.
+### [Motion](motion.md)
+
+The [Motion](motion.md) guide gives the motion tokens, the rules for animation in WooCommerce blocks, the rules for reduced motion, and how to add and test motion.
+
### [CSS Build System](css-build-system.md)
Last but not least, to get an insight into how CSS is built, refer to the [CSS Build System](css-build-system.md) guide. A firm grasp of this will ensure your CSS files meet the standards and quality expected.
diff --git a/plugins/woocommerce/client/blocks/docs/contributors/motion.md b/plugins/woocommerce/client/blocks/docs/contributors/motion.md
new file mode 100644
index 00000000000..a2b69e90513
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/docs/contributors/motion.md
@@ -0,0 +1,129 @@
+# Motion
+
+This guide gives the rules for motion in WooCommerce blocks, how to add motion, and how to test it. Motion started in the Cart and Checkout blocks, so most examples come from them.
+
+The rules use the [WordPress Design System](https://github.com/WordPress/gutenberg/tree/trunk/packages/theme) (WPDS) motion tokens and its approach to reduced motion.
+
+This guide uses these terms:
+
+- **Movement**: a change to position, size, or the visible area of an element.
+- **State change**: a change to color, background, border color, opacity, or a focus ring.
+- **Reduced motion**: the `prefers-reduced-motion: reduce` setting.
+
+## Rules
+
+- **Animate what the shopper does.** A click or a tap animates. Content that loads with the page appears immediately, apart from the lists in the next rule. A later change that the shopper's action causes can animate, such as a totals row, a notice, or an error.
+- **Where appropriate, list items stagger on first load.** The items of a list, such as cart items, order summary items, or the order confirmation sections, can rise in 50ms apart when the page first shows them. They do not stagger again, such as after an update, a new item, or a key press. Lists of options, such as shipping or payment methods, appear immediately.
+- **Keyboard changes apply immediately.** A shopper can press keys quickly, for example to move through options. After a key press, content that shows, hides, or swaps does not animate.
+- **Content moves to make space.** Content that appears grows from nothing, and the content below moves down. Content that goes collapses, and the content below moves up. Nothing jumps.
+- **One change, one movement.** When one action changes many things, the content below moves one time, in one direction.
+- **Motion follows the selection.** When the shopper picks another option in a row of options, such as Ship or Pickup, the selection slides to the new option. Content that the choice swaps moves the same way: the old content leaves in that direction, and the new content follows from the other side.
+- **Exits are shorter than entrances.** Movement in takes 300ms. Movement out takes 200ms.
+- **Interrupted motion turns around.** When the direction changes during motion, the motion continues from its current position. For example, a panel can close while it opens.
+- **Nothing blocks.** Clicks and typing work while motion runs.
+- **Leave nothing behind.** When motion ends, the page is the same as without motion. Remove all extra elements, inline styles, attributes, and held animations.
+- **Respect reduced motion.** Nothing moves, but changes are still visible. See [Reduced motion](#reduced-motion).
+- **Keep public components compatible.** Components in `packages/public-api/blocks-components` are public. Add only optional props, keep the markup and class names that themes can use, and write each change to them in the PR description. Scope new motion to the blocks that use it, such as `.wp-block-woocommerce-cart`.
+
+## Tokens
+
+Use a token for every duration and easing. Do not write raw values. Do not write a fallback inside `var()`: the build adds it, so that the storefront works without the WPDS stylesheet.
+
+| Token | Value | Use |
+|-------|-------|-----|
+| `--wpds-motion-duration-xs` | 50ms | Stagger steps. |
+| `--wpds-motion-duration-sm` | 100ms | The button press only. |
+| `--wpds-motion-duration-md` | 200ms | State changes, small changes in place, and exits. |
+| `--wpds-motion-duration-lg` | 300ms | Movement in. |
+| `--wpds-motion-easing-expressive` | `cubic-bezier(0.25, 0, 0, 1)` | Entrances, exits, and the press. |
+| `--wpds-motion-easing-balanced` | `cubic-bezier(0.4, 0, 0.2, 1)` | Movement between two positions, and size changes. |
+| `--wpds-motion-easing-subtle` | `cubic-bezier(0.15, 0, 0.15, 1)` | State changes. |
+
+`assets/css/abstracts/_motion.scss` has Woo constants for values that WPDS does not have, such as `$wc-scale-press`.
+
+## Durations
+
+| What | In | Out | Examples |
+|------|----|-----|----------|
+| Movement | `lg` 300ms | `md` 200ms | Content that rises in, grows, or collapses. Dropdowns, notices, snackbars. |
+| State change | `md` 200ms | `md` 200ms | Hover and focus, selected options, dims, field borders. |
+| Small change in place | `md` 200ms | `md` 200ms | Checkbox tick, radio dot, icon and spinner swaps. |
+| Press | `sm` 100ms | `sm` 100ms | The button press scale. |
+
+- A change of less than 200ms is too fast to see. WPDS uses 100ms for state changes, so Woo uses 200ms.
+- Opacity always uses the state change timing. When content moves in over 300ms, it fades in over 200ms.
+- Do not use `linear` easing, except for constant motion such as the spinner. Do not bounce.
+
+## Reduced motion
+
+With reduced motion, nothing moves, but changes are still visible. Fades and color changes still run, because they show what changed.
+
+Movement runs only inside `@include motion-safe` (`@media (prefers-reduced-motion: no-preference)`). Put the resting values outside it. The helpers do this for you.
+
+- Content that appears or goes still fades.
+- Movement that only adds feel, such as the press scale, has no reduced version.
+- The spinner stops halfway through a turn. The skeleton shimmer stops.
+
+The `woocommerce/motion-safe` stylelint rule checks this, and that durations use tokens. Another rule checks that transitions do not use `all`. These rules apply to the blocks that use motion and to the components they share. When a block starts to use motion, add its stylesheets to the `overrides` `files` list in `.stylelintrc.json`.
+
+## Helpers
+
+Use the helpers in `assets/css/abstracts/_motion.scss`. Do not write `transition` or `animation` values by hand. Each helper writes the state change so that it always runs, and adds the movement inside `motion-safe`.
+
+| Helper | Use | Example |
+|--------|-----|---------|
+| `transition: motion-state( … )` | A state change: 200ms, subtle. | `transition: motion-state( opacity, box-shadow );` |
+| `@include motion-transition( $state, $move, $duration, $easing )` | A state change and movement. `$move` runs over `$duration` (default `lg`), only when motion is allowed. | `@include motion-transition( $state: opacity, $move: translate );` |
+| `motion-hold( … )` | Keeps a property, such as `visibility`, at its old value until a fade ends. | `transition: motion-state( opacity ), motion-hold( visibility );` |
+| `@include motion-enter( $keyframes, $duration, $delay )` | Content that appears. It fades in, and plays `$keyframes` (default `wc-rise`). | `@include motion-enter( wc-grow, md );` |
+| `@include motion-exit( $keyframes )` | Content that goes. It fades out over 200ms and keeps the end state until it unmounts. | `@include motion-exit( wc-shrink );` |
+| `@include motion-stagger( $keyframes )` | Sibling rows that enter 50ms apart. It counts rows with `sibling-index()`, and with `nth-child` in browsers that do not have it. | `@include motion-stagger;` |
+| `@include motion-fade-in` / `motion-fade-out` | A fade with no movement. | |
+| `@include motion-dim( $states )` | Dims the element while `$states` matches, such as `".is-disabled"`. | Cart rows, disabled radios |
+| `@include motion-safe { … }` | Movement that the other helpers do not cover. | |
+
+`assets/css/style.scss` has the shared keyframes. `wc-fade-in` and `wc-fade-out` only fade. `wc-rise`, `wc-grow`, and `wc-shrink` move with `translate`, `scale`, and `filter`, so they combine with a fade and with the resting `transform` of an element.
+
+Use `@starting-style` with transitions for an element that is new on the page, such as a dropdown. Then all of its motion is a transition, and a transition turns around by itself.
+
+Motion that changes the layout runs in JavaScript, because it must measure sizes. JavaScript helpers end immediately when nothing animates, and in Jest. This section lists the JavaScript helpers when they are added.
+
+## Techniques
+
+Find the change in this table, and use the helpers above.
+
+| Change | Technique |
+|---|---|
+| Color, background, border color, opacity, or focus ring | A state change, both ways. |
+| An element is busy or disabled | It dims, and fades both ways. |
+| The shopper presses a button | The button scales down a little while pressed. |
+| A button shows a spinner | The label fades out, and the spinner grows in. |
+| A small icon, dot, or tick changes | It grows from a smaller size and fades in. |
+| Content appears in place, such as an empty state | It rises in and fades in. |
+| The rows of a list appear | The same rise, 50ms apart. A section that enters as one unit does not stagger its rows. |
+| A small item goes, such as a chip | It fades and shrinks in place. Then it unmounts. |
+| A dropdown opens from a field | It slides 4px from the field and fades in. It slides back to close. |
+| A toast or snackbar appears and goes | It rises in and drops out. |
+| Content appears or goes and moves the content below, such as a panel, notice, field error, or section | It grows and collapses in the real layout. It stays mounted while it goes. |
+| An element becomes a different view of itself, such as an address card that becomes its form | The two views crossfade while the height changes. |
+| A table row goes | It fades in place, and the rows below slide up. |
+
+Real layout means the element's height, padding, and margins change, so theme borders, spacing, and extension markup move with it. Use `transform` for everything else.
+
+## Test motion
+
+Automated tests cannot show how motion looks: Jest has no Web Animations API, layout, or paint, and end-to-end tests depend on timing. Check motion by hand in a real browser, on pages that use the blocks that you changed. Check at desktop width and phone width, in Chrome first. For motion that JavaScript runs, also check Safari and Firefox.
+
+To see the motion, slow it down with the Animations panel in DevTools, or record the screen and look at each frame.
+
+Do these checks by hand for each change, also with reduced motion:
+
+- **Change and reverse.** Do the change, then do the reverse. The content below moves in one direction each time, and nothing jumps.
+- **Interruption.** Reverse the change 80–150ms after it starts. The motion turns around from its current position.
+- **Keyboard.** Use Tab, Space, Enter, or the arrow keys. The change applies immediately.
+- **Late content.** Content that loads after the change, such as rates or totals, does not jump.
+- **First time.** Open the element for the first time on the page, with the smallest input that opens it. It must stay open. Motion makes an existing flicker easy to see, so fix the cause.
+- **Settled.** About 1 second after each change, the blocks have no attributes, inline styles, copies of content, or running animations that the motion added, and no console errors.
+- **Complete an order.** Place an order after the tests. Motion must not leave a field invalid or a button that does not work.
+
+Also run stylelint, ESLint, `pnpm test:js`, and the build. Make sure that the compiled CSS keeps the token fallbacks, for example `var(--wpds-motion-duration-md, .2s)`.
diff --git a/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/radio-control/style.scss b/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/radio-control/style.scss
index c96d1706db8..cf46763b5fb 100644
--- a/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/radio-control/style.scss
+++ b/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/radio-control/style.scss
@@ -238,11 +238,8 @@ $content-padding-left: calc($gap + 24px + $gap-smaller);
}
}
- &[aria-disabled="true"],
- &[disabled] {
+ @include motion-dim('[aria-disabled="true"], [disabled]') {
cursor: not-allowed;
- opacity: 0.5;
- transition: opacity 200ms ease;
}
}
}
diff --git a/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/spinner/style.scss b/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/spinner/style.scss
index faba6ecbcad..becb21e9024 100644
--- a/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/spinner/style.scss
+++ b/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/spinner/style.scss
@@ -18,12 +18,15 @@
height: 1em;
box-sizing: border-box;
transform-origin: 50% 50%;
- transform: translateZ(0) scale(0.5);
+ // Halfway through a turn. With reduced motion, the spinner stops in this position.
+ transform: rotate(180deg);
backface-visibility: hidden;
border-radius: 50%;
border: 0.2em solid currentColor;
border-left-color: transparent;
@include spinner-animation();
- animation: spinner__animation 1s infinite linear;
+ @include motion-safe {
+ animation: spinner__animation 1s infinite linear;
+ }
}
}
diff --git a/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/text-input/style.scss b/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/text-input/style.scss
index ed1c8240ac2..6eee1ee2282 100644
--- a/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/text-input/style.scss
+++ b/plugins/woocommerce/client/blocks/packages/public-api/blocks-components/text-input/style.scss
@@ -20,19 +20,17 @@
left: $gap-smaller * 1.25;
top: 25px;
transform-origin: top left;
- transition: all 200ms ease;
margin: 0;
overflow: hidden;
text-overflow: ellipsis;
max-width: calc(100% - #{2 * $gap-small});
cursor: text;
+ // Themes and extensions position the label with `top`, so `top` also animates.
+ @include motion-transition($state: color, $move: (top, transform), $duration: md, $easing: balanced);
.has-dark-controls & {
color: $input-placeholder-dark;
}
- @media screen and (prefers-reduced-motion: reduce) {
- transition: none;
- }
}
input[type="tel"],
@@ -88,13 +86,11 @@
}
// We delay the reveal so the mask doesn't sit behind the label while it floats up.
+ // With reduced motion, the label moves immediately, so there is no delay.
input[type="date"]::-webkit-datetime-edit {
- transition: opacity 150ms ease 150ms;
- }
-
- @media screen and (prefers-reduced-motion: reduce) {
- input[type="date"]::-webkit-datetime-edit {
- transition: none;
+ transition: motion-state(opacity);
+ @include motion-safe {
+ transition-delay: motion-duration(md);
}
}
diff --git a/plugins/woocommerce/client/blocks/tests/js/jest.config.js b/plugins/woocommerce/client/blocks/tests/js/jest.config.js
index 3e8fab394d9..85b94825bb4 100644
--- a/plugins/woocommerce/client/blocks/tests/js/jest.config.js
+++ b/plugins/woocommerce/client/blocks/tests/js/jest.config.js
@@ -134,7 +134,8 @@ module.exports = {
'<rootDir>/tests/js/config/msw-setup.js',
],
testPathIgnorePatterns: [
- '<rootDir>/bin/',
+ // The tests of the stylelint plugins run with the others.
+ '<rootDir>/bin/(?!stylelint-plugins/test/)',
'<rootDir>/build/',
'<rootDir>/docs/',
'<rootDir>/node_modules/',