@proedis/react 2.1.1 → 2.2.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/README.md +29 -1
- package/cjs/hooks/useAnnouncer.js +81 -0
- package/cjs/hooks/useAnnouncer.js.map +1 -0
- package/cjs/hooks/useClipboard.js +116 -0
- package/cjs/hooks/useClipboard.js.map +1 -0
- package/cjs/hooks/useDelayedBusy.js +80 -0
- package/cjs/hooks/useDelayedBusy.js.map +1 -0
- package/cjs/hooks/useForkRef.js +7 -2
- package/cjs/hooks/useForkRef.js.map +1 -1
- package/cjs/hooks/useMediaQuery.js +69 -0
- package/cjs/hooks/useMediaQuery.js.map +1 -0
- package/cjs/hooks/useOverflowItems.js +129 -0
- package/cjs/hooks/useOverflowItems.js.map +1 -0
- package/cjs/hooks/usePrefersReducedMotion.js +34 -0
- package/cjs/hooks/usePrefersReducedMotion.js.map +1 -0
- package/cjs/index.js +16 -0
- package/cjs/index.js.map +1 -1
- package/cjs/utils/contextBuilder.js +26 -0
- package/cjs/utils/contextBuilder.js.map +1 -1
- package/cjs/utils/inertValue.js +40 -0
- package/cjs/utils/inertValue.js.map +1 -0
- package/esm/hooks/useAnnouncer.js +60 -0
- package/esm/hooks/useAnnouncer.js.map +1 -0
- package/esm/hooks/useClipboard.js +95 -0
- package/esm/hooks/useClipboard.js.map +1 -0
- package/esm/hooks/useDelayedBusy.js +59 -0
- package/esm/hooks/useDelayedBusy.js.map +1 -0
- package/esm/hooks/useForkRef.js +7 -2
- package/esm/hooks/useForkRef.js.map +1 -1
- package/esm/hooks/useMediaQuery.js +48 -0
- package/esm/hooks/useMediaQuery.js.map +1 -0
- package/esm/hooks/useOverflowItems.js +107 -0
- package/esm/hooks/useOverflowItems.js.map +1 -0
- package/esm/hooks/usePrefersReducedMotion.js +32 -0
- package/esm/hooks/usePrefersReducedMotion.js.map +1 -0
- package/esm/index.js +8 -1
- package/esm/index.js.map +1 -1
- package/esm/utils/contextBuilder.js +26 -1
- package/esm/utils/contextBuilder.js.map +1 -1
- package/esm/utils/inertValue.js +19 -0
- package/esm/utils/inertValue.js.map +1 -0
- package/package.json +3 -3
- package/types/hooks/index.d.ts +6 -0
- package/types/hooks/useAnnouncer.d.ts +22 -0
- package/types/hooks/useClipboard.d.ts +28 -0
- package/types/hooks/useDelayedBusy.d.ts +28 -0
- package/types/hooks/useForkRef.d.ts +8 -2
- package/types/hooks/useMediaQuery.d.ts +25 -0
- package/types/hooks/useOverflowItems.d.ts +46 -0
- package/types/hooks/usePrefersReducedMotion.d.ts +18 -0
- package/types/utils/contextBuilder.d.ts +20 -0
- package/types/utils/index.d.ts +1 -0
- package/types/utils/inertValue.d.ts +9 -0
package/cjs/index.js
CHANGED
|
@@ -1,48 +1,64 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var RenderWhen = require('./components/RenderWhen/RenderWhen.js');
|
|
4
|
+
var useAnnouncer = require('./hooks/useAnnouncer.js');
|
|
4
5
|
var useAutoControlledState = require('./hooks/useAutoControlledState.js');
|
|
5
6
|
var useAutoSizer = require('./hooks/useAutoSizer.js');
|
|
6
7
|
var useClickOutside = require('./hooks/useClickOutside.js');
|
|
8
|
+
var useClipboard = require('./hooks/useClipboard.js');
|
|
7
9
|
var useDataManager = require('./hooks/useDataManager.js');
|
|
8
10
|
var useDataSelector = require('./hooks/useDataSelector.js');
|
|
9
11
|
var useDebouncedCallback = require('./hooks/useDebouncedCallback.js');
|
|
12
|
+
var useDelayedBusy = require('./hooks/useDelayedBusy.js');
|
|
10
13
|
var useElementType = require('./hooks/useElementType.js');
|
|
11
14
|
var useEnhancedEffect = require('./hooks/useEnhancedEffect.js');
|
|
12
15
|
var useEvent = require('./hooks/useEvent.js');
|
|
13
16
|
var useForkRef = require('./hooks/useForkRef.js');
|
|
14
17
|
var useInputValue = require('./hooks/useInputValue.js');
|
|
18
|
+
var useMediaQuery = require('./hooks/useMediaQuery.js');
|
|
15
19
|
var useObjectState = require('./hooks/useObjectState.js');
|
|
20
|
+
var useOverflowItems = require('./hooks/useOverflowItems.js');
|
|
21
|
+
var usePrefersReducedMotion = require('./hooks/usePrefersReducedMotion.js');
|
|
16
22
|
var useSafeState = require('./hooks/useSafeState.js');
|
|
17
23
|
var useSyncedRef = require('./hooks/useSyncedRef.js');
|
|
18
24
|
var useUnmountEffect = require('./hooks/useUnmountEffect.js');
|
|
19
25
|
var useWindowSize = require('./hooks/useWindowSize.js');
|
|
20
26
|
var compose = require('./utils/compose.js');
|
|
21
27
|
var contextBuilder = require('./utils/contextBuilder.js');
|
|
28
|
+
var inertValue = require('./utils/inertValue.js');
|
|
22
29
|
var shorthands = require('./utils/shorthands.js');
|
|
23
30
|
|
|
24
31
|
|
|
25
32
|
|
|
26
33
|
exports.RenderWhen = RenderWhen;
|
|
34
|
+
exports.useAnnouncer = useAnnouncer.useAnnouncer;
|
|
27
35
|
exports.useAutoControlledState = useAutoControlledState.useAutoControlledState;
|
|
28
36
|
exports.getAncestorsSpace = useAutoSizer.getAncestorsSpace;
|
|
29
37
|
exports.useAutoSizer = useAutoSizer.useAutoSizer;
|
|
30
38
|
exports.useClickOutside = useClickOutside.useClickOutside;
|
|
39
|
+
exports.useClipboard = useClipboard.useClipboard;
|
|
31
40
|
exports.useDataManager = useDataManager.useDataManager;
|
|
32
41
|
exports.useDataSelector = useDataSelector.useDataSelector;
|
|
33
42
|
exports.useDebouncedCallback = useDebouncedCallback.useDebouncedCallback;
|
|
43
|
+
exports.useDelayedBusy = useDelayedBusy.useDelayedBusy;
|
|
34
44
|
exports.useElementType = useElementType.useElementType;
|
|
35
45
|
exports.useEnhancedEffect = useEnhancedEffect.useEnhancedEffect;
|
|
36
46
|
exports.useEvent = useEvent.useEvent;
|
|
37
47
|
exports.useForkRef = useForkRef.useForkRef;
|
|
38
48
|
exports.useInputValue = useInputValue.useInputValue;
|
|
49
|
+
exports.useMediaQuery = useMediaQuery.useMediaQuery;
|
|
39
50
|
exports.useObjectState = useObjectState.useObjectState;
|
|
51
|
+
exports.fitItems = useOverflowItems.fitItems;
|
|
52
|
+
exports.useOverflowItems = useOverflowItems.useOverflowItems;
|
|
53
|
+
exports.usePrefersReducedMotion = usePrefersReducedMotion.usePrefersReducedMotion;
|
|
40
54
|
exports.useSafeState = useSafeState.useSafeState;
|
|
41
55
|
exports.useSyncedRef = useSyncedRef.useSyncedRef;
|
|
42
56
|
exports.useUnmountEffect = useUnmountEffect.useUnmountEffect;
|
|
43
57
|
exports.useWindowSize = useWindowSize.useWindowSize;
|
|
44
58
|
exports.compose = compose.compose;
|
|
45
59
|
exports.contextBuilder = contextBuilder.contextBuilder;
|
|
60
|
+
exports.optionalContextBuilder = contextBuilder.optionalContextBuilder;
|
|
61
|
+
exports.inertValue = inertValue.inertValue;
|
|
46
62
|
exports.creatableComponent = shorthands.creatableComponent;
|
|
47
63
|
exports.createShorthandFactory = shorthands.createShorthandFactory;
|
|
48
64
|
exports.renderShorthandContent = shorthands.renderShorthandContent;
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -46,6 +46,32 @@ function contextBuilder(name, initialContext) {
|
|
|
46
46
|
BaseContext.displayName = name;
|
|
47
47
|
return [BaseContext, useContextHook];
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* The same pair for a context whose provider is **optional**: outside it the hook returns the default
|
|
51
|
+
* value instead of throwing.
|
|
52
|
+
*
|
|
53
|
+
* ```tsx
|
|
54
|
+
* const [ FieldContext, useFieldContext ] = optionalContextBuilder<FieldState>('Field', NO_FIELD);
|
|
55
|
+
*
|
|
56
|
+
* const field = useFieldContext(); // NO_FIELD outside a Field: the control works on its own
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* `contextBuilder` is right when a missing provider is a mistake. This one is for the other case, a
|
|
60
|
+
* component that also works alone and only reads the context when something above provides it: a
|
|
61
|
+
* control inside or outside a field, a dialog nested or not. The value may be anything, a primitive
|
|
62
|
+
* included (`optionalContextBuilder('OverlayLevel', 0)`), which `contextBuilder` cannot take because
|
|
63
|
+
* it tells a missing provider apart by a falsy value.
|
|
64
|
+
*
|
|
65
|
+
* @param name The name shown by React DevTools
|
|
66
|
+
* @param defaultValue What the hook returns with no provider above
|
|
67
|
+
*/
|
|
68
|
+
function optionalContextBuilder(name, defaultValue) {
|
|
69
|
+
const BaseContext = React__namespace.createContext(defaultValue);
|
|
70
|
+
const useContextHook = () => React__namespace.useContext(BaseContext);
|
|
71
|
+
BaseContext.displayName = name;
|
|
72
|
+
return [BaseContext, useContextHook];
|
|
73
|
+
}
|
|
49
74
|
|
|
50
75
|
exports.contextBuilder = contextBuilder;
|
|
76
|
+
exports.optionalContextBuilder = optionalContextBuilder;
|
|
51
77
|
//# sourceMappingURL=contextBuilder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextBuilder.js","sources":["../../../src/utils/contextBuilder.ts"],"sourcesContent":[null],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAWA;;;;;;AAMG;AACG,SAAU,cAAc,CAAsB,IAAY,EAAE,cAAkB,EAAA;;IAGlF,MAAM,WAAW,GAAGA,gBAAK,CAAC,aAAa,CAAgB,cAAc,CAAC;;IAGtE,MAAM,cAAc,GAAY,MAAK;;QAEnC,MAAM,YAAY,GAAGA,gBAAK,CAAC,UAAU,CAAC,WAAW,CAAC;;QAElD,IAAI,CAAC,YAAY,EAAE;AACjB,YAAA,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,CAAA,yCAAA,CAA2C,CAAC;QAC3F;;AAEA,QAAA,OAAO,YAAY;AACrB,IAAA,CAAC;;AAGD,IAAA,WAAW,CAAC,WAAW,GAAG,IAAI;AAE9B,IAAA,OAAO,CAAE,WAAW,EAAE,cAAc,CAAE;AACxC
|
|
1
|
+
{"version":3,"file":"contextBuilder.js","sources":["../../../src/utils/contextBuilder.ts"],"sourcesContent":[null],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAWA;;;;;;AAMG;AACG,SAAU,cAAc,CAAsB,IAAY,EAAE,cAAkB,EAAA;;IAGlF,MAAM,WAAW,GAAGA,gBAAK,CAAC,aAAa,CAAgB,cAAc,CAAC;;IAGtE,MAAM,cAAc,GAAY,MAAK;;QAEnC,MAAM,YAAY,GAAGA,gBAAK,CAAC,UAAU,CAAC,WAAW,CAAC;;QAElD,IAAI,CAAC,YAAY,EAAE;AACjB,YAAA,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,CAAA,yCAAA,CAA2C,CAAC;QAC3F;;AAEA,QAAA,OAAO,YAAY;AACrB,IAAA,CAAC;;AAGD,IAAA,WAAW,CAAC,WAAW,GAAG,IAAI;AAE9B,IAAA,OAAO,CAAE,WAAW,EAAE,cAAc,CAAE;AACxC;AAGA;;;;;;;;;;;;;;;;;;AAkBG;AACG,SAAU,sBAAsB,CAAI,IAAY,EAAE,YAAe,EAAA;IACrE,MAAM,WAAW,GAAGA,gBAAK,CAAC,aAAa,CAAI,YAAY,CAAC;IAExD,MAAM,cAAc,GAAG,MAASA,gBAAK,CAAC,UAAU,CAAC,WAAW,CAAC;AAE7D,IAAA,WAAW,CAAC,WAAW,GAAG,IAAI;AAE9B,IAAA,OAAO,CAAE,WAAW,EAAE,cAAc,CAAE;AACxC;;;;;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
function _interopNamespaceDefault(e) {
|
|
6
|
+
var n = Object.create(null);
|
|
7
|
+
if (e) {
|
|
8
|
+
Object.keys(e).forEach(function (k) {
|
|
9
|
+
if (k !== 'default') {
|
|
10
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return e[k]; }
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
n.default = e;
|
|
19
|
+
return Object.freeze(n);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The value of the `inert` attribute for the React running: a boolean on 19, an empty string on 18,
|
|
26
|
+
* which drops a boolean with a warning and leaves the element live.
|
|
27
|
+
*
|
|
28
|
+
* ```tsx
|
|
29
|
+
* <div inert={inertValue(wait.busy)}>…</div>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
function inertValue(value) {
|
|
33
|
+
if (!value) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return (Number.parseInt(React__namespace.version, 10) >= 19 ? true : '');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.inertValue = inertValue;
|
|
40
|
+
//# sourceMappingURL=inertValue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inertValue.js","sources":["../../../src/utils/inertValue.ts"],"sourcesContent":[null],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAGA;;;;;;;AAOG;AACG,SAAU,UAAU,CAAC,KAA0B,EAAA;IACnD,IAAI,CAAC,KAAK,EAAE;AACV,QAAA,OAAO,SAAS;IAClB;IAEA,QAAQ,MAAM,CAAC,QAAQ,CAACA,gBAAK,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,IAAI,GAAG,EAAE;AAC9D;;;;"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use client';import * as React from 'react';
|
|
2
|
+
import { useUnmountEffect } from './useUnmountEffect.js';
|
|
3
|
+
|
|
4
|
+
/* --------
|
|
5
|
+
* Hook Definition
|
|
6
|
+
* -------- */
|
|
7
|
+
/**
|
|
8
|
+
* The text of a live region, announced again even when it repeats.
|
|
9
|
+
*
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const [ message, announce ] = useAnnouncer();
|
|
12
|
+
*
|
|
13
|
+
* <button onClick={() => { remove(file); announce(`${file.name} removed`); }}>Remove</button>
|
|
14
|
+
* <span role={'status'} className={'sr-only'}>{message}</span>
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* A screen reader speaks a live region when its content changes, so setting the same text twice in
|
|
18
|
+
* a row says nothing the second time: two files with the same name removed one after the other, the
|
|
19
|
+
* same sort applied again. `announce` empties the region first and writes the text on the next task,
|
|
20
|
+
* which makes every call a change.
|
|
21
|
+
*
|
|
22
|
+
* A call replaces one still pending, so only the last text is spoken; an empty text is ignored, so
|
|
23
|
+
* an optional label can be passed as it is. The region itself is the caller's: the hook renders
|
|
24
|
+
* nothing, and the element, its role and its slot stay where the component decides.
|
|
25
|
+
*/
|
|
26
|
+
function useAnnouncer() {
|
|
27
|
+
// ----
|
|
28
|
+
// Internal State
|
|
29
|
+
// ----
|
|
30
|
+
const [message, setMessage] = React.useState('');
|
|
31
|
+
const timerRef = React.useRef(null);
|
|
32
|
+
// ----
|
|
33
|
+
// Handlers
|
|
34
|
+
// ----
|
|
35
|
+
const announce = React.useCallback((text) => {
|
|
36
|
+
if (!text) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (timerRef.current !== null) {
|
|
40
|
+
window.clearTimeout(timerRef.current);
|
|
41
|
+
}
|
|
42
|
+
setMessage('');
|
|
43
|
+
timerRef.current = window.setTimeout(() => {
|
|
44
|
+
timerRef.current = null;
|
|
45
|
+
setMessage(text);
|
|
46
|
+
});
|
|
47
|
+
}, []);
|
|
48
|
+
// ----
|
|
49
|
+
// Lifecycle Events
|
|
50
|
+
// ----
|
|
51
|
+
useUnmountEffect(() => {
|
|
52
|
+
if (timerRef.current !== null) {
|
|
53
|
+
window.clearTimeout(timerRef.current);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return [message, announce];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { useAnnouncer };
|
|
60
|
+
//# sourceMappingURL=useAnnouncer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAnnouncer.js","sources":["../../../src/hooks/useAnnouncer.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAeA;;AAEc;AAEd;;;;;;;;;;;;;;;;;;AAkBG;SACa,YAAY,GAAA;;;;AAK1B,IAAA,MAAM,CAAE,OAAO,EAAE,UAAU,CAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;IAClD,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAgB,IAAI,CAAC;;;;IAMlD,MAAM,QAAQ,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,IAA+B,KAAU;QAC3E,IAAI,CAAC,IAAI,EAAE;YACT;QACF;AAEA,QAAA,IAAI,QAAQ,CAAC,OAAO,KAAK,IAAI,EAAE;AAC7B,YAAA,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC;QACvC;QAEA,UAAU,CAAC,EAAE,CAAC;QAEd,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,MAAK;AACxC,YAAA,QAAQ,CAAC,OAAO,GAAG,IAAI;YACvB,UAAU,CAAC,IAAI,CAAC;AAClB,QAAA,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC;;;;IAMN,gBAAgB,CAAC,MAAK;AACpB,QAAA,IAAI,QAAQ,CAAC,OAAO,KAAK,IAAI,EAAE;AAC7B,YAAA,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC;QACvC;AACF,IAAA,CAAC,CAAC;AAGF,IAAA,OAAO,CAAE,OAAO,EAAE,QAAQ,CAAW;AAEvC;;;;"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use client';import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/* --------
|
|
4
|
+
* Helpers
|
|
5
|
+
* -------- */
|
|
6
|
+
/**
|
|
7
|
+
* Writes the text with the Clipboard API where the page may use it, a secure context, and with a
|
|
8
|
+
* selected textarea and `execCommand('copy')` elsewhere: an intranet served over plain http has no
|
|
9
|
+
* `navigator.clipboard` at all. The focus goes back where it was, without scrolling.
|
|
10
|
+
*/
|
|
11
|
+
async function writeText(text) {
|
|
12
|
+
if (window.isSecureContext && typeof navigator.clipboard?.writeText === 'function') {
|
|
13
|
+
await navigator.clipboard.writeText(text);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const active = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
17
|
+
const area = document.createElement('textarea');
|
|
18
|
+
area.value = text;
|
|
19
|
+
area.setAttribute('readonly', '');
|
|
20
|
+
area.setAttribute('aria-hidden', 'true');
|
|
21
|
+
area.style.position = 'fixed';
|
|
22
|
+
area.style.inset = '0 auto auto 0';
|
|
23
|
+
area.style.opacity = '0';
|
|
24
|
+
area.style.pointerEvents = 'none';
|
|
25
|
+
document.body.appendChild(area);
|
|
26
|
+
area.select();
|
|
27
|
+
try {
|
|
28
|
+
/* Deprecated, and the only way left where the Clipboard API is not offered */
|
|
29
|
+
if (!document.execCommand('copy')) {
|
|
30
|
+
throw new Error('The browser refused to copy');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
area.remove();
|
|
35
|
+
active?.focus({ preventScroll: true });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/* --------
|
|
39
|
+
* Hook Definition
|
|
40
|
+
* -------- */
|
|
41
|
+
/**
|
|
42
|
+
* Copies a text to the clipboard and says how it went, for a button that turns into a tick for a moment.
|
|
43
|
+
*
|
|
44
|
+
* ```tsx
|
|
45
|
+
* const clipboard = useClipboard();
|
|
46
|
+
*
|
|
47
|
+
* <button onClick={() => clipboard.copy(apiKey)}>
|
|
48
|
+
* {clipboard.status === 'copied' ? 'Copied' : 'Copy'}
|
|
49
|
+
* </button>
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* The value may be a function, read at the moment of the copy, and it may be asynchronous: a link
|
|
53
|
+
* created on demand. A second copy before the reset starts the time again.
|
|
54
|
+
*/
|
|
55
|
+
function useClipboard(options = {}) {
|
|
56
|
+
// ----
|
|
57
|
+
// Options Deconstruct
|
|
58
|
+
// ----
|
|
59
|
+
const { resetAfter = 1500 } = options;
|
|
60
|
+
// ----
|
|
61
|
+
// Internal State
|
|
62
|
+
// ----
|
|
63
|
+
const [status, setStatus] = React.useState('idle');
|
|
64
|
+
const timerRef = React.useRef(undefined);
|
|
65
|
+
// ----
|
|
66
|
+
// Lifecycle Events
|
|
67
|
+
// ----
|
|
68
|
+
React.useEffect(() => () => window.clearTimeout(timerRef.current), []);
|
|
69
|
+
// ----
|
|
70
|
+
// Handlers
|
|
71
|
+
// ----
|
|
72
|
+
const settle = React.useCallback((next) => {
|
|
73
|
+
window.clearTimeout(timerRef.current);
|
|
74
|
+
setStatus(next);
|
|
75
|
+
timerRef.current = window.setTimeout(() => setStatus('idle'), resetAfter);
|
|
76
|
+
}, [resetAfter]);
|
|
77
|
+
const copy = React.useCallback(async (value) => {
|
|
78
|
+
try {
|
|
79
|
+
await writeText(typeof value === 'function' ? await value() : value);
|
|
80
|
+
settle('copied');
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
settle('failed');
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}, [settle]);
|
|
88
|
+
// ----
|
|
89
|
+
// Hook Return
|
|
90
|
+
// ----
|
|
91
|
+
return { status, copy };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { useClipboard };
|
|
95
|
+
//# sourceMappingURL=useClipboard.js.map
|
|
@@ -0,0 +1 @@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|
|
3
|
+
/* --------
|
|
4
|
+
* Hook Definition
|
|
5
|
+
* -------- */
|
|
6
|
+
/**
|
|
7
|
+
* The timing every wait shares, in two values: the block comes at once, the look after 300ms, and
|
|
8
|
+
* once shown it stays at least 400ms.
|
|
9
|
+
*
|
|
10
|
+
* ```tsx
|
|
11
|
+
* const wait = useDelayedBusy(query.isFetching);
|
|
12
|
+
*
|
|
13
|
+
* <div aria-busy={wait.busy}>
|
|
14
|
+
* {wait.visible && <LoadingBar />}
|
|
15
|
+
* </div>
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* Data that arrives is shown at once and replaces a skeleton: the minimum holds only the indicator
|
|
19
|
+
* (a bar, a veil, a spinner), which is what `visible` drives.
|
|
20
|
+
*/
|
|
21
|
+
function useDelayedBusy(busy, options = {}) {
|
|
22
|
+
// ----
|
|
23
|
+
// Options Deconstruct
|
|
24
|
+
// ----
|
|
25
|
+
const { delay = 300, minDuration = 400 } = options;
|
|
26
|
+
// ----
|
|
27
|
+
// Internal State
|
|
28
|
+
// ----
|
|
29
|
+
const [visible, setVisible] = React.useState(false);
|
|
30
|
+
const shownAtRef = React.useRef(0);
|
|
31
|
+
// ----
|
|
32
|
+
// Lifecycle Events
|
|
33
|
+
// ----
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
if (busy) {
|
|
36
|
+
if (visible) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
const timer = window.setTimeout(() => {
|
|
40
|
+
shownAtRef.current = Date.now();
|
|
41
|
+
setVisible(true);
|
|
42
|
+
}, delay);
|
|
43
|
+
return () => window.clearTimeout(timer);
|
|
44
|
+
}
|
|
45
|
+
if (!visible) {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
const left = Math.max(0, minDuration - (Date.now() - shownAtRef.current));
|
|
49
|
+
const timer = window.setTimeout(() => setVisible(false), left);
|
|
50
|
+
return () => window.clearTimeout(timer);
|
|
51
|
+
}, [busy, visible, delay, minDuration]);
|
|
52
|
+
// ----
|
|
53
|
+
// Hook Return
|
|
54
|
+
// ----
|
|
55
|
+
return { busy, visible };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { useDelayedBusy };
|
|
59
|
+
//# sourceMappingURL=useDelayedBusy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDelayedBusy.js","sources":["../../../src/hooks/useDelayedBusy.ts"],"sourcesContent":[null],"names":[],"mappings":";;AA0BA;;AAEc;AAEd;;;;;;;;;;;;;;AAcG;SACa,cAAc,CAAC,IAAa,EAAE,UAA8B,EAAE,EAAA;;;;IAK5E,MAAM,EAAE,KAAK,GAAG,GAAG,EAAE,WAAW,GAAG,GAAG,EAAE,GAAG,OAAO;;;;AAMlD,IAAA,MAAM,CAAE,OAAO,EAAE,UAAU,CAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC;IACrD,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;;;;AAMlC,IAAA,KAAK,CAAC,SAAS,CAAC,MAAK;QACnB,IAAI,IAAI,EAAE;YACR,IAAI,OAAO,EAAE;AACX,gBAAA,OAAO,SAAS;YAClB;AAEA,YAAA,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,MAAK;AACnC,gBAAA,UAAU,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE;gBAC/B,UAAU,CAAC,IAAI,CAAC;YAClB,CAAC,EAAE,KAAK,CAAC;YAET,OAAO,MAAM,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC;QACzC;QAEA,IAAI,CAAC,OAAO,EAAE;AACZ,YAAA,OAAO,SAAS;QAClB;QAEA,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;AACzE,QAAA,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,UAAU,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC;QAE9D,OAAO,MAAM,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC;IACzC,CAAC,EAAE,CAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,CAAE,CAAC;;;;AAMzC,IAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE;AAE1B;;;;"}
|
package/esm/hooks/useForkRef.js
CHANGED
|
@@ -19,7 +19,7 @@ import * as React from 'react';
|
|
|
19
19
|
* @example
|
|
20
20
|
* const Input = React.forwardRef<HTMLInputElement, Props>((props, ref) => {
|
|
21
21
|
* const innerRef = React.useRef<HTMLInputElement>(null);
|
|
22
|
-
* const handleRef = useForkRef(innerRef, ref
|
|
22
|
+
* const handleRef = useForkRef(innerRef, ref);
|
|
23
23
|
*
|
|
24
24
|
* return <input {...props} ref={handleRef} />;
|
|
25
25
|
* });
|
|
@@ -27,7 +27,12 @@ import * as React from 'react';
|
|
|
27
27
|
function useForkRef(...refs) {
|
|
28
28
|
return React.useCallback((refValue) => {
|
|
29
29
|
refs.forEach((ref) => {
|
|
30
|
-
ref
|
|
30
|
+
if (typeof ref === 'function') {
|
|
31
|
+
ref(refValue);
|
|
32
|
+
}
|
|
33
|
+
else if (ref) {
|
|
34
|
+
ref.current = refValue;
|
|
35
|
+
}
|
|
31
36
|
});
|
|
32
37
|
},
|
|
33
38
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForkRef.js","sources":["../../../src/hooks/useForkRef.ts"],"sourcesContent":[null],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"useForkRef.js","sources":["../../../src/hooks/useForkRef.ts"],"sourcesContent":[null],"names":[],"mappings":";;AA2BA;;AAEc;AAEd;;;;;;;;;;;;;;;;;;;;AAoBG;AACG,SAAU,UAAU,CAAI,GAAG,IAAsB,EAAA;AACrD,IAAA,OAAO,KAAK,CAAC,WAAW,CACtB,CAAC,QAAkB,KAAI;AACrB,QAAA,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,KAAI;AACnB,YAAA,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;gBAC7B,GAAG,CAAC,QAAQ,CAAC;YACf;iBACK,IAAI,GAAG,EAAE;AACZ,gBAAA,GAAG,CAAC,OAAO,GAAG,QAAQ;YACxB;AACF,QAAA,CAAC,CAAC;IACJ,CAAC;AACD;;;;;;;;;;;AAWG;;AAEH,IAAA,CAAE,GAAG,IAAI,CAAE,CACZ;AACH;;;;"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use client';import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/* --------
|
|
4
|
+
* Hook Definition
|
|
5
|
+
* -------- */
|
|
6
|
+
/**
|
|
7
|
+
* Whether a media query matches, kept in sync with the browser.
|
|
8
|
+
*
|
|
9
|
+
* The primitive `usePrefersReducedMotion` is built on, here, and `useBreakpoint` / `useIsMobile` in
|
|
10
|
+
* `@proedis/ui`, which add the vocabulary of the Tailwind breakpoints on top. Exported because a named
|
|
11
|
+
* breakpoint is not the only question worth asking: `(prefers-reduced-motion: reduce)`,
|
|
12
|
+
* `(prefers-contrast: more)`, `print`, `(orientation: landscape)`, `(hover: hover)` and a width outside
|
|
13
|
+
* the theme's scale all end here.
|
|
14
|
+
*
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const isLandscape = useMediaQuery('(orientation: landscape)');
|
|
17
|
+
* const canHover = useMediaQuery('(hover: hover)');
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* `useSyncExternalStore` rather than an effect with a `setState`: it takes a server snapshot as an
|
|
21
|
+
* argument, which is what turns a hydration-safe read into one line instead of the mounted-guard
|
|
22
|
+
* dance. The same snapshot is used while **hydrating** what the server rendered, so it has to be the
|
|
23
|
+
* answer that is safe to be wrong about for one frame; a tree rendered on the client only reads the
|
|
24
|
+
* real value from its first render.
|
|
25
|
+
*
|
|
26
|
+
* @param query - Any CSS media query, as `window.matchMedia` accepts it.
|
|
27
|
+
* @param serverSnapshot - What to answer with no `window` and while hydrating. Defaults
|
|
28
|
+
* to `false`, i.e. "does not match".
|
|
29
|
+
*/
|
|
30
|
+
function useMediaQuery(query, serverSnapshot = false) {
|
|
31
|
+
// ----
|
|
32
|
+
// Handlers
|
|
33
|
+
// ----
|
|
34
|
+
const subscribe = React.useCallback((onStoreChange) => {
|
|
35
|
+
const list = window.matchMedia(query);
|
|
36
|
+
list.addEventListener('change', onStoreChange);
|
|
37
|
+
return () => list.removeEventListener('change', onStoreChange);
|
|
38
|
+
}, [query]);
|
|
39
|
+
const getSnapshot = React.useCallback(() => window.matchMedia(query).matches, [query]);
|
|
40
|
+
const getServerSnapshot = React.useCallback(() => serverSnapshot, [serverSnapshot]);
|
|
41
|
+
// ----
|
|
42
|
+
// Hook Return
|
|
43
|
+
// ----
|
|
44
|
+
return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export { useMediaQuery };
|
|
48
|
+
//# sourceMappingURL=useMediaQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMediaQuery.js","sources":["../../../src/hooks/useMediaQuery.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA;;AAEc;AAEd;;;;;;;;;;;;;;;;;;;;;;;AAuBG;SACa,aAAa,CAAC,KAAa,EAAE,iBAA0B,KAAK,EAAA;;;;IAK1E,MAAM,SAAS,GAAG,KAAK,CAAC,WAAW,CACjC,CAAC,aAAyB,KAAI;QAC5B,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC;AAErC,QAAA,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,aAAa,CAAC;QAE9C,OAAO,MAAM,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,aAAa,CAAC;AAChE,IAAA,CAAC,EACD,CAAE,KAAK,CAAE,CACV;IAED,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAE,KAAK,CAAE,CAAC;AAExF,IAAA,MAAM,iBAAiB,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,cAAc,EAAE,CAAE,cAAc,CAAE,CAAC;;;;IAMrF,OAAO,KAAK,CAAC,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,iBAAiB,CAAC;AAE9E;;;;"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use client';import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/* --------
|
|
4
|
+
* Helpers
|
|
5
|
+
* -------- */
|
|
6
|
+
/** Which items fit, as a pure function of the measures: no frame where the pinned item is missing */
|
|
7
|
+
function fitItems(widths, available, options) {
|
|
8
|
+
const { gap, pinned, reserve } = options;
|
|
9
|
+
const all = widths.map((_, index) => index);
|
|
10
|
+
const total = widths.reduce((sum, width) => sum + width, 0) + gap * Math.max(0, widths.length - 1);
|
|
11
|
+
if (widths.length === 0 || total <= available) {
|
|
12
|
+
return { visible: all, overflow: [] };
|
|
13
|
+
}
|
|
14
|
+
const room = available - reserve;
|
|
15
|
+
const visible = [];
|
|
16
|
+
let used = 0;
|
|
17
|
+
for (const index of all) {
|
|
18
|
+
const width = widths[index] + (visible.length > 0 ? gap : 0);
|
|
19
|
+
if (used + width > room) {
|
|
20
|
+
break;
|
|
21
|
+
}
|
|
22
|
+
visible.push(index);
|
|
23
|
+
used += width;
|
|
24
|
+
}
|
|
25
|
+
if (pinned !== undefined && pinned >= 0 && pinned < widths.length && !visible.includes(pinned)) {
|
|
26
|
+
const pinnedWidth = () => widths[pinned] + (visible.length > 0 ? gap : 0);
|
|
27
|
+
while (visible.length > 0 && used + pinnedWidth() > room) {
|
|
28
|
+
const last = visible.pop();
|
|
29
|
+
used -= widths[last] + (visible.length > 0 ? gap : 0);
|
|
30
|
+
}
|
|
31
|
+
visible.push(pinned);
|
|
32
|
+
}
|
|
33
|
+
return { visible, overflow: all.filter((index) => !visible.includes(index)) };
|
|
34
|
+
}
|
|
35
|
+
/* --------
|
|
36
|
+
* Hook Definition
|
|
37
|
+
* -------- */
|
|
38
|
+
/**
|
|
39
|
+
* Which items of a row fit, and which go into a "More" menu: the tabs of a detail, the tabs of a
|
|
40
|
+
* header. The widths come from a hidden copy of the row (`measureRef`, `aria-hidden` and `inert`),
|
|
41
|
+
* one child per item, so measuring never moves what the user sees.
|
|
42
|
+
*
|
|
43
|
+
* ```tsx
|
|
44
|
+
* const { visible, overflow } = useOverflowItems(rowRef, copyRef, { count: tabs.length, pinned: active });
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* It measures again when the row or the copy changes size, so a count that arrives late is taken in.
|
|
48
|
+
*/
|
|
49
|
+
function useOverflowItems(containerRef, measureRef, options) {
|
|
50
|
+
// ----
|
|
51
|
+
// Options Deconstruct
|
|
52
|
+
// ----
|
|
53
|
+
const { available: readAvailable, count, gap, pinned, reserve } = options;
|
|
54
|
+
// ----
|
|
55
|
+
// Internal State
|
|
56
|
+
// ----
|
|
57
|
+
const [measures, setMeasures] = React.useState(null);
|
|
58
|
+
const readRef = React.useRef(readAvailable);
|
|
59
|
+
React.useEffect(() => {
|
|
60
|
+
readRef.current = readAvailable;
|
|
61
|
+
});
|
|
62
|
+
// ----
|
|
63
|
+
// Lifecycle Events
|
|
64
|
+
// ----
|
|
65
|
+
React.useEffect(() => {
|
|
66
|
+
const container = containerRef.current;
|
|
67
|
+
const copy = measureRef.current;
|
|
68
|
+
if (!container || !copy) {
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
const measure = () => {
|
|
72
|
+
const available = readRef.current ? readRef.current(container) : container.clientWidth;
|
|
73
|
+
const children = Array.from(copy.children);
|
|
74
|
+
const reserveElement = children.find((child) => child.hasAttribute('data-overflow-reserve'));
|
|
75
|
+
const widths = children.filter((child) => child !== reserveElement).map((child) => child.getBoundingClientRect().width);
|
|
76
|
+
const measuredReserve = reserveElement ? reserveElement.getBoundingClientRect().width : 0;
|
|
77
|
+
const measuredGap = Number.parseFloat(getComputedStyle(copy).columnGap) || 0;
|
|
78
|
+
setMeasures((previous) => (previous
|
|
79
|
+
&& previous.available === available
|
|
80
|
+
&& previous.reserve === measuredReserve
|
|
81
|
+
&& previous.gap === measuredGap
|
|
82
|
+
&& previous.widths.length === widths.length
|
|
83
|
+
&& previous.widths.every((width, index) => width === widths[index])
|
|
84
|
+
? previous
|
|
85
|
+
: { available, widths, reserve: measuredReserve, gap: measuredGap }));
|
|
86
|
+
};
|
|
87
|
+
const observer = new ResizeObserver(measure);
|
|
88
|
+
observer.observe(container);
|
|
89
|
+
observer.observe(copy);
|
|
90
|
+
measure();
|
|
91
|
+
return () => observer.disconnect();
|
|
92
|
+
}, [containerRef, measureRef]);
|
|
93
|
+
// ----
|
|
94
|
+
// Hook Return
|
|
95
|
+
// ----
|
|
96
|
+
if (!measures || measures.widths.length !== count) {
|
|
97
|
+
return { visible: Array.from({ length: count }, (_, index) => index), overflow: [] };
|
|
98
|
+
}
|
|
99
|
+
return fitItems(measures.widths, measures.available, {
|
|
100
|
+
gap: gap ?? measures.gap,
|
|
101
|
+
pinned,
|
|
102
|
+
reserve: reserve ?? measures.reserve
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { fitItems, useOverflowItems };
|
|
107
|
+
//# sourceMappingURL=useOverflowItems.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOverflowItems.js","sources":["../../../src/hooks/useOverflowItems.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAgDA;;AAEc;AAEd;SACgB,QAAQ,CACtB,MAAyB,EACzB,SAAiB,EACjB,OAA0D,EAAA;IAE1D,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO;AACxC,IAAA,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC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,EAAE,UAAU,CAAE,CAAC;;;;IAMhC,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,KAAK,KAAK,EAAE;QACjD,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,KAAK,KAAK,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;IACtF;IAEA,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,EAAE;AACnD,QAAA,GAAG,EAAM,GAAG,IAAI,QAAQ,CAAC,GAAG;QAC5B,MAAM;AACN,QAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,CAAC;AAC9B,KAAA,CAAC;AAEJ;;;;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use client';import { useMediaQuery } from './useMediaQuery.js';
|
|
2
|
+
|
|
3
|
+
/* --------
|
|
4
|
+
* Constants Definition
|
|
5
|
+
* -------- */
|
|
6
|
+
const QUERY = '(prefers-reduced-motion: reduce)';
|
|
7
|
+
/* --------
|
|
8
|
+
* Hook Definition
|
|
9
|
+
* -------- */
|
|
10
|
+
/**
|
|
11
|
+
* Whether the user asked the system to reduce motion.
|
|
12
|
+
*
|
|
13
|
+
* For animation driven from JavaScript — a spring, a scroll interpolation, an autoplaying carousel.
|
|
14
|
+
* A transition written in CSS does **not** need this: `@media (prefers-reduced-motion: reduce)`
|
|
15
|
+
* answers the same question where the animation lives, without shipping a hook to the client.
|
|
16
|
+
*
|
|
17
|
+
* ```tsx
|
|
18
|
+
* const still = usePrefersReducedMotion();
|
|
19
|
+
* <motion.div animate={still ? {} : { y: 0 }} />
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* ⚠️ It answers **`true`** with no `window` and on the first client render, unlike the other media
|
|
23
|
+
* query hooks, and the asymmetry is on purpose: the two possible mistakes are not equivalent. Guessing
|
|
24
|
+
* "reduce" and correcting to "animate" costs one frame of stillness; guessing the other way plays
|
|
25
|
+
* the animation this preference exists to prevent, to the person who asked for it not to.
|
|
26
|
+
*/
|
|
27
|
+
function usePrefersReducedMotion() {
|
|
28
|
+
return useMediaQuery(QUERY, true);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { usePrefersReducedMotion };
|
|
32
|
+
//# sourceMappingURL=usePrefersReducedMotion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePrefersReducedMotion.js","sources":["../../../src/hooks/usePrefersReducedMotion.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA;;AAEc;AACd,MAAM,KAAK,GAAG,kCAAkC;AAGhD;;AAEc;AAEd;;;;;;;;;;;;;;;;AAgBG;SACa,uBAAuB,GAAA;AACrC,IAAA,OAAO,aAAa,CAAC,KAAK,EAAE,IAAI,CAAC;AACnC;;;;"}
|
package/esm/index.js
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
export { default as RenderWhen } from './components/RenderWhen/RenderWhen.js';
|
|
2
|
+
export { useAnnouncer } from './hooks/useAnnouncer.js';
|
|
2
3
|
export { useAutoControlledState } from './hooks/useAutoControlledState.js';
|
|
3
4
|
export { getAncestorsSpace, useAutoSizer } from './hooks/useAutoSizer.js';
|
|
4
5
|
export { useClickOutside } from './hooks/useClickOutside.js';
|
|
6
|
+
export { useClipboard } from './hooks/useClipboard.js';
|
|
5
7
|
export { useDataManager } from './hooks/useDataManager.js';
|
|
6
8
|
export { useDataSelector } from './hooks/useDataSelector.js';
|
|
7
9
|
export { useDebouncedCallback } from './hooks/useDebouncedCallback.js';
|
|
10
|
+
export { useDelayedBusy } from './hooks/useDelayedBusy.js';
|
|
8
11
|
export { useElementType } from './hooks/useElementType.js';
|
|
9
12
|
export { useEnhancedEffect } from './hooks/useEnhancedEffect.js';
|
|
10
13
|
export { useEvent } from './hooks/useEvent.js';
|
|
11
14
|
export { useForkRef } from './hooks/useForkRef.js';
|
|
12
15
|
export { useInputValue } from './hooks/useInputValue.js';
|
|
16
|
+
export { useMediaQuery } from './hooks/useMediaQuery.js';
|
|
13
17
|
export { useObjectState } from './hooks/useObjectState.js';
|
|
18
|
+
export { fitItems, useOverflowItems } from './hooks/useOverflowItems.js';
|
|
19
|
+
export { usePrefersReducedMotion } from './hooks/usePrefersReducedMotion.js';
|
|
14
20
|
export { useSafeState } from './hooks/useSafeState.js';
|
|
15
21
|
export { useSyncedRef } from './hooks/useSyncedRef.js';
|
|
16
22
|
export { useUnmountEffect } from './hooks/useUnmountEffect.js';
|
|
17
23
|
export { useWindowSize } from './hooks/useWindowSize.js';
|
|
18
24
|
export { compose } from './utils/compose.js';
|
|
19
|
-
export { contextBuilder } from './utils/contextBuilder.js';
|
|
25
|
+
export { contextBuilder, optionalContextBuilder } from './utils/contextBuilder.js';
|
|
26
|
+
export { inertValue } from './utils/inertValue.js';
|
|
20
27
|
export { creatableComponent, createShorthandFactory, renderShorthandContent } from './utils/shorthands.js';
|
|
21
28
|
//# sourceMappingURL=index.js.map
|