@octanejs/mantine-hooks 0.1.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/LICENSE +21 -0
- package/README.md +29 -0
- package/package.json +45 -0
- package/src/index.ts +259 -0
- package/src/internal.ts +6 -0
- package/src/use-click-outside/use-click-outside.ts +57 -0
- package/src/use-clipboard/use-clipboard.ts +69 -0
- package/src/use-collapse/use-collapse.ts +162 -0
- package/src/use-collapse/use-horizontal-collapse.ts +164 -0
- package/src/use-color-scheme/use-color-scheme.ts +13 -0
- package/src/use-counter/use-counter.ts +59 -0
- package/src/use-debounced-callback/use-debounced-callback.ts +159 -0
- package/src/use-debounced-state/use-debounced-state.ts +44 -0
- package/src/use-debounced-value/use-debounced-value.ts +71 -0
- package/src/use-did-update/use-did-update.ts +26 -0
- package/src/use-disclosure/use-disclosure.ts +57 -0
- package/src/use-document-title/use-document-title.ts +9 -0
- package/src/use-document-visibility/use-document-visibility.ts +14 -0
- package/src/use-drag/use-drag.ts +463 -0
- package/src/use-event-listener/use-event-listener.ts +47 -0
- package/src/use-eye-dropper/use-eye-dropper.ts +41 -0
- package/src/use-favicon/use-favicon.ts +41 -0
- package/src/use-fetch/use-fetch.ts +85 -0
- package/src/use-file-dialog/use-file-dialog.ts +140 -0
- package/src/use-floating-window/use-floating-window.ts +431 -0
- package/src/use-focus-return/use-focus-return.ts +65 -0
- package/src/use-focus-trap/scope-tab.ts +36 -0
- package/src/use-focus-trap/tabbable.ts +65 -0
- package/src/use-focus-trap/use-focus-trap.ts +84 -0
- package/src/use-focus-within/use-focus-within.ts +90 -0
- package/src/use-force-update/use-force-update.ts +8 -0
- package/src/use-fullscreen/use-fullscreen.ts +153 -0
- package/src/use-hash/use-hash.ts +42 -0
- package/src/use-headroom/use-headroom.ts +160 -0
- package/src/use-hotkeys/parse-hotkey.ts +130 -0
- package/src/use-hotkeys/use-hotkeys.ts +63 -0
- package/src/use-hover/use-hover.ts +57 -0
- package/src/use-id/use-id.ts +23 -0
- package/src/use-idle/use-idle.ts +54 -0
- package/src/use-in-viewport/use-in-viewport.ts +34 -0
- package/src/use-input-state/use-input-state.ts +41 -0
- package/src/use-intersection/use-intersection.ts +41 -0
- package/src/use-interval/use-interval.ts +84 -0
- package/src/use-is-first-render/use-is-first-render.ts +12 -0
- package/src/use-isomorphic-effect/use-isomorphic-effect.ts +5 -0
- package/src/use-list-state/use-list-state.ts +157 -0
- package/src/use-local-storage/create-storage.ts +200 -0
- package/src/use-local-storage/use-local-storage.ts +19 -0
- package/src/use-logger/use-logger.ts +16 -0
- package/src/use-long-press/use-long-press.ts +188 -0
- package/src/use-map/use-map.ts +28 -0
- package/src/use-mask/use-mask.ts +1049 -0
- package/src/use-media-query/use-media-query.ts +57 -0
- package/src/use-merged-ref/use-merged-ref.ts +53 -0
- package/src/use-mounted/use-mounted.ts +7 -0
- package/src/use-mouse/use-mouse.ts +91 -0
- package/src/use-move/use-move.ts +165 -0
- package/src/use-mutation-observer/use-mutation-observer.ts +61 -0
- package/src/use-network/use-network.ts +70 -0
- package/src/use-orientation/use-orientation.ts +87 -0
- package/src/use-os/use-os.ts +93 -0
- package/src/use-page-leave/use-page-leave.ts +10 -0
- package/src/use-pagination/use-pagination.ts +149 -0
- package/src/use-previous/use-previous.ts +11 -0
- package/src/use-queue/use-queue.ts +71 -0
- package/src/use-radial-move/use-radial-move.ts +161 -0
- package/src/use-reduced-motion/use-reduced-motion.ts +6 -0
- package/src/use-resize-observer/use-resize-observer.ts +95 -0
- package/src/use-roving-index/use-roving-index.ts +386 -0
- package/src/use-scroll-direction/use-scroll-direction.ts +41 -0
- package/src/use-scroll-into-view/use-scroll-into-view.ts +294 -0
- package/src/use-scroll-spy/use-scroll-spy.ts +155 -0
- package/src/use-scroller/use-scroller.ts +225 -0
- package/src/use-selection/use-selection.ts +120 -0
- package/src/use-session-storage/use-session-storage.ts +19 -0
- package/src/use-set/use-set.ts +88 -0
- package/src/use-set-state/use-set-state.ts +29 -0
- package/src/use-shallow-effect/use-shallow-effect.ts +40 -0
- package/src/use-splitter/use-splitter.ts +1242 -0
- package/src/use-state-history/use-state-history.ts +70 -0
- package/src/use-text-selection/use-text-selection.ts +20 -0
- package/src/use-throttled-callback/use-throttled-callback.ts +60 -0
- package/src/use-throttled-state/use-throttled-state.ts +12 -0
- package/src/use-throttled-value/use-throttled-value.ts +23 -0
- package/src/use-timeout/use-timeout.ts +56 -0
- package/src/use-toggle/use-toggle.ts +23 -0
- package/src/use-uncontrolled/use-uncontrolled.ts +53 -0
- package/src/use-validated-state/use-validated-state.ts +50 -0
- package/src/use-viewport-size/use-viewport-size.ts +23 -0
- package/src/use-window-event/use-window-event.ts +16 -0
- package/src/use-window-scroll/use-window-scroll.ts +49 -0
- package/src/utils/clamp/clamp.ts +15 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/lower-first/lower-first.ts +3 -0
- package/src/utils/random-id/random-id.ts +3 -0
- package/src/utils/range/range.ts +10 -0
- package/src/utils/shallow-equal/shallow-equal.ts +34 -0
- package/src/utils/upper-first/upper-first.ts +3 -0
- package/src/utils/use-callback-ref/use-callback-ref.ts +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dominic Gannaway
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @octanejs/mantine-hooks
|
|
2
|
+
|
|
3
|
+
Mantine hooks for Octane. This package ports the complete
|
|
4
|
+
`@mantine/hooks@9.5.0` runtime surface to Octane hooks while preserving Mantine's
|
|
5
|
+
public names, arguments, return values, and browser behavior.
|
|
6
|
+
|
|
7
|
+
```tsrx
|
|
8
|
+
import { useCounter, useDisclosure } from '@octanejs/mantine-hooks';
|
|
9
|
+
|
|
10
|
+
export function Controls() @{
|
|
11
|
+
const [count, counter] = useCounter(0, { min: 0, max: 10 });
|
|
12
|
+
const [opened, disclosure] = useDisclosure(false);
|
|
13
|
+
|
|
14
|
+
<section>
|
|
15
|
+
<button onClick={counter.increment}>{count as string}</button>
|
|
16
|
+
<button onClick={disclosure.toggle}>{opened ? 'close' : 'open'}</button>
|
|
17
|
+
</section>
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Compatibility
|
|
22
|
+
|
|
23
|
+
- All runtime exports from `@mantine/hooks@9.5.0` are present.
|
|
24
|
+
- Hook implementations use Octane state, effects, refs, memoization, and
|
|
25
|
+
compiler-injected hook slots.
|
|
26
|
+
- DOM subscriptions use native browser events, matching Mantine's underlying
|
|
27
|
+
behavior.
|
|
28
|
+
- React is not a runtime dependency. React type declarations are retained for
|
|
29
|
+
source-compatible ref, event, and style types.
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@octanejs/mantine-hooks",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=22"
|
|
8
|
+
},
|
|
9
|
+
"description": "Mantine hooks for Octane, ported from @mantine/hooks with Octane-native lifecycle and state hooks.",
|
|
10
|
+
"author": {
|
|
11
|
+
"name": "Dominic Gannaway",
|
|
12
|
+
"email": "dg@domgan.com"
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/octanejs/octane.git",
|
|
20
|
+
"directory": "packages/mantine-hooks"
|
|
21
|
+
},
|
|
22
|
+
"main": "src/index.ts",
|
|
23
|
+
"module": "src/index.ts",
|
|
24
|
+
"types": "src/index.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"src",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"exports": {
|
|
30
|
+
".": "./src/index.ts"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"octane": "0.1.19"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@mantine/hooks": "9.5.0",
|
|
37
|
+
"@types/react": "^19.2.17",
|
|
38
|
+
"react": "^19.2.7",
|
|
39
|
+
"vitest": "^4.1.10",
|
|
40
|
+
"octane": "0.1.19"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"test": "vitest run --root ../.. --project mantine-hooks --project mantine-hooks-ssr"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
export * from './utils/index.js';
|
|
2
|
+
|
|
3
|
+
export { useDebouncedCallback } from './use-debounced-callback/use-debounced-callback.js';
|
|
4
|
+
export { useClickOutside } from './use-click-outside/use-click-outside.js';
|
|
5
|
+
export { useClipboard } from './use-clipboard/use-clipboard.js';
|
|
6
|
+
export { useColorScheme } from './use-color-scheme/use-color-scheme.js';
|
|
7
|
+
export { useCounter } from './use-counter/use-counter.js';
|
|
8
|
+
export { useDebouncedState } from './use-debounced-state/use-debounced-state.js';
|
|
9
|
+
export { useDebouncedValue } from './use-debounced-value/use-debounced-value.js';
|
|
10
|
+
export { useDocumentTitle } from './use-document-title/use-document-title.js';
|
|
11
|
+
export { useDocumentVisibility } from './use-document-visibility/use-document-visibility.js';
|
|
12
|
+
export { useFocusReturn } from './use-focus-return/use-focus-return.js';
|
|
13
|
+
export { useDidUpdate } from './use-did-update/use-did-update.js';
|
|
14
|
+
export { useFocusTrap } from './use-focus-trap/use-focus-trap.js';
|
|
15
|
+
export { useForceUpdate } from './use-force-update/use-force-update.js';
|
|
16
|
+
export { useId } from './use-id/use-id.js';
|
|
17
|
+
export { useIdle } from './use-idle/use-idle.js';
|
|
18
|
+
export { useInterval } from './use-interval/use-interval.js';
|
|
19
|
+
export { useIsomorphicEffect } from './use-isomorphic-effect/use-isomorphic-effect.js';
|
|
20
|
+
export { useListState } from './use-list-state/use-list-state.js';
|
|
21
|
+
export { useLocalStorage, readLocalStorageValue } from './use-local-storage/use-local-storage.js';
|
|
22
|
+
export {
|
|
23
|
+
useSessionStorage,
|
|
24
|
+
readSessionStorageValue,
|
|
25
|
+
} from './use-session-storage/use-session-storage.js';
|
|
26
|
+
export { useMediaQuery } from './use-media-query/use-media-query.js';
|
|
27
|
+
export { useMergedRef, mergeRefs, assignRef } from './use-merged-ref/use-merged-ref.js';
|
|
28
|
+
export { useMouse, useMousePosition } from './use-mouse/use-mouse.js';
|
|
29
|
+
export { useMove, clampUseMovePosition } from './use-move/use-move.js';
|
|
30
|
+
export { usePagination } from './use-pagination/use-pagination.js';
|
|
31
|
+
export { useQueue } from './use-queue/use-queue.js';
|
|
32
|
+
export { usePageLeave } from './use-page-leave/use-page-leave.js';
|
|
33
|
+
export { useReducedMotion } from './use-reduced-motion/use-reduced-motion.js';
|
|
34
|
+
export { useScrollIntoView } from './use-scroll-into-view/use-scroll-into-view.js';
|
|
35
|
+
export { useResizeObserver, useElementSize } from './use-resize-observer/use-resize-observer.js';
|
|
36
|
+
export { useShallowEffect } from './use-shallow-effect/use-shallow-effect.js';
|
|
37
|
+
export { useToggle } from './use-toggle/use-toggle.js';
|
|
38
|
+
export { useUncontrolled } from './use-uncontrolled/use-uncontrolled.js';
|
|
39
|
+
export { useViewportSize } from './use-viewport-size/use-viewport-size.js';
|
|
40
|
+
export { useWindowEvent } from './use-window-event/use-window-event.js';
|
|
41
|
+
export { useWindowScroll } from './use-window-scroll/use-window-scroll.js';
|
|
42
|
+
export { useIntersection } from './use-intersection/use-intersection.js';
|
|
43
|
+
export { useHash } from './use-hash/use-hash.js';
|
|
44
|
+
export { useHotkeys, getHotkeyHandler } from './use-hotkeys/use-hotkeys.js';
|
|
45
|
+
export { useFullscreenDocument, useFullscreenElement } from './use-fullscreen/use-fullscreen.js';
|
|
46
|
+
export { useLogger } from './use-logger/use-logger.js';
|
|
47
|
+
export { useHover } from './use-hover/use-hover.js';
|
|
48
|
+
export { useValidatedState } from './use-validated-state/use-validated-state.js';
|
|
49
|
+
export { useOs } from './use-os/use-os.js';
|
|
50
|
+
export { useSetState } from './use-set-state/use-set-state.js';
|
|
51
|
+
export { useInputState } from './use-input-state/use-input-state.js';
|
|
52
|
+
export { useEventListener } from './use-event-listener/use-event-listener.js';
|
|
53
|
+
export { useDisclosure } from './use-disclosure/use-disclosure.js';
|
|
54
|
+
export { useFocusWithin } from './use-focus-within/use-focus-within.js';
|
|
55
|
+
export { useNetwork } from './use-network/use-network.js';
|
|
56
|
+
export { useTimeout } from './use-timeout/use-timeout.js';
|
|
57
|
+
export { useTextSelection } from './use-text-selection/use-text-selection.js';
|
|
58
|
+
export { usePrevious } from './use-previous/use-previous.js';
|
|
59
|
+
export { useFavicon } from './use-favicon/use-favicon.js';
|
|
60
|
+
export { useHeadroom } from './use-headroom/use-headroom.js';
|
|
61
|
+
export { useScrollDirection } from './use-scroll-direction/use-scroll-direction.js';
|
|
62
|
+
export { useEyeDropper } from './use-eye-dropper/use-eye-dropper.js';
|
|
63
|
+
export { useInViewport } from './use-in-viewport/use-in-viewport.js';
|
|
64
|
+
export {
|
|
65
|
+
useMutationObserver,
|
|
66
|
+
useMutationObserverTarget,
|
|
67
|
+
} from './use-mutation-observer/use-mutation-observer.js';
|
|
68
|
+
export { useMounted } from './use-mounted/use-mounted.js';
|
|
69
|
+
export { useStateHistory } from './use-state-history/use-state-history.js';
|
|
70
|
+
export { useMap } from './use-map/use-map.js';
|
|
71
|
+
export { useSet } from './use-set/use-set.js';
|
|
72
|
+
export { useThrottledCallback } from './use-throttled-callback/use-throttled-callback.js';
|
|
73
|
+
export { useThrottledState } from './use-throttled-state/use-throttled-state.js';
|
|
74
|
+
export { useThrottledValue } from './use-throttled-value/use-throttled-value.js';
|
|
75
|
+
export { useIsFirstRender } from './use-is-first-render/use-is-first-render.js';
|
|
76
|
+
export { useOrientation } from './use-orientation/use-orientation.js';
|
|
77
|
+
export { useFetch } from './use-fetch/use-fetch.js';
|
|
78
|
+
export { useRadialMove, normalizeRadialValue } from './use-radial-move/use-radial-move.js';
|
|
79
|
+
export { useScrollSpy } from './use-scroll-spy/use-scroll-spy.js';
|
|
80
|
+
export { useScroller } from './use-scroller/use-scroller.js';
|
|
81
|
+
export { useFileDialog } from './use-file-dialog/use-file-dialog.js';
|
|
82
|
+
export { useLongPress } from './use-long-press/use-long-press.js';
|
|
83
|
+
export { useSelection } from './use-selection/use-selection.js';
|
|
84
|
+
export { useFloatingWindow } from './use-floating-window/use-floating-window.js';
|
|
85
|
+
export { useCollapse } from './use-collapse/use-collapse.js';
|
|
86
|
+
export { useHorizontalCollapse } from './use-collapse/use-horizontal-collapse.js';
|
|
87
|
+
export {
|
|
88
|
+
useMask,
|
|
89
|
+
formatMask,
|
|
90
|
+
unformatMask,
|
|
91
|
+
isMaskComplete,
|
|
92
|
+
generatePattern,
|
|
93
|
+
} from './use-mask/use-mask.js';
|
|
94
|
+
export { useRovingIndex } from './use-roving-index/use-roving-index.js';
|
|
95
|
+
export { useDrag } from './use-drag/use-drag.js';
|
|
96
|
+
export { useSplitter } from './use-splitter/use-splitter.js';
|
|
97
|
+
|
|
98
|
+
export type { UseMediaQueryOptions } from './use-media-query/use-media-query';
|
|
99
|
+
export type {
|
|
100
|
+
UseClipboardInput as UseClipboardOptions,
|
|
101
|
+
UseClipboardReturnValue,
|
|
102
|
+
} from './use-clipboard/use-clipboard';
|
|
103
|
+
export type { UseColorSchemeValue } from './use-color-scheme/use-color-scheme';
|
|
104
|
+
export type {
|
|
105
|
+
UseCounterOptions,
|
|
106
|
+
UseCounterHandlers,
|
|
107
|
+
UseCounterReturnValue,
|
|
108
|
+
} from './use-counter/use-counter';
|
|
109
|
+
export type {
|
|
110
|
+
UseDebouncedCallbackOptions,
|
|
111
|
+
UseDebouncedCallbackReturnValue,
|
|
112
|
+
} from './use-debounced-callback/use-debounced-callback';
|
|
113
|
+
export type {
|
|
114
|
+
UseDebouncedStateOptions,
|
|
115
|
+
UseDebouncedStateReturnValue,
|
|
116
|
+
} from './use-debounced-state/use-debounced-state';
|
|
117
|
+
export type {
|
|
118
|
+
UseDebouncedValueHandlers,
|
|
119
|
+
UseDebouncedValueOptions,
|
|
120
|
+
UseDebouncedValueReturnValue,
|
|
121
|
+
} from './use-debounced-value/use-debounced-value';
|
|
122
|
+
export type {
|
|
123
|
+
UseDisclosureOptions,
|
|
124
|
+
UseDisclosureHandlers,
|
|
125
|
+
UseDisclosureReturnValue,
|
|
126
|
+
} from './use-disclosure/use-disclosure';
|
|
127
|
+
export type {
|
|
128
|
+
EyeDropperOpenOptions,
|
|
129
|
+
EyeDropperOpenReturnType,
|
|
130
|
+
UseEyeDropperReturnValue,
|
|
131
|
+
} from './use-eye-dropper/use-eye-dropper';
|
|
132
|
+
export type { UseFetchOptions, UseFetchReturnValue } from './use-fetch/use-fetch';
|
|
133
|
+
export type {
|
|
134
|
+
UseFileDialogOptions,
|
|
135
|
+
UseFileDialogReturnValue,
|
|
136
|
+
} from './use-file-dialog/use-file-dialog';
|
|
137
|
+
export type {
|
|
138
|
+
UseFocusReturnInput as UseFocusReturnOptions,
|
|
139
|
+
UseFocusReturnReturnValue,
|
|
140
|
+
} from './use-focus-return/use-focus-return';
|
|
141
|
+
export type {
|
|
142
|
+
UseFocusWithinOptions,
|
|
143
|
+
UseFocusWithinReturnValue,
|
|
144
|
+
} from './use-focus-within/use-focus-within';
|
|
145
|
+
export type { UseFullscreenElementReturnValue } from './use-fullscreen/use-fullscreen';
|
|
146
|
+
export type { UseHashInput as UseHashOptions, UseHashReturnValue } from './use-hash/use-hash';
|
|
147
|
+
export type { UseHeadroomInput as UseHeadroomOptions } from './use-headroom/use-headroom';
|
|
148
|
+
export type { ScrollDirection } from './use-scroll-direction/use-scroll-direction';
|
|
149
|
+
export type { HotkeyItemOptions, HotkeyItem } from './use-hotkeys/use-hotkeys';
|
|
150
|
+
export type { UseHoverReturnValue } from './use-hover/use-hover';
|
|
151
|
+
export type { UseIdleOptions } from './use-idle/use-idle';
|
|
152
|
+
export type { UseInViewportReturnValue } from './use-in-viewport/use-in-viewport';
|
|
153
|
+
export type { UseInputStateReturnValue } from './use-input-state/use-input-state';
|
|
154
|
+
export type { UseIntersectionReturnValue } from './use-intersection/use-intersection';
|
|
155
|
+
export type { UseIntervalOptions, UseIntervalReturnValue } from './use-interval/use-interval';
|
|
156
|
+
export type {
|
|
157
|
+
UseListStateReturnValue,
|
|
158
|
+
UseListStateHandlers,
|
|
159
|
+
} from './use-list-state/use-list-state';
|
|
160
|
+
export type { UseStorageOptions, UseStorageReturnValue } from './use-local-storage/create-storage';
|
|
161
|
+
export type { UseMovePosition, UseMoveHandlers, UseMoveReturnValue } from './use-move/use-move';
|
|
162
|
+
export type { UserNetworkReturnValue } from './use-network/use-network';
|
|
163
|
+
export type {
|
|
164
|
+
UseOrientationOptions,
|
|
165
|
+
UseOrientationReturnType,
|
|
166
|
+
} from './use-orientation/use-orientation';
|
|
167
|
+
export type { UseOSReturnValue, UseOsOptions } from './use-os/use-os';
|
|
168
|
+
export type {
|
|
169
|
+
UsePaginationOptions,
|
|
170
|
+
UsePaginationReturnValue,
|
|
171
|
+
} from './use-pagination/use-pagination';
|
|
172
|
+
export type { UseQueueOptions, UseQueueReturnValue } from './use-queue/use-queue';
|
|
173
|
+
export type {
|
|
174
|
+
UseRadialMoveOptions,
|
|
175
|
+
UseRadialMoveReturnValue,
|
|
176
|
+
} from './use-radial-move/use-radial-move';
|
|
177
|
+
export type {
|
|
178
|
+
UseScrollIntoViewOptions,
|
|
179
|
+
UseScrollIntoViewReturnValue,
|
|
180
|
+
} from './use-scroll-into-view/use-scroll-into-view';
|
|
181
|
+
export type {
|
|
182
|
+
UseScrollSpyOptions,
|
|
183
|
+
UseScrollSpyHeadingData,
|
|
184
|
+
UseScrollSpyReturnValue,
|
|
185
|
+
} from './use-scroll-spy/use-scroll-spy';
|
|
186
|
+
export type {
|
|
187
|
+
UseScrollerOptions,
|
|
188
|
+
UseScrollerReturnValue,
|
|
189
|
+
UseScrollerScrollState,
|
|
190
|
+
} from './use-scroller/use-scroller';
|
|
191
|
+
export type { UseSetStateCallback, UseSetStateReturnValue } from './use-set-state/use-set-state';
|
|
192
|
+
export type {
|
|
193
|
+
UseStateHistoryHandlers,
|
|
194
|
+
UseStateHistoryValue as StateHistory,
|
|
195
|
+
UseStateHistoryValue,
|
|
196
|
+
UseStateHistoryReturnValue,
|
|
197
|
+
} from './use-state-history/use-state-history';
|
|
198
|
+
export type { UseTimeoutOptions, UseTimeoutReturnValue } from './use-timeout/use-timeout';
|
|
199
|
+
export type { UseToggleReturnValue } from './use-toggle/use-toggle';
|
|
200
|
+
export type {
|
|
201
|
+
UseUncontrolledOptions,
|
|
202
|
+
UseUncontrolledReturnValue,
|
|
203
|
+
} from './use-uncontrolled/use-uncontrolled';
|
|
204
|
+
export type {
|
|
205
|
+
UseValidatedStateValue,
|
|
206
|
+
UseValidatedStateReturnValue,
|
|
207
|
+
} from './use-validated-state/use-validated-state';
|
|
208
|
+
export type {
|
|
209
|
+
UseWindowScrollPosition,
|
|
210
|
+
UseWindowScrollTo,
|
|
211
|
+
UseWindowScrollReturnValue,
|
|
212
|
+
} from './use-window-scroll/use-window-scroll';
|
|
213
|
+
export type {
|
|
214
|
+
UseLongPressEvent,
|
|
215
|
+
UseLongPressOptions,
|
|
216
|
+
UseLongPressReturnValue,
|
|
217
|
+
} from './use-long-press/use-long-press';
|
|
218
|
+
export type {
|
|
219
|
+
SetFloatingWindowPosition,
|
|
220
|
+
UseFloatingWindowOptions,
|
|
221
|
+
UseFloatingWindowReturnValue,
|
|
222
|
+
} from './use-floating-window/use-floating-window';
|
|
223
|
+
export type {
|
|
224
|
+
UseSelectionHandlers,
|
|
225
|
+
UseSelectionInput,
|
|
226
|
+
UseSelectionReturnValue,
|
|
227
|
+
} from './use-selection/use-selection';
|
|
228
|
+
export type {
|
|
229
|
+
UseElementSizeReturnValue,
|
|
230
|
+
UseResizeObserverReturnValue,
|
|
231
|
+
ObserverRect,
|
|
232
|
+
} from './use-resize-observer/use-resize-observer';
|
|
233
|
+
export type {
|
|
234
|
+
UseCollapseInput,
|
|
235
|
+
UseCollapseReturnValue,
|
|
236
|
+
UseCollapseState,
|
|
237
|
+
} from './use-collapse/use-collapse';
|
|
238
|
+
export type {
|
|
239
|
+
UseHorizontalCollapseInput,
|
|
240
|
+
UseHorizontalCollapseReturnValue,
|
|
241
|
+
UseHorizontalCollapseState,
|
|
242
|
+
} from './use-collapse/use-horizontal-collapse';
|
|
243
|
+
export type { UseMaskOptions, UseMaskReturnValue, MaskState } from './use-mask/use-mask';
|
|
244
|
+
export type {
|
|
245
|
+
UseRovingIndexInput,
|
|
246
|
+
UseRovingIndexGetItemPropsInput,
|
|
247
|
+
UseRovingIndexReturnValue,
|
|
248
|
+
} from './use-roving-index/use-roving-index';
|
|
249
|
+
export type { UseDragState, UseDragOptions, UseDragReturnValue } from './use-drag/use-drag';
|
|
250
|
+
export type {
|
|
251
|
+
UseSplitterPanel,
|
|
252
|
+
UseSplitterOptions,
|
|
253
|
+
UseSplitterReturnValue,
|
|
254
|
+
UseSplitterRedistributeInput,
|
|
255
|
+
UseSplitterRedistributeFn,
|
|
256
|
+
UseSplitterResolvedPanel,
|
|
257
|
+
SplitterPaneSize,
|
|
258
|
+
SplitterStep,
|
|
259
|
+
} from './use-splitter/use-splitter';
|
package/src/internal.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Compiled TSRX calls append their hook slot as a trailing Symbol. When a public
|
|
2
|
+
// hook omits an optional argument, that slot occupies the argument position and
|
|
3
|
+
// must be removed before applying the hook's runtime default.
|
|
4
|
+
export function withoutSlot<T>(value: T | symbol | undefined): T | undefined {
|
|
5
|
+
return typeof value === 'symbol' ? undefined : value;
|
|
6
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useEffect, useEffectEvent, useRef } from 'octane';
|
|
2
|
+
|
|
3
|
+
type EventType = MouseEvent | TouchEvent;
|
|
4
|
+
|
|
5
|
+
const DEFAULT_EVENTS = ['mousedown', 'touchstart'];
|
|
6
|
+
|
|
7
|
+
function withoutSlot<T>(value: T | symbol): T | undefined {
|
|
8
|
+
return typeof value === 'symbol' ? undefined : value;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function useClickOutside<T extends HTMLElement = any>(
|
|
12
|
+
callback: (event: EventType) => void,
|
|
13
|
+
events?: string[] | null,
|
|
14
|
+
nodes?: (HTMLElement | null)[],
|
|
15
|
+
enabled: boolean = true,
|
|
16
|
+
) {
|
|
17
|
+
const ref = useRef<T | null>(null);
|
|
18
|
+
const eventsList = withoutSlot(events) || DEFAULT_EVENTS;
|
|
19
|
+
const nodesList = withoutSlot(nodes);
|
|
20
|
+
const isEnabled = withoutSlot(enabled) ?? true;
|
|
21
|
+
|
|
22
|
+
const listener = useEffectEvent((event: Event) => {
|
|
23
|
+
const { target } = event ?? {};
|
|
24
|
+
const shouldIgnore =
|
|
25
|
+
!document.body.contains(target as Node) && (target as Element)?.tagName !== 'HTML';
|
|
26
|
+
|
|
27
|
+
if (shouldIgnore) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const path = event.composedPath();
|
|
32
|
+
|
|
33
|
+
if (Array.isArray(nodesList)) {
|
|
34
|
+
const shouldTrigger = nodesList.every((node) => !!node && !path.includes(node));
|
|
35
|
+
shouldTrigger && callback(event as EventType);
|
|
36
|
+
} else if (ref.current && !path.includes(ref.current)) {
|
|
37
|
+
callback(event as EventType);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const eventsKey = eventsList.join(',');
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (!isEnabled) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const events = eventsKey.split(',');
|
|
49
|
+
events.forEach((fn) => document.addEventListener(fn, listener));
|
|
50
|
+
|
|
51
|
+
return () => {
|
|
52
|
+
events.forEach((fn) => document.removeEventListener(fn, listener));
|
|
53
|
+
};
|
|
54
|
+
}, [eventsKey, isEnabled]);
|
|
55
|
+
|
|
56
|
+
return ref;
|
|
57
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'octane';
|
|
2
|
+
import { withoutSlot } from '../internal';
|
|
3
|
+
|
|
4
|
+
export interface UseClipboardInput {
|
|
5
|
+
/** Time in ms after which the copied state will reset, `2000` by default */
|
|
6
|
+
timeout?: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface UseClipboardReturnValue {
|
|
10
|
+
/** Function to copy value to clipboard */
|
|
11
|
+
copy: (value: any) => void;
|
|
12
|
+
|
|
13
|
+
/** Function to reset copied state and error */
|
|
14
|
+
reset: () => void;
|
|
15
|
+
|
|
16
|
+
/** Error if copying failed */
|
|
17
|
+
error: Error | null;
|
|
18
|
+
|
|
19
|
+
/** Boolean indicating if the value was copied successfully */
|
|
20
|
+
copied: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function useClipboard(options: UseClipboardInput = {}): UseClipboardReturnValue {
|
|
24
|
+
const normalizedOptions = withoutSlot(options) ?? {};
|
|
25
|
+
const timeout = normalizedOptions.timeout ?? 2000;
|
|
26
|
+
const [error, setError] = useState<Error | null>(null);
|
|
27
|
+
const [copied, setCopied] = useState(false);
|
|
28
|
+
const timeoutRef = useRef<number | null>(null);
|
|
29
|
+
|
|
30
|
+
useEffect(
|
|
31
|
+
() => () => {
|
|
32
|
+
window.clearTimeout(timeoutRef.current!);
|
|
33
|
+
},
|
|
34
|
+
[],
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const handleCopyResult = (value: boolean) => {
|
|
38
|
+
window.clearTimeout(timeoutRef.current!);
|
|
39
|
+
timeoutRef.current = window.setTimeout(() => setCopied(false), timeout);
|
|
40
|
+
setCopied(value);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const copy = (value: any) => {
|
|
44
|
+
if ('clipboard' in navigator) {
|
|
45
|
+
navigator.clipboard
|
|
46
|
+
.writeText(value)
|
|
47
|
+
.then(() => {
|
|
48
|
+
setError(null);
|
|
49
|
+
handleCopyResult(true);
|
|
50
|
+
})
|
|
51
|
+
.catch((err) => setError(err));
|
|
52
|
+
} else {
|
|
53
|
+
setError(new Error('useClipboard: navigator.clipboard is not supported'));
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const reset = () => {
|
|
58
|
+
setCopied(false);
|
|
59
|
+
setError(null);
|
|
60
|
+
window.clearTimeout(timeoutRef.current!);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return { copy, reset, error, copied };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export namespace useClipboard {
|
|
67
|
+
export type Input = UseClipboardInput;
|
|
68
|
+
export type ReturnValue = UseClipboardReturnValue;
|
|
69
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
import type { CSSProperties } from 'react';
|
|
3
|
+
import { flushSync, useEffectEvent, useRef, useState } from 'octane';
|
|
4
|
+
import type { Octane } from 'octane/jsx-runtime';
|
|
5
|
+
import { useDidUpdate } from '../use-did-update/use-did-update';
|
|
6
|
+
import { mergeRefs } from '../use-merged-ref/use-merged-ref';
|
|
7
|
+
|
|
8
|
+
function getAutoHeightDuration(height: number | string) {
|
|
9
|
+
if (!height || typeof height === 'string') {
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
12
|
+
const constant = height / 36;
|
|
13
|
+
return Math.round((4 + 15 * constant ** 0.25 + constant / 5) * 10);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getElementHeight(elementRef: React.RefObject<HTMLElement | null>) {
|
|
17
|
+
return elementRef.current ? elementRef.current.scrollHeight : 'auto';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface UseCollapseInput {
|
|
21
|
+
/** Expanded state */
|
|
22
|
+
expanded: boolean;
|
|
23
|
+
|
|
24
|
+
/** Transition duration in milliseconds, by default calculated based on content height */
|
|
25
|
+
transitionDuration?: number;
|
|
26
|
+
|
|
27
|
+
/** Transition timing function, `ease` by default */
|
|
28
|
+
transitionTimingFunction?: string;
|
|
29
|
+
|
|
30
|
+
/** Called when transition ends */
|
|
31
|
+
onTransitionEnd?: () => void;
|
|
32
|
+
|
|
33
|
+
/** Called when transition starts */
|
|
34
|
+
onTransitionStart?: () => void;
|
|
35
|
+
|
|
36
|
+
/** If true, collapsed content is kept in the DOM and hidden with `display: none` styles */
|
|
37
|
+
keepMounted?: boolean;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface GetCollapsePropsInput {
|
|
41
|
+
style?: CSSProperties;
|
|
42
|
+
ref?: Octane.Ref<HTMLDivElement>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface GetCollapsePropsReturnValue {
|
|
46
|
+
'aria-hidden': boolean;
|
|
47
|
+
inert: boolean;
|
|
48
|
+
ref: React.RefCallback<HTMLDivElement>;
|
|
49
|
+
onTransitionEnd: (event: TransitionEvent & { currentTarget: Element & EventTarget }) => void;
|
|
50
|
+
style: React.CSSProperties;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type UseCollapseState = 'entering' | 'entered' | 'exiting' | 'exited';
|
|
54
|
+
|
|
55
|
+
export interface UseCollapseReturnValue {
|
|
56
|
+
/** Current transition state */
|
|
57
|
+
state: UseCollapseState;
|
|
58
|
+
|
|
59
|
+
/** Props to pass down to the collapsible element */
|
|
60
|
+
getCollapseProps: (input?: GetCollapsePropsInput) => GetCollapsePropsReturnValue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function useCollapse({
|
|
64
|
+
transitionDuration,
|
|
65
|
+
transitionTimingFunction = 'ease',
|
|
66
|
+
onTransitionEnd,
|
|
67
|
+
onTransitionStart,
|
|
68
|
+
expanded,
|
|
69
|
+
keepMounted,
|
|
70
|
+
}: UseCollapseInput): UseCollapseReturnValue {
|
|
71
|
+
const collapsedStyles = {
|
|
72
|
+
height: 0,
|
|
73
|
+
overflow: 'hidden',
|
|
74
|
+
...(keepMounted ? {} : { display: 'none' }),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const onTransitionStartEvent = useEffectEvent(() => onTransitionStart?.());
|
|
78
|
+
|
|
79
|
+
const elementRef = useRef<HTMLElement | null>(null);
|
|
80
|
+
const [styles, setStylesRaw] = useState<CSSProperties>(expanded ? {} : collapsedStyles);
|
|
81
|
+
const [state, setState] = useState<UseCollapseState>(expanded ? 'entered' : 'exited');
|
|
82
|
+
const setStyles = (newStyles: React.SetStateAction<CSSProperties>) => {
|
|
83
|
+
flushSync(() => setStylesRaw(newStyles));
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const mergeStyles = (newStyles: CSSProperties) => {
|
|
87
|
+
setStyles((oldStyles) => ({ ...oldStyles, ...newStyles }));
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const getTransitionStyles = (height: number | string) => {
|
|
91
|
+
const duration = transitionDuration ?? getAutoHeightDuration(height);
|
|
92
|
+
return {
|
|
93
|
+
transition: `height ${duration}ms ${transitionTimingFunction}, opacity ${duration}ms ${transitionTimingFunction}`,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
useDidUpdate(() => {
|
|
98
|
+
const shouldTransition = transitionDuration !== 0;
|
|
99
|
+
|
|
100
|
+
if (shouldTransition) {
|
|
101
|
+
onTransitionStartEvent();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (expanded) {
|
|
105
|
+
window.requestAnimationFrame(() => {
|
|
106
|
+
flushSync(() => setState('entering'));
|
|
107
|
+
mergeStyles({ willChange: 'height', display: 'block', overflow: 'hidden' });
|
|
108
|
+
window.requestAnimationFrame(() => {
|
|
109
|
+
const height = getElementHeight(elementRef);
|
|
110
|
+
mergeStyles({ ...getTransitionStyles(height), height });
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
} else {
|
|
114
|
+
window.requestAnimationFrame(() => {
|
|
115
|
+
flushSync(() => setState('exiting'));
|
|
116
|
+
const height = getElementHeight(elementRef);
|
|
117
|
+
mergeStyles({ ...getTransitionStyles(height), willChange: 'height', height });
|
|
118
|
+
window.requestAnimationFrame(() => mergeStyles({ height: 0, overflow: 'hidden' }));
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}, [expanded]);
|
|
122
|
+
|
|
123
|
+
const handleTransitionEnd = (event: TransitionEvent): void => {
|
|
124
|
+
if (event.target !== elementRef.current || event.propertyName !== 'height') {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (expanded) {
|
|
129
|
+
const height = getElementHeight(elementRef);
|
|
130
|
+
|
|
131
|
+
if (height === styles.height) {
|
|
132
|
+
setStyles({});
|
|
133
|
+
} else {
|
|
134
|
+
mergeStyles({ height });
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
setState('entered');
|
|
138
|
+
onTransitionEnd?.();
|
|
139
|
+
} else if (styles.height === 0) {
|
|
140
|
+
setStyles(collapsedStyles);
|
|
141
|
+
setState('exited');
|
|
142
|
+
onTransitionEnd?.();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
state,
|
|
148
|
+
getCollapseProps: (input) => ({
|
|
149
|
+
'aria-hidden': !expanded,
|
|
150
|
+
inert: !expanded,
|
|
151
|
+
ref: mergeRefs(elementRef, input?.ref),
|
|
152
|
+
onTransitionEnd: handleTransitionEnd,
|
|
153
|
+
style: { boxSizing: 'border-box', ...input?.style, ...styles },
|
|
154
|
+
}),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export namespace useCollapse {
|
|
159
|
+
export type Input = UseCollapseInput;
|
|
160
|
+
export type ReturnValue = UseCollapseReturnValue;
|
|
161
|
+
export type State = UseCollapseState;
|
|
162
|
+
}
|