@crisp-ui-kit/crisp 0.19.0 → 0.19.1
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/cjs/components/wheelpicker/wheelpicker.js +8 -2
- package/dist/cjs/core/index.js +3 -1
- package/dist/cjs/core/use-prefers-reduced-motion.js +67 -0
- package/dist/esm/components/wheelpicker/wheelpicker.js +8 -2
- package/dist/esm/core/index.js +1 -0
- package/dist/esm/core/use-prefers-reduced-motion.js +31 -0
- package/dist/types/core/index.d.ts +1 -0
- package/dist/types/core/use-prefers-reduced-motion.d.ts +17 -0
- package/package.json +1 -1
|
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.WheelPicker = WheelPicker;
|
|
37
37
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
38
|
const React = __importStar(require("react"));
|
|
39
|
+
const core_1 = require("../../core");
|
|
39
40
|
const wheelpicker_recipe_1 = require("./wheelpicker.recipe");
|
|
40
41
|
const ITEM_HEIGHT = { small: 36, medium: 44 };
|
|
41
42
|
/**
|
|
@@ -70,6 +71,11 @@ function WheelPicker({ columns, value: valueProp, defaultValue, onValueChange, s
|
|
|
70
71
|
setInternal(merged);
|
|
71
72
|
onValueChange?.(merged);
|
|
72
73
|
};
|
|
74
|
+
// CSS cannot reach this: `scroll-behavior` in a stylesheet does not override
|
|
75
|
+
// an explicit `behavior` passed to scrollTo, so the preference is read here
|
|
76
|
+
// and the two "smooth" call sites go through `glide` (#208).
|
|
77
|
+
const reduceMotion = (0, core_1.usePrefersReducedMotion)();
|
|
78
|
+
const glide = reduceMotion ? "auto" : "smooth";
|
|
73
79
|
const scrollTo = React.useCallback((key, index, behavior) => {
|
|
74
80
|
const el = refs.current.get(key);
|
|
75
81
|
if (!el || index < 0)
|
|
@@ -107,7 +113,7 @@ function WheelPicker({ columns, value: valueProp, defaultValue, onValueChange, s
|
|
|
107
113
|
if (!opt)
|
|
108
114
|
return;
|
|
109
115
|
commit(col.key, opt.value);
|
|
110
|
-
scrollTo(col.key, clamped,
|
|
116
|
+
scrollTo(col.key, clamped, glide);
|
|
111
117
|
};
|
|
112
118
|
if (e.key === "ArrowDown")
|
|
113
119
|
go(i + 1);
|
|
@@ -127,7 +133,7 @@ function WheelPicker({ columns, value: valueProp, defaultValue, onValueChange, s
|
|
|
127
133
|
const selected = opt.value === value[col.key];
|
|
128
134
|
return ((0, jsx_runtime_1.jsx)("div", { id: optionId(col.key, opt.value), role: "option", "aria-selected": selected, "data-selected": selected ? "" : undefined, className: "wheelpicker-item", onClick: () => {
|
|
129
135
|
commit(col.key, opt.value);
|
|
130
|
-
scrollTo(col.key, col.options.indexOf(opt),
|
|
136
|
+
scrollTo(col.key, col.options.indexOf(opt), glide);
|
|
131
137
|
}, children: opt.label }, opt.value));
|
|
132
138
|
}) }, col.key))) }) })] }));
|
|
133
139
|
}
|
package/dist/cjs/core/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.resolveRecipe = exports.Primitive = exports.defineRecipe = exports.cx = void 0;
|
|
17
|
+
exports.usePrefersReducedMotion = exports.resolveRecipe = exports.Primitive = exports.defineRecipe = exports.cx = void 0;
|
|
18
18
|
var cx_1 = require("./cx");
|
|
19
19
|
Object.defineProperty(exports, "cx", { enumerable: true, get: function () { return cx_1.cx; } });
|
|
20
20
|
var define_1 = require("./define");
|
|
@@ -24,3 +24,5 @@ Object.defineProperty(exports, "Primitive", { enumerable: true, get: function ()
|
|
|
24
24
|
var resolve_1 = require("./resolve");
|
|
25
25
|
Object.defineProperty(exports, "resolveRecipe", { enumerable: true, get: function () { return resolve_1.resolveRecipe; } });
|
|
26
26
|
__exportStar(require("./rtl"), exports);
|
|
27
|
+
var use_prefers_reduced_motion_1 = require("./use-prefers-reduced-motion");
|
|
28
|
+
Object.defineProperty(exports, "usePrefersReducedMotion", { enumerable: true, get: function () { return use_prefers_reduced_motion_1.usePrefersReducedMotion; } });
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.usePrefersReducedMotion = usePrefersReducedMotion;
|
|
37
|
+
const React = __importStar(require("react"));
|
|
38
|
+
const QUERY = "(prefers-reduced-motion: reduce)";
|
|
39
|
+
const subscribe = (onChange) => {
|
|
40
|
+
if (typeof window === "undefined" || !window.matchMedia)
|
|
41
|
+
return () => { };
|
|
42
|
+
const mq = window.matchMedia(QUERY);
|
|
43
|
+
mq.addEventListener("change", onChange);
|
|
44
|
+
return () => mq.removeEventListener("change", onChange);
|
|
45
|
+
};
|
|
46
|
+
const getSnapshot = () => typeof window !== "undefined" && window.matchMedia
|
|
47
|
+
? window.matchMedia(QUERY).matches
|
|
48
|
+
: false;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the user has asked for reduced motion, live.
|
|
51
|
+
*
|
|
52
|
+
* crisp's CSS carries a `@media (prefers-reduced-motion: reduce)` override in
|
|
53
|
+
* every animating recipe, and `bun run spec` checks it. That covers CSS.
|
|
54
|
+
* Motion driven from JavaScript — `scrollTo({ behavior: "smooth" })`,
|
|
55
|
+
* `element.animate()` — is invisible to a stylesheet: `scroll-behavior` in CSS
|
|
56
|
+
* does NOT override an explicit `behavior` argument. Those call sites have to
|
|
57
|
+
* read the preference here (#208).
|
|
58
|
+
*
|
|
59
|
+
* The server snapshot is `false` rather than "unknown" on purpose. It is the
|
|
60
|
+
* only value that keeps the markup identical on both sides, and a component
|
|
61
|
+
* using this must not put the result in its output for the same reason — the
|
|
62
|
+
* preference belongs in a handler or an effect, where it changes behaviour
|
|
63
|
+
* rather than HTML.
|
|
64
|
+
*/
|
|
65
|
+
function usePrefersReducedMotion() {
|
|
66
|
+
return React.useSyncExternalStore(subscribe, getSnapshot, () => false);
|
|
67
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
|
+
import { usePrefersReducedMotion } from "../../core/index.js";
|
|
3
4
|
import { wheelpickerRecipe } from "./wheelpicker.recipe.js";
|
|
4
5
|
const ITEM_HEIGHT = { small: 36, medium: 44 };
|
|
5
6
|
/**
|
|
@@ -34,6 +35,11 @@ export function WheelPicker({ columns, value: valueProp, defaultValue, onValueCh
|
|
|
34
35
|
setInternal(merged);
|
|
35
36
|
onValueChange?.(merged);
|
|
36
37
|
};
|
|
38
|
+
// CSS cannot reach this: `scroll-behavior` in a stylesheet does not override
|
|
39
|
+
// an explicit `behavior` passed to scrollTo, so the preference is read here
|
|
40
|
+
// and the two "smooth" call sites go through `glide` (#208).
|
|
41
|
+
const reduceMotion = usePrefersReducedMotion();
|
|
42
|
+
const glide = reduceMotion ? "auto" : "smooth";
|
|
37
43
|
const scrollTo = React.useCallback((key, index, behavior) => {
|
|
38
44
|
const el = refs.current.get(key);
|
|
39
45
|
if (!el || index < 0)
|
|
@@ -71,7 +77,7 @@ export function WheelPicker({ columns, value: valueProp, defaultValue, onValueCh
|
|
|
71
77
|
if (!opt)
|
|
72
78
|
return;
|
|
73
79
|
commit(col.key, opt.value);
|
|
74
|
-
scrollTo(col.key, clamped,
|
|
80
|
+
scrollTo(col.key, clamped, glide);
|
|
75
81
|
};
|
|
76
82
|
if (e.key === "ArrowDown")
|
|
77
83
|
go(i + 1);
|
|
@@ -91,7 +97,7 @@ export function WheelPicker({ columns, value: valueProp, defaultValue, onValueCh
|
|
|
91
97
|
const selected = opt.value === value[col.key];
|
|
92
98
|
return (_jsx("div", { id: optionId(col.key, opt.value), role: "option", "aria-selected": selected, "data-selected": selected ? "" : undefined, className: "wheelpicker-item", onClick: () => {
|
|
93
99
|
commit(col.key, opt.value);
|
|
94
|
-
scrollTo(col.key, col.options.indexOf(opt),
|
|
100
|
+
scrollTo(col.key, col.options.indexOf(opt), glide);
|
|
95
101
|
}, children: opt.label }, opt.value));
|
|
96
102
|
}) }, col.key))) }) })] }));
|
|
97
103
|
}
|
package/dist/esm/core/index.js
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
const QUERY = "(prefers-reduced-motion: reduce)";
|
|
3
|
+
const subscribe = (onChange) => {
|
|
4
|
+
if (typeof window === "undefined" || !window.matchMedia)
|
|
5
|
+
return () => { };
|
|
6
|
+
const mq = window.matchMedia(QUERY);
|
|
7
|
+
mq.addEventListener("change", onChange);
|
|
8
|
+
return () => mq.removeEventListener("change", onChange);
|
|
9
|
+
};
|
|
10
|
+
const getSnapshot = () => typeof window !== "undefined" && window.matchMedia
|
|
11
|
+
? window.matchMedia(QUERY).matches
|
|
12
|
+
: false;
|
|
13
|
+
/**
|
|
14
|
+
* Whether the user has asked for reduced motion, live.
|
|
15
|
+
*
|
|
16
|
+
* crisp's CSS carries a `@media (prefers-reduced-motion: reduce)` override in
|
|
17
|
+
* every animating recipe, and `bun run spec` checks it. That covers CSS.
|
|
18
|
+
* Motion driven from JavaScript — `scrollTo({ behavior: "smooth" })`,
|
|
19
|
+
* `element.animate()` — is invisible to a stylesheet: `scroll-behavior` in CSS
|
|
20
|
+
* does NOT override an explicit `behavior` argument. Those call sites have to
|
|
21
|
+
* read the preference here (#208).
|
|
22
|
+
*
|
|
23
|
+
* The server snapshot is `false` rather than "unknown" on purpose. It is the
|
|
24
|
+
* only value that keeps the markup identical on both sides, and a component
|
|
25
|
+
* using this must not put the result in its output for the same reason — the
|
|
26
|
+
* preference belongs in a handler or an effect, where it changes behaviour
|
|
27
|
+
* rather than HTML.
|
|
28
|
+
*/
|
|
29
|
+
export function usePrefersReducedMotion() {
|
|
30
|
+
return React.useSyncExternalStore(subscribe, getSnapshot, () => false);
|
|
31
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the user has asked for reduced motion, live.
|
|
3
|
+
*
|
|
4
|
+
* crisp's CSS carries a `@media (prefers-reduced-motion: reduce)` override in
|
|
5
|
+
* every animating recipe, and `bun run spec` checks it. That covers CSS.
|
|
6
|
+
* Motion driven from JavaScript — `scrollTo({ behavior: "smooth" })`,
|
|
7
|
+
* `element.animate()` — is invisible to a stylesheet: `scroll-behavior` in CSS
|
|
8
|
+
* does NOT override an explicit `behavior` argument. Those call sites have to
|
|
9
|
+
* read the preference here (#208).
|
|
10
|
+
*
|
|
11
|
+
* The server snapshot is `false` rather than "unknown" on purpose. It is the
|
|
12
|
+
* only value that keeps the markup identical on both sides, and a component
|
|
13
|
+
* using this must not put the result in its output for the same reason — the
|
|
14
|
+
* preference belongs in a handler or an effect, where it changes behaviour
|
|
15
|
+
* rather than HTML.
|
|
16
|
+
*/
|
|
17
|
+
export declare function usePrefersReducedMotion(): boolean;
|