@reactuses/core 2.2.3 → 2.2.4
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/dist/index.cjs +36 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.mjs +35 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2784,11 +2784,47 @@ function useAsyncEffect(effect, cleanup = noop, deps) {
|
|
|
2784
2784
|
}, deps);
|
|
2785
2785
|
}
|
|
2786
2786
|
|
|
2787
|
+
const padZero = (time) => {
|
|
2788
|
+
return `${time}`.length < 2 ? `0${time}` : `${time}`;
|
|
2789
|
+
};
|
|
2790
|
+
const getHMSTime = (timeDiff) => {
|
|
2791
|
+
if (timeDiff <= 0) {
|
|
2792
|
+
return ["00", "00", "00"];
|
|
2793
|
+
}
|
|
2794
|
+
if (timeDiff > 100 * 3600) {
|
|
2795
|
+
return ["99", "59", "59"];
|
|
2796
|
+
}
|
|
2797
|
+
const hour = Math.floor(timeDiff / 3600);
|
|
2798
|
+
const minute = Math.floor((timeDiff - hour * 3600) / 60);
|
|
2799
|
+
const second = timeDiff - hour * 3600 - minute * 60;
|
|
2800
|
+
return [padZero(hour), padZero(minute), padZero(second)];
|
|
2801
|
+
};
|
|
2802
|
+
const useCountDown = (time, format = getHMSTime, callback) => {
|
|
2803
|
+
const [remainTime, setRemainTime] = React.useState(time);
|
|
2804
|
+
const [delay, setDelay] = React.useState(1e3);
|
|
2805
|
+
useInterval(() => {
|
|
2806
|
+
if (remainTime <= 0) {
|
|
2807
|
+
setDelay(null);
|
|
2808
|
+
return;
|
|
2809
|
+
}
|
|
2810
|
+
setRemainTime(remainTime - 1);
|
|
2811
|
+
}, delay);
|
|
2812
|
+
React.useEffect(() => {
|
|
2813
|
+
if (time > 0 && remainTime <= 0) {
|
|
2814
|
+
callback && callback();
|
|
2815
|
+
}
|
|
2816
|
+
}, [callback, remainTime, time]);
|
|
2817
|
+
const [hour, minute, secoud] = format(remainTime);
|
|
2818
|
+
return [hour, minute, secoud];
|
|
2819
|
+
};
|
|
2820
|
+
|
|
2821
|
+
exports.getHMSTime = getHMSTime;
|
|
2787
2822
|
exports.useActiveElement = useActiveElement;
|
|
2788
2823
|
exports.useAsyncEffect = useAsyncEffect;
|
|
2789
2824
|
exports.useClickOutside = useClickOutSide;
|
|
2790
2825
|
exports.useClipboard = useClipBorad;
|
|
2791
2826
|
exports.useControlled = useControlled;
|
|
2827
|
+
exports.useCountDown = useCountDown;
|
|
2792
2828
|
exports.useCounter = useCounter;
|
|
2793
2829
|
exports.useCustomCompareEffect = useCustomCompareEffect;
|
|
2794
2830
|
exports.useCycleList = useCycleList;
|
package/dist/index.d.ts
CHANGED
|
@@ -813,4 +813,7 @@ declare const useSticky: ({ targetElement, scrollElement, axis, nav, }: UseStick
|
|
|
813
813
|
|
|
814
814
|
declare function useAsyncEffect<T extends void>(effect: () => Promise<T> | T, cleanup?: typeof effect, deps?: DependencyList): void;
|
|
815
815
|
|
|
816
|
-
|
|
816
|
+
declare const getHMSTime: (timeDiff: number) => [string, string, string];
|
|
817
|
+
declare const useCountDown: (time: number, format?: (number: any) => [string, string, string], callback?: () => void) => readonly [string, string, string];
|
|
818
|
+
|
|
819
|
+
export { ColorScheme, Contrast, CursorState, GeneralPermissionDescriptor, IDisposable, IEvent, IEventOnce, IListener, INetworkInformation, IState, IUseNetworkState, KeyModifier, MousePressedOptions, MouseSourceType, OrientationState, RafLoopReturns, ScrollIntoViewAnimation, ScrollIntoViewParams, State, Status, Target, UseDarkOptions, UseDraggableOptions, UseElementBoundingOptions, UseEventEmitterReturn, UseFileDialogOptions, UseFpsOptions, UseFullScreenOptions, UseInfiniteScrollOptions, UseLongPressOptions, UseModifierOptions, UseScriptTagOptions, UseScrollOptions, UseStickyParams, UseTextDirectionOptions, UseTextDirectionValue, UseTimeoutFnOptions, UseVirtualListItem, UseVirtualListOptions, UseVirtualListReturn, WindowSize, getHMSTime, useActiveElement, useAsyncEffect, useClickOutSide as useClickOutside, useClipBorad as useClipboard, useControlled, useCountDown, useCounter, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useFavicon, useFileDialog, useFirstMountState, useFocus, _default$2 as useFps, useFullscreen, useGeolocation, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLongPress, _default$3 as useMediaDevices, useMediaQuery, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, _default$1 as useOnceEffect, _default as useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSticky, useTextDirection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, _default$5 as useUpdateEffect, _default$4 as useUpdateLayoutEffect, useVirtualList, useWindowScroll, useWindowSize, useWindowsFocus };
|
package/dist/index.mjs
CHANGED
|
@@ -2776,4 +2776,38 @@ function useAsyncEffect(effect, cleanup = noop, deps) {
|
|
|
2776
2776
|
}, deps);
|
|
2777
2777
|
}
|
|
2778
2778
|
|
|
2779
|
-
|
|
2779
|
+
const padZero = (time) => {
|
|
2780
|
+
return `${time}`.length < 2 ? `0${time}` : `${time}`;
|
|
2781
|
+
};
|
|
2782
|
+
const getHMSTime = (timeDiff) => {
|
|
2783
|
+
if (timeDiff <= 0) {
|
|
2784
|
+
return ["00", "00", "00"];
|
|
2785
|
+
}
|
|
2786
|
+
if (timeDiff > 100 * 3600) {
|
|
2787
|
+
return ["99", "59", "59"];
|
|
2788
|
+
}
|
|
2789
|
+
const hour = Math.floor(timeDiff / 3600);
|
|
2790
|
+
const minute = Math.floor((timeDiff - hour * 3600) / 60);
|
|
2791
|
+
const second = timeDiff - hour * 3600 - minute * 60;
|
|
2792
|
+
return [padZero(hour), padZero(minute), padZero(second)];
|
|
2793
|
+
};
|
|
2794
|
+
const useCountDown = (time, format = getHMSTime, callback) => {
|
|
2795
|
+
const [remainTime, setRemainTime] = useState(time);
|
|
2796
|
+
const [delay, setDelay] = useState(1e3);
|
|
2797
|
+
useInterval(() => {
|
|
2798
|
+
if (remainTime <= 0) {
|
|
2799
|
+
setDelay(null);
|
|
2800
|
+
return;
|
|
2801
|
+
}
|
|
2802
|
+
setRemainTime(remainTime - 1);
|
|
2803
|
+
}, delay);
|
|
2804
|
+
useEffect(() => {
|
|
2805
|
+
if (time > 0 && remainTime <= 0) {
|
|
2806
|
+
callback && callback();
|
|
2807
|
+
}
|
|
2808
|
+
}, [callback, remainTime, time]);
|
|
2809
|
+
const [hour, minute, secoud] = format(remainTime);
|
|
2810
|
+
return [hour, minute, secoud];
|
|
2811
|
+
};
|
|
2812
|
+
|
|
2813
|
+
export { getHMSTime, useActiveElement, useAsyncEffect, useClickOutSide as useClickOutside, useClipBorad as useClipboard, useControlled, useCountDown, useCounter, useCustomCompareEffect, useCycleList, useDarkMode, useDebounce, useDebounceFn, useDeepCompareEffect, useDocumentVisibility, useDraggable, useDropZone, useElementBounding, useElementSize, useElementVisibility, useEvent, useEventEmitter, useEventListener, useFavicon, useFileDialog, useFirstMountState, useFocus, useFps$1 as useFps, useFullscreen, useGeolocation, useIdle, useInfiniteScroll, useIntersectionObserver, useInterval, useIsomorphicLayoutEffect, useKeyModifier, useLatest, useLocalStorage, useLongPress, useMediaDevices$1 as useMediaDevices, useMediaQuery, useMount, useMountedState, useMouse, useMousePressed, useMutationObserver, useNetwork, useObjectUrl, useOnceEffect, useOnceLayoutEffect, useOnline, useOrientation, usePageLeave, usePermission, usePreferredColorScheme, usePreferredContrast, usePreferredDark, usePrevious, useRafFn, useRafState, useReducedMotion, useResizeObserver, useScriptTag, useScroll, useScrollIntoView, useScrollLock, useSessionStorage, useSticky, useTextDirection, useThrottle, useThrottleFn, useTimeout, useTimeoutFn, useTitle, useToggle, useUnmount, useUpdate, useUpdateEffect, useUpdateLayoutEffect, useVirtualList, useWindowScroll, useWindowSize, useWindowsFocus };
|