@oneplatformdev/hooks 0.1.0-9 → 0.1.0-90
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/CHANGELOG.md +316 -0
- package/package.json +14 -19
- package/{dist/useEventListener → useEventListener}/useEventListener.d.ts +4 -2
- package/{dist/useEventListener → useEventListener}/useEventListener.d.ts.map +1 -1
- package/{dist/useHover → useHover}/useHover.d.ts +1 -1
- package/{dist/useHover → useHover}/useHover.d.ts.map +1 -1
- package/{dist/useOnClickOutside → useOnClickOutside}/useOnClickOutside.d.ts +1 -1
- package/{dist/useOnClickOutside → useOnClickOutside}/useOnClickOutside.d.ts.map +1 -1
- package/{dist/useResizeObserver → useResizeObserver}/useResizeObserver.d.ts +1 -1
- package/{dist/useResizeObserver → useResizeObserver}/useResizeObserver.d.ts.map +1 -1
- package/.babelrc +0 -12
- package/dist/CHANGELOG.md +0 -19
- package/dist/LICENSE +0 -21
- package/dist/README.md +0 -7
- package/dist/package.json +0 -68
- package/node_modules/@types/lodash.debounce/LICENSE +0 -21
- package/node_modules/@types/lodash.debounce/README.md +0 -23
- package/node_modules/@types/lodash.debounce/index.d.ts +0 -4
- package/node_modules/@types/lodash.debounce/package.json +0 -32
- package/node_modules/@types/react/LICENSE +0 -21
- package/node_modules/@types/react/README.md +0 -15
- package/node_modules/@types/react/canary.d.ts +0 -35
- package/node_modules/@types/react/compiler-runtime.d.ts +0 -4
- package/node_modules/@types/react/experimental.d.ts +0 -125
- package/node_modules/@types/react/global.d.ts +0 -160
- package/node_modules/@types/react/index.d.ts +0 -4206
- package/node_modules/@types/react/jsx-dev-runtime.d.ts +0 -45
- package/node_modules/@types/react/jsx-runtime.d.ts +0 -36
- package/node_modules/@types/react/package.json +0 -210
- package/node_modules/@types/react/ts5.0/canary.d.ts +0 -35
- package/node_modules/@types/react/ts5.0/experimental.d.ts +0 -125
- package/node_modules/@types/react/ts5.0/global.d.ts +0 -160
- package/node_modules/@types/react/ts5.0/index.d.ts +0 -4193
- package/node_modules/@types/react/ts5.0/jsx-dev-runtime.d.ts +0 -44
- package/node_modules/@types/react/ts5.0/jsx-runtime.d.ts +0 -35
- package/node_modules/@types/react/ts5.0/v18/global.d.ts +0 -160
- package/node_modules/@types/react/ts5.0/v18/index.d.ts +0 -4543
- package/node_modules/@types/react/ts5.0/v18/jsx-dev-runtime.d.ts +0 -45
- package/node_modules/@types/react/ts5.0/v18/jsx-runtime.d.ts +0 -36
- package/node_modules/@types/react/ts5.0/v18/ts5.0/global.d.ts +0 -160
- package/node_modules/@types/react/ts5.0/v18/ts5.0/index.d.ts +0 -4530
- package/node_modules/@types/react/ts5.0/v18/ts5.0/jsx-dev-runtime.d.ts +0 -44
- package/node_modules/@types/react/ts5.0/v18/ts5.0/jsx-runtime.d.ts +0 -35
- package/src/index.ts +0 -36
- package/src/useBoolean/index.ts +0 -1
- package/src/useBoolean/useBoolean.ts +0 -50
- package/src/useClickAnyWhere/index.ts +0 -1
- package/src/useClickAnyWhere/useClickAnyWhere.ts +0 -22
- package/src/useCopyToClipboard/index.ts +0 -1
- package/src/useCopyToClipboard/useCopyToClipboard.ts +0 -58
- package/src/useCountdown/index.ts +0 -1
- package/src/useCountdown/useCountdown.ts +0 -102
- package/src/useCounter/index.ts +0 -1
- package/src/useCounter/useCounter.ts +0 -52
- package/src/useDarkMode/index.ts +0 -1
- package/src/useDarkMode/useDarkMode.ts +0 -92
- package/src/useDebounceCallback/index.ts +0 -2
- package/src/useDebounceCallback/useDebounceCallback.ts +0 -115
- package/src/useDebounceValue/index.ts +0 -1
- package/src/useDebounceValue/useDebounceValue.ts +0 -67
- package/src/useDocumentTitle/index.ts +0 -1
- package/src/useDocumentTitle/useDocumentTitle.ts +0 -43
- package/src/useEventCallback/index.ts +0 -1
- package/src/useEventCallback/useEventCallback.ts +0 -40
- package/src/useEventListener/index.ts +0 -1
- package/src/useEventListener/useEventListener.ts +0 -121
- package/src/useHover/index.ts +0 -1
- package/src/useHover/useHover.ts +0 -37
- package/src/useIntersectionObserver/index.ts +0 -1
- package/src/useIntersectionObserver/useIntersectionObserver.ts +0 -186
- package/src/useInterval/index.ts +0 -1
- package/src/useInterval/useInterval.ts +0 -43
- package/src/useIsClient/index.ts +0 -1
- package/src/useIsClient/useIsClient.ts +0 -22
- package/src/useIsMobile/index.ts +0 -2
- package/src/useIsMobile/types.ts +0 -3
- package/src/useIsMobile/useIsMobile.tsx +0 -23
- package/src/useIsMounted/index.ts +0 -1
- package/src/useIsMounted/useIsMounted.ts +0 -15
- package/src/useIsomorphicLayoutEffect/index.ts +0 -1
- package/src/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.ts +0 -17
- package/src/useLocalStorage/index.ts +0 -1
- package/src/useLocalStorage/useLocalStorage.ts +0 -191
- package/src/useLockBody/index.ts +0 -1
- package/src/useLockBody/useLockBody.tsx +0 -12
- package/src/useMap/index.ts +0 -1
- package/src/useMap/useMap.ts +0 -83
- package/src/useMediaQuery/index.ts +0 -1
- package/src/useMediaQuery/useMediaQuery.ts +0 -83
- package/src/useOnClickOutside/index.ts +0 -1
- package/src/useOnClickOutside/useOnClickOutside.ts +0 -61
- package/src/useQueryString/index.ts +0 -1
- package/src/useQueryString/useQueryString.ts +0 -26
- package/src/useReadLocalStorage/index.ts +0 -1
- package/src/useReadLocalStorage/useReadLocalStorage.ts +0 -122
- package/src/useResizeObserver/index.ts +0 -1
- package/src/useResizeObserver/useResizeObserver.ts +0 -131
- package/src/useScreen/index.ts +0 -1
- package/src/useScreen/useScreen.ts +0 -106
- package/src/useScript/index.ts +0 -1
- package/src/useScript/useScript.ts +0 -142
- package/src/useScrollLock/index.ts +0 -1
- package/src/useScrollLock/useScrollLock.ts +0 -141
- package/src/useSessionStorage/index.ts +0 -1
- package/src/useSessionStorage/useSessionStorage.ts +0 -191
- package/src/useStep/index.ts +0 -1
- package/src/useStep/useStep.ts +0 -83
- package/src/useTernaryDarkMode/index.ts +0 -1
- package/src/useTernaryDarkMode/useTernaryDarkMode.ts +0 -81
- package/src/useTimeout/index.ts +0 -1
- package/src/useTimeout/useTimeout.ts +0 -44
- package/src/useToggle/index.ts +0 -1
- package/src/useToggle/useToggle.ts +0 -30
- package/src/useUnmount/index.ts +0 -1
- package/src/useUnmount/useUnmount.ts +0 -26
- package/src/useWindowSize/index.ts +0 -1
- package/src/useWindowSize/useWindowSize.ts +0 -100
- package/tsconfig.json +0 -10
- package/tsconfig.lib.json +0 -33
- package/vite.config.ts +0 -62
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.d.ts.map → index.d.ts.map} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/useBoolean → useBoolean}/index.d.ts +0 -0
- /package/{dist/useBoolean → useBoolean}/index.d.ts.map +0 -0
- /package/{dist/useBoolean → useBoolean}/index.js +0 -0
- /package/{dist/useBoolean → useBoolean}/useBoolean.d.ts +0 -0
- /package/{dist/useBoolean → useBoolean}/useBoolean.d.ts.map +0 -0
- /package/{dist/useBoolean → useBoolean}/useBoolean.js +0 -0
- /package/{dist/useClickAnyWhere → useClickAnyWhere}/index.d.ts +0 -0
- /package/{dist/useClickAnyWhere → useClickAnyWhere}/index.d.ts.map +0 -0
- /package/{dist/useClickAnyWhere → useClickAnyWhere}/index.js +0 -0
- /package/{dist/useClickAnyWhere → useClickAnyWhere}/useClickAnyWhere.d.ts +0 -0
- /package/{dist/useClickAnyWhere → useClickAnyWhere}/useClickAnyWhere.d.ts.map +0 -0
- /package/{dist/useClickAnyWhere → useClickAnyWhere}/useClickAnyWhere.js +0 -0
- /package/{dist/useCopyToClipboard → useCopyToClipboard}/index.d.ts +0 -0
- /package/{dist/useCopyToClipboard → useCopyToClipboard}/index.d.ts.map +0 -0
- /package/{dist/useCopyToClipboard → useCopyToClipboard}/index.js +0 -0
- /package/{dist/useCopyToClipboard → useCopyToClipboard}/useCopyToClipboard.d.ts +0 -0
- /package/{dist/useCopyToClipboard → useCopyToClipboard}/useCopyToClipboard.d.ts.map +0 -0
- /package/{dist/useCopyToClipboard → useCopyToClipboard}/useCopyToClipboard.js +0 -0
- /package/{dist/useCountdown → useCountdown}/index.d.ts +0 -0
- /package/{dist/useCountdown → useCountdown}/index.d.ts.map +0 -0
- /package/{dist/useCountdown → useCountdown}/index.js +0 -0
- /package/{dist/useCountdown → useCountdown}/useCountdown.d.ts +0 -0
- /package/{dist/useCountdown → useCountdown}/useCountdown.d.ts.map +0 -0
- /package/{dist/useCountdown → useCountdown}/useCountdown.js +0 -0
- /package/{dist/useCounter → useCounter}/index.d.ts +0 -0
- /package/{dist/useCounter → useCounter}/index.d.ts.map +0 -0
- /package/{dist/useCounter → useCounter}/index.js +0 -0
- /package/{dist/useCounter → useCounter}/useCounter.d.ts +0 -0
- /package/{dist/useCounter → useCounter}/useCounter.d.ts.map +0 -0
- /package/{dist/useCounter → useCounter}/useCounter.js +0 -0
- /package/{dist/useDarkMode → useDarkMode}/index.d.ts +0 -0
- /package/{dist/useDarkMode → useDarkMode}/index.d.ts.map +0 -0
- /package/{dist/useDarkMode → useDarkMode}/index.js +0 -0
- /package/{dist/useDarkMode → useDarkMode}/useDarkMode.d.ts +0 -0
- /package/{dist/useDarkMode → useDarkMode}/useDarkMode.d.ts.map +0 -0
- /package/{dist/useDarkMode → useDarkMode}/useDarkMode.js +0 -0
- /package/{dist/useDebounceCallback → useDebounceCallback}/index.d.ts +0 -0
- /package/{dist/useDebounceCallback → useDebounceCallback}/index.d.ts.map +0 -0
- /package/{dist/useDebounceCallback → useDebounceCallback}/index.js +0 -0
- /package/{dist/useDebounceCallback → useDebounceCallback}/useDebounceCallback.d.ts +0 -0
- /package/{dist/useDebounceCallback → useDebounceCallback}/useDebounceCallback.d.ts.map +0 -0
- /package/{dist/useDebounceCallback → useDebounceCallback}/useDebounceCallback.js +0 -0
- /package/{dist/useDebounceValue → useDebounceValue}/index.d.ts +0 -0
- /package/{dist/useDebounceValue → useDebounceValue}/index.d.ts.map +0 -0
- /package/{dist/useDebounceValue → useDebounceValue}/index.js +0 -0
- /package/{dist/useDebounceValue → useDebounceValue}/useDebounceValue.d.ts +0 -0
- /package/{dist/useDebounceValue → useDebounceValue}/useDebounceValue.d.ts.map +0 -0
- /package/{dist/useDebounceValue → useDebounceValue}/useDebounceValue.js +0 -0
- /package/{dist/useDocumentTitle → useDocumentTitle}/index.d.ts +0 -0
- /package/{dist/useDocumentTitle → useDocumentTitle}/index.d.ts.map +0 -0
- /package/{dist/useDocumentTitle → useDocumentTitle}/index.js +0 -0
- /package/{dist/useDocumentTitle → useDocumentTitle}/useDocumentTitle.d.ts +0 -0
- /package/{dist/useDocumentTitle → useDocumentTitle}/useDocumentTitle.d.ts.map +0 -0
- /package/{dist/useDocumentTitle → useDocumentTitle}/useDocumentTitle.js +0 -0
- /package/{dist/useEventCallback → useEventCallback}/index.d.ts +0 -0
- /package/{dist/useEventCallback → useEventCallback}/index.d.ts.map +0 -0
- /package/{dist/useEventCallback → useEventCallback}/index.js +0 -0
- /package/{dist/useEventCallback → useEventCallback}/useEventCallback.d.ts +0 -0
- /package/{dist/useEventCallback → useEventCallback}/useEventCallback.d.ts.map +0 -0
- /package/{dist/useEventCallback → useEventCallback}/useEventCallback.js +0 -0
- /package/{dist/useEventListener → useEventListener}/index.d.ts +0 -0
- /package/{dist/useEventListener → useEventListener}/index.d.ts.map +0 -0
- /package/{dist/useEventListener → useEventListener}/index.js +0 -0
- /package/{dist/useEventListener → useEventListener}/useEventListener.js +0 -0
- /package/{dist/useHover → useHover}/index.d.ts +0 -0
- /package/{dist/useHover → useHover}/index.d.ts.map +0 -0
- /package/{dist/useHover → useHover}/index.js +0 -0
- /package/{dist/useHover → useHover}/useHover.js +0 -0
- /package/{dist/useIntersectionObserver → useIntersectionObserver}/index.d.ts +0 -0
- /package/{dist/useIntersectionObserver → useIntersectionObserver}/index.d.ts.map +0 -0
- /package/{dist/useIntersectionObserver → useIntersectionObserver}/index.js +0 -0
- /package/{dist/useIntersectionObserver → useIntersectionObserver}/useIntersectionObserver.d.ts +0 -0
- /package/{dist/useIntersectionObserver → useIntersectionObserver}/useIntersectionObserver.d.ts.map +0 -0
- /package/{dist/useIntersectionObserver → useIntersectionObserver}/useIntersectionObserver.js +0 -0
- /package/{dist/useInterval → useInterval}/index.d.ts +0 -0
- /package/{dist/useInterval → useInterval}/index.d.ts.map +0 -0
- /package/{dist/useInterval → useInterval}/index.js +0 -0
- /package/{dist/useInterval → useInterval}/useInterval.d.ts +0 -0
- /package/{dist/useInterval → useInterval}/useInterval.d.ts.map +0 -0
- /package/{dist/useInterval → useInterval}/useInterval.js +0 -0
- /package/{dist/useIsClient → useIsClient}/index.d.ts +0 -0
- /package/{dist/useIsClient → useIsClient}/index.d.ts.map +0 -0
- /package/{dist/useIsClient → useIsClient}/index.js +0 -0
- /package/{dist/useIsClient → useIsClient}/useIsClient.d.ts +0 -0
- /package/{dist/useIsClient → useIsClient}/useIsClient.d.ts.map +0 -0
- /package/{dist/useIsClient → useIsClient}/useIsClient.js +0 -0
- /package/{dist/useIsMobile → useIsMobile}/index.d.ts +0 -0
- /package/{dist/useIsMobile → useIsMobile}/index.d.ts.map +0 -0
- /package/{dist/useIsMobile → useIsMobile}/index.js +0 -0
- /package/{dist/useIsMobile → useIsMobile}/types.d.ts +0 -0
- /package/{dist/useIsMobile → useIsMobile}/types.d.ts.map +0 -0
- /package/{dist/useIsMobile → useIsMobile}/types.js +0 -0
- /package/{dist/useIsMobile → useIsMobile}/useIsMobile.d.ts +0 -0
- /package/{dist/useIsMobile → useIsMobile}/useIsMobile.d.ts.map +0 -0
- /package/{dist/useIsMobile → useIsMobile}/useIsMobile.js +0 -0
- /package/{dist/useIsMounted → useIsMounted}/index.d.ts +0 -0
- /package/{dist/useIsMounted → useIsMounted}/index.d.ts.map +0 -0
- /package/{dist/useIsMounted → useIsMounted}/index.js +0 -0
- /package/{dist/useIsMounted → useIsMounted}/useIsMounted.d.ts +0 -0
- /package/{dist/useIsMounted → useIsMounted}/useIsMounted.d.ts.map +0 -0
- /package/{dist/useIsMounted → useIsMounted}/useIsMounted.js +0 -0
- /package/{dist/useIsomorphicLayoutEffect → useIsomorphicLayoutEffect}/index.d.ts +0 -0
- /package/{dist/useIsomorphicLayoutEffect → useIsomorphicLayoutEffect}/index.d.ts.map +0 -0
- /package/{dist/useIsomorphicLayoutEffect → useIsomorphicLayoutEffect}/index.js +0 -0
- /package/{dist/useIsomorphicLayoutEffect → useIsomorphicLayoutEffect}/useIsomorphicLayoutEffect.d.ts +0 -0
- /package/{dist/useIsomorphicLayoutEffect → useIsomorphicLayoutEffect}/useIsomorphicLayoutEffect.d.ts.map +0 -0
- /package/{dist/useIsomorphicLayoutEffect → useIsomorphicLayoutEffect}/useIsomorphicLayoutEffect.js +0 -0
- /package/{dist/useLocalStorage → useLocalStorage}/index.d.ts +0 -0
- /package/{dist/useLocalStorage → useLocalStorage}/index.d.ts.map +0 -0
- /package/{dist/useLocalStorage → useLocalStorage}/index.js +0 -0
- /package/{dist/useLocalStorage → useLocalStorage}/useLocalStorage.d.ts +0 -0
- /package/{dist/useLocalStorage → useLocalStorage}/useLocalStorage.d.ts.map +0 -0
- /package/{dist/useLocalStorage → useLocalStorage}/useLocalStorage.js +0 -0
- /package/{dist/useLockBody → useLockBody}/index.d.ts +0 -0
- /package/{dist/useLockBody → useLockBody}/index.d.ts.map +0 -0
- /package/{dist/useLockBody → useLockBody}/index.js +0 -0
- /package/{dist/useLockBody → useLockBody}/useLockBody.d.ts +0 -0
- /package/{dist/useLockBody → useLockBody}/useLockBody.d.ts.map +0 -0
- /package/{dist/useLockBody → useLockBody}/useLockBody.js +0 -0
- /package/{dist/useMap → useMap}/index.d.ts +0 -0
- /package/{dist/useMap → useMap}/index.d.ts.map +0 -0
- /package/{dist/useMap → useMap}/index.js +0 -0
- /package/{dist/useMap → useMap}/useMap.d.ts +0 -0
- /package/{dist/useMap → useMap}/useMap.d.ts.map +0 -0
- /package/{dist/useMap → useMap}/useMap.js +0 -0
- /package/{dist/useMediaQuery → useMediaQuery}/index.d.ts +0 -0
- /package/{dist/useMediaQuery → useMediaQuery}/index.d.ts.map +0 -0
- /package/{dist/useMediaQuery → useMediaQuery}/index.js +0 -0
- /package/{dist/useMediaQuery → useMediaQuery}/useMediaQuery.d.ts +0 -0
- /package/{dist/useMediaQuery → useMediaQuery}/useMediaQuery.d.ts.map +0 -0
- /package/{dist/useMediaQuery → useMediaQuery}/useMediaQuery.js +0 -0
- /package/{dist/useOnClickOutside → useOnClickOutside}/index.d.ts +0 -0
- /package/{dist/useOnClickOutside → useOnClickOutside}/index.d.ts.map +0 -0
- /package/{dist/useOnClickOutside → useOnClickOutside}/index.js +0 -0
- /package/{dist/useOnClickOutside → useOnClickOutside}/useOnClickOutside.js +0 -0
- /package/{dist/useQueryString → useQueryString}/index.d.ts +0 -0
- /package/{dist/useQueryString → useQueryString}/index.d.ts.map +0 -0
- /package/{dist/useQueryString → useQueryString}/index.js +0 -0
- /package/{dist/useQueryString → useQueryString}/useQueryString.d.ts +0 -0
- /package/{dist/useQueryString → useQueryString}/useQueryString.d.ts.map +0 -0
- /package/{dist/useQueryString → useQueryString}/useQueryString.js +0 -0
- /package/{dist/useReadLocalStorage → useReadLocalStorage}/index.d.ts +0 -0
- /package/{dist/useReadLocalStorage → useReadLocalStorage}/index.d.ts.map +0 -0
- /package/{dist/useReadLocalStorage → useReadLocalStorage}/index.js +0 -0
- /package/{dist/useReadLocalStorage → useReadLocalStorage}/useReadLocalStorage.d.ts +0 -0
- /package/{dist/useReadLocalStorage → useReadLocalStorage}/useReadLocalStorage.d.ts.map +0 -0
- /package/{dist/useReadLocalStorage → useReadLocalStorage}/useReadLocalStorage.js +0 -0
- /package/{dist/useResizeObserver → useResizeObserver}/index.d.ts +0 -0
- /package/{dist/useResizeObserver → useResizeObserver}/index.d.ts.map +0 -0
- /package/{dist/useResizeObserver → useResizeObserver}/index.js +0 -0
- /package/{dist/useResizeObserver → useResizeObserver}/useResizeObserver.js +0 -0
- /package/{dist/useScreen → useScreen}/index.d.ts +0 -0
- /package/{dist/useScreen → useScreen}/index.d.ts.map +0 -0
- /package/{dist/useScreen → useScreen}/index.js +0 -0
- /package/{dist/useScreen → useScreen}/useScreen.d.ts +0 -0
- /package/{dist/useScreen → useScreen}/useScreen.d.ts.map +0 -0
- /package/{dist/useScreen → useScreen}/useScreen.js +0 -0
- /package/{dist/useScript → useScript}/index.d.ts +0 -0
- /package/{dist/useScript → useScript}/index.d.ts.map +0 -0
- /package/{dist/useScript → useScript}/index.js +0 -0
- /package/{dist/useScript → useScript}/useScript.d.ts +0 -0
- /package/{dist/useScript → useScript}/useScript.d.ts.map +0 -0
- /package/{dist/useScript → useScript}/useScript.js +0 -0
- /package/{dist/useScrollLock → useScrollLock}/index.d.ts +0 -0
- /package/{dist/useScrollLock → useScrollLock}/index.d.ts.map +0 -0
- /package/{dist/useScrollLock → useScrollLock}/index.js +0 -0
- /package/{dist/useScrollLock → useScrollLock}/useScrollLock.d.ts +0 -0
- /package/{dist/useScrollLock → useScrollLock}/useScrollLock.d.ts.map +0 -0
- /package/{dist/useScrollLock → useScrollLock}/useScrollLock.js +0 -0
- /package/{dist/useSessionStorage → useSessionStorage}/index.d.ts +0 -0
- /package/{dist/useSessionStorage → useSessionStorage}/index.d.ts.map +0 -0
- /package/{dist/useSessionStorage → useSessionStorage}/index.js +0 -0
- /package/{dist/useSessionStorage → useSessionStorage}/useSessionStorage.d.ts +0 -0
- /package/{dist/useSessionStorage → useSessionStorage}/useSessionStorage.d.ts.map +0 -0
- /package/{dist/useSessionStorage → useSessionStorage}/useSessionStorage.js +0 -0
- /package/{dist/useStep → useStep}/index.d.ts +0 -0
- /package/{dist/useStep → useStep}/index.d.ts.map +0 -0
- /package/{dist/useStep → useStep}/index.js +0 -0
- /package/{dist/useStep → useStep}/useStep.d.ts +0 -0
- /package/{dist/useStep → useStep}/useStep.d.ts.map +0 -0
- /package/{dist/useStep → useStep}/useStep.js +0 -0
- /package/{dist/useTernaryDarkMode → useTernaryDarkMode}/index.d.ts +0 -0
- /package/{dist/useTernaryDarkMode → useTernaryDarkMode}/index.d.ts.map +0 -0
- /package/{dist/useTernaryDarkMode → useTernaryDarkMode}/index.js +0 -0
- /package/{dist/useTernaryDarkMode → useTernaryDarkMode}/useTernaryDarkMode.d.ts +0 -0
- /package/{dist/useTernaryDarkMode → useTernaryDarkMode}/useTernaryDarkMode.d.ts.map +0 -0
- /package/{dist/useTernaryDarkMode → useTernaryDarkMode}/useTernaryDarkMode.js +0 -0
- /package/{dist/useTimeout → useTimeout}/index.d.ts +0 -0
- /package/{dist/useTimeout → useTimeout}/index.d.ts.map +0 -0
- /package/{dist/useTimeout → useTimeout}/index.js +0 -0
- /package/{dist/useTimeout → useTimeout}/useTimeout.d.ts +0 -0
- /package/{dist/useTimeout → useTimeout}/useTimeout.d.ts.map +0 -0
- /package/{dist/useTimeout → useTimeout}/useTimeout.js +0 -0
- /package/{dist/useToggle → useToggle}/index.d.ts +0 -0
- /package/{dist/useToggle → useToggle}/index.d.ts.map +0 -0
- /package/{dist/useToggle → useToggle}/index.js +0 -0
- /package/{dist/useToggle → useToggle}/useToggle.d.ts +0 -0
- /package/{dist/useToggle → useToggle}/useToggle.d.ts.map +0 -0
- /package/{dist/useToggle → useToggle}/useToggle.js +0 -0
- /package/{dist/useUnmount → useUnmount}/index.d.ts +0 -0
- /package/{dist/useUnmount → useUnmount}/index.d.ts.map +0 -0
- /package/{dist/useUnmount → useUnmount}/index.js +0 -0
- /package/{dist/useUnmount → useUnmount}/useUnmount.d.ts +0 -0
- /package/{dist/useUnmount → useUnmount}/useUnmount.d.ts.map +0 -0
- /package/{dist/useUnmount → useUnmount}/useUnmount.js +0 -0
- /package/{dist/useWindowSize → useWindowSize}/index.d.ts +0 -0
- /package/{dist/useWindowSize → useWindowSize}/index.d.ts.map +0 -0
- /package/{dist/useWindowSize → useWindowSize}/index.js +0 -0
- /package/{dist/useWindowSize → useWindowSize}/useWindowSize.d.ts +0 -0
- /package/{dist/useWindowSize → useWindowSize}/useWindowSize.d.ts.map +0 -0
- /package/{dist/useWindowSize → useWindowSize}/useWindowSize.js +0 -0
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import type { Dispatch, SetStateAction } from 'react'
|
|
4
|
-
|
|
5
|
-
import { useEventCallback } from '../useEventCallback'
|
|
6
|
-
import { useEventListener } from '../useEventListener'
|
|
7
|
-
|
|
8
|
-
declare global {
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
|
|
10
|
-
interface WindowEventMap {
|
|
11
|
-
'session-storage': CustomEvent
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Represents the options for customizing the behavior of serialization and deserialization.
|
|
17
|
-
* @template T - The type of the state to be stored in session storage.
|
|
18
|
-
*/
|
|
19
|
-
type UseSessionStorageOptions<T> = {
|
|
20
|
-
/** A function to serialize the value before storing it. */
|
|
21
|
-
serializer?: (value: T) => string
|
|
22
|
-
/** A function to deserialize the stored value. */
|
|
23
|
-
deserializer?: (value: string) => T
|
|
24
|
-
/**
|
|
25
|
-
* If `true` (default), the hook will initialize reading the session storage. In SSR, you should set it to `false`, returning the initial value initially.
|
|
26
|
-
* @default true
|
|
27
|
-
*/
|
|
28
|
-
initializeWithValue?: boolean
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const IS_SERVER = typeof window === 'undefined'
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Custom hook that uses the [`sessionStorage API`](https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage) to persist state across page reloads.
|
|
35
|
-
* @template T - The type of the state to be stored in session storage.
|
|
36
|
-
* @param {string} key - The key under which the value will be stored in session storage.
|
|
37
|
-
* @param {T | (() => T)} initialValue - The initial value of the state or a function that returns the initial value.
|
|
38
|
-
* @param {?UseSessionStorageOptions<T>} [options] - Options for customizing the behavior of serialization and deserialization (optional).
|
|
39
|
-
* @returns {[T, Dispatch<SetStateAction<T>>, () => void]} A tuple containing the stored value, a function to set the value and a function to remove the key from storage.
|
|
40
|
-
* @public
|
|
41
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-session-storage)
|
|
42
|
-
* @example
|
|
43
|
-
* ```tsx
|
|
44
|
-
* const [count, setCount, removeCount] = useSessionStorage('count', 0);
|
|
45
|
-
* // Access the `count` value, the `setCount` function to update it and `removeCount` function to remove the key from storage.
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
export function useSessionStorage<T>(
|
|
49
|
-
key: string,
|
|
50
|
-
initialValue: T | (() => T),
|
|
51
|
-
options: UseSessionStorageOptions<T> = {},
|
|
52
|
-
): [T, Dispatch<SetStateAction<T>>, () => void] {
|
|
53
|
-
const { initializeWithValue = true } = options
|
|
54
|
-
|
|
55
|
-
const serializer = useCallback<(value: T) => string>(
|
|
56
|
-
value => {
|
|
57
|
-
if (options.serializer) {
|
|
58
|
-
return options.serializer(value)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return JSON.stringify(value)
|
|
62
|
-
},
|
|
63
|
-
[options],
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
const deserializer = useCallback<(value: string) => T>(
|
|
67
|
-
value => {
|
|
68
|
-
if (options.deserializer) {
|
|
69
|
-
return options.deserializer(value)
|
|
70
|
-
}
|
|
71
|
-
// Support 'undefined' as a value
|
|
72
|
-
if (value === 'undefined') {
|
|
73
|
-
return undefined as unknown as T
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const defaultValue =
|
|
77
|
-
initialValue instanceof Function ? initialValue() : initialValue
|
|
78
|
-
|
|
79
|
-
let parsed: unknown
|
|
80
|
-
try {
|
|
81
|
-
parsed = JSON.parse(value)
|
|
82
|
-
} catch (error) {
|
|
83
|
-
console.error('Error parsing JSON:', error)
|
|
84
|
-
return defaultValue // Return initialValue if parsing fails
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return parsed as T
|
|
88
|
-
},
|
|
89
|
-
[options, initialValue],
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
// Get from session storage then
|
|
93
|
-
// parse stored json or return initialValue
|
|
94
|
-
const readValue = useCallback((): T => {
|
|
95
|
-
const initialValueToUse =
|
|
96
|
-
initialValue instanceof Function ? initialValue() : initialValue
|
|
97
|
-
|
|
98
|
-
// Prevent build error "window is undefined" but keep working
|
|
99
|
-
if (IS_SERVER) {
|
|
100
|
-
return initialValueToUse
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
const raw = window.sessionStorage.getItem(key)
|
|
105
|
-
return raw ? deserializer(raw) : initialValueToUse
|
|
106
|
-
} catch (error) {
|
|
107
|
-
console.warn(`Error reading sessionStorage key “${key}”:`, error)
|
|
108
|
-
return initialValueToUse
|
|
109
|
-
}
|
|
110
|
-
}, [initialValue, key, deserializer])
|
|
111
|
-
|
|
112
|
-
const [storedValue, setStoredValue] = useState(() => {
|
|
113
|
-
if (initializeWithValue) {
|
|
114
|
-
return readValue()
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return initialValue instanceof Function ? initialValue() : initialValue
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
// Return a wrapped version of useState's setter function that ...
|
|
121
|
-
// ... persists the new value to sessionStorage.
|
|
122
|
-
const setValue: Dispatch<SetStateAction<T>> = useEventCallback(value => {
|
|
123
|
-
// Prevent build error "window is undefined" but keeps working
|
|
124
|
-
if (IS_SERVER) {
|
|
125
|
-
console.warn(
|
|
126
|
-
`Tried setting sessionStorage key “${key}” even though environment is not a client`,
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
try {
|
|
131
|
-
// Allow value to be a function so we have the same API as useState
|
|
132
|
-
const newValue = value instanceof Function ? value(readValue()) : value
|
|
133
|
-
|
|
134
|
-
// Save to session storage
|
|
135
|
-
window.sessionStorage.setItem(key, serializer(newValue))
|
|
136
|
-
|
|
137
|
-
// Save state
|
|
138
|
-
setStoredValue(newValue)
|
|
139
|
-
|
|
140
|
-
// We dispatch a custom event so every similar useSessionStorage hook is notified
|
|
141
|
-
window.dispatchEvent(new StorageEvent('session-storage', { key }))
|
|
142
|
-
} catch (error) {
|
|
143
|
-
console.warn(`Error setting sessionStorage key “${key}”:`, error)
|
|
144
|
-
}
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
const removeValue = useEventCallback(() => {
|
|
148
|
-
// Prevent build error "window is undefined" but keeps working
|
|
149
|
-
if (IS_SERVER) {
|
|
150
|
-
console.warn(
|
|
151
|
-
`Tried removing sessionStorage key “${key}” even though environment is not a client`,
|
|
152
|
-
)
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const defaultValue =
|
|
156
|
-
initialValue instanceof Function ? initialValue() : initialValue
|
|
157
|
-
|
|
158
|
-
// Remove the key from session storage
|
|
159
|
-
window.sessionStorage.removeItem(key)
|
|
160
|
-
|
|
161
|
-
// Save state with default value
|
|
162
|
-
setStoredValue(defaultValue)
|
|
163
|
-
|
|
164
|
-
// We dispatch a custom event so every similar useSessionStorage hook is notified
|
|
165
|
-
window.dispatchEvent(new StorageEvent('session-storage', { key }))
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
useEffect(() => {
|
|
169
|
-
setStoredValue(readValue())
|
|
170
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
171
|
-
}, [key])
|
|
172
|
-
|
|
173
|
-
const handleStorageChange = useCallback(
|
|
174
|
-
(event: StorageEvent | CustomEvent) => {
|
|
175
|
-
if ((event as StorageEvent).key && (event as StorageEvent).key !== key) {
|
|
176
|
-
return
|
|
177
|
-
}
|
|
178
|
-
setStoredValue(readValue())
|
|
179
|
-
},
|
|
180
|
-
[key, readValue],
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
// this only works for other documents, not the current one
|
|
184
|
-
useEventListener('storage', handleStorageChange)
|
|
185
|
-
|
|
186
|
-
// this is a custom event, triggered in writeValueToSessionStorage
|
|
187
|
-
// See: useSessionStorage()
|
|
188
|
-
useEventListener('session-storage', handleStorageChange)
|
|
189
|
-
|
|
190
|
-
return [storedValue, setValue, removeValue]
|
|
191
|
-
}
|
package/src/useStep/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useStep'
|
package/src/useStep/useStep.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { useCallback, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import type { Dispatch, SetStateAction } from 'react'
|
|
4
|
-
|
|
5
|
-
/** Represents the second element of the output of the `useStep` hook. */
|
|
6
|
-
type UseStepActions = {
|
|
7
|
-
/** Go to the next step in the process. */
|
|
8
|
-
goToNextStep: () => void
|
|
9
|
-
/** Go to the previous step in the process. */
|
|
10
|
-
goToPrevStep: () => void
|
|
11
|
-
/** Reset the step to the initial step. */
|
|
12
|
-
reset: () => void
|
|
13
|
-
/** Check if the next step is available. */
|
|
14
|
-
canGoToNextStep: boolean
|
|
15
|
-
/** Check if the previous step is available. */
|
|
16
|
-
canGoToPrevStep: boolean
|
|
17
|
-
/** Set the current step to a specific value. */
|
|
18
|
-
setStep: Dispatch<SetStateAction<number>>
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type SetStepCallbackType = (step: number | ((step: number) => number)) => void
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Custom hook that manages and navigates between steps in a multi-step process.
|
|
25
|
-
* @param {number} maxStep - The maximum step in the process.
|
|
26
|
-
* @returns {[number, UseStepActions]} An tuple containing the current step and helper functions for navigating steps.
|
|
27
|
-
* @public
|
|
28
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-step)
|
|
29
|
-
* @example
|
|
30
|
-
* ```tsx
|
|
31
|
-
* const [currentStep, { goToNextStep, goToPrevStep, reset, canGoToNextStep, canGoToPrevStep, setStep }] = useStep(3);
|
|
32
|
-
* // Access and use the current step and provided helper functions.
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export function useStep(maxStep: number): [number, UseStepActions] {
|
|
36
|
-
const [currentStep, setCurrentStep] = useState(1)
|
|
37
|
-
|
|
38
|
-
const canGoToNextStep = currentStep + 1 <= maxStep
|
|
39
|
-
const canGoToPrevStep = currentStep - 1 > 0
|
|
40
|
-
|
|
41
|
-
const setStep = useCallback<SetStepCallbackType>(
|
|
42
|
-
step => {
|
|
43
|
-
// Allow value to be a function so we have the same API as useState
|
|
44
|
-
const newStep = step instanceof Function ? step(currentStep) : step
|
|
45
|
-
|
|
46
|
-
if (newStep >= 1 && newStep <= maxStep) {
|
|
47
|
-
setCurrentStep(newStep)
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
throw new Error('Step not valid')
|
|
52
|
-
},
|
|
53
|
-
[maxStep, currentStep],
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
const goToNextStep = useCallback(() => {
|
|
57
|
-
if (canGoToNextStep) {
|
|
58
|
-
setCurrentStep(step => step + 1)
|
|
59
|
-
}
|
|
60
|
-
}, [canGoToNextStep])
|
|
61
|
-
|
|
62
|
-
const goToPrevStep = useCallback(() => {
|
|
63
|
-
if (canGoToPrevStep) {
|
|
64
|
-
setCurrentStep(step => step - 1)
|
|
65
|
-
}
|
|
66
|
-
}, [canGoToPrevStep])
|
|
67
|
-
|
|
68
|
-
const reset = useCallback(() => {
|
|
69
|
-
setCurrentStep(1)
|
|
70
|
-
}, [])
|
|
71
|
-
|
|
72
|
-
return [
|
|
73
|
-
currentStep,
|
|
74
|
-
{
|
|
75
|
-
goToNextStep,
|
|
76
|
-
goToPrevStep,
|
|
77
|
-
canGoToNextStep,
|
|
78
|
-
canGoToPrevStep,
|
|
79
|
-
setStep,
|
|
80
|
-
reset,
|
|
81
|
-
},
|
|
82
|
-
]
|
|
83
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useTernaryDarkMode'
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import type { Dispatch, SetStateAction } from 'react'
|
|
2
|
-
|
|
3
|
-
import { useLocalStorage } from '../useLocalStorage'
|
|
4
|
-
import { useMediaQuery } from '../useMediaQuery'
|
|
5
|
-
|
|
6
|
-
const COLOR_SCHEME_QUERY = '(prefers-color-scheme: dark)'
|
|
7
|
-
const LOCAL_STORAGE_KEY = 'usehooks-ts-ternary-dark-mode'
|
|
8
|
-
|
|
9
|
-
/** Ternary dark mode options. */
|
|
10
|
-
export type TernaryDarkMode = 'system' | 'dark' | 'light'
|
|
11
|
-
|
|
12
|
-
/** Options for the `useTernaryDarkMode` hook. */
|
|
13
|
-
export type TernaryDarkModeOptions = {
|
|
14
|
-
/**
|
|
15
|
-
* The default value for the dark mode.
|
|
16
|
-
* @default 'system'
|
|
17
|
-
*/
|
|
18
|
-
defaultValue?: TernaryDarkMode
|
|
19
|
-
/**
|
|
20
|
-
* The key for storing dark mode preference in local storage.
|
|
21
|
-
* @default 'usehooks-ts-ternary-dark-mode'
|
|
22
|
-
*/
|
|
23
|
-
localStorageKey?: string
|
|
24
|
-
/**
|
|
25
|
-
* If `true` (default), the hook will initialize reading `localStorage`. In SSR, you should set it to `false`, returning default values initially.
|
|
26
|
-
* @default true
|
|
27
|
-
*/
|
|
28
|
-
initializeWithValue?: boolean
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Represents the return type of the `useTernaryDarkMode` hook. */
|
|
32
|
-
export type TernaryDarkModeReturn = {
|
|
33
|
-
/** The current state of the dark mode. */
|
|
34
|
-
isDarkMode: boolean
|
|
35
|
-
/** The current state of the dark mode. */
|
|
36
|
-
ternaryDarkMode: TernaryDarkMode
|
|
37
|
-
/** A function to set the dark mode state. */
|
|
38
|
-
setTernaryDarkMode: Dispatch<SetStateAction<TernaryDarkMode>>
|
|
39
|
-
/** A function to toggle the dark mode state. */
|
|
40
|
-
toggleTernaryDarkMode: () => void
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Custom hook that manages ternary (system, dark, light) dark mode with local storage support.
|
|
45
|
-
* @param {?TernaryDarkModeOptions | string} [options] - Options or the local storage key for the hook.
|
|
46
|
-
* @returns {TernaryDarkModeReturn} An object containing the dark mode state and helper functions.
|
|
47
|
-
* @public
|
|
48
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-ternary-dark-mode)
|
|
49
|
-
* @example
|
|
50
|
-
* ```tsx
|
|
51
|
-
* const { isDarkMode, ternaryDarkMode, setTernaryDarkMode, toggleTernaryDarkMode } = useTernaryDarkMode({ defaultValue: 'dark' });
|
|
52
|
-
* // Access and use the dark mode state and provided helper functions.
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
export function useTernaryDarkMode({
|
|
56
|
-
defaultValue = 'system',
|
|
57
|
-
localStorageKey = LOCAL_STORAGE_KEY,
|
|
58
|
-
initializeWithValue = true,
|
|
59
|
-
}: TernaryDarkModeOptions = {}): TernaryDarkModeReturn {
|
|
60
|
-
const isDarkOS = useMediaQuery(COLOR_SCHEME_QUERY, { initializeWithValue })
|
|
61
|
-
const [mode, setMode] = useLocalStorage(localStorageKey, defaultValue, {
|
|
62
|
-
initializeWithValue,
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
const isDarkMode = mode === 'dark' || (mode === 'system' && isDarkOS)
|
|
66
|
-
|
|
67
|
-
const toggleTernaryDarkMode = () => {
|
|
68
|
-
const modes: TernaryDarkMode[] = ['light', 'system', 'dark']
|
|
69
|
-
setMode((prevMode): TernaryDarkMode => {
|
|
70
|
-
const nextIndex = (modes.indexOf(prevMode) + 1) % modes.length
|
|
71
|
-
return modes[nextIndex]
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
isDarkMode,
|
|
77
|
-
ternaryDarkMode: mode,
|
|
78
|
-
setTernaryDarkMode: setMode,
|
|
79
|
-
toggleTernaryDarkMode,
|
|
80
|
-
}
|
|
81
|
-
}
|
package/src/useTimeout/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useTimeout'
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react'
|
|
2
|
-
|
|
3
|
-
import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Custom hook that handles timeouts in React components using the [`setTimeout API`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout).
|
|
7
|
-
* @param {() => void} callback - The function to be executed when the timeout elapses.
|
|
8
|
-
* @param {number | null} delay - The duration (in milliseconds) for the timeout. Set to `null` to clear the timeout.
|
|
9
|
-
* @returns {void} This hook does not return anything.
|
|
10
|
-
* @public
|
|
11
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-timeout)
|
|
12
|
-
* @example
|
|
13
|
-
* ```tsx
|
|
14
|
-
* // Usage of useTimeout hook
|
|
15
|
-
* useTimeout(() => {
|
|
16
|
-
* // Code to be executed after the specified delay
|
|
17
|
-
* }, 1000); // Set a timeout of 1000 milliseconds (1 second)
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export function useTimeout(callback: () => void, delay: number | null): void {
|
|
21
|
-
const savedCallback = useRef(callback)
|
|
22
|
-
|
|
23
|
-
// Remember the latest callback if it changes.
|
|
24
|
-
useIsomorphicLayoutEffect(() => {
|
|
25
|
-
savedCallback.current = callback
|
|
26
|
-
}, [callback])
|
|
27
|
-
|
|
28
|
-
// Set up the timeout.
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
// Don't schedule if no delay is specified.
|
|
31
|
-
// Note: 0 is a valid value for delay.
|
|
32
|
-
if (!delay && delay !== 0) {
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const id = setTimeout(() => {
|
|
37
|
-
savedCallback.current()
|
|
38
|
-
}, delay)
|
|
39
|
-
|
|
40
|
-
return () => {
|
|
41
|
-
clearTimeout(id)
|
|
42
|
-
}
|
|
43
|
-
}, [delay])
|
|
44
|
-
}
|
package/src/useToggle/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useToggle'
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { useCallback, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import type { Dispatch, SetStateAction } from 'react'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Custom hook that manages a boolean toggle state in React components.
|
|
7
|
-
* @param {boolean} [defaultValue] - The initial value for the toggle state.
|
|
8
|
-
* @returns {[boolean, () => void, Dispatch<SetStateAction<boolean>>]} A tuple containing the current state,
|
|
9
|
-
* a function to toggle the state, and a function to set the state explicitly.
|
|
10
|
-
* @public
|
|
11
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-toggle)
|
|
12
|
-
* @example
|
|
13
|
-
* ```tsx
|
|
14
|
-
* const [isToggled, toggle, setToggle] = useToggle(); // Initial value is false
|
|
15
|
-
* // OR
|
|
16
|
-
* const [isToggled, toggle, setToggle] = useToggle(true); // Initial value is true
|
|
17
|
-
* // Use isToggled in your component, toggle to switch the state, setToggle to set the state explicitly.
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export function useToggle(
|
|
21
|
-
defaultValue?: boolean,
|
|
22
|
-
): [boolean, () => void, Dispatch<SetStateAction<boolean>>] {
|
|
23
|
-
const [value, setValue] = useState(!!defaultValue)
|
|
24
|
-
|
|
25
|
-
const toggle = useCallback(() => {
|
|
26
|
-
setValue(x => !x)
|
|
27
|
-
}, [])
|
|
28
|
-
|
|
29
|
-
return [value, toggle, setValue]
|
|
30
|
-
}
|
package/src/useUnmount/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useUnmount'
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Custom hook that runs a cleanup function when the component is unmounted.
|
|
5
|
-
* @param {() => void} func - The cleanup function to be executed on unmount.
|
|
6
|
-
* @public
|
|
7
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-unmount)
|
|
8
|
-
* @example
|
|
9
|
-
* ```tsx
|
|
10
|
-
* useUnmount(() => {
|
|
11
|
-
* // Cleanup logic here
|
|
12
|
-
* });
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
export function useUnmount(func: () => void) {
|
|
16
|
-
const funcRef = useRef(func)
|
|
17
|
-
|
|
18
|
-
funcRef.current = func
|
|
19
|
-
|
|
20
|
-
useEffect(
|
|
21
|
-
() => () => {
|
|
22
|
-
funcRef.current()
|
|
23
|
-
},
|
|
24
|
-
[],
|
|
25
|
-
)
|
|
26
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useWindowSize'
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import { useDebounceCallback } from '../useDebounceCallback'
|
|
4
|
-
import { useEventListener } from '../useEventListener'
|
|
5
|
-
import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Represent the dimension of the window.
|
|
9
|
-
* @template T - The type of the dimension (number or undefined).
|
|
10
|
-
*/
|
|
11
|
-
type WindowSize<T extends number | undefined = number | undefined> = {
|
|
12
|
-
/** The width of the window. */
|
|
13
|
-
width: T
|
|
14
|
-
/** The height of the window. */
|
|
15
|
-
height: T
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Hook options.
|
|
20
|
-
* @template InitializeWithValue - If `true` (default), the hook will initialize reading the window size. In SSR, you should set it to `false`, returning `undefined` initially.
|
|
21
|
-
*/
|
|
22
|
-
type UseWindowSizeOptions<InitializeWithValue extends boolean | undefined> = {
|
|
23
|
-
/**
|
|
24
|
-
* If `true` (default), the hook will initialize reading the window size. In SSR, you should set it to `false`, returning `undefined` initially.
|
|
25
|
-
* @default true
|
|
26
|
-
*/
|
|
27
|
-
initializeWithValue: InitializeWithValue
|
|
28
|
-
/**
|
|
29
|
-
* The delay in milliseconds before the state is updated (disabled by default for retro-compatibility).
|
|
30
|
-
* @default undefined
|
|
31
|
-
*/
|
|
32
|
-
debounceDelay?: number
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const IS_SERVER = typeof window === 'undefined'
|
|
36
|
-
|
|
37
|
-
// SSR version of useWindowSize.
|
|
38
|
-
export function useWindowSize(options: UseWindowSizeOptions<false>): WindowSize
|
|
39
|
-
// CSR version of useWindowSize.
|
|
40
|
-
export function useWindowSize(
|
|
41
|
-
options?: Partial<UseWindowSizeOptions<true>>,
|
|
42
|
-
): WindowSize<number>
|
|
43
|
-
/**
|
|
44
|
-
* Custom hook that tracks the size of the window.
|
|
45
|
-
* @param {?UseWindowSizeOptions} [options] - The options for customizing the behavior of the hook (optional).
|
|
46
|
-
* @returns {object} An object containing the width and height of the window.
|
|
47
|
-
* @public
|
|
48
|
-
* @see [Documentation](https://usehooks-ts.com/react-hook/use-window-size)
|
|
49
|
-
* @example
|
|
50
|
-
* ```tsx
|
|
51
|
-
* const { width = 0, height = 0 } = useWindowSize();
|
|
52
|
-
* console.log(`Window size: ${width} x ${height}`);
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
export function useWindowSize(
|
|
56
|
-
options: Partial<UseWindowSizeOptions<boolean>> = {},
|
|
57
|
-
): WindowSize | WindowSize<number> {
|
|
58
|
-
let { initializeWithValue = true } = options
|
|
59
|
-
if (IS_SERVER) {
|
|
60
|
-
initializeWithValue = false
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const [windowSize, setWindowSize] = useState<WindowSize>(() => {
|
|
64
|
-
if (initializeWithValue) {
|
|
65
|
-
return {
|
|
66
|
-
width: window.innerWidth,
|
|
67
|
-
height: window.innerHeight,
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
width: undefined,
|
|
72
|
-
height: undefined,
|
|
73
|
-
}
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
const debouncedSetWindowSize = useDebounceCallback(
|
|
77
|
-
setWindowSize,
|
|
78
|
-
options.debounceDelay,
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
function handleSize() {
|
|
82
|
-
const setSize = options.debounceDelay
|
|
83
|
-
? debouncedSetWindowSize
|
|
84
|
-
: setWindowSize
|
|
85
|
-
|
|
86
|
-
setSize({
|
|
87
|
-
width: window.innerWidth,
|
|
88
|
-
height: window.innerHeight,
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
useEventListener('resize', handleSize)
|
|
93
|
-
|
|
94
|
-
// Set size at the first client-side load
|
|
95
|
-
useIsomorphicLayoutEffect(() => {
|
|
96
|
-
handleSize()
|
|
97
|
-
}, [])
|
|
98
|
-
|
|
99
|
-
return windowSize
|
|
100
|
-
}
|
package/tsconfig.json
DELETED
package/tsconfig.lib.json
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "dist",
|
|
5
|
-
"types": [
|
|
6
|
-
"node",
|
|
7
|
-
"@nx/react/typings/cssmodule.d.ts",
|
|
8
|
-
"@nx/react/typings/image.d.ts",
|
|
9
|
-
"vite/client"
|
|
10
|
-
],
|
|
11
|
-
"rootDir": "src",
|
|
12
|
-
"jsx": "react-jsx",
|
|
13
|
-
"tsBuildInfoFile": "dist/tsconfig.lib.tsbuildinfo"
|
|
14
|
-
},
|
|
15
|
-
"exclude": [
|
|
16
|
-
"out-tsc",
|
|
17
|
-
"dist",
|
|
18
|
-
"**/*.spec.ts",
|
|
19
|
-
"**/*.test.ts",
|
|
20
|
-
"**/*.spec.tsx",
|
|
21
|
-
"**/*.test.tsx",
|
|
22
|
-
"**/*.spec.js",
|
|
23
|
-
"**/*.test.js",
|
|
24
|
-
"**/*.spec.jsx",
|
|
25
|
-
"**/*.test.jsx"
|
|
26
|
-
],
|
|
27
|
-
"include": [
|
|
28
|
-
"src/**/*.js",
|
|
29
|
-
"src/**/*.jsx",
|
|
30
|
-
"src/**/*.ts",
|
|
31
|
-
"src/**/*.tsx"
|
|
32
|
-
]
|
|
33
|
-
}
|
package/vite.config.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/// <reference types='vitest' />
|
|
2
|
-
import { defineConfig } from 'vite';
|
|
3
|
-
import react from '@vitejs/plugin-react';
|
|
4
|
-
import dts from 'vite-plugin-dts';
|
|
5
|
-
import * as path from 'path';
|
|
6
|
-
import { globSync } from 'glob';
|
|
7
|
-
import { viteStaticCopy } from 'vite-plugin-static-copy';
|
|
8
|
-
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
9
|
-
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
|
|
10
|
-
|
|
11
|
-
export default defineConfig(() => ({
|
|
12
|
-
root: __dirname,
|
|
13
|
-
cacheDir: '../../node_modules/.vite/packages/hooks',
|
|
14
|
-
plugins: [
|
|
15
|
-
react(),
|
|
16
|
-
nxViteTsPaths(),
|
|
17
|
-
nxCopyAssetsPlugin(['*.md', 'LICENSE', 'package.json']),
|
|
18
|
-
dts({
|
|
19
|
-
entryRoot: 'src',
|
|
20
|
-
tsconfigPath: path.join(__dirname, 'tsconfig.lib.json')
|
|
21
|
-
})
|
|
22
|
-
],
|
|
23
|
-
build: {
|
|
24
|
-
outDir: './dist',
|
|
25
|
-
emptyOutDir: true,
|
|
26
|
-
reportCompressedSize: true,
|
|
27
|
-
commonjsOptions: {
|
|
28
|
-
transformMixedEsModules: true,
|
|
29
|
-
},
|
|
30
|
-
sourcemap: false,
|
|
31
|
-
target: 'es2022',
|
|
32
|
-
lib: {
|
|
33
|
-
name: '@oneplatformdev/hooks',
|
|
34
|
-
formats: [ 'es' as const ],
|
|
35
|
-
entry: {
|
|
36
|
-
index: path.resolve(__dirname, 'src/index.ts'),
|
|
37
|
-
...Object.fromEntries(
|
|
38
|
-
globSync('src/**/*.{ts,tsx}').map((filename) => {
|
|
39
|
-
return [
|
|
40
|
-
path.relative(
|
|
41
|
-
'src',
|
|
42
|
-
filename.slice(0, filename.length - path.extname(filename).length)
|
|
43
|
-
),
|
|
44
|
-
path.resolve(__dirname, filename),
|
|
45
|
-
]
|
|
46
|
-
})
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
rollupOptions: {
|
|
51
|
-
external: [ 'react', 'react-dom', 'react/jsx-runtime', "lodash.debounce" ],
|
|
52
|
-
output: {
|
|
53
|
-
preserveModules: true,
|
|
54
|
-
preserveModulesRoot: 'src',
|
|
55
|
-
globals: {
|
|
56
|
-
react: 'React',
|
|
57
|
-
'react-dom': 'ReactDOM',
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
}));
|
|
File without changes
|
|
File without changes
|