@ringcentral/spring-base 1.8.0 → 1.9.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/hooks.js +51 -7
- package/index.js +3 -2
- package/package.json +1 -1
- package/src/hooks/index.d.ts +2 -0
- package/src/hooks/useActive/useActive.d.ts +4 -2
- package/src/hooks/useButton/index.d.ts +1 -0
- package/src/hooks/useButton/useButton.d.ts +2 -0
- package/src/hooks/useVirtuosoExternalWindow/index.d.ts +1 -0
- package/src/hooks/useVirtuosoExternalWindow/useVirtuosoExternalWindow.d.ts +5 -0
- package/src/typings/ComponentTypes.d.ts +4 -4
package/hooks.js
CHANGED
|
@@ -2,13 +2,14 @@ import { unstable_useEventCallback, unstable_ownerDocument, unstable_Timeout, un
|
|
|
2
2
|
export { unstable_useControlled as useControlled } from '@mui/utils';
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { useState, useEffect, useRef, useCallback, useLayoutEffect, useMemo } from 'react';
|
|
5
|
-
import uniqueId from 'lodash/uniqueId';
|
|
6
5
|
import { useWindowContext, useResponsiveContext, getMatchDetail } from './contexts.js';
|
|
7
|
-
import
|
|
8
|
-
import '
|
|
6
|
+
import uniqueId from 'lodash/uniqueId';
|
|
7
|
+
import { useButton as useButton$1 } from '@mui/base/useButton';
|
|
8
|
+
import { c as combineProps, a as ariaHideOutside, g as getRefElement, l as logInDev, o as ownerWindow } from './chunks/twMerge.js';
|
|
9
9
|
import './config.js';
|
|
10
10
|
import 'lodash/omit';
|
|
11
11
|
import 'lodash/pick';
|
|
12
|
+
import 'lodash/isPlainObject';
|
|
12
13
|
import debounce from 'lodash/debounce';
|
|
13
14
|
import noop from 'lodash/noop';
|
|
14
15
|
import throttle from 'lodash/throttle';
|
|
@@ -39,18 +40,29 @@ const isNativeButton = (el) => {
|
|
|
39
40
|
['button', 'submit', 'reset'].includes(el?.type)) ||
|
|
40
41
|
(tag === 'A' && el?.href));
|
|
41
42
|
};
|
|
42
|
-
const useActive = ({ onKeyDown, onKeyUp, onClick, disabled = false, } = {}) => {
|
|
43
|
+
const useActive = ({ onKeyDown, onKeyUp, onMouseDown, onClick, disabled = false, } = {}) => {
|
|
43
44
|
const [active, setActive] = useState(false);
|
|
45
|
+
const { document: targetDocument = document } = useWindowContext();
|
|
44
46
|
useEffect(() => {
|
|
45
47
|
if (disabled)
|
|
46
48
|
setActive(false);
|
|
47
49
|
}, [disabled]);
|
|
48
50
|
if (disabled) {
|
|
49
51
|
return {
|
|
50
|
-
activeHandlers: { onKeyDown, onKeyUp, onClick },
|
|
52
|
+
activeHandlers: { onKeyDown, onKeyUp, onMouseDown, onClick },
|
|
51
53
|
active: false,
|
|
52
54
|
};
|
|
53
55
|
}
|
|
56
|
+
const handleMouseDown = (event) => {
|
|
57
|
+
onMouseDown?.(event);
|
|
58
|
+
if (event.defaultPrevented) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
setActive(true);
|
|
62
|
+
targetDocument.addEventListener('mouseup', () => {
|
|
63
|
+
setActive(false);
|
|
64
|
+
}, { once: true });
|
|
65
|
+
};
|
|
54
66
|
const handleKeyDown = (event) => {
|
|
55
67
|
onKeyDown?.(event);
|
|
56
68
|
if (event.defaultPrevented) {
|
|
@@ -84,7 +96,12 @@ const useActive = ({ onKeyDown, onKeyUp, onClick, disabled = false, } = {}) => {
|
|
|
84
96
|
}
|
|
85
97
|
};
|
|
86
98
|
return {
|
|
87
|
-
activeHandlers: {
|
|
99
|
+
activeHandlers: {
|
|
100
|
+
onKeyDown: handleKeyDown,
|
|
101
|
+
onKeyUp: handleKeyUp,
|
|
102
|
+
onMouseDown: handleMouseDown,
|
|
103
|
+
onClick,
|
|
104
|
+
},
|
|
88
105
|
active,
|
|
89
106
|
};
|
|
90
107
|
};
|
|
@@ -155,6 +172,23 @@ const useAnnouncer = (id) => {
|
|
|
155
172
|
}, []);
|
|
156
173
|
};
|
|
157
174
|
|
|
175
|
+
function useButton(parameters) {
|
|
176
|
+
const muiButtonResult = useButton$1(parameters);
|
|
177
|
+
const { active: customActive, activeHandlers } = useActive({
|
|
178
|
+
disabled: parameters.disabled,
|
|
179
|
+
});
|
|
180
|
+
const originalGetRootProps = muiButtonResult.getRootProps;
|
|
181
|
+
const getRootProps = (externalProps) => {
|
|
182
|
+
const mergedProps = combineProps(externalProps, activeHandlers);
|
|
183
|
+
return originalGetRootProps(mergedProps);
|
|
184
|
+
};
|
|
185
|
+
return {
|
|
186
|
+
...muiButtonResult,
|
|
187
|
+
active: customActive,
|
|
188
|
+
getRootProps,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
158
192
|
const useAriaHideOutside = (props = {}) => {
|
|
159
193
|
const { enable = true } = props;
|
|
160
194
|
const { externalWindow, document } = useWindowContext();
|
|
@@ -1473,4 +1507,14 @@ const useBodyScrollLock = (isLocked, targetElement, options = {}) => {
|
|
|
1473
1507
|
]);
|
|
1474
1508
|
};
|
|
1475
1509
|
|
|
1476
|
-
|
|
1510
|
+
const useVirtuosoExternalWindow = () => {
|
|
1511
|
+
const { externalWindow } = useWindowContext();
|
|
1512
|
+
if (externalWindow && externalWindow !== globalThis.window) {
|
|
1513
|
+
return {
|
|
1514
|
+
externalWindow,
|
|
1515
|
+
};
|
|
1516
|
+
}
|
|
1517
|
+
return undefined;
|
|
1518
|
+
};
|
|
1519
|
+
|
|
1520
|
+
export { createGlobalListener, globalListenerEventMap, isElmEqualOrContain, isTouchEvent, moveIndexInTwoDimension, teardown, useA11yKeyEvent, useActive, useAnnouncer, useAriaHideOutside, useAudio, useBodyScrollLock, useButton, 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, useVirtuosoExternalWindow, visuallyHiddenStyles };
|
package/index.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export { configure, rcConfiguration } from './config.js';
|
|
2
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';
|
|
3
|
+
export { createGlobalListener, globalListenerEventMap, isElmEqualOrContain, isTouchEvent, moveIndexInTwoDimension, teardown, useA11yKeyEvent, useActive, useAnnouncer, useAriaHideOutside, useAudio, useBodyScrollLock, useButton, 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, useVirtuosoExternalWindow, visuallyHiddenStyles } from './hooks.js';
|
|
4
4
|
export { unstable_ownerDocument as ownerDocument, unstable_useControlled as useControlled } from '@mui/utils';
|
|
5
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
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
7
|
import 'react';
|
|
8
8
|
import 'lodash/uniqueId';
|
|
9
|
-
import '
|
|
9
|
+
import '@mui/base/useButton';
|
|
10
10
|
import 'lodash/omit';
|
|
11
11
|
import 'lodash/pick';
|
|
12
|
+
import 'lodash/isPlainObject';
|
|
12
13
|
import 'lodash/debounce';
|
|
13
14
|
import 'lodash/noop';
|
|
14
15
|
import 'lodash/throttle';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ringcentral/spring-base",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"author": "RingCentral",
|
|
5
5
|
"description": "Core utilities, hooks, and foundational functionality for Spring UI components, providing essential building blocks for React applications",
|
|
6
6
|
"main": "./index.js",
|
package/src/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './useA11yKeyEvent';
|
|
2
2
|
export * from './useActive';
|
|
3
3
|
export * from './useAnnouncer';
|
|
4
|
+
export * from './useButton';
|
|
4
5
|
export * from './useAriaHideOutside';
|
|
5
6
|
export * from './useAudio';
|
|
6
7
|
export * from './useChange';
|
|
@@ -41,3 +42,4 @@ export * from './useTimeout';
|
|
|
41
42
|
export * from './useTouchMouseEvent';
|
|
42
43
|
export * from './useFontLoaded';
|
|
43
44
|
export * from './useBodyScrollLock';
|
|
45
|
+
export * from './useVirtuosoExternalWindow';
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { EventHandler, KeyboardEventHandler, SyntheticEvent } from 'react';
|
|
1
|
+
import { EventHandler, KeyboardEventHandler, MouseEventHandler, SyntheticEvent } from 'react';
|
|
2
2
|
export declare type UseActiveOptions = {
|
|
3
3
|
onKeyDown?: KeyboardEventHandler;
|
|
4
4
|
onKeyUp?: KeyboardEventHandler;
|
|
5
|
+
onMouseDown?: MouseEventHandler;
|
|
5
6
|
onClick?: EventHandler<SyntheticEvent>;
|
|
6
7
|
disabled?: boolean;
|
|
7
8
|
};
|
|
8
|
-
export declare const useActive: ({ onKeyDown, onKeyUp, onClick, disabled, }?: UseActiveOptions) => {
|
|
9
|
+
export declare const useActive: ({ onKeyDown, onKeyUp, onMouseDown, onClick, disabled, }?: UseActiveOptions) => {
|
|
9
10
|
activeHandlers: {
|
|
10
11
|
onKeyDown: KeyboardEventHandler<Element> | undefined;
|
|
11
12
|
onKeyUp: KeyboardEventHandler<Element> | undefined;
|
|
13
|
+
onMouseDown: MouseEventHandler<Element> | undefined;
|
|
12
14
|
onClick: ((event: SyntheticEvent<Element, Event>) => void) | undefined;
|
|
13
15
|
};
|
|
14
16
|
active: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useButton } from './useButton';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useVirtuosoExternalWindow';
|
|
@@ -7,15 +7,15 @@ export declare type GroupedMotionProps<P = {}> = Pick<MotionProps, Extract<keyof
|
|
|
7
7
|
export declare type ClassesProp<K extends string> = {
|
|
8
8
|
classes?: Partial<Record<K | 'root' | GlobalStateClassesKey, string>>;
|
|
9
9
|
};
|
|
10
|
-
export declare type PropsWithRoot<P, R extends ElementType, O extends string = ''> = P & Omit<ComponentPropsWithRef<R>, keyof P | O
|
|
11
|
-
export declare type StandardProps<P, C extends string, R extends ElementType | void = void, O extends string = '', ExtendAttributes = HTMLDataAttribute> = ClassesProp<C> & (R extends ElementType ? PropsWithRoot<P, R, 'classes' | O> : P & {
|
|
10
|
+
export declare type PropsWithRoot<P, R extends ElementType, O extends string = '', E = HTMLDataAttribute> = P & Omit<ComponentPropsWithRef<R>, keyof P | O> & E;
|
|
11
|
+
export declare type StandardProps<P, C extends string, R extends ElementType | void = void, O extends string = '', ExtendAttributes = HTMLDataAttribute> = ClassesProp<C> & (R extends ElementType ? PropsWithRoot<P, R, 'classes' | O, ExtendAttributes> : P & {
|
|
12
12
|
className?: string;
|
|
13
13
|
}) & ExtendAttributes;
|
|
14
14
|
export declare type WithClassesProps<P, C extends string> = P & ClassesProp<C>;
|
|
15
15
|
export declare type BaseOverridableProps<P, C extends string> = WithClassesProps<P, C>;
|
|
16
|
-
export declare type OverridableProps<B, T extends ElementType> = B & {
|
|
16
|
+
export declare type OverridableProps<B, T extends ElementType, E = HTMLDataAttribute> = B & {
|
|
17
17
|
component?: T;
|
|
18
|
-
} & Omit<ComponentPropsWithRef<T>, keyof B
|
|
18
|
+
} & Omit<ComponentPropsWithRef<T>, keyof B> & E;
|
|
19
19
|
export declare type RefFromProps<P> = P extends {
|
|
20
20
|
ref?: LegacyRef<infer R> | undefined;
|
|
21
21
|
} ? R : never;
|