@ringcentral/spring-base 1.7.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.
Files changed (146) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +61 -0
  3. package/chunks/twMerge.js +409 -0
  4. package/config.js +78 -0
  5. package/contexts.js +71 -0
  6. package/hooks.js +2101 -0
  7. package/index.d.ts +1 -0
  8. package/index.js +16 -0
  9. package/package.json +30 -0
  10. package/src/config.d.ts +40 -0
  11. package/src/contexts/ResponsiveContext/ResponsiveContext.d.ts +7 -0
  12. package/src/contexts/ResponsiveContext/breakpointList.d.ts +3 -0
  13. package/src/contexts/ResponsiveContext/getMatchDetail.d.ts +2 -0
  14. package/src/contexts/ResponsiveContext/index.d.ts +4 -0
  15. package/src/contexts/ResponsiveContext/types.d.ts +24 -0
  16. package/src/contexts/WindowContext.d.ts +9 -0
  17. package/src/contexts/index.d.ts +2 -0
  18. package/src/hooks/index.d.ts +43 -0
  19. package/src/hooks/useA11yKeyEvent/index.d.ts +1 -0
  20. package/src/hooks/useA11yKeyEvent/useA11yKeyEvent.d.ts +23 -0
  21. package/src/hooks/useActive/index.d.ts +1 -0
  22. package/src/hooks/useActive/useActive.d.ts +23 -0
  23. package/src/hooks/useAnnouncer/index.d.ts +1 -0
  24. package/src/hooks/useAnnouncer/useAnnouncer.d.ts +12 -0
  25. package/src/hooks/useAriaHideOutside/index.d.ts +1 -0
  26. package/src/hooks/useAriaHideOutside/useAriaHideOutside.d.ts +12 -0
  27. package/src/hooks/useAudio/index.d.ts +1 -0
  28. package/src/hooks/useAudio/useAudio.d.ts +21 -0
  29. package/src/hooks/useBodyScrollLock/index.d.ts +1 -0
  30. package/src/hooks/useBodyScrollLock/useBodyScrollLock.d.ts +25 -0
  31. package/src/hooks/useChange/index.d.ts +1 -0
  32. package/src/hooks/useChange/useChange.d.ts +12 -0
  33. package/src/hooks/useClickAway/index.d.ts +1 -0
  34. package/src/hooks/useClickAway/useClickAway.d.ts +22 -0
  35. package/src/hooks/useControlled/index.d.ts +1 -0
  36. package/src/hooks/useControlled/useControlled.d.ts +1 -0
  37. package/src/hooks/useDebounce/index.d.ts +1 -0
  38. package/src/hooks/useDebounce/useDebounce.d.ts +8 -0
  39. package/src/hooks/useEventCallback/index.d.ts +1 -0
  40. package/src/hooks/useEventCallback/useEventCallback.d.ts +1 -0
  41. package/src/hooks/useEventListener/index.d.ts +1 -0
  42. package/src/hooks/useEventListener/useEventListener.d.ts +32 -0
  43. package/src/hooks/useEver/index.d.ts +1 -0
  44. package/src/hooks/useEver/useEver.d.ts +13 -0
  45. package/src/hooks/useFocusVisible/index.d.ts +1 -0
  46. package/src/hooks/useFocusVisible/useFocusVisible.d.ts +22 -0
  47. package/src/hooks/useFontLoaded/index.d.ts +1 -0
  48. package/src/hooks/useFontLoaded/useFontLoaded.d.ts +13 -0
  49. package/src/hooks/useForceUpdate/index.d.ts +1 -0
  50. package/src/hooks/useForceUpdate/useForceUpdate.d.ts +5 -0
  51. package/src/hooks/useForkRef/index.d.ts +1 -0
  52. package/src/hooks/useForkRef/useForkRef.d.ts +19 -0
  53. package/src/hooks/useGlobalListener/createGlobalListener.d.ts +55 -0
  54. package/src/hooks/useGlobalListener/index.d.ts +2 -0
  55. package/src/hooks/useGlobalListener/useGlobalListener.d.ts +14 -0
  56. package/src/hooks/useHiddenTabindex/index.d.ts +1 -0
  57. package/src/hooks/useHiddenTabindex/useHiddenTabindex.d.ts +9 -0
  58. package/src/hooks/useHover/index.d.ts +2 -0
  59. package/src/hooks/useHover/useHover.d.ts +17 -0
  60. package/src/hooks/useHover/useHoverDirty.d.ts +8 -0
  61. package/src/hooks/useId/index.d.ts +1 -0
  62. package/src/hooks/useId/useId.d.ts +15 -0
  63. package/src/hooks/useImgLoaded/index.d.ts +1 -0
  64. package/src/hooks/useImgLoaded/useImgLoaded.d.ts +24 -0
  65. package/src/hooks/useInterval/index.d.ts +1 -0
  66. package/src/hooks/useInterval/useInterval.d.ts +43 -0
  67. package/src/hooks/useIsFocusVisible/index.d.ts +2 -0
  68. package/src/hooks/useIsFocusVisible/useIsFocusVisible.d.ts +9 -0
  69. package/src/hooks/useKeyDownOnce/index.d.ts +1 -0
  70. package/src/hooks/useKeyDownOnce/useKeyDownOnce.d.ts +15 -0
  71. package/src/hooks/useKeyboardMoveFocus/index.d.ts +3 -0
  72. package/src/hooks/useKeyboardMoveFocus/moveIndexInTwoDimension.d.ts +18 -0
  73. package/src/hooks/useKeyboardMoveFocus/useKeyboardMoveFocus.d.ts +49 -0
  74. package/src/hooks/useKeyboardMoveFocus/useOnlyOneFocusable.d.ts +17 -0
  75. package/src/hooks/useLongPress/index.d.ts +1 -0
  76. package/src/hooks/useLongPress/useLongPress.d.ts +39 -0
  77. package/src/hooks/useMountState/index.d.ts +1 -0
  78. package/src/hooks/useMountState/useMountState.d.ts +16 -0
  79. package/src/hooks/useOnLayoutReRender/index.d.ts +1 -0
  80. package/src/hooks/useOnLayoutReRender/useOnLayoutReRender.d.ts +5 -0
  81. package/src/hooks/useOnReRender/index.d.ts +1 -0
  82. package/src/hooks/useOnReRender/useOnReRender.d.ts +5 -0
  83. package/src/hooks/useOverflow/index.d.ts +1 -0
  84. package/src/hooks/useOverflow/useOverflow.d.ts +11 -0
  85. package/src/hooks/usePrevious/index.d.ts +1 -0
  86. package/src/hooks/usePrevious/usePrevious.d.ts +7 -0
  87. package/src/hooks/useRefState/index.d.ts +1 -0
  88. package/src/hooks/useRefState/useRefState.d.ts +21 -0
  89. package/src/hooks/useResizeObserver/index.d.ts +1 -0
  90. package/src/hooks/useResizeObserver/useResizeObserver.d.ts +24 -0
  91. package/src/hooks/useResponsiveMatch/index.d.ts +1 -0
  92. package/src/hooks/useResponsiveMatch/useResponsiveMatch.d.ts +7 -0
  93. package/src/hooks/useResultRef/index.d.ts +1 -0
  94. package/src/hooks/useResultRef/useResultRef.d.ts +10 -0
  95. package/src/hooks/useRetry/index.d.ts +1 -0
  96. package/src/hooks/useRetry/useRetry.d.ts +35 -0
  97. package/src/hooks/useSleep/index.d.ts +1 -0
  98. package/src/hooks/useSleep/useSleep.d.ts +22 -0
  99. package/src/hooks/useTabOut/index.d.ts +1 -0
  100. package/src/hooks/useTabOut/useTabOut.d.ts +10 -0
  101. package/src/hooks/useTestRunnerDetection.d.ts +7 -0
  102. package/src/hooks/useThrottle/index.d.ts +1 -0
  103. package/src/hooks/useThrottle/useThrottle.d.ts +8 -0
  104. package/src/hooks/useTimeout/index.d.ts +1 -0
  105. package/src/hooks/useTimeout/useTimeout.d.ts +2 -0
  106. package/src/hooks/useTouchMouseEvent/index.d.ts +1 -0
  107. package/src/hooks/useTouchMouseEvent/useTouchMouseEvent.d.ts +56 -0
  108. package/src/index.d.ts +5 -0
  109. package/src/typings/BaseColor.d.ts +14 -0
  110. package/src/typings/BaseSize.d.ts +15 -0
  111. package/src/typings/ComponentTypes.d.ts +50 -0
  112. package/src/typings/ExtractValue.d.ts +2 -0
  113. package/src/typings/OverridableTypes.d.ts +45 -0
  114. package/src/typings/UnionOmit.d.ts +3 -0
  115. package/src/typings/UnitMap.d.ts +28 -0
  116. package/src/typings/index.d.ts +7 -0
  117. package/src/utils/a11yKeyboardCode.d.ts +8 -0
  118. package/src/utils/ariaHideOutside.d.ts +9 -0
  119. package/src/utils/capitalize.d.ts +1 -0
  120. package/src/utils/checkDefaultPrevented.d.ts +3 -0
  121. package/src/utils/checkElementName.d.ts +2 -0
  122. package/src/utils/checkKeyboardEvent.d.ts +2 -0
  123. package/src/utils/classes/globalStateClasses.d.ts +14 -0
  124. package/src/utils/classes/index.d.ts +2 -0
  125. package/src/utils/classes/useClasses.d.ts +41 -0
  126. package/src/utils/combineProps.d.ts +90 -0
  127. package/src/utils/devlog.d.ts +7 -0
  128. package/src/utils/getRefElement.d.ts +6 -0
  129. package/src/utils/getTitle.d.ts +1 -0
  130. package/src/utils/index.d.ts +25 -0
  131. package/src/utils/isRef.d.ts +2 -0
  132. package/src/utils/isSuiElement.d.ts +1 -0
  133. package/src/utils/isUrl.d.ts +1 -0
  134. package/src/utils/isWebKit154.d.ts +9 -0
  135. package/src/utils/omit.d.ts +2 -0
  136. package/src/utils/outerSize.d.ts +8 -0
  137. package/src/utils/ownerDocument.d.ts +1 -0
  138. package/src/utils/ownerWindow.d.ts +1 -0
  139. package/src/utils/pick.d.ts +2 -0
  140. package/src/utils/preloadImg.d.ts +2 -0
  141. package/src/utils/removeClassName.d.ts +35 -0
  142. package/src/utils/runKeyHandler.d.ts +12 -0
  143. package/src/utils/selectionHandler.d.ts +23 -0
  144. package/src/utils/twMerge.d.ts +4 -0
  145. package/typings.js +1 -0
  146. package/utils.js +333 -0
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './src';
package/index.js ADDED
@@ -0,0 +1,16 @@
1
+ export { configure, rcConfiguration } from './config.js';
2
+ export { RcResponsiveContext, WindowContext, breakpointList, getMatchDetail, useResponsiveContext, useWindowContext } from './contexts.js';
3
+ export { createGlobalListener, globalListenerEventMap, isElmEqualOrContain, isTouchEvent, moveIndexInTwoDimension, teardown, useA11yKeyEvent, useActive, useAnnouncer, useAriaHideOutside, useAudio, useBodyScrollLock, useChange, useClickAway, useDebounce, useDepsChange, useEventCallback, useEventListener, useEver, useFocusVisible, useFontLoaded, useForceUpdate, useForkRef, useGlobalListener, useHiddenTabindex, useHover, useHoverDirty, useId, useImgLoaded, useInterval, useIsFocusVisible, useKeyDownOnce, useKeyboardMoveFocus, useLongPress, useMountState, useOnLayoutReRender, useOnReRender, useOnlyOneFocusable, useOverflow, usePrevious, useRefState, useResizeObserver, useResponsiveMatch, useResultRef, useRetry, useSleep, useTabOut, useTestRunnerDetection, useThrottle, useTimeout, useTouchMouseEvent, visuallyHiddenStyles } from './hooks.js';
4
+ export { unstable_ownerDocument as ownerDocument, unstable_useControlled as useControlled } from '@mui/utils';
5
+ export { a11yKeyboard, capitalize, checkDefaultPrevented, checkElementName, clearWindowSelection, getSelectionPosition, getTitle, globalStateClasses, isDeleteKeyboardEvent, isSuiElement, isUrl, isWebKit154, omit, outerSize, pick, preloadImg, removeClassName, runKeyHandler, setSelectionPosition, useClasses } from './utils.js';
6
+ export { a as ariaHideOutside, b as combineClasses, c as combineProps, g as getRefElement, i as isRef, l as logInDev, o as ownerWindow, t as twMerge } from './chunks/twMerge.js';
7
+ import 'react';
8
+ import 'lodash/uniqueId';
9
+ import 'lodash/isPlainObject';
10
+ import 'lodash/omit';
11
+ import 'lodash/pick';
12
+ import 'lodash/debounce';
13
+ import 'lodash/noop';
14
+ import 'lodash/throttle';
15
+ import 'body-scroll-lock';
16
+ import 'tailwind-merge';
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@ringcentral/spring-base",
3
+ "version": "1.7.0",
4
+ "author": "RingCentral",
5
+ "description": "Core utilities, hooks, and foundational functionality for Spring UI components, providing essential building blocks for React applications",
6
+ "main": "./index.js",
7
+ "module": "./index.js",
8
+ "types": "./index.d.ts",
9
+ "dependencies": {
10
+ "@mui/utils": "^6.0.2",
11
+ "@types/lodash": "^4.14.182",
12
+ "body-scroll-lock": "4.0.0-beta.0",
13
+ "clsx": "^1.2.1",
14
+ "framer-motion": "^6.5.1",
15
+ "lodash": "^4.17.21",
16
+ "tailwind-merge": "^2.5.4",
17
+ "type-fest": "^2.12.2"
18
+ },
19
+ "peerDependencies": {
20
+ "@types/react": ">=17.0.3",
21
+ "react": ">=17.0.2",
22
+ "react-dom": ">=17.0.2"
23
+ },
24
+ "sideEffects": false,
25
+ "license": "MIT",
26
+ "private": false,
27
+ "publishConfig": {
28
+ "access": "public"
29
+ }
30
+ }
@@ -0,0 +1,40 @@
1
+ declare type WarningFunctionType = ((
2
+ /** warning message */
3
+ message: string,
4
+ /** addition options with that warning */
5
+ options?: {
6
+ level: 'warn' | 'error';
7
+ }) => void) | undefined;
8
+ interface RcConfigurationType {
9
+ /** is ignore all warning show from spring */
10
+ WARNING_IGNORE: boolean;
11
+ WARNING_FUNCTION: WarningFunctionType;
12
+ }
13
+ /**
14
+ * config global setting
15
+ *
16
+ * ```ts
17
+ * configure({
18
+ * warning: false
19
+ * })
20
+ * ```
21
+ * ## WARNING related method and only work in `development mode`
22
+ *
23
+ * `WARNING_IGNORE`: only work in `development mode`
24
+ * `WARNING_FUNCTION` only work in `development mode`
25
+ */
26
+ declare let rcConfiguration: RcConfigurationType;
27
+ declare type RcConfigure = {
28
+ /** is show warning message in development */
29
+ warning?: boolean;
30
+ /** custom warning callback */
31
+ warningFunction?: WarningFunctionType;
32
+ };
33
+ /**
34
+ * set config with Spring
35
+ *
36
+ * ## WARNING method only work in `development mode`
37
+ */
38
+ export declare const configure: (options: RcConfigure) => void;
39
+ export { rcConfiguration };
40
+ export type { WarningFunctionType };
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { MatchedBreakpoint } from './types';
3
+ declare type RcResponsiveContextValue = MatchedBreakpoint | undefined;
4
+ declare const RcResponsiveContext: import("react").Context<RcResponsiveContextValue>;
5
+ declare const useResponsiveContext: () => RcResponsiveContextValue;
6
+ export { RcResponsiveContext, useResponsiveContext };
7
+ export type { RcResponsiveContextValue };
@@ -0,0 +1,3 @@
1
+ import { Breakpoint } from './types';
2
+ /** small to large */
3
+ export declare const breakpointList: Breakpoint[];
@@ -0,0 +1,2 @@
1
+ import { BreakpointMatchDetail, MatchedBreakpoint } from './types';
2
+ export declare const getMatchDetail: (breakpoint: MatchedBreakpoint) => BreakpointMatchDetail;
@@ -0,0 +1,4 @@
1
+ export * from './breakpointList';
2
+ export * from './getMatchDetail';
3
+ export * from './ResponsiveContext';
4
+ export * from './types';
@@ -0,0 +1,24 @@
1
+ export declare type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
2
+ /**
3
+ * null is no match, it means small than XS
4
+ */
5
+ export declare type MatchedBreakpoint = Breakpoint | null;
6
+ export declare type GTBreakpoint = 'gt-xs' | 'gt-sm' | 'gt-md' | 'gt-lg' | 'gt-xl';
7
+ export declare type LTBreakpoint = 'lt-sm' | 'lt-md' | 'lt-lg' | 'lt-xl';
8
+ export declare type FullBreakpoint = GTBreakpoint | LTBreakpoint | Breakpoint;
9
+ export declare type BreakpointMatchMap = Partial<Record<'gtXS' | 'gtSM' | 'gtMD' | 'gtLG' | 'gtXL' | 'ltSM' | 'ltMD' | 'ltLG' | 'ltXL' | FullBreakpoint, true>>;
10
+ export declare type BreakpointMatchDetail = {
11
+ matchBP: MatchedBreakpoint;
12
+ /**
13
+ * large to small
14
+ * example: [gtSM, gtXS]
15
+ */
16
+ gtMatchGroup: GTBreakpoint[];
17
+ /**
18
+ * small to large
19
+ * example: [ltSM, ltLG]
20
+ */
21
+ ltMatchGroup: LTBreakpoint[];
22
+ matchMap: BreakpointMatchMap;
23
+ };
24
+ export declare type BreakpointMatchGroups = Pick<BreakpointMatchDetail, 'gtMatchGroup' | 'ltMatchGroup'>;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ declare type WindowContextValue = {
3
+ globalThis: typeof globalThis;
4
+ externalWindow?: Window & typeof globalThis;
5
+ document?: Document;
6
+ };
7
+ declare const WindowContext: import("react").Context<WindowContextValue>;
8
+ declare const useWindowContext: () => WindowContextValue;
9
+ export { WindowContext, useWindowContext };
@@ -0,0 +1,2 @@
1
+ export * from './WindowContext';
2
+ export * from './ResponsiveContext';
@@ -0,0 +1,43 @@
1
+ export * from './useA11yKeyEvent';
2
+ export * from './useActive';
3
+ export * from './useAnnouncer';
4
+ export * from './useAriaHideOutside';
5
+ export * from './useAudio';
6
+ export * from './useChange';
7
+ export * from './useClickAway';
8
+ export * from './useControlled';
9
+ export * from './useDebounce';
10
+ export * from './useEventCallback';
11
+ export * from './useEventListener';
12
+ export * from './useEver';
13
+ export * from './useFocusVisible';
14
+ export * from './useForceUpdate';
15
+ export * from './useForkRef';
16
+ export * from './useGlobalListener';
17
+ export * from './useHiddenTabindex';
18
+ export * from './useHover';
19
+ export * from './useId';
20
+ export * from './useImgLoaded';
21
+ export * from './useInterval';
22
+ export * from './useIsFocusVisible';
23
+ export * from './useKeyDownOnce';
24
+ export * from './useKeyboardMoveFocus';
25
+ export * from './useLongPress';
26
+ export * from './useMountState';
27
+ export * from './useOnLayoutReRender';
28
+ export * from './useOnReRender';
29
+ export * from './useOverflow';
30
+ export * from './usePrevious';
31
+ export * from './useRefState';
32
+ export * from './useResizeObserver';
33
+ export * from './useResponsiveMatch';
34
+ export * from './useResultRef';
35
+ export * from './useRetry';
36
+ export * from './useSleep';
37
+ export * from './useTabOut';
38
+ export * from './useThrottle';
39
+ export * from './useTestRunnerDetection';
40
+ export * from './useTimeout';
41
+ export * from './useTouchMouseEvent';
42
+ export * from './useFontLoaded';
43
+ export * from './useBodyScrollLock';
@@ -0,0 +1 @@
1
+ export * from './useA11yKeyEvent';
@@ -0,0 +1,23 @@
1
+ export declare type useA11yKeyEventOptions = {
2
+ /**
3
+ * that event should only trigger from target element, ignore all `propagation` events
4
+ */
5
+ onlyOnFocus?: boolean;
6
+ /**
7
+ * is that need preventDefault when trigger `callBack`,
8
+ * @default true
9
+ */
10
+ preventDefault?: boolean;
11
+ /**
12
+ * check point for `event.key`
13
+ *
14
+ * @default ['Enter', ' ']
15
+ */
16
+ checkKeys?: string[];
17
+ };
18
+ /**
19
+ * bind event with a11y keyboard, `space`, `enter`, only trigger when key includes in `checkKeys`
20
+ *
21
+ * that will auto preventDefault by default, if you don't want that, set `false` with `preventDefault`
22
+ */
23
+ export declare const useA11yKeyEvent: (fn?: ((e: any) => void) | undefined, { onlyOnFocus, preventDefault, checkKeys, }?: useA11yKeyEventOptions) => (event: React.KeyboardEvent<HTMLElement>) => void;
@@ -0,0 +1 @@
1
+ export * from './useActive';
@@ -0,0 +1,23 @@
1
+ import { EventHandler, KeyboardEventHandler, SyntheticEvent } from 'react';
2
+ export declare type UseActiveOptions = {
3
+ onKeyDown?: KeyboardEventHandler;
4
+ onKeyUp?: KeyboardEventHandler;
5
+ /**
6
+ * will receive keyboard event
7
+ */
8
+ onClick?: EventHandler<SyntheticEvent>;
9
+ disabled?: boolean;
10
+ };
11
+ /**
12
+ * bind event with a11y keyboard, `space`. help not native button to implement `:active`
13
+ *
14
+ * that will auto preventDefault by default, if you don't want that, set `false` with `preventDefault`
15
+ */
16
+ export declare const useActive: ({ onKeyDown, onKeyUp, onClick, disabled, }?: UseActiveOptions) => {
17
+ activeHandlers: {
18
+ onKeyDown: KeyboardEventHandler<Element> | undefined;
19
+ onKeyUp: KeyboardEventHandler<Element> | undefined;
20
+ onClick: ((event: SyntheticEvent<Element, Event>) => void) | undefined;
21
+ };
22
+ active: boolean;
23
+ };
@@ -0,0 +1 @@
1
+ export * from './useAnnouncer';
@@ -0,0 +1,12 @@
1
+ export declare const visuallyHiddenStyles = "\n clip-path: inset(100%);\n clip: rect(1px, 1px, 1px, 1px);\n height: 1px;\n overflow: hidden;\n position: absolute;\n white-space: nowrap;\n width: 1px;\n";
2
+ /**
3
+ * read announce when need read message.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * const announce = useAnnouncer('simpleId');
8
+ *
9
+ * announce(`You click "Announce" button`);
10
+ * ```
11
+ */
12
+ export declare const useAnnouncer: (id?: string | undefined) => (message?: string | undefined) => void;
@@ -0,0 +1 @@
1
+ export * from './useAriaHideOutside';
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ export declare type UseAriaHideOutsideProps = {
3
+ enable?: boolean;
4
+ };
5
+ export declare const useAriaHideOutside: (props?: UseAriaHideOutsideProps) => {
6
+ ariaHideOutsideRef: import("react").RefObject<HTMLElement>;
7
+ /**
8
+ * Whether the `aria-hidden` attribute is being applied to outside elements.
9
+ * When true, elements outside the ref are hidden from screen readers.
10
+ */
11
+ ariaHideEnabled: boolean;
12
+ };
@@ -0,0 +1 @@
1
+ export * from './useAudio';
@@ -0,0 +1,21 @@
1
+ /**
2
+ * get Browser `Audio` instance, and auto destroy when component be destroyed.
3
+ *
4
+ *
5
+ * @param init a callback when you init that audio
6
+ *
7
+ * @example
8
+ *
9
+ * ```ts
10
+ * const audio = useAudio((instance) => {
11
+ * instance.src = 'https://your.audio'
12
+ * });
13
+ *
14
+ * const click = () => audio.play();
15
+ *
16
+ * click();
17
+ * ```
18
+ * @see stories {@link https://develop-rcui-int.fiji.gliprc.com/?path=/story/%F0%9F%94%A7-foundation-hooks-useaudio--simple-announcer 🔧-foundation-hooks-useaudio--simple-announcer}
19
+ * @see {@link https://chromium-review.googlesource.com/c/chromium/src/+/2816118}
20
+ */
21
+ export declare const useAudio: (init?: ((audio: HTMLAudioElement) => void) | undefined) => HTMLAudioElement;
@@ -0,0 +1 @@
1
+ export * from './useBodyScrollLock';
@@ -0,0 +1,25 @@
1
+ export interface UseBodyScrollLockOptions {
2
+ /**
3
+ * If true, disables the scroll lock
4
+ * @default false
5
+ */
6
+ disabled?: boolean;
7
+ /**
8
+ * Reserve scrollbar gap to prevent layout shift
9
+ * @default true
10
+ */
11
+ reserveScrollBarGap?: boolean;
12
+ /**
13
+ * Allow touch move on specific elements
14
+ */
15
+ allowTouchMove?: (el: Element) => boolean;
16
+ }
17
+ /**
18
+ * Hook to lock body scroll while allowing scroll on target element
19
+ * Uses body-scroll-lock library for cross-platform compatibility
20
+ *
21
+ * @param isLocked - Whether scroll should be locked
22
+ * @param targetElement - Element that should remain scrollable (optional)
23
+ * @param options - Configuration options
24
+ */
25
+ export declare const useBodyScrollLock: (isLocked: boolean, targetElement?: HTMLElement | null | undefined, options?: UseBodyScrollLockOptions) => void;
@@ -0,0 +1 @@
1
+ export * from './useChange';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * get value when prev listen value change
3
+ * @param cb that method you want calculate to get value
4
+ * @param listenCb prev compare listener value
5
+ */
6
+ export declare const useChange: <T, K>(cb: (prevValue: K | undefined, nextValue: K) => T, listenCb: () => K) => T;
7
+ /**
8
+ * get value when prev deps one of array value change
9
+ * @param cb that method you want calculate to get value
10
+ * @param deps prev compare value array
11
+ */
12
+ export declare const useDepsChange: <T, K extends any[]>(cb: (prevValue: K | undefined, nextValue: K) => T, deps: K) => T;
@@ -0,0 +1 @@
1
+ export * from './useClickAway';
@@ -0,0 +1,22 @@
1
+ import { SyntheticEvent } from 'react';
2
+ export declare type useClickAwayProps = {
3
+ /**
4
+ * If `true`, the React tree is ignored and only the DOM tree is considered.
5
+ * This prop changes how portaled elements are handled.
6
+ * @default false
7
+ */
8
+ disableReactTree?: boolean;
9
+ isEnabled?: boolean;
10
+ };
11
+ /**
12
+ * @deprecated Use `ClickAwayListener` from `@mui/base` instead.
13
+ *
14
+ * @param onClickAway Callback fired when a "click away" event is detected.
15
+ */
16
+ export declare const useClickAway: (onClickAway: (event: MouseEvent | TouchEvent) => void, props?: useClickAwayProps) => {
17
+ clickAwayRef: (instance: Element | null) => void;
18
+ clickAwayHandler: {
19
+ onClick: (e: SyntheticEvent) => void;
20
+ onTouchEnd: (e: SyntheticEvent) => void;
21
+ };
22
+ };
@@ -0,0 +1 @@
1
+ export * from './useControlled';
@@ -0,0 +1 @@
1
+ export { unstable_useControlled as useControlled } from '@mui/utils';
@@ -0,0 +1 @@
1
+ export * from './useDebounce';
@@ -0,0 +1,8 @@
1
+ import type { DebounceSettings } from 'lodash';
2
+ /**
3
+ * provide a debounce method for debounce method
4
+ * @param fn method for debounce
5
+ * @param debounceTime debounce timeout value, default is `200`ms
6
+ * @param options debounce setting, default is `{trailing: true, leading: flase}`, detail see lodash
7
+ */
8
+ export declare const useDebounce: <F extends (...args: any[]) => any>(fn: F, debounceTime?: number, options?: DebounceSettings | undefined) => import("lodash").DebouncedFunc<F>;
@@ -0,0 +1 @@
1
+ export * from './useEventCallback';
@@ -0,0 +1 @@
1
+ export declare const useEventCallback: <T extends (...args: any[]) => any>(func: T) => T;
@@ -0,0 +1 @@
1
+ export * from './useEventListener';
@@ -0,0 +1,32 @@
1
+ import { RefOrElementOrCallback } from '../../utils';
2
+ export declare type UseEventListenerAction = {
3
+ listen: () => void;
4
+ remove: () => void;
5
+ };
6
+ export declare type UseEventListenerConfig = {
7
+ /**
8
+ * start listening when component mounted
9
+ *
10
+ * @default true
11
+ */
12
+ startImmediately?: boolean;
13
+ };
14
+ /**
15
+ * bind event when component mount and auto remove event when destroy.
16
+ * can remove listener by call returned function or pass empty 'target'.
17
+ *
18
+ * @param target
19
+ * listener will be removed when target is changed to null,
20
+ * or rebinding to new element when `ref.current` change
21
+ * @returns a method object
22
+ * - listen() listen listener again, if that have listener, that will not listen again
23
+ * - remove() remove listener
24
+ * @example
25
+ * ```ts
26
+ * useEventListener(window, 'keyup', () => console.log('window key up'))
27
+ * ```
28
+ */
29
+ export declare function useEventListener<T = Event>(target: RefOrElementOrCallback<EventTarget> | EventTarget | null | undefined, key: string, callback: (event: T) => void, options?: AddEventListenerOptions & UseEventListenerConfig): {
30
+ listen: () => void;
31
+ remove: () => void;
32
+ };
@@ -0,0 +1 @@
1
+ export * from './useEver';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * that value ever to be `you want value`
3
+ * Return true when the value ever to be `you want value` once.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * // once that isOpen is true, that result will always be `true`
8
+ * const isEverOpen = useEver(isOpen);
9
+ *
10
+ * const isEverToBe2 = useEver(count, (val) => val === 2);
11
+ * ```
12
+ */
13
+ export declare const useEver: <T>(value: T, targetValue?: (value: T) => boolean) => boolean;
@@ -0,0 +1 @@
1
+ export * from './useFocusVisible';
@@ -0,0 +1,22 @@
1
+ import { FocusEventHandler, FocusEvent, Ref } from 'react';
2
+ export declare type UseFocusVisibleOptions = {
3
+ /** invoke when focusVisiable or focusVisibleWithin is true */
4
+ onFocusVisible?: FocusEventHandler;
5
+ onFocus?: FocusEventHandler;
6
+ onBlur?: FocusEventHandler;
7
+ within?: boolean;
8
+ };
9
+ /**
10
+ * bind event with a11y keyboard, `space`, `enter`, only trigger when key includes in `checkKeys`
11
+ *
12
+ * that will auto preventDefault by default, if you don't want that, set `false` with `preventDefault`
13
+ */
14
+ export declare const useFocusVisible: ({ onFocusVisible, onFocus, onBlur, within, }?: UseFocusVisibleOptions) => {
15
+ focusVisibleHandlers: {
16
+ onBlur: (event: FocusEvent) => void;
17
+ onFocus: (event: FocusEvent<HTMLElement>) => void;
18
+ };
19
+ focusVisibleRef: Ref<any>;
20
+ focusVisible: boolean;
21
+ focusVisibleWithin: boolean;
22
+ };
@@ -0,0 +1 @@
1
+ export * from './useFontLoaded';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Hook to detect when fonts are loaded
3
+ *
4
+ * This hook provides graceful degradation:
5
+ * - When Font Loading API is not available (older browsers, SSR, test environments),
6
+ * it assumes fonts are loaded to prevent blocking UI
7
+ * - When disabled, it immediately returns true without listening to font events
8
+ * - When enabled and API is available, it listens for font loading completion
9
+ *
10
+ * @param enabled - Whether to listen for font loading events (default: true)
11
+ * @returns boolean indicating whether fonts are loaded
12
+ */
13
+ export declare const useFontLoaded: (enabled?: boolean) => boolean;
@@ -0,0 +1 @@
1
+ export * from './useForceUpdate';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * a method for trigger force update
3
+ * @returns force update method
4
+ */
5
+ export declare function useForceUpdate(): () => void;
@@ -0,0 +1 @@
1
+ export * from './useForkRef';
@@ -0,0 +1,19 @@
1
+ import { unstable_useForkRef as MuiUseForkRef } from '@mui/utils';
2
+ /**
3
+ * That method will give you ability fork same value `ref object` or `method`
4
+ * Example:
5
+ * ```ts
6
+ * const refA = useRef();
7
+ * const refB = useRef();
8
+ *
9
+ * const ref = useForkRef(refA, refB)
10
+ *
11
+ * useEffect(() => {
12
+ * console.log(refA); // get that current div dom
13
+ * console.log(refB); // also get that current div dom
14
+ * },[])
15
+ *
16
+ * return <div ref={ref} />
17
+ * ```
18
+ */
19
+ export declare const useForkRef: typeof MuiUseForkRef;
@@ -0,0 +1,55 @@
1
+ import { SyntheticEvent } from 'react';
2
+ import { RefOrElementOrCallback } from '../../utils';
3
+ export declare const globalListenerEventMap: Map<string, {
4
+ /**
5
+ * listener exec method
6
+ */
7
+ exec: (e: any) => void;
8
+ /**
9
+ * all listener
10
+ */
11
+ listeners: Set<(e: any) => void>;
12
+ }>;
13
+ export declare type CreateGlobalListenerConfig = {
14
+ /**
15
+ * custom key for determining different event group, default is same as `key`
16
+ */
17
+ customKey?: string;
18
+ /**
19
+ * custom binding event target, default is `window`
20
+ */
21
+ target?: RefOrElementOrCallback | EventTarget;
22
+ };
23
+ /**
24
+ * create globalListener handler for share one listener event
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const globalListener = createGlobalListener('focus', () => { console.log('focus') });
29
+ * const globalListener2 = createGlobalListener('focus', () => { console.log('focus') });
30
+ * globalListener.listen();
31
+ * globalListener2.listen();
32
+ *
33
+ * => // that will only create an event listener on window, but every callback will get emit value when event triggered
34
+ * ```
35
+ */
36
+ export declare const createGlobalListener: <T extends SyntheticEvent<Element, Event>>(key: string, listener: (event?: T | undefined) => void, options?: boolean | AddEventListenerOptions | undefined, { customKey, target: targetProp, }?: CreateGlobalListenerConfig) => {
37
+ listen: () => void;
38
+ /**
39
+ * remove listener
40
+ */
41
+ remove: () => void;
42
+ /**
43
+ * current listener state
44
+ */
45
+ readonly state: {
46
+ /**
47
+ * current listener state count
48
+ */
49
+ readonly count: number;
50
+ /**
51
+ * is that be listening
52
+ */
53
+ listening: boolean;
54
+ };
55
+ };
@@ -0,0 +1,2 @@
1
+ export * from './createGlobalListener';
2
+ export * from './useGlobalListener';
@@ -0,0 +1,14 @@
1
+ import { SyntheticEvent } from 'react';
2
+ import { createGlobalListener, CreateGlobalListenerConfig } from './createGlobalListener';
3
+ declare type GlobalListener = ReturnType<typeof createGlobalListener>;
4
+ export declare type UseGlobalListenerConfig = CreateGlobalListenerConfig & {
5
+ /**
6
+ * start listening when component mounted
7
+ *
8
+ * @default true
9
+ */
10
+ startImmediately?: boolean;
11
+ };
12
+ export declare function useGlobalListener<T extends SyntheticEvent>(key: string, listener: (event?: T) => void, config?: UseGlobalListenerConfig): GlobalListener;
13
+ export declare function useGlobalListener<T extends SyntheticEvent>(key: string, listener: (event?: T) => void, options?: AddEventListenerOptions | boolean, config?: UseGlobalListenerConfig): GlobalListener;
14
+ export {};
@@ -0,0 +1 @@
1
+ export * from './useHiddenTabindex';
@@ -0,0 +1,9 @@
1
+ import { RefOrElementOrCallback } from '../../utils';
2
+ /**
3
+ * group hidden logic, when binding events element focus,
4
+ * that hiddenRef will auto be `tabindex={-1}` *
5
+ */
6
+ export declare const useHiddenTabindex: <T extends HTMLElement>(target: RefOrElementOrCallback<T>) => {
7
+ onFocus: () => void;
8
+ onBlur: () => void;
9
+ };