@necto-react/hooks 2.12.6 → 2.13.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 +1 -0
- package/dist/index.cjs +30 -1
- package/dist/index.d.cts +591 -159
- package/dist/index.d.ts +591 -159
- package/dist/index.global.js +31 -4
- package/dist/index.js +30 -1
- package/package.json +19 -18
- package/LICENSE +0 -21
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { ForwardedRef, Context,
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { ForwardedRef, Context, RefObject, FocusEvent, ReactNode, CSSProperties, AriaAttributes, useLayoutEffect, PointerEvent, MouseEvent as MouseEvent$1 } from 'react';
|
|
2
|
+
import { FocusableElement, PressEvent, KeyboardDelegate, Key } from '@necto/types';
|
|
3
|
+
export { KeyboardDelegate } from '@necto/types';
|
|
4
|
+
import { FocusEvents, DOMAttributes, FocusableDOMProps, HoverEvent, KeyboardEvents, RenderProps, SelectionManager, FocusStrategy } from '@necto-react/types';
|
|
5
|
+
export { FocusStrategy, SelectionManager, SelectionMode } from '@necto-react/types';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -11,9 +13,9 @@ import { FocusableElement, PressEvent } from '@necto/types';
|
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
|
-
*
|
|
16
|
+
* Options for the useContextProps hook.
|
|
15
17
|
*/
|
|
16
|
-
interface
|
|
18
|
+
interface UseContextPropsOptions<T, E extends Element> {
|
|
17
19
|
/**
|
|
18
20
|
* Component props, must include optional slot property and optional ref.
|
|
19
21
|
*/
|
|
@@ -61,87 +63,10 @@ type UseContextPropsReturn<T, E extends Element> = [
|
|
|
61
63
|
*
|
|
62
64
|
* @template T The props type.
|
|
63
65
|
* @template E The element type.
|
|
64
|
-
* @param {
|
|
66
|
+
* @param {UseContextPropsOptions<T, E>} options - Component props, ref, and context.
|
|
65
67
|
* @returns {UseContextPropsReturn<T, E>} A tuple of merged props and merged ref.
|
|
66
68
|
*/
|
|
67
|
-
declare function useContextProps<T, E extends Element>({ props, ref, context }:
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
71
|
-
*
|
|
72
|
-
* This source code is licensed under the MIT license found in the
|
|
73
|
-
* LICENSE file in the root directory of this source tree.
|
|
74
|
-
*
|
|
75
|
-
*/
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Props for the useDisabled hook.
|
|
79
|
-
*/
|
|
80
|
-
interface UseDisabledProps {
|
|
81
|
-
/** The key of the disabled flag to check. Defaults to 'general'. */
|
|
82
|
-
type?: keyof DisabledFlags;
|
|
83
|
-
/** The fallback value if the flag is not set. Defaults to false. */
|
|
84
|
-
defaultFallback?: boolean;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Return type for the useDisabled hook.
|
|
88
|
-
*/
|
|
89
|
-
type UseDisabledPropsReturn = boolean;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
93
|
-
*
|
|
94
|
-
* This source code is licensed under the MIT license found in the
|
|
95
|
-
* LICENSE file in the root directory of this source tree.
|
|
96
|
-
*
|
|
97
|
-
*/
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* React hook to determine if a specific feature or component type is disabled.
|
|
101
|
-
*
|
|
102
|
-
* @param {keyof DisabledFlags} type - The key of the disabled flag to check. Defaults to 'general'.
|
|
103
|
-
* @param {boolean} defaultFallback - The fallback value if the flag is not set. Defaults to false.
|
|
104
|
-
* @returns {boolean} True if the specified type is disabled, otherwise the fallback value.
|
|
105
|
-
*/
|
|
106
|
-
declare function useDisabled(props?: UseDisabledProps): UseDisabledPropsReturn;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
110
|
-
*
|
|
111
|
-
* This source code is licensed under the MIT license found in the
|
|
112
|
-
* LICENSE file in the root directory of this source tree.
|
|
113
|
-
*
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Props for the useDisabledProps hook.
|
|
118
|
-
*/
|
|
119
|
-
interface UseDisabledPropsProps {
|
|
120
|
-
/** The key of the disabled flag to check. Defaults to 'general'. */
|
|
121
|
-
type?: keyof DisabledFlags;
|
|
122
|
-
/** Additional props to merge with the disabled attributes. */
|
|
123
|
-
extraProps?: HTMLAttributes<HTMLElement>;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Return type for the useDisabledProps hook.
|
|
127
|
-
*/
|
|
128
|
-
type UseDisabledPropsPropsReturn = HTMLAttributes<HTMLElement>;
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
132
|
-
*
|
|
133
|
-
* This source code is licensed under the MIT license found in the
|
|
134
|
-
* LICENSE file in the root directory of this source tree.
|
|
135
|
-
*
|
|
136
|
-
*/
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Returns HTML props with appropriate disabled attributes based on the disabled state.
|
|
140
|
-
*
|
|
141
|
-
* @param {UseDisabledPropsOptions} options - Options for the hook.
|
|
142
|
-
* @returns {HTMLAttributes<HTMLElement>} The merged props including disabled and aria-disabled if applicable.
|
|
143
|
-
*/
|
|
144
|
-
declare function useDisabledProps(props?: UseDisabledPropsProps): UseDisabledPropsPropsReturn;
|
|
69
|
+
declare function useContextProps<T, E extends Element>({ props, ref, context }: UseContextPropsOptions<T, E>): UseContextPropsReturn<T, E>;
|
|
145
70
|
|
|
146
71
|
/**
|
|
147
72
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -155,9 +80,9 @@ declare function useDisabledProps(props?: UseDisabledPropsProps): UseDisabledPro
|
|
|
155
80
|
*/
|
|
156
81
|
type PartialVisibility = boolean | 'top' | 'right' | 'bottom' | 'left';
|
|
157
82
|
/**
|
|
158
|
-
*
|
|
83
|
+
* Options for the useElementVisibility hook.
|
|
159
84
|
*/
|
|
160
|
-
interface
|
|
85
|
+
interface UseElementVisibilityOptions {
|
|
161
86
|
/** Whether partial visibility is allowed, or which edge to check. */
|
|
162
87
|
partialVisibility?: PartialVisibility;
|
|
163
88
|
/** The threshold(s) at which to trigger the observer callback. */
|
|
@@ -209,10 +134,10 @@ type UseElementVisibilityReturn<T extends Element = Element> = [
|
|
|
209
134
|
* React hook that observes the visibility of a DOM element using the Intersection Observer API.
|
|
210
135
|
*
|
|
211
136
|
* @template T The type of the element being observed.
|
|
212
|
-
* @param {
|
|
137
|
+
* @param {UseElementVisibilityOptions} [options] - Options to control visibility observation and callbacks.
|
|
213
138
|
* @returns {UseElementVisibilityReturn<T>} A tuple containing the ref to the element, the visibility state, and intersection details.
|
|
214
139
|
*/
|
|
215
|
-
declare function useElementVisibility<T extends Element = Element>(
|
|
140
|
+
declare function useElementVisibility<T extends Element = Element>(options?: UseElementVisibilityOptions): UseElementVisibilityReturn<T>;
|
|
216
141
|
|
|
217
142
|
/**
|
|
218
143
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -223,9 +148,9 @@ declare function useElementVisibility<T extends Element = Element>(props?: UseEl
|
|
|
223
148
|
*/
|
|
224
149
|
|
|
225
150
|
/**
|
|
226
|
-
*
|
|
151
|
+
* Options for the useFocus hook.
|
|
227
152
|
*/
|
|
228
|
-
interface
|
|
153
|
+
interface UseFocusOptions<T = FocusableElement> extends FocusEvents<T> {
|
|
229
154
|
/** Whether focus events are disabled. */
|
|
230
155
|
isDisabled?: boolean;
|
|
231
156
|
}
|
|
@@ -256,10 +181,10 @@ interface UseFocusReturn<T = FocusableElement> {
|
|
|
256
181
|
* React hook that manages focus and blur event handling for a focusable element.
|
|
257
182
|
*
|
|
258
183
|
* @template T The type of the focusable element.
|
|
259
|
-
* @param {
|
|
184
|
+
* @param {UseFocusOptions<T>} [options] - Options and event handlers for focus management.
|
|
260
185
|
* @returns {UseFocusReturn<T>} An object containing props to spread on the target element for focus management.
|
|
261
186
|
*/
|
|
262
|
-
declare function useFocus<T extends FocusableElement = FocusableElement>(
|
|
187
|
+
declare function useFocus<T extends FocusableElement = FocusableElement>(options?: UseFocusOptions<T>): UseFocusReturn<T>;
|
|
263
188
|
|
|
264
189
|
/**
|
|
265
190
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -269,7 +194,10 @@ declare function useFocus<T extends FocusableElement = FocusableElement>(props?:
|
|
|
269
194
|
*
|
|
270
195
|
*/
|
|
271
196
|
|
|
272
|
-
|
|
197
|
+
/**
|
|
198
|
+
* Options for the useFocusable hook.
|
|
199
|
+
*/
|
|
200
|
+
interface UseFocusableOptions extends FocusableDOMProps, FocusEvents {
|
|
273
201
|
isDisabled?: boolean;
|
|
274
202
|
autoFocus?: boolean;
|
|
275
203
|
}
|
|
@@ -296,11 +224,11 @@ type UseFocusableReturn = Readonly<{
|
|
|
296
224
|
* React hook that provides focus management and keyboard accessibility for a focusable element.
|
|
297
225
|
* Handles autofocus, disabled state, tab order, and merges focus and keyboard props.
|
|
298
226
|
*
|
|
299
|
-
* @param {
|
|
227
|
+
* @param {UseFocusableOptions} options - Options controlling focus behavior and accessibility.
|
|
300
228
|
* @param {RefObject<FocusableElement | null>} domRef - Ref to the DOM element to manage focus for.
|
|
301
229
|
* @returns {UseFocusableReturn} Object containing merged props for focusable behavior.
|
|
302
230
|
*/
|
|
303
|
-
declare function useFocusable(
|
|
231
|
+
declare function useFocusable(options: UseFocusableOptions, domRef: RefObject<FocusableElement | null>): UseFocusableReturn;
|
|
304
232
|
|
|
305
233
|
/**
|
|
306
234
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -311,9 +239,9 @@ declare function useFocusable(props: UseFocusableProps, domRef: RefObject<Focusa
|
|
|
311
239
|
*/
|
|
312
240
|
|
|
313
241
|
/**
|
|
314
|
-
*
|
|
242
|
+
* Options for the useFocusRing hook.
|
|
315
243
|
*/
|
|
316
|
-
interface
|
|
244
|
+
interface UseFocusRingOptions {
|
|
317
245
|
/** Whether to track focus visibility within a subtree instead of just the element. */
|
|
318
246
|
within?: boolean;
|
|
319
247
|
/** Whether the target element is a text input. */
|
|
@@ -351,10 +279,10 @@ interface UseFocusRingReturn {
|
|
|
351
279
|
/**
|
|
352
280
|
* React hook that manages focus state and focus ring visibility for an element.
|
|
353
281
|
*
|
|
354
|
-
* @param {
|
|
282
|
+
* @param {UseFocusRingOptions} [options] - Options to control focus ring behavior.
|
|
355
283
|
* @returns {UseFocusRingReturn} An object containing focus state, focus visibility, and props to spread on the target element.
|
|
356
284
|
*/
|
|
357
|
-
declare function useFocusRing(
|
|
285
|
+
declare function useFocusRing(options?: UseFocusRingOptions): UseFocusRingReturn;
|
|
358
286
|
|
|
359
287
|
/**
|
|
360
288
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -364,9 +292,9 @@ declare function useFocusRing(props?: UseFocusRingProps): UseFocusRingReturn;
|
|
|
364
292
|
*
|
|
365
293
|
*/
|
|
366
294
|
/**
|
|
367
|
-
*
|
|
295
|
+
* Options for the useFocusVisible hook.
|
|
368
296
|
*/
|
|
369
|
-
interface
|
|
297
|
+
interface UseFocusVisibleOptions {
|
|
370
298
|
/** Whether the target element is a text input. */
|
|
371
299
|
isTextInput?: boolean;
|
|
372
300
|
/** Whether the element should automatically receive focus when mounted. */
|
|
@@ -398,10 +326,10 @@ interface UseFocusVisibleReturn {
|
|
|
398
326
|
/**
|
|
399
327
|
* React hook that provides focus visibility tracking.
|
|
400
328
|
*
|
|
401
|
-
* @param {
|
|
329
|
+
* @param {UseFocusVisibleOptions} [options] - Options for focus visibility behavior.
|
|
402
330
|
* @returns {UseFocusVisibleReturn} An object containing the focus visibility state.
|
|
403
331
|
*/
|
|
404
|
-
declare function useFocusVisible(
|
|
332
|
+
declare function useFocusVisible(options?: UseFocusVisibleOptions): UseFocusVisibleReturn;
|
|
405
333
|
|
|
406
334
|
/**
|
|
407
335
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -419,9 +347,9 @@ declare function useFocusVisible(props?: UseFocusVisibleProps): UseFocusVisibleR
|
|
|
419
347
|
*/
|
|
420
348
|
type Modality = 'keyboard' | 'pointer' | 'virtual';
|
|
421
349
|
/**
|
|
422
|
-
*
|
|
350
|
+
* Options for the useFocusVisibleListener hook.
|
|
423
351
|
*/
|
|
424
|
-
interface
|
|
352
|
+
interface UseFocusVisibleListenerOptions {
|
|
425
353
|
/** Function called when focus visibility changes. */
|
|
426
354
|
fn: (isFocusVisible: boolean) => void;
|
|
427
355
|
/** Dependency array that determines when to rebind the listener. */
|
|
@@ -450,10 +378,10 @@ declare function getInteractionModality(): Modality | null;
|
|
|
450
378
|
/**
|
|
451
379
|
* React hook that listens for focus visibility changes based on interaction modality.
|
|
452
380
|
*
|
|
453
|
-
* @param {
|
|
381
|
+
* @param {UseFocusVisibleListenerOptions} options - The options for the focus visible listener.
|
|
454
382
|
* @returns {void}
|
|
455
383
|
*/
|
|
456
|
-
declare function useFocusVisibleListener(
|
|
384
|
+
declare function useFocusVisibleListener(options: UseFocusVisibleListenerOptions): void;
|
|
457
385
|
|
|
458
386
|
/**
|
|
459
387
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -464,9 +392,9 @@ declare function useFocusVisibleListener(props: UseFocusVisibleListenerProps): v
|
|
|
464
392
|
*/
|
|
465
393
|
|
|
466
394
|
/**
|
|
467
|
-
*
|
|
395
|
+
* Options for the useFocusWithin hook.
|
|
468
396
|
*/
|
|
469
|
-
interface
|
|
397
|
+
interface UseFocusWithinOptions {
|
|
470
398
|
/** Whether the focus events should be disabled. */
|
|
471
399
|
isDisabled?: boolean;
|
|
472
400
|
/** Handler that is called when focus enters the element or its descendants. */
|
|
@@ -499,7 +427,7 @@ interface FocusWithinReturn {
|
|
|
499
427
|
* Modifications have been made to adapt the code for use in this project.
|
|
500
428
|
*/
|
|
501
429
|
|
|
502
|
-
declare function useFocusWithin(
|
|
430
|
+
declare function useFocusWithin(options: UseFocusWithinOptions): FocusWithinReturn;
|
|
503
431
|
|
|
504
432
|
/**
|
|
505
433
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -618,9 +546,9 @@ declare function useHover(props?: UseHoverProps): UseHoverReturn;
|
|
|
618
546
|
*
|
|
619
547
|
*/
|
|
620
548
|
/**
|
|
621
|
-
*
|
|
549
|
+
* Options for the useId hook.
|
|
622
550
|
*/
|
|
623
|
-
interface
|
|
551
|
+
interface UseIdOptions {
|
|
624
552
|
/** Optional custom prefix for the generated ID. */
|
|
625
553
|
prefix?: string;
|
|
626
554
|
/** Optional default ID to use instead of generating one. */
|
|
@@ -630,10 +558,10 @@ interface UseIdProps {
|
|
|
630
558
|
/**
|
|
631
559
|
* Generates a unique, stable ID for React components, optionally with a custom prefix.
|
|
632
560
|
*
|
|
633
|
-
* @param {
|
|
634
|
-
* @returns {
|
|
561
|
+
* @param {UseIdOptions} [options] - Optional options object. You can provide a custom prefix and/or a defaultId.
|
|
562
|
+
* @returns {string} The generated or provided unique ID.
|
|
635
563
|
*/
|
|
636
|
-
declare function useId(
|
|
564
|
+
declare function useId(options?: UseIdOptions): string;
|
|
637
565
|
|
|
638
566
|
/**
|
|
639
567
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -644,9 +572,9 @@ declare function useId(props?: UseIdProps): string;
|
|
|
644
572
|
*/
|
|
645
573
|
|
|
646
574
|
/**
|
|
647
|
-
*
|
|
575
|
+
* Options for the useKeyboard hook.
|
|
648
576
|
*/
|
|
649
|
-
interface
|
|
577
|
+
interface UseKeyboardOptions extends KeyboardEvents {
|
|
650
578
|
/**
|
|
651
579
|
* Whether the keyboard interaction is disabled.
|
|
652
580
|
* Defaults to false.
|
|
@@ -674,10 +602,10 @@ interface UseKeyboardReturn {
|
|
|
674
602
|
/**
|
|
675
603
|
* React hook that provides keyboard event handlers based on the disabled state.
|
|
676
604
|
*
|
|
677
|
-
* @param {
|
|
605
|
+
* @param {UseKeyboardOptions} options - Options controlling keyboard interaction.
|
|
678
606
|
* @returns {UseKeyboardReturn} Object containing keyboard event handler props.
|
|
679
607
|
*/
|
|
680
|
-
declare function useKeyboard(
|
|
608
|
+
declare function useKeyboard(options: UseKeyboardOptions): UseKeyboardReturn;
|
|
681
609
|
|
|
682
610
|
/**
|
|
683
611
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -692,9 +620,9 @@ declare function useKeyboard(props: UseKeyboardProps): UseKeyboardReturn;
|
|
|
692
620
|
*/
|
|
693
621
|
type MountedAccessType = 'function' | 'ref' | 'boolean';
|
|
694
622
|
/**
|
|
695
|
-
*
|
|
623
|
+
* Options for the useMounted hook.
|
|
696
624
|
*/
|
|
697
|
-
interface
|
|
625
|
+
interface UseMountedOptions {
|
|
698
626
|
/** The type of access to the mounted state. */
|
|
699
627
|
type?: MountedAccessType;
|
|
700
628
|
}
|
|
@@ -719,10 +647,10 @@ type UseMountedReturn<T extends MountedAccessType> = T extends 'ref' ? RefObject
|
|
|
719
647
|
* React hook that tracks whether a component is mounted.
|
|
720
648
|
*
|
|
721
649
|
* @template T The type of access to the mounted state (function, ref, or boolean).
|
|
722
|
-
* @param {
|
|
650
|
+
* @param {UseMountedOptions & { type: T }} [options] - Options to configure the hook behavior.
|
|
723
651
|
* @returns {UseMountedReturn<T>} The mounted state in the requested format.
|
|
724
652
|
*/
|
|
725
|
-
declare function useMounted<T extends MountedAccessType = 'function'>(
|
|
653
|
+
declare function useMounted<T extends MountedAccessType = 'function'>(options?: UseMountedOptions & {
|
|
726
654
|
type: T;
|
|
727
655
|
}): UseMountedReturn<T>;
|
|
728
656
|
|
|
@@ -797,9 +725,9 @@ declare function usePress(props?: UsePressProps): UsePressReturn;
|
|
|
797
725
|
*/
|
|
798
726
|
|
|
799
727
|
/**
|
|
800
|
-
*
|
|
728
|
+
* Options for the useRenderer hook.
|
|
801
729
|
*/
|
|
802
|
-
interface
|
|
730
|
+
interface UseRendererOptions<T> extends RenderProps<T> {
|
|
803
731
|
id?: string;
|
|
804
732
|
values: T;
|
|
805
733
|
defaultChildren?: ReactNode;
|
|
@@ -824,7 +752,13 @@ interface UseRendererReturn {
|
|
|
824
752
|
*
|
|
825
753
|
*/
|
|
826
754
|
|
|
827
|
-
|
|
755
|
+
/**
|
|
756
|
+
* React hook that handles rendering logic for components with render props.
|
|
757
|
+
*
|
|
758
|
+
* @param {UseRendererOptions} options - Options for the hook.
|
|
759
|
+
* @returns {UseRendererReturn} The resolved rendering properties.
|
|
760
|
+
*/
|
|
761
|
+
declare function useRenderer<T>(options: UseRendererOptions<T>): UseRendererReturn;
|
|
828
762
|
|
|
829
763
|
/**
|
|
830
764
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -888,22 +822,19 @@ declare function useSlottedContext<T>(props: UseSlottedContextProps<T>): UseSlot
|
|
|
888
822
|
*/
|
|
889
823
|
|
|
890
824
|
/**
|
|
891
|
-
*
|
|
892
|
-
*
|
|
893
|
-
* @template T The type of the element or value referenced.
|
|
825
|
+
* Options for the useSyntheticBlurEvent hook.
|
|
894
826
|
*/
|
|
895
|
-
interface
|
|
827
|
+
interface UseSyntheticBlurEventOptions<T extends Element = Element> {
|
|
896
828
|
/**
|
|
897
|
-
*
|
|
898
|
-
|
|
899
|
-
context?: {
|
|
900
|
-
ref?: RefObject<T | null>;
|
|
901
|
-
};
|
|
902
|
-
/**
|
|
903
|
-
* Optional local ref to synchronize with the context ref.
|
|
829
|
+
* Handler called when the blur event is triggered on the target element.
|
|
830
|
+
* Receives a React FocusEvent for the target element.
|
|
904
831
|
*/
|
|
905
|
-
|
|
832
|
+
onBlur: (event: FocusEvent<T>) => void;
|
|
906
833
|
}
|
|
834
|
+
/**
|
|
835
|
+
* Return type for the useSyntheticBlurEvent hook.
|
|
836
|
+
*/
|
|
837
|
+
type UseSyntheticBlurEventReturn<T> = (event: FocusEvent<T>) => void;
|
|
907
838
|
|
|
908
839
|
/**
|
|
909
840
|
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
@@ -920,7 +851,66 @@ interface UseSyncContextRefProps<T> {
|
|
|
920
851
|
* Modifications have been made to adapt the code for use in this project.
|
|
921
852
|
*/
|
|
922
853
|
|
|
923
|
-
|
|
854
|
+
/**
|
|
855
|
+
* React hook to handle synthetic blur events, particularly for disabled elements.
|
|
856
|
+
*
|
|
857
|
+
* @param {UseSyntheticBlurEventOptions} options - Options for the hook.
|
|
858
|
+
* @returns A callback to attach to the element's blur event.
|
|
859
|
+
*/
|
|
860
|
+
declare function useSyntheticBlurEvent<T extends Element = Element>(options: UseSyntheticBlurEventOptions<T>): UseSyntheticBlurEventReturn<T>;
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* Returns a stable event callback that always invokes the latest version of the provided function.
|
|
864
|
+
*
|
|
865
|
+
* @param {T} fn - The event handler function to stabilize.
|
|
866
|
+
* @returns {T} A memoized callback that always calls the latest version of `fn`.
|
|
867
|
+
*/
|
|
868
|
+
declare function useEffectEvent<T extends (...args: any[]) => any>(fn: T): T;
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
872
|
+
*
|
|
873
|
+
* This source code is licensed under the MIT license found in the
|
|
874
|
+
* LICENSE file in the root directory of this source tree.
|
|
875
|
+
*
|
|
876
|
+
*/
|
|
877
|
+
/**
|
|
878
|
+
* React hook that determines if a browser feature is supported.
|
|
879
|
+
*
|
|
880
|
+
* @param {() => unknown} fn - Function that tests for feature support.
|
|
881
|
+
* @returns {boolean} Whether the feature is supported in the current environment.
|
|
882
|
+
*/
|
|
883
|
+
declare function useSupported(fn: () => unknown): boolean;
|
|
884
|
+
|
|
885
|
+
/**
|
|
886
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
887
|
+
*
|
|
888
|
+
* This source code is licensed under the MIT license found in the
|
|
889
|
+
* LICENSE file in the root directory of this source tree.
|
|
890
|
+
*
|
|
891
|
+
*/
|
|
892
|
+
/**
|
|
893
|
+
* Options for the useScrollLock hook.
|
|
894
|
+
*/
|
|
895
|
+
interface UseScrollLockOptions {
|
|
896
|
+
/** Whether to automatically lock scroll on mount. */
|
|
897
|
+
autoLock?: boolean;
|
|
898
|
+
/** The target element to lock scrolling on. Can be an HTMLElement or a CSS selector string. Defaults to document.body. */
|
|
899
|
+
target?: HTMLElement | string;
|
|
900
|
+
/** Whether to add padding to prevent layout shift when scrollbar is hidden. */
|
|
901
|
+
widthReflow?: boolean;
|
|
902
|
+
}
|
|
903
|
+
/**
|
|
904
|
+
* Return type for the useScrollLock hook.
|
|
905
|
+
*/
|
|
906
|
+
interface UseScrollLockReturn {
|
|
907
|
+
/** Whether scroll is currently locked. */
|
|
908
|
+
isLocked: boolean;
|
|
909
|
+
/** Function to lock scrolling. */
|
|
910
|
+
lock: () => void;
|
|
911
|
+
/** Function to unlock scrolling. */
|
|
912
|
+
unlock: () => void;
|
|
913
|
+
}
|
|
924
914
|
|
|
925
915
|
/**
|
|
926
916
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -931,19 +921,182 @@ declare function useSyncContextRef<T>(props?: UseSyncContextRefProps<T>): void;
|
|
|
931
921
|
*/
|
|
932
922
|
|
|
933
923
|
/**
|
|
934
|
-
*
|
|
924
|
+
* React hook that locks scrolling on a target element or the entire page.
|
|
925
|
+
*
|
|
926
|
+
* @param {UseScrollLockOptions} [options] - Options to configure scroll lock behavior.
|
|
927
|
+
* @returns {UseScrollLockReturn} An object with isLocked state and lock/unlock functions.
|
|
928
|
+
*/
|
|
929
|
+
declare function useScrollLock(options?: UseScrollLockOptions): UseScrollLockReturn;
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
933
|
+
*
|
|
934
|
+
* This source code is licensed under the MIT license found in the
|
|
935
|
+
* LICENSE file in the root directory of this source tree.
|
|
936
|
+
*
|
|
937
|
+
*/
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* Options for the useAriaProps hook.
|
|
941
|
+
*/
|
|
942
|
+
interface UseAriaPropsOptions {
|
|
943
|
+
/** Whether the element is invalid. */
|
|
944
|
+
isInvalid?: boolean;
|
|
945
|
+
/** Whether the element is disabled. */
|
|
946
|
+
isDisabled?: boolean;
|
|
947
|
+
/** Whether the element is read-only. */
|
|
948
|
+
isReadOnly?: boolean;
|
|
949
|
+
/** Whether the element is required. */
|
|
950
|
+
isRequired?: boolean;
|
|
951
|
+
/** Whether the element is busy. */
|
|
952
|
+
isBusy?: boolean;
|
|
953
|
+
/** Whether the element is pressed. */
|
|
954
|
+
isPressed?: boolean | 'mixed';
|
|
955
|
+
/** Whether the element is expanded. */
|
|
956
|
+
isExpanded?: boolean;
|
|
957
|
+
/** Whether the element is selected. */
|
|
958
|
+
isSelected?: boolean;
|
|
959
|
+
/** Whether the element is checked. */
|
|
960
|
+
isChecked?: boolean | 'mixed';
|
|
961
|
+
/** Whether the element is hidden. */
|
|
962
|
+
isHidden?: boolean;
|
|
963
|
+
/** Whether the element has a popup. */
|
|
964
|
+
hasPopup?: boolean | 'menu' | 'listbox' | 'tree' | 'grid' | 'dialog';
|
|
965
|
+
/** The current value (for range widgets). */
|
|
966
|
+
valueCurrent?: number;
|
|
967
|
+
/** The minimum value (for range widgets). */
|
|
968
|
+
valueMin?: number;
|
|
969
|
+
/** The maximum value (for range widgets). */
|
|
970
|
+
valueMax?: number;
|
|
971
|
+
/** The current value as text (for range widgets). */
|
|
972
|
+
valueText?: string;
|
|
973
|
+
/** A label for the element. */
|
|
974
|
+
label?: string;
|
|
975
|
+
/** ID of the element that labels this element. */
|
|
976
|
+
labelledBy?: string;
|
|
977
|
+
/** ID of the element that describes this element. */
|
|
978
|
+
describedBy?: string;
|
|
979
|
+
/** ID of the element that this element controls. */
|
|
980
|
+
controls?: string;
|
|
981
|
+
/** ID of the element that owns this element. */
|
|
982
|
+
owns?: string;
|
|
983
|
+
}
|
|
984
|
+
/**
|
|
985
|
+
* Return type for the useAriaProps hook.
|
|
935
986
|
*/
|
|
936
|
-
|
|
987
|
+
type UseAriaPropsReturn = AriaAttributes;
|
|
988
|
+
|
|
989
|
+
/**
|
|
990
|
+
* Returns ARIA attributes based on the provided state flags.
|
|
991
|
+
* Automatically filters out undefined values to avoid adding empty ARIA attributes.
|
|
992
|
+
*
|
|
993
|
+
* @param {UseAriaPropsOptions} options - State flags to convert to ARIA attributes.
|
|
994
|
+
* @returns {UseAriaPropsReturn} The ARIA attributes object with only defined values.
|
|
995
|
+
*/
|
|
996
|
+
declare function useAriaProps(options?: UseAriaPropsOptions): UseAriaPropsReturn;
|
|
997
|
+
|
|
998
|
+
/**
|
|
999
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
1000
|
+
*
|
|
1001
|
+
* This source code is licensed under the MIT license found in the
|
|
1002
|
+
* LICENSE file in the root directory of this source tree.
|
|
1003
|
+
*
|
|
1004
|
+
*/
|
|
1005
|
+
/**
|
|
1006
|
+
* Options for the useStyleInjection hook.
|
|
1007
|
+
*/
|
|
1008
|
+
interface UseStyleInjectionOptions {
|
|
1009
|
+
id?: string;
|
|
1010
|
+
css: string | string[];
|
|
1011
|
+
window?: Window | null;
|
|
1012
|
+
insertionPoint?: HTMLElement | null;
|
|
1013
|
+
enabled?: boolean;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
/**
|
|
1017
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
1018
|
+
*
|
|
1019
|
+
* This source code is licensed under the MIT license found in the
|
|
1020
|
+
* LICENSE file in the root directory of this source tree.
|
|
1021
|
+
*
|
|
1022
|
+
*/
|
|
1023
|
+
|
|
1024
|
+
/**
|
|
1025
|
+
* React hook that injects CSS styles into the document.
|
|
1026
|
+
*
|
|
1027
|
+
* @param {UseStyleInjectionOptions} options - Options for the hook.
|
|
1028
|
+
*/
|
|
1029
|
+
declare function useStyleInjection({ id, css, insertionPoint, enabled, window: targetWindow }: UseStyleInjectionOptions): void;
|
|
1030
|
+
|
|
1031
|
+
declare function useLatestRef<T>(value: T): React.RefObject<T>;
|
|
1032
|
+
|
|
1033
|
+
/**
|
|
1034
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
1035
|
+
*
|
|
1036
|
+
* This source code is licensed under the MIT license found in the
|
|
1037
|
+
* LICENSE file in the root directory of this source tree.
|
|
1038
|
+
*
|
|
1039
|
+
*/
|
|
1040
|
+
|
|
1041
|
+
declare const useIsomorphicInsertionEffect: typeof useLayoutEffect;
|
|
1042
|
+
|
|
1043
|
+
/**
|
|
1044
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
1045
|
+
*
|
|
1046
|
+
* This source code is licensed under the MIT license found in the
|
|
1047
|
+
* LICENSE file in the root directory of this source tree.
|
|
1048
|
+
*
|
|
1049
|
+
*/
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* Event passed to long press callbacks.
|
|
1053
|
+
*/
|
|
1054
|
+
interface LongPressEvent {
|
|
1055
|
+
/** The type of event. */
|
|
1056
|
+
type: 'longpressstart' | 'longpressend' | 'longpress';
|
|
1057
|
+
/** The pointer type that triggered the event. */
|
|
1058
|
+
pointerType: PressEvent['pointerType'];
|
|
1059
|
+
/** The target element. */
|
|
1060
|
+
target: EventTarget;
|
|
1061
|
+
}
|
|
1062
|
+
/**
|
|
1063
|
+
* Options for the useLongPress hook.
|
|
1064
|
+
*/
|
|
1065
|
+
interface UseLongPressOptions {
|
|
1066
|
+
/** Whether long press events are disabled. */
|
|
1067
|
+
isDisabled?: boolean;
|
|
1068
|
+
/** Ref to the target element. */
|
|
1069
|
+
ref?: RefObject<HTMLElement | null>;
|
|
1070
|
+
/** Handler called when a long press interaction starts. */
|
|
1071
|
+
onLongPressStart?: (e: LongPressEvent) => void;
|
|
1072
|
+
/** Handler called when a long press interaction ends. */
|
|
1073
|
+
onLongPressEnd?: (e: LongPressEvent) => void;
|
|
1074
|
+
/** Handler called when the long press threshold is reached. */
|
|
1075
|
+
onLongPress?: (e: LongPressEvent) => void;
|
|
937
1076
|
/**
|
|
938
|
-
*
|
|
939
|
-
*
|
|
1077
|
+
* The duration in milliseconds before a press is considered a long press.
|
|
1078
|
+
* @default 500
|
|
940
1079
|
*/
|
|
941
|
-
|
|
1080
|
+
threshold?: number;
|
|
1081
|
+
/**
|
|
1082
|
+
* A description for assistive technology users indicating that a long press
|
|
1083
|
+
* action is available, e.g. "Long press to open menu".
|
|
1084
|
+
*/
|
|
1085
|
+
accessibilityDescription?: string;
|
|
942
1086
|
}
|
|
943
1087
|
/**
|
|
944
|
-
* Return
|
|
1088
|
+
* Return value from the useLongPress hook.
|
|
945
1089
|
*/
|
|
946
|
-
|
|
1090
|
+
interface UseLongPressReturn {
|
|
1091
|
+
/** Props to spread on the target element for long press behavior. */
|
|
1092
|
+
longPressProps: {
|
|
1093
|
+
onPointerDown?: (e: PointerEvent) => void;
|
|
1094
|
+
onPointerUp?: (e: PointerEvent) => void;
|
|
1095
|
+
onPointerCancel?: (e: PointerEvent) => void;
|
|
1096
|
+
onContextMenu?: (e: MouseEvent$1) => void;
|
|
1097
|
+
'aria-description'?: string;
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
947
1100
|
|
|
948
1101
|
/**
|
|
949
1102
|
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
@@ -961,20 +1114,72 @@ type UseSyntheticBlurEventReturn<T> = (event: FocusEvent<T>) => void;
|
|
|
961
1114
|
*/
|
|
962
1115
|
|
|
963
1116
|
/**
|
|
964
|
-
*
|
|
1117
|
+
* Handles long press interactions for touch and pointer devices.
|
|
1118
|
+
* A long press is triggered when the user holds down a pointer for a specified duration.
|
|
1119
|
+
*/
|
|
1120
|
+
declare function useLongPress(options?: UseLongPressOptions): UseLongPressReturn;
|
|
1121
|
+
|
|
1122
|
+
/**
|
|
1123
|
+
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
1124
|
+
* licensed under the Apache License, Version 2.0.
|
|
1125
|
+
* Copyright (c) Adobe. All rights reserved.
|
|
1126
|
+
* See: https://github.com/adobe/react-spectrum
|
|
965
1127
|
*
|
|
966
|
-
*
|
|
967
|
-
*
|
|
1128
|
+
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
1129
|
+
*
|
|
1130
|
+
* This file contains code licensed under:
|
|
1131
|
+
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
1132
|
+
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
1133
|
+
*
|
|
1134
|
+
* Modifications have been made to adapt the code for use in this project.
|
|
968
1135
|
*/
|
|
969
|
-
declare function useSyntheticBlurEvent<T extends Element = Element>(props: UseSyntheticBlurEventProps<T>): UseSyntheticBlurEventReturn<T>;
|
|
970
1136
|
|
|
971
1137
|
/**
|
|
972
|
-
*
|
|
1138
|
+
* Options for the useAnimation hook.
|
|
1139
|
+
*/
|
|
1140
|
+
interface UseAnimationOptions {
|
|
1141
|
+
/** A ref to the element being animated. */
|
|
1142
|
+
ref: RefObject<HTMLElement | null>;
|
|
1143
|
+
/** Whether the element is currently open/visible. Controls enter and exit animations. */
|
|
1144
|
+
isOpen: boolean;
|
|
1145
|
+
/** Whether the element is ready for the enter animation. @default true */
|
|
1146
|
+
isReady?: boolean;
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* Return type for the useAnimation hook.
|
|
1150
|
+
*/
|
|
1151
|
+
interface UseAnimationReturn {
|
|
1152
|
+
/** Whether the element is currently in the entering animation phase. */
|
|
1153
|
+
isEntering: boolean;
|
|
1154
|
+
/** Whether the element is currently in the exiting animation phase. */
|
|
1155
|
+
isExiting: boolean;
|
|
1156
|
+
/** Whether the element should be rendered (open or still exiting). */
|
|
1157
|
+
isRendered: boolean;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/**
|
|
1161
|
+
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
1162
|
+
* licensed under the Apache License, Version 2.0.
|
|
1163
|
+
* Copyright (c) Adobe. All rights reserved.
|
|
1164
|
+
* See: https://github.com/adobe/react-spectrum
|
|
973
1165
|
*
|
|
974
|
-
*
|
|
975
|
-
*
|
|
1166
|
+
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
1167
|
+
*
|
|
1168
|
+
* This file contains code licensed under:
|
|
1169
|
+
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
1170
|
+
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
1171
|
+
*
|
|
1172
|
+
* Modifications have been made to adapt the code for use in this project.
|
|
976
1173
|
*/
|
|
977
|
-
|
|
1174
|
+
|
|
1175
|
+
/**
|
|
1176
|
+
* Manages enter and exit CSS animations/transitions on a ref element.
|
|
1177
|
+
*
|
|
1178
|
+
* - When `isOpen` becomes `true`, the element enters an entering phase until all animations finish.
|
|
1179
|
+
* - When `isOpen` becomes `false`, the element enters an exiting phase and stays mounted until all animations complete.
|
|
1180
|
+
* - `isRendered` indicates whether the element should remain in the DOM (open or still exiting).
|
|
1181
|
+
*/
|
|
1182
|
+
declare function useAnimation(options: UseAnimationOptions): UseAnimationReturn;
|
|
978
1183
|
|
|
979
1184
|
/**
|
|
980
1185
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -983,12 +1188,239 @@ declare function useEffectEvent<T extends (...args: any[]) => any>(fn: T): T;
|
|
|
983
1188
|
* LICENSE file in the root directory of this source tree.
|
|
984
1189
|
*
|
|
985
1190
|
*/
|
|
1191
|
+
|
|
1192
|
+
/** Direction for text/layout. */
|
|
1193
|
+
type Direction = 'ltr' | 'rtl';
|
|
1194
|
+
/** Orientation of the collection. */
|
|
1195
|
+
type Orientation = 'horizontal' | 'vertical' | 'both';
|
|
1196
|
+
/** Behavior when Escape key is pressed. */
|
|
1197
|
+
type EscapeBehavior = 'clearSelection' | 'none';
|
|
1198
|
+
/** Behavior for link items in the collection. */
|
|
1199
|
+
type LinkBehavior = 'action' | 'selection' | 'override';
|
|
986
1200
|
/**
|
|
987
|
-
*
|
|
1201
|
+
* Options for useCollectionNavigation hook.
|
|
1202
|
+
*/
|
|
1203
|
+
interface UseCollectionNavigationOptions {
|
|
1204
|
+
/**
|
|
1205
|
+
* Manager for reading and updating selection state.
|
|
1206
|
+
*/
|
|
1207
|
+
selectionManager: SelectionManager;
|
|
1208
|
+
/**
|
|
1209
|
+
* Delegate for keyboard navigation behavior.
|
|
1210
|
+
*/
|
|
1211
|
+
keyboardDelegate: KeyboardDelegate;
|
|
1212
|
+
/**
|
|
1213
|
+
* Ref to the collection container element.
|
|
1214
|
+
*/
|
|
1215
|
+
ref: RefObject<HTMLElement | null>;
|
|
1216
|
+
/**
|
|
1217
|
+
* Whether to auto-focus on mount.
|
|
1218
|
+
* @default false
|
|
1219
|
+
*/
|
|
1220
|
+
autoFocus?: boolean | FocusStrategy;
|
|
1221
|
+
/**
|
|
1222
|
+
* Whether focus should wrap at ends.
|
|
1223
|
+
* @default false
|
|
1224
|
+
*/
|
|
1225
|
+
shouldFocusWrap?: boolean;
|
|
1226
|
+
/**
|
|
1227
|
+
* Whether empty selection is disallowed.
|
|
1228
|
+
* @default false
|
|
1229
|
+
*/
|
|
1230
|
+
disallowEmptySelection?: boolean;
|
|
1231
|
+
/**
|
|
1232
|
+
* Whether Ctrl+A select all is disallowed.
|
|
1233
|
+
* @default false
|
|
1234
|
+
*/
|
|
1235
|
+
disallowSelectAll?: boolean;
|
|
1236
|
+
/**
|
|
1237
|
+
* Behavior when Escape is pressed.
|
|
1238
|
+
* @default 'clearSelection'
|
|
1239
|
+
*/
|
|
1240
|
+
escapeBehavior?: EscapeBehavior;
|
|
1241
|
+
/**
|
|
1242
|
+
* Whether to select items on focus.
|
|
1243
|
+
* @default false
|
|
1244
|
+
*/
|
|
1245
|
+
selectOnFocus?: boolean;
|
|
1246
|
+
/**
|
|
1247
|
+
* Whether type-ahead is disabled.
|
|
1248
|
+
* @default false
|
|
1249
|
+
*/
|
|
1250
|
+
disallowTypeAhead?: boolean;
|
|
1251
|
+
/**
|
|
1252
|
+
* Whether to use virtual focus (aria-activedescendant).
|
|
1253
|
+
* @default false
|
|
1254
|
+
*/
|
|
1255
|
+
shouldUseVirtualFocus?: boolean;
|
|
1256
|
+
/**
|
|
1257
|
+
* Whether Tab key navigation is allowed.
|
|
1258
|
+
* @default false
|
|
1259
|
+
*/
|
|
1260
|
+
allowsTabNavigation?: boolean;
|
|
1261
|
+
/**
|
|
1262
|
+
* Whether the collection is virtualized.
|
|
1263
|
+
* @default false
|
|
1264
|
+
*/
|
|
1265
|
+
isVirtualized?: boolean;
|
|
1266
|
+
/**
|
|
1267
|
+
* Ref to the scrollable container (defaults to ref).
|
|
1268
|
+
*/
|
|
1269
|
+
scrollRef?: RefObject<HTMLElement | null>;
|
|
1270
|
+
/**
|
|
1271
|
+
* Text direction for RTL support.
|
|
1272
|
+
* @default 'ltr'
|
|
1273
|
+
*/
|
|
1274
|
+
direction?: Direction;
|
|
1275
|
+
/**
|
|
1276
|
+
* Orientation of the collection.
|
|
1277
|
+
* @default 'vertical'
|
|
1278
|
+
*/
|
|
1279
|
+
orientation?: Orientation;
|
|
1280
|
+
/**
|
|
1281
|
+
* Disabled keys in the collection.
|
|
1282
|
+
*/
|
|
1283
|
+
disabledKeys?: Set<Key>;
|
|
1284
|
+
/**
|
|
1285
|
+
* Called when navigation occurs.
|
|
1286
|
+
*/
|
|
1287
|
+
onNavigate?: (key: Key | null) => void;
|
|
1288
|
+
/**
|
|
1289
|
+
* Called when an item should be focused.
|
|
1290
|
+
*/
|
|
1291
|
+
onFocusItem?: (key: Key) => void;
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* Return value from useCollectionNavigation hook.
|
|
1295
|
+
*/
|
|
1296
|
+
interface UseCollectionNavigationReturn {
|
|
1297
|
+
/** Props to spread on the collection element. */
|
|
1298
|
+
collectionProps: DOMAttributes;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
/**
|
|
1302
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
1303
|
+
*
|
|
1304
|
+
* This source code is licensed under the MIT license found in the
|
|
1305
|
+
* LICENSE file in the root directory of this source tree.
|
|
988
1306
|
*
|
|
989
|
-
* @param {() => unknown} fn - Function that tests for feature support.
|
|
990
|
-
* @returns {boolean} Whether the feature is supported in the current environment.
|
|
991
1307
|
*/
|
|
992
|
-
declare function useSupported(fn: () => unknown): boolean;
|
|
993
1308
|
|
|
994
|
-
|
|
1309
|
+
/**
|
|
1310
|
+
* Handles keyboard navigation and selection for collections.
|
|
1311
|
+
* Supports lists, grids, tabs, menus, and other selectable collections.
|
|
1312
|
+
*/
|
|
1313
|
+
declare function useCollectionNavigation(options: UseCollectionNavigationOptions): UseCollectionNavigationReturn;
|
|
1314
|
+
|
|
1315
|
+
/**
|
|
1316
|
+
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
1317
|
+
* licensed under the Apache License, Version 2.0.
|
|
1318
|
+
* Copyright (c) Adobe. All rights reserved.
|
|
1319
|
+
* See: https://github.com/adobe/react-spectrum
|
|
1320
|
+
*
|
|
1321
|
+
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
1322
|
+
*
|
|
1323
|
+
* This file contains code licensed under:
|
|
1324
|
+
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
1325
|
+
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
1326
|
+
*
|
|
1327
|
+
* Modifications have been made to adapt the code for use in this project.
|
|
1328
|
+
*/
|
|
1329
|
+
/** A validation error message string, or an array of messages. */
|
|
1330
|
+
type ValidationError = string | string[];
|
|
1331
|
+
/** A map of field names to their validation errors, used for server-side error propagation. */
|
|
1332
|
+
type ValidationErrors = Record<string, ValidationError>;
|
|
1333
|
+
/** A function that validates a value and returns error messages, or `true`/`null` for valid. */
|
|
1334
|
+
type ValidationFunction<T> = (value: T) => ValidationError | true | null | undefined;
|
|
1335
|
+
/** The result of validating a form field value. */
|
|
1336
|
+
interface ValidationResult {
|
|
1337
|
+
/** Whether the value is invalid. */
|
|
1338
|
+
isInvalid: boolean;
|
|
1339
|
+
/** The validation error messages. */
|
|
1340
|
+
validationErrors: string[];
|
|
1341
|
+
/** The native validity state details. */
|
|
1342
|
+
validationDetails: ValidityState;
|
|
1343
|
+
}
|
|
1344
|
+
/** Component-facing validation props for form fields. */
|
|
1345
|
+
interface Validation<T> {
|
|
1346
|
+
/** Whether the value is invalid. */
|
|
1347
|
+
isInvalid?: boolean;
|
|
1348
|
+
/**
|
|
1349
|
+
* @deprecated Use `isInvalid` instead.
|
|
1350
|
+
* Whether the value is valid or invalid.
|
|
1351
|
+
*/
|
|
1352
|
+
validationState?: 'valid' | 'invalid';
|
|
1353
|
+
/**
|
|
1354
|
+
* Controls when validation errors are displayed.
|
|
1355
|
+
* - `'aria'`: errors are displayed in realtime as the user edits.
|
|
1356
|
+
* - `'native'`: errors are displayed on form submit or explicit commit.
|
|
1357
|
+
* @default 'aria'
|
|
1358
|
+
*/
|
|
1359
|
+
validationBehavior?: 'aria' | 'native';
|
|
1360
|
+
/** A custom validation function for the field value. */
|
|
1361
|
+
validate?: ValidationFunction<T>;
|
|
1362
|
+
}
|
|
1363
|
+
/** Options for the `useFormState` hook. */
|
|
1364
|
+
interface UseFormStateOptions<T> extends Validation<T> {
|
|
1365
|
+
/** The current value of the form field. */
|
|
1366
|
+
value: T | null;
|
|
1367
|
+
/** The name of the form field, used to look up server errors from context. */
|
|
1368
|
+
name?: string | string[];
|
|
1369
|
+
/** Built-in browser validation result, passed from the native element. */
|
|
1370
|
+
builtinValidation?: ValidationResult;
|
|
1371
|
+
}
|
|
1372
|
+
/** Return type for the `useFormState` hook. */
|
|
1373
|
+
interface UseFormStateReturn {
|
|
1374
|
+
/** Realtime validation results, updated as the user edits the value. */
|
|
1375
|
+
realtimeValidation: ValidationResult;
|
|
1376
|
+
/** Currently displayed validation results, updated when the user commits their changes. */
|
|
1377
|
+
displayValidation: ValidationResult;
|
|
1378
|
+
/** Updates the current validation result. Not displayed to the user until `commitValidation` is called. */
|
|
1379
|
+
updateValidation(result: ValidationResult): void;
|
|
1380
|
+
/** Resets the displayed validation state to valid when the user resets the form. */
|
|
1381
|
+
resetValidation(): void;
|
|
1382
|
+
/** Commits the realtime validation so it is displayed to the user. */
|
|
1383
|
+
commitValidation(): void;
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
/**
|
|
1387
|
+
* Portions of this file are based on code from the React Aria Spectrum library by Adobe,
|
|
1388
|
+
* licensed under the Apache License, Version 2.0.
|
|
1389
|
+
* Copyright (c) Adobe. All rights reserved.
|
|
1390
|
+
* See: https://github.com/adobe/react-spectrum
|
|
1391
|
+
*
|
|
1392
|
+
* Modifications copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
1393
|
+
*
|
|
1394
|
+
* This file contains code licensed under:
|
|
1395
|
+
* - The MIT License (see LICENSE in the root directory) for Corinvo modifications.
|
|
1396
|
+
* - The Apache License, Version 2.0 for portions from Adobe.
|
|
1397
|
+
*
|
|
1398
|
+
* Modifications have been made to adapt the code for use in this project.
|
|
1399
|
+
*/
|
|
1400
|
+
|
|
1401
|
+
/** An all-valid `ValidityState` where every constraint passes. */
|
|
1402
|
+
declare const VALID_VALIDITY_STATE: ValidityState;
|
|
1403
|
+
/** The default validation result representing a valid state. */
|
|
1404
|
+
declare const DEFAULT_VALIDATION_RESULT: ValidationResult;
|
|
1405
|
+
/** Context for propagating server-side validation errors to form fields. */
|
|
1406
|
+
declare const FormValidationContext: Context<ValidationErrors>;
|
|
1407
|
+
/**
|
|
1408
|
+
* Private prop key used by parent form components (e.g. a future `useForm`)
|
|
1409
|
+
* to pass pre-computed validation state to child fields, avoiding redundant computation.
|
|
1410
|
+
*/
|
|
1411
|
+
declare const privateValidationStateProp: string;
|
|
1412
|
+
/**
|
|
1413
|
+
* Manages form field validation state, combining custom validation,
|
|
1414
|
+
* built-in browser validation, server errors, and controlled invalid state.
|
|
1415
|
+
*
|
|
1416
|
+
* Returns realtime and display validation results along with methods
|
|
1417
|
+
* to update, reset, and commit validation.
|
|
1418
|
+
*/
|
|
1419
|
+
declare function useFormState<T>(props: UseFormStateOptions<T>): UseFormStateReturn;
|
|
1420
|
+
/**
|
|
1421
|
+
* Merges multiple validation results into one, combining error messages
|
|
1422
|
+
* and validity details. Useful for group components (e.g. checkbox groups).
|
|
1423
|
+
*/
|
|
1424
|
+
declare function mergeValidation(...results: ValidationResult[]): ValidationResult;
|
|
1425
|
+
|
|
1426
|
+
export { DEFAULT_VALIDATION_RESULT, type Direction, type EscapeBehavior, type FocusWithinReturn, FormValidationContext, type LinkBehavior, type LongPressEvent, type Orientation, type UseAnimationOptions, type UseAnimationReturn, type UseAriaPropsOptions, type UseAriaPropsReturn, type UseCollectionNavigationOptions, type UseCollectionNavigationReturn, type UseContextPropsOptions, type UseContextPropsReturn, type UseElementVisibilityOptions, type UseElementVisibilityReturn, type UseFocusOptions, type UseFocusReturn, type UseFocusRingOptions, type UseFocusRingReturn, type UseFocusVisibleListenerOptions, type UseFocusVisibleOptions, type UseFocusVisibleReturn, type UseFocusWithinOptions, type UseFocusableOptions, type UseFocusableReturn, type UseFormStateOptions, type UseFormStateReturn, type UseGlobalListenersReturn, type UseHoverProps, type UseHoverReturn, type UseIdOptions, type UseLongPressOptions, type UseLongPressReturn, type UseMountedOptions, type UseMountedReturn, type UsePressProps, type UsePressReturn, type UseRendererOptions, type UseRendererReturn, type UseScrollLockOptions, type UseScrollLockReturn, type UseSlottedContextProps, type UseSlottedContextReturn, type UseStyleInjectionOptions, type UseSyntheticBlurEventOptions, type UseSyntheticBlurEventReturn, VALID_VALIDITY_STATE, type Validation, type ValidationError, type ValidationErrors, type ValidationFunction, type ValidationResult, getInteractionModality, mergeValidation, privateValidationStateProp, useAnimation, useAriaProps, useCollectionNavigation, useContextProps, useEffectEvent, useElementVisibility, useFocus, useFocusRing, useFocusVisible, useFocusVisibleListener, useFocusWithin, useFocusable, useFormState, useGlobalListeners, useHover, useId, useIsomorphicInsertionEffect, useKeyboard, useLatestRef, useLongPress, useMounted, usePress, useRenderer, useScrollLock, useSlottedContext, useStyleInjection, useSupported, useSyntheticBlurEvent };
|