@vvedantb/ui 0.52.0 → 0.53.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/client.js +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/marketing/ProductHero.js +2 -2
- package/dist/src/marketing/landing.css +12 -13
- package/dist/src/motion/motion-provider.js +50 -18
- package/dist/src/motion/reduced-motion.js +50 -0
- package/dist/src/ui/overlay-a11y.js +4 -3
- package/dist/tokens/src/css/motion.css +20 -7
- package/dist/tokens/src/css/utilities.css +14 -0
- package/package.json +1 -1
- package/src/client.ts +1 -0
- package/src/index.ts +1 -0
- package/src/marketing/ProductHero.tsx +2 -2
- package/src/marketing/landing.css +12 -13
- package/src/motion/motion-provider.tsx +15 -6
- package/src/motion/reduced-motion.ts +43 -0
- package/src/ui/overlay-a11y.ts +3 -6
- package/tokens/src/css/motion.css +20 -7
- package/tokens/src/css/utilities.css +14 -0
package/dist/src/client.js
CHANGED
|
@@ -32,6 +32,7 @@ export { BulkActionBar } from "./ui/bulk-action-bar.js";
|
|
|
32
32
|
export { CopyLinkMenuItem } from "./ui/copy-link-menu-item.js";
|
|
33
33
|
export { ToggleSearch } from "./ui/toggle-search.js";
|
|
34
34
|
export { MotionProvider } from "./motion/motion-provider.js";
|
|
35
|
+
export { useReducedMotionSetting } from "./motion/reduced-motion.js";
|
|
35
36
|
export { MarqueeOnHover } from "./ui/marquee-on-hover.js";
|
|
36
37
|
export { RelativeDateTime } from "./ui/relative-date-time.js";
|
|
37
38
|
export { ImageLightbox } from "./ui/image-lightbox.js";
|
package/dist/src/index.js
CHANGED
|
@@ -28,6 +28,7 @@ export { BulkActionBar } from "./ui/bulk-action-bar.js";
|
|
|
28
28
|
export { CopyLinkMenuItem } from "./ui/copy-link-menu-item.js";
|
|
29
29
|
export { ToggleSearch } from "./ui/toggle-search.js";
|
|
30
30
|
export { MotionProvider } from "./motion/motion-provider.js";
|
|
31
|
+
export { useReducedMotionSetting } from "./motion/reduced-motion.js";
|
|
31
32
|
export { MarqueeOnHover } from "./ui/marquee-on-hover.js";
|
|
32
33
|
export { RelativeDateTime } from "./ui/relative-date-time.js";
|
|
33
34
|
export { ImageLightbox } from "./ui/image-lightbox.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import { Button } from "../ui/button.js";
|
|
3
3
|
import { pageTitleClass } from "../ui/page-title.js";
|
|
4
|
-
import {
|
|
4
|
+
import { useReducedMotionSetting } from "../motion/reduced-motion.js";
|
|
5
5
|
import { cn } from "../utils/cn.js";
|
|
6
6
|
import { landingShellClass, productHeroSocialProofClass } from "./marketing-classes.js";
|
|
7
7
|
import { PROJECT_V_HOME_URL } from "./projectV.js";
|
|
@@ -14,7 +14,7 @@ function UserCountProof(t0) {
|
|
|
14
14
|
const {
|
|
15
15
|
count
|
|
16
16
|
} = t0;
|
|
17
|
-
const reducedMotion =
|
|
17
|
+
const reducedMotion = useReducedMotionSetting();
|
|
18
18
|
const t1 = !reducedMotion && "animate-pulse";
|
|
19
19
|
let t2;
|
|
20
20
|
if ($[0] !== t1) {
|
|
@@ -265,23 +265,22 @@ html:has(#top) {
|
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
/* Reduced motion follows the root `MotionProvider reducedMotion` setting
|
|
269
|
+
(`html[data-reduced-motion]`), as in motion.css. */
|
|
268
270
|
@media (prefers-reduced-motion: reduce) {
|
|
269
|
-
html:has(#top) {
|
|
271
|
+
html:not([data-reduced-motion="never"]):has(#top) {
|
|
270
272
|
scroll-behavior: auto;
|
|
271
273
|
}
|
|
272
274
|
|
|
273
|
-
.landing-graph-dash,
|
|
274
|
-
.landing-preview-pulse,
|
|
275
|
-
.landing-pulse-dot,
|
|
276
|
-
.landing-ambient-drift,
|
|
277
|
-
.landing-ambient-node-a,
|
|
278
|
-
.landing-ambient-node-b,
|
|
279
|
-
.landing-ambient-node-c,
|
|
280
|
-
.landing-ambient-node-d,
|
|
281
|
-
.landing-ambient-node-e,
|
|
282
|
-
.landing-ambient-node-f,
|
|
283
|
-
.landing-ambient-node-g,
|
|
284
|
-
.landing-ambient-node-h {
|
|
275
|
+
html:not([data-reduced-motion="never"]) :is(.landing-graph-dash, .landing-preview-pulse, .landing-pulse-dot, .landing-ambient-drift, .landing-ambient-node-a, .landing-ambient-node-b, .landing-ambient-node-c, .landing-ambient-node-d, .landing-ambient-node-e, .landing-ambient-node-f, .landing-ambient-node-g, .landing-ambient-node-h) {
|
|
285
276
|
animation: none !important;
|
|
286
277
|
}
|
|
287
278
|
}
|
|
279
|
+
|
|
280
|
+
html[data-reduced-motion="always"]:has(#top) {
|
|
281
|
+
scroll-behavior: auto;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
html[data-reduced-motion="always"] :is(.landing-graph-dash, .landing-preview-pulse, .landing-pulse-dot, .landing-ambient-drift, .landing-ambient-node-a, .landing-ambient-node-b, .landing-ambient-node-c, .landing-ambient-node-d, .landing-ambient-node-e, .landing-ambient-node-f, .landing-ambient-node-g, .landing-ambient-node-h) {
|
|
285
|
+
animation: none !important;
|
|
286
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import { LazyMotion, MotionConfig, domMax } from "motion/react";
|
|
3
|
-
import {
|
|
3
|
+
import { useLayoutEffect } from "react";
|
|
4
|
+
import { ReducedMotionContext } from "./reduced-motion.js";
|
|
5
|
+
|
|
4
6
|
/**
|
|
5
7
|
* The app-wide Motion setup that `m.*` components (in this package and the
|
|
6
8
|
* app) need: one lazy feature bundle under `strict`, so a stray `motion.*`
|
|
@@ -10,10 +12,13 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
10
12
|
* (`layoutId` shared highlights); `domAnimation` is smaller if the app has
|
|
11
13
|
* none. Under `strict` a missing feature silently skips the animation.
|
|
12
14
|
* `reducedMotion` defaults to `"user"` (follow the OS setting); pass `"never"`
|
|
13
|
-
* to always animate.
|
|
15
|
+
* to always animate. It governs the whole package, not only `m.*`: dialogs,
|
|
16
|
+
* sheets, the `motion-reduce:` variant and motion.css read it too, through
|
|
17
|
+
* `html[data-reduced-motion]` (stamped here, kept after unmount) and context.
|
|
14
18
|
*/
|
|
19
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
20
|
export function MotionProvider(t0) {
|
|
16
|
-
const $ = _c(
|
|
21
|
+
const $ = _c(12);
|
|
17
22
|
const {
|
|
18
23
|
children,
|
|
19
24
|
features: t1,
|
|
@@ -22,29 +27,56 @@ export function MotionProvider(t0) {
|
|
|
22
27
|
const features = t1 === undefined ? domMax : t1;
|
|
23
28
|
const reducedMotion = t2 === undefined ? "user" : t2;
|
|
24
29
|
let t3;
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
let t4;
|
|
31
|
+
if ($[0] !== reducedMotion) {
|
|
32
|
+
t3 = () => {
|
|
33
|
+
document.documentElement.dataset.reducedMotion = reducedMotion;
|
|
34
|
+
};
|
|
35
|
+
t4 = [reducedMotion];
|
|
36
|
+
$[0] = reducedMotion;
|
|
37
|
+
$[1] = t3;
|
|
38
|
+
$[2] = t4;
|
|
39
|
+
} else {
|
|
40
|
+
t3 = $[1];
|
|
41
|
+
t4 = $[2];
|
|
42
|
+
}
|
|
43
|
+
useLayoutEffect(t3, t4);
|
|
44
|
+
let t5;
|
|
45
|
+
if ($[3] !== children || $[4] !== reducedMotion) {
|
|
46
|
+
t5 = /*#__PURE__*/_jsx(MotionConfig, {
|
|
27
47
|
reducedMotion: reducedMotion,
|
|
28
48
|
children: children
|
|
29
49
|
});
|
|
30
|
-
$[
|
|
31
|
-
$[
|
|
32
|
-
$[
|
|
50
|
+
$[3] = children;
|
|
51
|
+
$[4] = reducedMotion;
|
|
52
|
+
$[5] = t5;
|
|
33
53
|
} else {
|
|
34
|
-
|
|
54
|
+
t5 = $[5];
|
|
35
55
|
}
|
|
36
|
-
let
|
|
37
|
-
if ($[
|
|
38
|
-
|
|
56
|
+
let t6;
|
|
57
|
+
if ($[6] !== features || $[7] !== t5) {
|
|
58
|
+
t6 = /*#__PURE__*/_jsx(LazyMotion, {
|
|
39
59
|
features: features,
|
|
40
60
|
strict: true,
|
|
41
|
-
children:
|
|
61
|
+
children: t5
|
|
62
|
+
});
|
|
63
|
+
$[6] = features;
|
|
64
|
+
$[7] = t5;
|
|
65
|
+
$[8] = t6;
|
|
66
|
+
} else {
|
|
67
|
+
t6 = $[8];
|
|
68
|
+
}
|
|
69
|
+
let t7;
|
|
70
|
+
if ($[9] !== reducedMotion || $[10] !== t6) {
|
|
71
|
+
t7 = /*#__PURE__*/_jsx(ReducedMotionContext, {
|
|
72
|
+
value: reducedMotion,
|
|
73
|
+
children: t6
|
|
42
74
|
});
|
|
43
|
-
$[
|
|
44
|
-
$[
|
|
45
|
-
$[
|
|
75
|
+
$[9] = reducedMotion;
|
|
76
|
+
$[10] = t6;
|
|
77
|
+
$[11] = t7;
|
|
46
78
|
} else {
|
|
47
|
-
|
|
79
|
+
t7 = $[11];
|
|
48
80
|
}
|
|
49
|
-
return
|
|
81
|
+
return t7;
|
|
50
82
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { c as _c } from "react/compiler-runtime";
|
|
2
|
+
import { createContext, use } from "react";
|
|
3
|
+
import { useMediaQuery } from "../hooks/use-media-query.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Whether the package's own motion follows the OS "reduce motion" setting.
|
|
7
|
+
* Set once at the root with `MotionProvider reducedMotion` (the same option as
|
|
8
|
+
* Motion's `MotionConfig` and HeroUI's provider):
|
|
9
|
+
* - `"user"` (default): follow `prefers-reduced-motion`.
|
|
10
|
+
* - `"always"`: always reduce.
|
|
11
|
+
* - `"never"`: always animate; the app owns its own "motion off" switch.
|
|
12
|
+
*
|
|
13
|
+
* `MotionProvider` stamps it on `html[data-reduced-motion]` for CSS and for
|
|
14
|
+
* non-React code, and provides it through context for components.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
18
|
+
export const ReducedMotionContext = /*#__PURE__*/createContext("user");
|
|
19
|
+
function resolve(setting, osReduces) {
|
|
20
|
+
if (setting === "never") return false;
|
|
21
|
+
if (setting === "always") return true;
|
|
22
|
+
return osReduces;
|
|
23
|
+
}
|
|
24
|
+
function documentSetting() {
|
|
25
|
+
const value = document.documentElement.dataset.reducedMotion;
|
|
26
|
+
return value === "always" || value === "never" ? value : "user";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Outside React (event handlers, DOM helpers): reads `html[data-reduced-motion]`. */
|
|
30
|
+
export function prefersReducedMotion() {
|
|
31
|
+
if (typeof window === "undefined") return false;
|
|
32
|
+
return resolve(documentSetting(), window.matchMedia(REDUCED_MOTION_QUERY).matches);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** In a component: the root setting from `MotionProvider`, then the OS query. */
|
|
36
|
+
export function useReducedMotionSetting() {
|
|
37
|
+
const $ = _c(3);
|
|
38
|
+
const setting = use(ReducedMotionContext);
|
|
39
|
+
const osReduces = useMediaQuery(REDUCED_MOTION_QUERY);
|
|
40
|
+
let t0;
|
|
41
|
+
if ($[0] !== osReduces || $[1] !== setting) {
|
|
42
|
+
t0 = resolve(setting, osReduces);
|
|
43
|
+
$[0] = osReduces;
|
|
44
|
+
$[1] = setting;
|
|
45
|
+
$[2] = t0;
|
|
46
|
+
} else {
|
|
47
|
+
t0 = $[2];
|
|
48
|
+
}
|
|
49
|
+
return t0;
|
|
50
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
|
+
import { prefersReducedMotion } from "../motion/reduced-motion.js";
|
|
3
4
|
|
|
4
5
|
/** Phones, plus short landscape viewports such as 844×390. */
|
|
5
6
|
export const COMPACT_OVERLAY_QUERY = "(max-width: 639px), (max-height: 500px)";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
7
|
+
|
|
8
|
+
/** The root `MotionProvider reducedMotion` setting, then the OS query. */
|
|
9
|
+
export { prefersReducedMotion };
|
|
9
10
|
export function useCompactOverlay() {
|
|
10
11
|
const $ = _c(2);
|
|
11
12
|
const [compact, setCompact] = React.useState(false);
|
|
@@ -106,22 +106,35 @@
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/*
|
|
110
|
+
* Reduced motion follows the root `MotionProvider reducedMotion` setting
|
|
111
|
+
* (`html[data-reduced-motion]`): the OS query unless it is `"never"`, and
|
|
112
|
+
* always when it is `"always"`.
|
|
113
|
+
*/
|
|
109
114
|
@media (prefers-reduced-motion: reduce) {
|
|
110
|
-
.ui-page-enter,
|
|
111
|
-
.ui-enter,
|
|
112
|
-
.ui-enter-up,
|
|
113
|
-
.ui-stagger > * {
|
|
115
|
+
html:not([data-reduced-motion="never"]) :is(.ui-page-enter, .ui-enter, .ui-enter-up, .ui-stagger > *) {
|
|
114
116
|
animation-duration: 1ms;
|
|
115
117
|
animation-name: ui-fade-only;
|
|
116
118
|
}
|
|
117
119
|
|
|
118
|
-
::view-transition-group(*),
|
|
119
|
-
::view-transition-old(*),
|
|
120
|
-
::view-transition-new(*) {
|
|
120
|
+
html:not([data-reduced-motion="never"])::view-transition-group(*),
|
|
121
|
+
html:not([data-reduced-motion="never"])::view-transition-old(*),
|
|
122
|
+
html:not([data-reduced-motion="never"])::view-transition-new(*) {
|
|
121
123
|
animation: none !important;
|
|
122
124
|
}
|
|
123
125
|
}
|
|
124
126
|
|
|
127
|
+
html[data-reduced-motion="always"] :is(.ui-page-enter, .ui-enter, .ui-enter-up, .ui-stagger > *) {
|
|
128
|
+
animation-duration: 1ms;
|
|
129
|
+
animation-name: ui-fade-only;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
html[data-reduced-motion="always"]::view-transition-group(*),
|
|
133
|
+
html[data-reduced-motion="always"]::view-transition-old(*),
|
|
134
|
+
html[data-reduced-motion="always"]::view-transition-new(*) {
|
|
135
|
+
animation: none !important;
|
|
136
|
+
}
|
|
137
|
+
|
|
125
138
|
/*
|
|
126
139
|
* PageMotionProvider `disabled` sets `html[data-page-motion="off"]`. Page and
|
|
127
140
|
* route enters, list stagger, `animate-in` / `animate-out`, the modal and
|
|
@@ -10,6 +10,20 @@
|
|
|
10
10
|
* --motion-ease-emphasized: cubic-bezier(0.2, 0.8, 0.2, 1)
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
/* `motion-reduce:` follows the root `MotionProvider reducedMotion` setting
|
|
14
|
+
(`html[data-reduced-motion]`), not only the OS: `"never"` turns it off,
|
|
15
|
+
`"always"` turns it on, `"user"` (or no provider) keeps the media query. */
|
|
16
|
+
@custom-variant motion-reduce {
|
|
17
|
+
@media (prefers-reduced-motion: reduce) {
|
|
18
|
+
html:not([data-reduced-motion="never"]) & {
|
|
19
|
+
@slot;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
html[data-reduced-motion="always"] & {
|
|
23
|
+
@slot;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
13
27
|
/* Extends sub-40px controls to a 40x40px tap target without changing layout.
|
|
14
28
|
Only force `relative` when the element is otherwise static: absolute /
|
|
15
29
|
fixed / sticky already form a containing block for ::after. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.53.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared React 19 UI for web apps: one main JavaScript entry (primitives, shell pieces, app helpers including the Convex and Clerk provider, VITE env parsing and ensure-user, artifact viewers over the @vvedantb/server artifacts core, native tokens), third-party brand logos (also @vvedantb/ui/logos), motion-driven animated SVG icons (@vvedantb/ui/icons/animated), a client entry without @vvedantb/server, convex or Clerk for Chrome extensions, design-token CSS, shared Tailwind v4 CSS, a Tailwind preset and packaged Instrument Sans fonts.",
|
|
6
6
|
"type": "module",
|
package/src/client.ts
CHANGED
|
@@ -43,6 +43,7 @@ export { CopyLinkMenuItem } from "./ui/copy-link-menu-item";
|
|
|
43
43
|
export { ToggleSearch } from "./ui/toggle-search";
|
|
44
44
|
export type { ToggleSearchProps, ToggleSearchVariant } from "./ui/toggle-search";
|
|
45
45
|
export { MotionProvider } from "./motion/motion-provider";
|
|
46
|
+
export { useReducedMotionSetting, type ReducedMotion } from "./motion/reduced-motion";
|
|
46
47
|
export { MarqueeOnHover } from "./ui/marquee-on-hover";
|
|
47
48
|
export { RelativeDateTime } from "./ui/relative-date-time";
|
|
48
49
|
export type { RelativeDateTimeProps } from "./ui/relative-date-time";
|
package/src/index.ts
CHANGED
|
@@ -39,6 +39,7 @@ export { CopyLinkMenuItem } from "./ui/copy-link-menu-item";
|
|
|
39
39
|
export { ToggleSearch } from "./ui/toggle-search";
|
|
40
40
|
export type { ToggleSearchProps, ToggleSearchVariant } from "./ui/toggle-search";
|
|
41
41
|
export { MotionProvider } from "./motion/motion-provider";
|
|
42
|
+
export { useReducedMotionSetting, type ReducedMotion } from "./motion/reduced-motion";
|
|
42
43
|
export { MarqueeOnHover } from "./ui/marquee-on-hover";
|
|
43
44
|
export { RelativeDateTime } from "./ui/relative-date-time";
|
|
44
45
|
export type { RelativeDateTimeProps } from "./ui/relative-date-time";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ComponentProps, MouseEventHandler, ReactNode } from "react";
|
|
2
2
|
import { Button } from "../ui/button";
|
|
3
3
|
import { pageTitleClass } from "../ui/page-title";
|
|
4
|
-
import {
|
|
4
|
+
import { useReducedMotionSetting } from "../motion/reduced-motion";
|
|
5
5
|
import { cn } from "../utils/cn";
|
|
6
6
|
import { landingShellClass, productHeroSocialProofClass } from "./marketing-classes";
|
|
7
7
|
import { PROJECT_V_HOME_URL } from "./projectV";
|
|
@@ -63,7 +63,7 @@ export type ProductHeroProps = {
|
|
|
63
63
|
const titleClass = `text-balance text-4xl sm:text-5xl lg:text-6xl ${pageTitleClass.replace(/\btext-xl\s*/, "")}`;
|
|
64
64
|
|
|
65
65
|
function UserCountProof({ count }: { count: number }) {
|
|
66
|
-
const reducedMotion =
|
|
66
|
+
const reducedMotion = useReducedMotionSetting();
|
|
67
67
|
return (
|
|
68
68
|
<p className={productHeroSocialProofClass} data-testid="user-count">
|
|
69
69
|
<span data-testid="user-count-dot" aria-hidden="true" className={cn("size-2 rounded-full bg-success", !reducedMotion && "animate-pulse")} />
|
|
@@ -265,23 +265,22 @@ html:has(#top) {
|
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
/* Reduced motion follows the root `MotionProvider reducedMotion` setting
|
|
269
|
+
(`html[data-reduced-motion]`), as in motion.css. */
|
|
268
270
|
@media (prefers-reduced-motion: reduce) {
|
|
269
|
-
html:has(#top) {
|
|
271
|
+
html:not([data-reduced-motion="never"]):has(#top) {
|
|
270
272
|
scroll-behavior: auto;
|
|
271
273
|
}
|
|
272
274
|
|
|
273
|
-
.landing-graph-dash,
|
|
274
|
-
.landing-preview-pulse,
|
|
275
|
-
.landing-pulse-dot,
|
|
276
|
-
.landing-ambient-drift,
|
|
277
|
-
.landing-ambient-node-a,
|
|
278
|
-
.landing-ambient-node-b,
|
|
279
|
-
.landing-ambient-node-c,
|
|
280
|
-
.landing-ambient-node-d,
|
|
281
|
-
.landing-ambient-node-e,
|
|
282
|
-
.landing-ambient-node-f,
|
|
283
|
-
.landing-ambient-node-g,
|
|
284
|
-
.landing-ambient-node-h {
|
|
275
|
+
html:not([data-reduced-motion="never"]) :is(.landing-graph-dash, .landing-preview-pulse, .landing-pulse-dot, .landing-ambient-drift, .landing-ambient-node-a, .landing-ambient-node-b, .landing-ambient-node-c, .landing-ambient-node-d, .landing-ambient-node-e, .landing-ambient-node-f, .landing-ambient-node-g, .landing-ambient-node-h) {
|
|
285
276
|
animation: none !important;
|
|
286
277
|
}
|
|
287
278
|
}
|
|
279
|
+
|
|
280
|
+
html[data-reduced-motion="always"]:has(#top) {
|
|
281
|
+
scroll-behavior: auto;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
html[data-reduced-motion="always"] :is(.landing-graph-dash, .landing-preview-pulse, .landing-pulse-dot, .landing-ambient-drift, .landing-ambient-node-a, .landing-ambient-node-b, .landing-ambient-node-c, .landing-ambient-node-d, .landing-ambient-node-e, .landing-ambient-node-f, .landing-ambient-node-g, .landing-ambient-node-h) {
|
|
285
|
+
animation: none !important;
|
|
286
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LazyMotion, MotionConfig, domMax, type FeatureBundle } from "motion/react";
|
|
2
|
-
import type
|
|
2
|
+
import { useLayoutEffect, type ReactNode } from "react";
|
|
3
|
+
import { ReducedMotionContext, type ReducedMotion } from "./reduced-motion";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The app-wide Motion setup that `m.*` components (in this package and the
|
|
@@ -10,7 +11,9 @@ import type { ReactNode } from "react";
|
|
|
10
11
|
* (`layoutId` shared highlights); `domAnimation` is smaller if the app has
|
|
11
12
|
* none. Under `strict` a missing feature silently skips the animation.
|
|
12
13
|
* `reducedMotion` defaults to `"user"` (follow the OS setting); pass `"never"`
|
|
13
|
-
* to always animate.
|
|
14
|
+
* to always animate. It governs the whole package, not only `m.*`: dialogs,
|
|
15
|
+
* sheets, the `motion-reduce:` variant and motion.css read it too, through
|
|
16
|
+
* `html[data-reduced-motion]` (stamped here, kept after unmount) and context.
|
|
14
17
|
*/
|
|
15
18
|
export function MotionProvider({
|
|
16
19
|
children,
|
|
@@ -19,11 +22,17 @@ export function MotionProvider({
|
|
|
19
22
|
}: {
|
|
20
23
|
children: ReactNode;
|
|
21
24
|
features?: FeatureBundle;
|
|
22
|
-
reducedMotion?:
|
|
25
|
+
reducedMotion?: ReducedMotion;
|
|
23
26
|
}) {
|
|
27
|
+
useLayoutEffect(() => {
|
|
28
|
+
document.documentElement.dataset.reducedMotion = reducedMotion;
|
|
29
|
+
}, [reducedMotion]);
|
|
30
|
+
|
|
24
31
|
return (
|
|
25
|
-
<
|
|
26
|
-
<
|
|
27
|
-
|
|
32
|
+
<ReducedMotionContext value={reducedMotion}>
|
|
33
|
+
<LazyMotion features={features} strict>
|
|
34
|
+
<MotionConfig reducedMotion={reducedMotion}>{children}</MotionConfig>
|
|
35
|
+
</LazyMotion>
|
|
36
|
+
</ReducedMotionContext>
|
|
28
37
|
);
|
|
29
38
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createContext, use } from "react";
|
|
2
|
+
import { useMediaQuery } from "../hooks/use-media-query";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Whether the package's own motion follows the OS "reduce motion" setting.
|
|
6
|
+
* Set once at the root with `MotionProvider reducedMotion` (the same option as
|
|
7
|
+
* Motion's `MotionConfig` and HeroUI's provider):
|
|
8
|
+
* - `"user"` (default): follow `prefers-reduced-motion`.
|
|
9
|
+
* - `"always"`: always reduce.
|
|
10
|
+
* - `"never"`: always animate; the app owns its own "motion off" switch.
|
|
11
|
+
*
|
|
12
|
+
* `MotionProvider` stamps it on `html[data-reduced-motion]` for CSS and for
|
|
13
|
+
* non-React code, and provides it through context for components.
|
|
14
|
+
*/
|
|
15
|
+
export type ReducedMotion = "user" | "always" | "never";
|
|
16
|
+
|
|
17
|
+
export const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
18
|
+
|
|
19
|
+
export const ReducedMotionContext = createContext<ReducedMotion>("user");
|
|
20
|
+
|
|
21
|
+
function resolve(setting: ReducedMotion, osReduces: boolean): boolean {
|
|
22
|
+
if (setting === "never") return false;
|
|
23
|
+
if (setting === "always") return true;
|
|
24
|
+
return osReduces;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function documentSetting(): ReducedMotion {
|
|
28
|
+
const value = document.documentElement.dataset.reducedMotion;
|
|
29
|
+
return value === "always" || value === "never" ? value : "user";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Outside React (event handlers, DOM helpers): reads `html[data-reduced-motion]`. */
|
|
33
|
+
export function prefersReducedMotion(): boolean {
|
|
34
|
+
if (typeof window === "undefined") return false;
|
|
35
|
+
return resolve(documentSetting(), window.matchMedia(REDUCED_MOTION_QUERY).matches);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** In a component: the root setting from `MotionProvider`, then the OS query. */
|
|
39
|
+
export function useReducedMotionSetting(): boolean {
|
|
40
|
+
const setting = use(ReducedMotionContext);
|
|
41
|
+
const osReduces = useMediaQuery(REDUCED_MOTION_QUERY);
|
|
42
|
+
return resolve(setting, osReduces);
|
|
43
|
+
}
|
package/src/ui/overlay-a11y.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { prefersReducedMotion } from "../motion/reduced-motion";
|
|
2
3
|
|
|
3
4
|
/** Phones, plus short landscape viewports such as 844×390. */
|
|
4
5
|
export const COMPACT_OVERLAY_QUERY = "(max-width: 639px), (max-height: 500px)";
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
typeof window !== "undefined" &&
|
|
9
|
-
window.matchMedia("(prefers-reduced-motion: reduce)").matches
|
|
10
|
-
);
|
|
11
|
-
}
|
|
7
|
+
/** The root `MotionProvider reducedMotion` setting, then the OS query. */
|
|
8
|
+
export { prefersReducedMotion };
|
|
12
9
|
|
|
13
10
|
export function useCompactOverlay(): boolean {
|
|
14
11
|
const [compact, setCompact] = React.useState(false);
|
|
@@ -106,22 +106,35 @@
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/*
|
|
110
|
+
* Reduced motion follows the root `MotionProvider reducedMotion` setting
|
|
111
|
+
* (`html[data-reduced-motion]`): the OS query unless it is `"never"`, and
|
|
112
|
+
* always when it is `"always"`.
|
|
113
|
+
*/
|
|
109
114
|
@media (prefers-reduced-motion: reduce) {
|
|
110
|
-
.ui-page-enter,
|
|
111
|
-
.ui-enter,
|
|
112
|
-
.ui-enter-up,
|
|
113
|
-
.ui-stagger > * {
|
|
115
|
+
html:not([data-reduced-motion="never"]) :is(.ui-page-enter, .ui-enter, .ui-enter-up, .ui-stagger > *) {
|
|
114
116
|
animation-duration: 1ms;
|
|
115
117
|
animation-name: ui-fade-only;
|
|
116
118
|
}
|
|
117
119
|
|
|
118
|
-
::view-transition-group(*),
|
|
119
|
-
::view-transition-old(*),
|
|
120
|
-
::view-transition-new(*) {
|
|
120
|
+
html:not([data-reduced-motion="never"])::view-transition-group(*),
|
|
121
|
+
html:not([data-reduced-motion="never"])::view-transition-old(*),
|
|
122
|
+
html:not([data-reduced-motion="never"])::view-transition-new(*) {
|
|
121
123
|
animation: none !important;
|
|
122
124
|
}
|
|
123
125
|
}
|
|
124
126
|
|
|
127
|
+
html[data-reduced-motion="always"] :is(.ui-page-enter, .ui-enter, .ui-enter-up, .ui-stagger > *) {
|
|
128
|
+
animation-duration: 1ms;
|
|
129
|
+
animation-name: ui-fade-only;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
html[data-reduced-motion="always"]::view-transition-group(*),
|
|
133
|
+
html[data-reduced-motion="always"]::view-transition-old(*),
|
|
134
|
+
html[data-reduced-motion="always"]::view-transition-new(*) {
|
|
135
|
+
animation: none !important;
|
|
136
|
+
}
|
|
137
|
+
|
|
125
138
|
/*
|
|
126
139
|
* PageMotionProvider `disabled` sets `html[data-page-motion="off"]`. Page and
|
|
127
140
|
* route enters, list stagger, `animate-in` / `animate-out`, the modal and
|
|
@@ -10,6 +10,20 @@
|
|
|
10
10
|
* --motion-ease-emphasized: cubic-bezier(0.2, 0.8, 0.2, 1)
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
/* `motion-reduce:` follows the root `MotionProvider reducedMotion` setting
|
|
14
|
+
(`html[data-reduced-motion]`), not only the OS: `"never"` turns it off,
|
|
15
|
+
`"always"` turns it on, `"user"` (or no provider) keeps the media query. */
|
|
16
|
+
@custom-variant motion-reduce {
|
|
17
|
+
@media (prefers-reduced-motion: reduce) {
|
|
18
|
+
html:not([data-reduced-motion="never"]) & {
|
|
19
|
+
@slot;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
html[data-reduced-motion="always"] & {
|
|
23
|
+
@slot;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
13
27
|
/* Extends sub-40px controls to a 40x40px tap target without changing layout.
|
|
14
28
|
Only force `relative` when the element is otherwise static: absolute /
|
|
15
29
|
fixed / sticky already form a containing block for ::after. */
|