@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.
- package/LICENSE +22 -0
- package/README.md +61 -0
- package/chunks/twMerge.js +409 -0
- package/config.js +78 -0
- package/contexts.js +71 -0
- package/hooks.js +2101 -0
- package/index.d.ts +1 -0
- package/index.js +16 -0
- package/package.json +30 -0
- package/src/config.d.ts +40 -0
- package/src/contexts/ResponsiveContext/ResponsiveContext.d.ts +7 -0
- package/src/contexts/ResponsiveContext/breakpointList.d.ts +3 -0
- package/src/contexts/ResponsiveContext/getMatchDetail.d.ts +2 -0
- package/src/contexts/ResponsiveContext/index.d.ts +4 -0
- package/src/contexts/ResponsiveContext/types.d.ts +24 -0
- package/src/contexts/WindowContext.d.ts +9 -0
- package/src/contexts/index.d.ts +2 -0
- package/src/hooks/index.d.ts +43 -0
- package/src/hooks/useA11yKeyEvent/index.d.ts +1 -0
- package/src/hooks/useA11yKeyEvent/useA11yKeyEvent.d.ts +23 -0
- package/src/hooks/useActive/index.d.ts +1 -0
- package/src/hooks/useActive/useActive.d.ts +23 -0
- package/src/hooks/useAnnouncer/index.d.ts +1 -0
- package/src/hooks/useAnnouncer/useAnnouncer.d.ts +12 -0
- package/src/hooks/useAriaHideOutside/index.d.ts +1 -0
- package/src/hooks/useAriaHideOutside/useAriaHideOutside.d.ts +12 -0
- package/src/hooks/useAudio/index.d.ts +1 -0
- package/src/hooks/useAudio/useAudio.d.ts +21 -0
- package/src/hooks/useBodyScrollLock/index.d.ts +1 -0
- package/src/hooks/useBodyScrollLock/useBodyScrollLock.d.ts +25 -0
- package/src/hooks/useChange/index.d.ts +1 -0
- package/src/hooks/useChange/useChange.d.ts +12 -0
- package/src/hooks/useClickAway/index.d.ts +1 -0
- package/src/hooks/useClickAway/useClickAway.d.ts +22 -0
- package/src/hooks/useControlled/index.d.ts +1 -0
- package/src/hooks/useControlled/useControlled.d.ts +1 -0
- package/src/hooks/useDebounce/index.d.ts +1 -0
- package/src/hooks/useDebounce/useDebounce.d.ts +8 -0
- package/src/hooks/useEventCallback/index.d.ts +1 -0
- package/src/hooks/useEventCallback/useEventCallback.d.ts +1 -0
- package/src/hooks/useEventListener/index.d.ts +1 -0
- package/src/hooks/useEventListener/useEventListener.d.ts +32 -0
- package/src/hooks/useEver/index.d.ts +1 -0
- package/src/hooks/useEver/useEver.d.ts +13 -0
- package/src/hooks/useFocusVisible/index.d.ts +1 -0
- package/src/hooks/useFocusVisible/useFocusVisible.d.ts +22 -0
- package/src/hooks/useFontLoaded/index.d.ts +1 -0
- package/src/hooks/useFontLoaded/useFontLoaded.d.ts +13 -0
- package/src/hooks/useForceUpdate/index.d.ts +1 -0
- package/src/hooks/useForceUpdate/useForceUpdate.d.ts +5 -0
- package/src/hooks/useForkRef/index.d.ts +1 -0
- package/src/hooks/useForkRef/useForkRef.d.ts +19 -0
- package/src/hooks/useGlobalListener/createGlobalListener.d.ts +55 -0
- package/src/hooks/useGlobalListener/index.d.ts +2 -0
- package/src/hooks/useGlobalListener/useGlobalListener.d.ts +14 -0
- package/src/hooks/useHiddenTabindex/index.d.ts +1 -0
- package/src/hooks/useHiddenTabindex/useHiddenTabindex.d.ts +9 -0
- package/src/hooks/useHover/index.d.ts +2 -0
- package/src/hooks/useHover/useHover.d.ts +17 -0
- package/src/hooks/useHover/useHoverDirty.d.ts +8 -0
- package/src/hooks/useId/index.d.ts +1 -0
- package/src/hooks/useId/useId.d.ts +15 -0
- package/src/hooks/useImgLoaded/index.d.ts +1 -0
- package/src/hooks/useImgLoaded/useImgLoaded.d.ts +24 -0
- package/src/hooks/useInterval/index.d.ts +1 -0
- package/src/hooks/useInterval/useInterval.d.ts +43 -0
- package/src/hooks/useIsFocusVisible/index.d.ts +2 -0
- package/src/hooks/useIsFocusVisible/useIsFocusVisible.d.ts +9 -0
- package/src/hooks/useKeyDownOnce/index.d.ts +1 -0
- package/src/hooks/useKeyDownOnce/useKeyDownOnce.d.ts +15 -0
- package/src/hooks/useKeyboardMoveFocus/index.d.ts +3 -0
- package/src/hooks/useKeyboardMoveFocus/moveIndexInTwoDimension.d.ts +18 -0
- package/src/hooks/useKeyboardMoveFocus/useKeyboardMoveFocus.d.ts +49 -0
- package/src/hooks/useKeyboardMoveFocus/useOnlyOneFocusable.d.ts +17 -0
- package/src/hooks/useLongPress/index.d.ts +1 -0
- package/src/hooks/useLongPress/useLongPress.d.ts +39 -0
- package/src/hooks/useMountState/index.d.ts +1 -0
- package/src/hooks/useMountState/useMountState.d.ts +16 -0
- package/src/hooks/useOnLayoutReRender/index.d.ts +1 -0
- package/src/hooks/useOnLayoutReRender/useOnLayoutReRender.d.ts +5 -0
- package/src/hooks/useOnReRender/index.d.ts +1 -0
- package/src/hooks/useOnReRender/useOnReRender.d.ts +5 -0
- package/src/hooks/useOverflow/index.d.ts +1 -0
- package/src/hooks/useOverflow/useOverflow.d.ts +11 -0
- package/src/hooks/usePrevious/index.d.ts +1 -0
- package/src/hooks/usePrevious/usePrevious.d.ts +7 -0
- package/src/hooks/useRefState/index.d.ts +1 -0
- package/src/hooks/useRefState/useRefState.d.ts +21 -0
- package/src/hooks/useResizeObserver/index.d.ts +1 -0
- package/src/hooks/useResizeObserver/useResizeObserver.d.ts +24 -0
- package/src/hooks/useResponsiveMatch/index.d.ts +1 -0
- package/src/hooks/useResponsiveMatch/useResponsiveMatch.d.ts +7 -0
- package/src/hooks/useResultRef/index.d.ts +1 -0
- package/src/hooks/useResultRef/useResultRef.d.ts +10 -0
- package/src/hooks/useRetry/index.d.ts +1 -0
- package/src/hooks/useRetry/useRetry.d.ts +35 -0
- package/src/hooks/useSleep/index.d.ts +1 -0
- package/src/hooks/useSleep/useSleep.d.ts +22 -0
- package/src/hooks/useTabOut/index.d.ts +1 -0
- package/src/hooks/useTabOut/useTabOut.d.ts +10 -0
- package/src/hooks/useTestRunnerDetection.d.ts +7 -0
- package/src/hooks/useThrottle/index.d.ts +1 -0
- package/src/hooks/useThrottle/useThrottle.d.ts +8 -0
- package/src/hooks/useTimeout/index.d.ts +1 -0
- package/src/hooks/useTimeout/useTimeout.d.ts +2 -0
- package/src/hooks/useTouchMouseEvent/index.d.ts +1 -0
- package/src/hooks/useTouchMouseEvent/useTouchMouseEvent.d.ts +56 -0
- package/src/index.d.ts +5 -0
- package/src/typings/BaseColor.d.ts +14 -0
- package/src/typings/BaseSize.d.ts +15 -0
- package/src/typings/ComponentTypes.d.ts +50 -0
- package/src/typings/ExtractValue.d.ts +2 -0
- package/src/typings/OverridableTypes.d.ts +45 -0
- package/src/typings/UnionOmit.d.ts +3 -0
- package/src/typings/UnitMap.d.ts +28 -0
- package/src/typings/index.d.ts +7 -0
- package/src/utils/a11yKeyboardCode.d.ts +8 -0
- package/src/utils/ariaHideOutside.d.ts +9 -0
- package/src/utils/capitalize.d.ts +1 -0
- package/src/utils/checkDefaultPrevented.d.ts +3 -0
- package/src/utils/checkElementName.d.ts +2 -0
- package/src/utils/checkKeyboardEvent.d.ts +2 -0
- package/src/utils/classes/globalStateClasses.d.ts +14 -0
- package/src/utils/classes/index.d.ts +2 -0
- package/src/utils/classes/useClasses.d.ts +41 -0
- package/src/utils/combineProps.d.ts +90 -0
- package/src/utils/devlog.d.ts +7 -0
- package/src/utils/getRefElement.d.ts +6 -0
- package/src/utils/getTitle.d.ts +1 -0
- package/src/utils/index.d.ts +25 -0
- package/src/utils/isRef.d.ts +2 -0
- package/src/utils/isSuiElement.d.ts +1 -0
- package/src/utils/isUrl.d.ts +1 -0
- package/src/utils/isWebKit154.d.ts +9 -0
- package/src/utils/omit.d.ts +2 -0
- package/src/utils/outerSize.d.ts +8 -0
- package/src/utils/ownerDocument.d.ts +1 -0
- package/src/utils/ownerWindow.d.ts +1 -0
- package/src/utils/pick.d.ts +2 -0
- package/src/utils/preloadImg.d.ts +2 -0
- package/src/utils/removeClassName.d.ts +35 -0
- package/src/utils/runKeyHandler.d.ts +12 -0
- package/src/utils/selectionHandler.d.ts +23 -0
- package/src/utils/twMerge.d.ts +4 -0
- package/typings.js +1 -0
- package/utils.js +333 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MouseEvent, MouseEventHandler } from 'react';
|
|
2
|
+
export declare type UseHoverOptions<E = HTMLElement> = {
|
|
3
|
+
onMouseEnter?: MouseEventHandler<E>;
|
|
4
|
+
onMouseLeave?: MouseEventHandler<E>;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
/**
|
|
7
|
+
* @default true
|
|
8
|
+
*/
|
|
9
|
+
disableReactTree?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare const useHover: <E = HTMLElement>({ onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, disabled, disableReactTree, }?: UseHoverOptions<E>) => {
|
|
12
|
+
hoverHandlers: {
|
|
13
|
+
onMouseEnter: (event: MouseEvent<E, globalThis.MouseEvent>) => void;
|
|
14
|
+
onMouseLeave: (event: MouseEvent<E, globalThis.MouseEvent>) => void;
|
|
15
|
+
};
|
|
16
|
+
hover: boolean;
|
|
17
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RefOrElementOrCallback } from '../../utils';
|
|
2
|
+
export declare type UseHoverDirtyOptions = {
|
|
3
|
+
target: RefOrElementOrCallback | EventTarget | null | undefined;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare const useHoverDirty: ({ target, disabled, }: UseHoverDirtyOptions) => {
|
|
7
|
+
hover: boolean;
|
|
8
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useId';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates a unique ID.
|
|
3
|
+
*
|
|
4
|
+
* @param id - Default component id or prefix id.
|
|
5
|
+
* @param prefixMode Whether enable prefix the ID with.
|
|
6
|
+
* @returns unique ID
|
|
7
|
+
* @example
|
|
8
|
+
* useId() => 'spring-id-xxxx'
|
|
9
|
+
* useId('') => 'spring-id-xxxx'
|
|
10
|
+
* useId(null) => 'spring-id-xxxx'
|
|
11
|
+
* useId(undefined) => 'spring-id-xxxx'
|
|
12
|
+
* useId('nameId') => 'nameId'
|
|
13
|
+
* useId('nameId', true) => 'nameId-xxxx'
|
|
14
|
+
*/
|
|
15
|
+
export declare function useId(id?: string, prefixMode?: boolean): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useImgLoaded';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ComponentProps } from 'react';
|
|
2
|
+
declare type UseImgLoadedProps = {
|
|
3
|
+
src?: string;
|
|
4
|
+
srcSet?: string;
|
|
5
|
+
crossOrigin?: ComponentProps<'img'>['crossOrigin'];
|
|
6
|
+
referrerPolicy?: ComponentProps<'img'>['referrerPolicy'];
|
|
7
|
+
};
|
|
8
|
+
declare type LoadedState = false | 'loaded' | 'error';
|
|
9
|
+
/**
|
|
10
|
+
* get load state of an image by passing src or srcSet
|
|
11
|
+
* - false: not load yet
|
|
12
|
+
* - 'loaded': successfully loaded
|
|
13
|
+
* - 'error': fail to load
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const loaded = useImgLoaded({
|
|
18
|
+
* src,
|
|
19
|
+
* srcSet,
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare const useImgLoaded: ({ crossOrigin, referrerPolicy, src, srcSet, }: UseImgLoadedProps) => LoadedState;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useInterval';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* controllable interval, provide easy way to control interval
|
|
3
|
+
*
|
|
4
|
+
* - cancel: cancel current interval
|
|
5
|
+
* - pause: pause current interval
|
|
6
|
+
* - play: play current interval
|
|
7
|
+
* - getRunning: return current interval running state
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const { cancel, play, pause } = useInterval(() => {
|
|
12
|
+
* console.log('interval be triggered');
|
|
13
|
+
* }, 1000)
|
|
14
|
+
*
|
|
15
|
+
* // get current run times
|
|
16
|
+
* useInterval((times) => {
|
|
17
|
+
* console.log('current times start from 1', times);
|
|
18
|
+
* }, 2000)
|
|
19
|
+
*
|
|
20
|
+
* // not start interval immediately
|
|
21
|
+
* useInterval((times) => {
|
|
22
|
+
* console.log('current times start from 1', times);
|
|
23
|
+
* }, 2000, false)
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const useInterval: (callback: (times: number) => void, delay?: number, startImmediately?: boolean) => {
|
|
27
|
+
/**
|
|
28
|
+
* cancel current interval
|
|
29
|
+
*/
|
|
30
|
+
cancel: () => void;
|
|
31
|
+
/**
|
|
32
|
+
* pause current interval
|
|
33
|
+
*/
|
|
34
|
+
pause: () => void;
|
|
35
|
+
/**
|
|
36
|
+
* play current interval
|
|
37
|
+
*/
|
|
38
|
+
play: () => void;
|
|
39
|
+
/**
|
|
40
|
+
* return current interval running state
|
|
41
|
+
*/
|
|
42
|
+
getRunning: () => boolean;
|
|
43
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare function teardown(doc: Document): void;
|
|
3
|
+
export interface UseIsFocusVisibleResult {
|
|
4
|
+
isFocusVisibleRef: React.MutableRefObject<boolean>;
|
|
5
|
+
onBlur: (event: React.FocusEvent<any>) => void;
|
|
6
|
+
onFocus: (event: React.FocusEvent<any>) => void;
|
|
7
|
+
ref: React.RefCallback<Element>;
|
|
8
|
+
}
|
|
9
|
+
export default function useIsFocusVisible(): UseIsFocusVisibleResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useKeyDownOnce';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type UseKeyDownOnce<T> = {
|
|
3
|
+
onKeyUp?: (e: React.KeyboardEvent<T>) => void;
|
|
4
|
+
onKeyDown?: (e: React.KeyboardEvent<T>) => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Provide user trigger `onKeyDown` only one time when hold press on key.
|
|
8
|
+
* @param includeKeys that check include keys
|
|
9
|
+
* @param methods trigger when first keydown or keyup
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const useKeyDownOnce: <T>(includeKeys: string[], { onKeyDown, onKeyUp }: UseKeyDownOnce<T>) => {
|
|
13
|
+
onKeyDown: (e: import("react").KeyboardEvent<T>) => void;
|
|
14
|
+
onKeyUp: (e: import("react").KeyboardEvent<T>) => void;
|
|
15
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare type MoveIndexInTwoDimensionalOptions = {
|
|
2
|
+
/** current index */
|
|
3
|
+
currIndex: number;
|
|
4
|
+
/** column number with that two dimensional */
|
|
5
|
+
columns: number;
|
|
6
|
+
/** total number of items */
|
|
7
|
+
total: number;
|
|
8
|
+
/**
|
|
9
|
+
* if that touch boundary, is that can move to next available infinite
|
|
10
|
+
*
|
|
11
|
+
* - when set value as `order`, that will increase or decrease when `ArrowLeft` or `ArrowRight` touch boundary
|
|
12
|
+
*/
|
|
13
|
+
infinite?: boolean | 'order';
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* that can move index in column array
|
|
17
|
+
*/
|
|
18
|
+
export declare function moveIndexInTwoDimension(direction: string, options: MoveIndexInTwoDimensionalOptions): number;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { MoveIndexInTwoDimensionalOptions } from './moveIndexInTwoDimension';
|
|
3
|
+
export declare type UseKeyboardMoveFocusParams<T> = {
|
|
4
|
+
/** current focused index `ref` */
|
|
5
|
+
focusedIndexRef: React.MutableRefObject<number>;
|
|
6
|
+
/** action when index change */
|
|
7
|
+
onFocusedIndexChange: (event: React.KeyboardEvent<HTMLElement>, index: number) => void;
|
|
8
|
+
/** children items */
|
|
9
|
+
options: T[];
|
|
10
|
+
/** column number with that move block, default is `1` */
|
|
11
|
+
columns?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Used to determine the disabled state for a given option.
|
|
14
|
+
*
|
|
15
|
+
* @param {T} option The option to test.
|
|
16
|
+
* @returns {boolean}
|
|
17
|
+
*/
|
|
18
|
+
getOptionDisabled?: (option: T) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Used to get option text for search focus by other text.
|
|
21
|
+
*
|
|
22
|
+
* @param {T} option
|
|
23
|
+
* @returns {string} that string for search
|
|
24
|
+
*/
|
|
25
|
+
getOptionSearchText?: (option: T) => string;
|
|
26
|
+
/**
|
|
27
|
+
* when typing search text, end this search debounce time
|
|
28
|
+
*
|
|
29
|
+
* @default 500
|
|
30
|
+
*/
|
|
31
|
+
endSearchDebounceTime?: number;
|
|
32
|
+
} & Pick<MoveIndexInTwoDimensionalOptions, 'infinite'>;
|
|
33
|
+
/**
|
|
34
|
+
* use keyboard move index in two dimensional
|
|
35
|
+
*/
|
|
36
|
+
export declare const useKeyboardMoveFocus: <T>({ infinite, options, focusedIndexRef, onFocusedIndexChange, getOptionDisabled, getOptionSearchText, columns, endSearchDebounceTime, }: UseKeyboardMoveFocusParams<T>) => {
|
|
37
|
+
/**
|
|
38
|
+
* Get previous focusable option(include current index).
|
|
39
|
+
*/
|
|
40
|
+
getPrevFocusableOption: (index?: number, isInfinite?: any) => number;
|
|
41
|
+
/**
|
|
42
|
+
* Get next focusable option(include current index).
|
|
43
|
+
*/
|
|
44
|
+
getNextFocusableOption: (index?: number, isInfinite?: any) => number;
|
|
45
|
+
/**
|
|
46
|
+
* Use to handle keyboard event.
|
|
47
|
+
*/
|
|
48
|
+
onKeyFocusedIndexHandle: (event: React.KeyboardEvent<any>) => void;
|
|
49
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type UseOnlyOneFocusableParams = {
|
|
3
|
+
/** current focused index `ref` */
|
|
4
|
+
focusedIndexRef: React.MutableRefObject<number>;
|
|
5
|
+
/** wrap container for below all only have one focusable */
|
|
6
|
+
containerRef: React.RefObject<HTMLElement>;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* when focus in container below element with binding `getItemProps`,
|
|
10
|
+
* that will only have one element can be focusable.
|
|
11
|
+
*/
|
|
12
|
+
export declare const useOnlyOneFocusable: ({ focusedIndexRef, containerRef, }: UseOnlyOneFocusableParams) => {
|
|
13
|
+
moveFocusedId: string;
|
|
14
|
+
focusIndex: (toIndex: number) => void;
|
|
15
|
+
setIndexTabIndex: (toIndex: number) => void;
|
|
16
|
+
getItemProps: (index: number, options?: Omit<import("react").HTMLAttributes<HTMLElement>, "children"> | undefined) => Omit<import("react").HTMLAttributes<HTMLElement>, "children">;
|
|
17
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useLongPress';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { UseTouchMouseEvent } from '../useTouchMouseEvent';
|
|
3
|
+
export declare const isTouchEvent: <T = unknown>(ev: React.MouseEvent<T, MouseEvent> | React.TouchEvent<T>) => ev is React.TouchEvent<T>;
|
|
4
|
+
export interface UseLongPressOptions {
|
|
5
|
+
/**
|
|
6
|
+
* auto event.preventDefault for `mousedown`, `touchstart`, `touchend`
|
|
7
|
+
* always use for not leave that element
|
|
8
|
+
*/
|
|
9
|
+
isPreventDefault?: boolean;
|
|
10
|
+
/** the longPress delay */
|
|
11
|
+
delay?: number;
|
|
12
|
+
/** for custom window */
|
|
13
|
+
externalWindow?: Window;
|
|
14
|
+
}
|
|
15
|
+
export declare type UseLongPressEventReason = 'keyboard' | 'click' | 'tap';
|
|
16
|
+
export declare type UseLongPressOutput<T> = {
|
|
17
|
+
/** trigger when click or tab or keyboard */
|
|
18
|
+
onTap?: (e: React.MouseEvent<T, MouseEvent> | React.TouchEvent<T> | React.KeyboardEvent<T>, reason: UseLongPressEventReason) => void;
|
|
19
|
+
/** trigger when press or long click */
|
|
20
|
+
onPress?: (e: React.MouseEvent<T, MouseEvent> | React.TouchEvent<T> | React.KeyboardEvent<T>, reason: UseLongPressEventReason) => void;
|
|
21
|
+
};
|
|
22
|
+
export declare type UseLongPressInput<T> = {
|
|
23
|
+
onKeyUp?: (e: React.KeyboardEvent<T>) => void;
|
|
24
|
+
onKeyDown?: (e: React.KeyboardEvent<T>) => void;
|
|
25
|
+
} & UseTouchMouseEvent<T>;
|
|
26
|
+
/**
|
|
27
|
+
* Provide longPress helper, both `click`/`tab`/`keydown` will trigger event
|
|
28
|
+
*
|
|
29
|
+
* - Trigger `onTap` when user action leave small than delay time.
|
|
30
|
+
* - Trigger `onPress` when action time is long than delay time.
|
|
31
|
+
*
|
|
32
|
+
* @default UseLongPressOptions { delay = 300 }
|
|
33
|
+
*/
|
|
34
|
+
export declare const useLongPress: <T extends HTMLElement = HTMLElement>({ onTap, onPress }: UseLongPressOutput<T>, { onTouchStart: onTouchStartArg, onTouchEnd: onTouchEndArg, onMouseDown, onKeyDown, onKeyUp, onMouseUp: onMouseUpArg, }?: UseLongPressInput<T>, { isPreventDefault, delay, externalWindow, }?: UseLongPressOptions) => {
|
|
35
|
+
onMouseDown: React.MouseEventHandler<T>;
|
|
36
|
+
ref: React.MutableRefObject<T | null>;
|
|
37
|
+
onKeyDown: (e: any) => void;
|
|
38
|
+
onKeyUp: (e: any) => void;
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useMountState';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* get that component mounted state `ref`
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
const isMountedRef = useMountState();
|
|
9
|
+
|
|
10
|
+
if (isMountedRef.current) {
|
|
11
|
+
console.log('component mounted');
|
|
12
|
+
}
|
|
13
|
+
*
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const useMountState: () => import("react").MutableRefObject<boolean>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useOnLayoutReRender';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useOnReRender';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useOverflow';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RefOrElementOrCallback } from '../../utils';
|
|
2
|
+
import { PerformanceOptions } from '../useResizeObserver';
|
|
3
|
+
/**
|
|
4
|
+
* trigger when overflow state change
|
|
5
|
+
*/
|
|
6
|
+
export declare const useOverflow: (target: RefOrElementOrCallback, cb: (state: boolean, value: {
|
|
7
|
+
scrollWidth: number;
|
|
8
|
+
clientWidth: number;
|
|
9
|
+
scrollHeight: number;
|
|
10
|
+
clientHeight: number;
|
|
11
|
+
}) => void, performance?: PerformanceOptions) => ResizeObserver;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './usePrevious';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* get previous render value
|
|
3
|
+
* @param cb that get method of target value
|
|
4
|
+
* @param isDefault if set `true`, the first time will get value from `cb`
|
|
5
|
+
* @returns previous value get from `cb`
|
|
6
|
+
*/
|
|
7
|
+
export declare function usePrevious<T, K extends boolean>(cb: () => T, isDefault?: K): T | (K extends true ? never : undefined);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useRefState';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* Returns a stateful like state with Ref, and a function to update it current value.
|
|
4
|
+
* can trigger update value without re-render
|
|
5
|
+
*
|
|
6
|
+
* @param value init value
|
|
7
|
+
* @param customUpdate you can custom you update method, or just set your `forceUpdate` to reuse same instance
|
|
8
|
+
* @returns an array with [ref, update]
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const [inputRef, updateInput] = useRefState(123);
|
|
13
|
+
*
|
|
14
|
+
* if(needReRender){
|
|
15
|
+
* updateInput(456); // trigger re-render
|
|
16
|
+
* } else {
|
|
17
|
+
* updateInput(456, false); // not trigger re-render
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const useRefState: <T>(value: T, customUpdate?: (() => void) | undefined) => readonly [import("react").MutableRefObject<T>, (toValue: T, isUpdate?: any) => void];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useResizeObserver';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type DebounceSettings, type ThrottleSettings } from 'lodash';
|
|
2
|
+
import { RefOrElementOrCallback } from '../../utils';
|
|
3
|
+
export declare type PerformanceOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* mode that improve performance, default is debounce
|
|
6
|
+
*
|
|
7
|
+
* throttle is better than debounce when use for responsive UI
|
|
8
|
+
*/
|
|
9
|
+
mode?: 'debounce' | 'throttle' | 'none';
|
|
10
|
+
/** debounce time or throttle time when resize, default is 200 */
|
|
11
|
+
time?: number;
|
|
12
|
+
/** ignore fire when observe */
|
|
13
|
+
ignoreFireWhenObserve?: boolean;
|
|
14
|
+
/** setting about debounce or throttle */
|
|
15
|
+
options?: ThrottleSettings | DebounceSettings;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* get resize event with auto disconnect when layout destroy.
|
|
19
|
+
* bring with debounce for event not too many
|
|
20
|
+
* @param ref that ref for element
|
|
21
|
+
* @param callback callback when element resize
|
|
22
|
+
* @param performance options that improve performance
|
|
23
|
+
*/
|
|
24
|
+
export declare const useResizeObserver: <T extends HTMLElement = HTMLElement>(target: RefOrElementOrCallback<T>, callback: ResizeObserverCallback, performance?: PerformanceOptions) => ResizeObserver;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useResponsiveMatch';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BreakpointMatchMap, MatchedBreakpoint } from '../../contexts';
|
|
2
|
+
/**
|
|
3
|
+
* get all matched breakpoints
|
|
4
|
+
* @param defaultBreakpoint use defaultBreakpoint when Responsive init (will pass undefined)
|
|
5
|
+
*/
|
|
6
|
+
declare const useResponsiveMatch: (defaultBreakpoint?: MatchedBreakpoint | undefined) => BreakpointMatchMap;
|
|
7
|
+
export { useResponsiveMatch };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useResultRef';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MutableRefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* provide a ref for only calculate `cb` once
|
|
4
|
+
* prevent `useRef(getValue())`, that `getValue` calculate every re-render
|
|
5
|
+
*
|
|
6
|
+
* @param cb that get method of get this ref init value, only calculate once
|
|
7
|
+
* @returns same as `useRef` result
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
10
|
+
export declare function useResultRef<T>(cb: () => T): MutableRefObject<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useRetry';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare type UseRetryOptions = {
|
|
2
|
+
/** times count that retry when `cb` return `false` */
|
|
3
|
+
retryTimes: number;
|
|
4
|
+
/** retry interval time */
|
|
5
|
+
intervalTime: number;
|
|
6
|
+
/** trigger when retry start */
|
|
7
|
+
onStart?: () => void;
|
|
8
|
+
/** trigger when retry be cancel */
|
|
9
|
+
onSuccess?: (
|
|
10
|
+
/** retry times */
|
|
11
|
+
times?: number) => void;
|
|
12
|
+
/** trigger when retry complete */
|
|
13
|
+
onComplete?: (
|
|
14
|
+
/** retry times */
|
|
15
|
+
times?: number) => void;
|
|
16
|
+
/** trigger when retry be cancel */
|
|
17
|
+
onCancel?: () => void;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* retry times when exec callback fail
|
|
21
|
+
*
|
|
22
|
+
* * `retry`: that will auto add `times` end of your call back
|
|
23
|
+
* * `cancel`: cancel that retry event, that only cancel inner interval promise, **if you need cancel your `cb` promise, you should handle by yourself.**
|
|
24
|
+
*/
|
|
25
|
+
export declare const useRetry: <T extends (...args: any[]) => boolean | Promise<boolean>>(cb: T, options?: UseRetryOptions | undefined) => {
|
|
26
|
+
/**
|
|
27
|
+
* retry method, that will be cancelable with `cancel`,
|
|
28
|
+
* and when trigger many time that will always clear previous retry
|
|
29
|
+
*/
|
|
30
|
+
retry: (...args: Parameters<T>) => Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* cancel current retry
|
|
33
|
+
*/
|
|
34
|
+
cancel: () => void;
|
|
35
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useSleep';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cancelable sleep method.
|
|
3
|
+
*
|
|
4
|
+
* - sleep: a promise sleep
|
|
5
|
+
* - cancel: cancel that sleep event
|
|
6
|
+
* - getSleeping: get current sleeping state
|
|
7
|
+
*/
|
|
8
|
+
export declare const useSleep: () => {
|
|
9
|
+
/**
|
|
10
|
+
* sleep method, that will be cancelable with `cancel`,
|
|
11
|
+
* and when trigger many time that will always clear previous sleep
|
|
12
|
+
*/
|
|
13
|
+
sleep: (time: number) => Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* cancel current sleep timer
|
|
16
|
+
*/
|
|
17
|
+
cancel: () => void;
|
|
18
|
+
/**
|
|
19
|
+
* return is current is sleeping
|
|
20
|
+
*/
|
|
21
|
+
getSleeping: () => boolean;
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useTabOut';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param onTabOut Callback fired when a "tab out" event is detected.
|
|
3
|
+
*/
|
|
4
|
+
export declare const useTabOut: (onTabOut: (e: React.FocusEvent<HTMLDivElement>) => void) => {
|
|
5
|
+
tabOutHandler: {
|
|
6
|
+
onKeyDown: (e: React.KeyboardEvent<HTMLDivElement>) => void;
|
|
7
|
+
onKeyUp: (e: React.KeyboardEvent<HTMLDivElement>) => void;
|
|
8
|
+
onBlur: (e: React.FocusEvent<HTMLDivElement>) => void;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal hook to detect if the component is running in a test runner environment
|
|
3
|
+
* Used by Storybook stories to disable network requests and animations during testing
|
|
4
|
+
* @returns {boolean} true if running in test runner (headless browser), false otherwise
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare const useTestRunnerDetection: () => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useThrottle';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ThrottleSettings } from 'lodash';
|
|
2
|
+
/**
|
|
3
|
+
* provide a throttle method for throttle method
|
|
4
|
+
* @param fn method for throttle
|
|
5
|
+
* @param throttleTime throttle timeout value, default is `200`ms
|
|
6
|
+
* @param options throttle setting, default is `{trailing: true, leading: true}`, detail see lodash
|
|
7
|
+
*/
|
|
8
|
+
export declare const useThrottle: <F extends (...args: any[]) => any>(fn: F, throttleTime?: number, options?: ThrottleSettings | undefined) => import("lodash").DebouncedFunc<F>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useTimeout';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useTouchMouseEvent';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { MouseEventHandler, TouchEventHandler } from 'react';
|
|
2
|
+
import { RefOrElementOrCallback } from '../../utils';
|
|
3
|
+
export interface UseTouchMouseEvent<T> extends Partial<UseTouchMouseOutputEvent<T>> {
|
|
4
|
+
onTouchEnd?: (event: React.TouchEvent<T>,
|
|
5
|
+
/**
|
|
6
|
+
* when set insideRef, that will also emit the state of host reference contain pointer element when action stop
|
|
7
|
+
*/
|
|
8
|
+
isInside?: boolean) => void;
|
|
9
|
+
onMouseUp?: (event: React.MouseEvent<T, globalThis.MouseEvent>,
|
|
10
|
+
/**
|
|
11
|
+
* when set insideRef, that will also emit the state of host reference contain pointer element when action stop
|
|
12
|
+
*/
|
|
13
|
+
isInside?: boolean) => void;
|
|
14
|
+
}
|
|
15
|
+
export interface UseTouchMouseOutputEvent<T> {
|
|
16
|
+
onMouseUp: MouseEventHandler<T>;
|
|
17
|
+
onMouseDown: MouseEventHandler<T>;
|
|
18
|
+
onTouchEnd: TouchEventHandler<T>;
|
|
19
|
+
onTouchStart: TouchEventHandler<T>;
|
|
20
|
+
}
|
|
21
|
+
export interface UseTouchMouseEventOptions<T extends HTMLElement> {
|
|
22
|
+
/**
|
|
23
|
+
* when set that elementRef, event will bring with leave state when `touchend` and `mouseup`
|
|
24
|
+
*
|
|
25
|
+
* stop action event in browser default can be trigger when `touchend`, `mouseup` outside target element,
|
|
26
|
+
* set that host ref to make sure `touchend`, `mouseup` event only trigger when release inside target element
|
|
27
|
+
*/
|
|
28
|
+
actionRef?: RefOrElementOrCallback<T>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Provide a utils for switch trigger touch event or mouse event between different device
|
|
32
|
+
*
|
|
33
|
+
* - Trigger `touch` event in `touch support` device
|
|
34
|
+
* - onTouchStart
|
|
35
|
+
* - onTouchEnd
|
|
36
|
+
* - Trigger `mouse` event in `non touch support` device
|
|
37
|
+
* - onMouseDown
|
|
38
|
+
* - onMouseUp
|
|
39
|
+
*
|
|
40
|
+
* ### Once that is touch support device, that mouse event will never can be trigger
|
|
41
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Touch_events/Supporting_both_TouchEvent_and_MouseEvent
|
|
42
|
+
*
|
|
43
|
+
* Event order:
|
|
44
|
+
* - touchstart
|
|
45
|
+
* - Zero or more touchmove events, depending on movement of the finger(s)
|
|
46
|
+
* - touchend
|
|
47
|
+
* - mousemove
|
|
48
|
+
* - mousedown
|
|
49
|
+
* - mouseup
|
|
50
|
+
* - click
|
|
51
|
+
*/
|
|
52
|
+
export declare const useTouchMouseEvent: <T extends HTMLElement = HTMLElement>({ onMouseDown: onMouseDownArg, onMouseUp: onMouseUpArg, onTouchStart: onTouchStartArg, onTouchEnd: onTouchEndArg, }: UseTouchMouseEvent<T>, { actionRef }?: UseTouchMouseEventOptions<T>) => UseTouchMouseOutputEvent<T>;
|
|
53
|
+
/**
|
|
54
|
+
* check is element equal or contains target element
|
|
55
|
+
*/
|
|
56
|
+
export declare const isElmEqualOrContain: (sourceTarget: RefOrElementOrCallback, containTarget: RefOrElementOrCallback) => boolean;
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare type DefaultBaseColor = {
|
|
2
|
+
primary: any;
|
|
3
|
+
secondary: any;
|
|
4
|
+
inherit: any;
|
|
5
|
+
default: any;
|
|
6
|
+
error: any;
|
|
7
|
+
/** */
|
|
8
|
+
positive: any;
|
|
9
|
+
negative: any;
|
|
10
|
+
action: any;
|
|
11
|
+
neutral: any;
|
|
12
|
+
};
|
|
13
|
+
export declare type BaseColor<T extends keyof DefaultBaseColor = 'primary' | 'secondary'> = keyof Pick<DefaultBaseColor, T>;
|
|
14
|
+
export {};
|