@toptal/picasso-utils 1.0.1-alpha-fx-4861-find-missing-deep-imports-in-staff-portal-77646e396.4080 → 1.0.1-alpha-fx-4861-find-missing-deep-imports-in-staff-portal-25389459e.4083
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-package/tsconfig.tsbuildinfo +1 -0
- package/package.json +5 -9
- package/src/index.ts +1 -0
- package/src/utils/Breakpoints/story/Breakpoints.example.tsx +49 -0
- package/src/utils/Breakpoints/story/MediaQueries.example.tsx +18 -0
- package/src/utils/Breakpoints/story/index.jsx +60 -0
- package/src/utils/Breakpoints/story/useBreakpoint.example.tsx +17 -0
- package/src/utils/Breakpoints/story/useScreens.example.tsx +60 -0
- package/src/utils/Colors/index.ts +2 -0
- package/src/utils/Colors/story/Default.example.tsx +59 -0
- package/src/utils/Colors/story/HowToUse.example.tsx +14 -0
- package/src/utils/Colors/story/index.jsx +21 -0
- package/src/utils/Formatters/format-amount.ts +34 -0
- package/src/utils/Formatters/index.ts +3 -0
- package/src/utils/Formatters/story/amount.example.tsx +63 -0
- package/src/utils/Formatters/story/index.jsx +16 -0
- package/src/utils/Formatters/test.ts +102 -0
- package/src/utils/Gradients/index.ts +2 -0
- package/src/utils/Gradients/story/Default.example.tsx +30 -0
- package/src/utils/Gradients/story/HowToUse.example.tsx +26 -0
- package/src/utils/Gradients/story/index.jsx +26 -0
- package/src/utils/Modal/__snapshots__/test.tsx.snap +209 -0
- package/src/utils/Modal/index.ts +2 -0
- package/src/utils/Modal/modal-manager.ts +27 -0
- package/src/utils/Modal/test.tsx +86 -0
- package/src/utils/Modal/use-modal.tsx +17 -0
- package/src/utils/Shadows/story/Default.example.tsx +45 -0
- package/src/utils/Shadows/story/HowToUse.example.tsx +19 -0
- package/src/utils/Shadows/story/index.jsx +19 -0
- package/src/utils/Transitions/Rotate180/Rotate180.tsx +44 -0
- package/src/utils/Transitions/Rotate180/__snapshots__/test.tsx.snap +29 -0
- package/src/utils/Transitions/Rotate180/index.ts +4 -0
- package/src/utils/Transitions/Rotate180/story/Default.example.tsx +22 -0
- package/src/utils/Transitions/Rotate180/styles.ts +11 -0
- package/src/utils/Transitions/Rotate180/test.tsx +26 -0
- package/src/utils/Transitions/index.ts +2 -0
- package/src/utils/Transitions/story/index.jsx +13 -0
- package/src/utils/Utils/story/Browser.example.tsx +28 -0
- package/src/utils/Utils/story/Colors.example.tsx +29 -0
- package/src/utils/Utils/story/Generic.example.tsx +30 -0
- package/src/utils/Utils/story/React.example.tsx +32 -0
- package/src/utils/Utils/story/Strings.example.tsx +33 -0
- package/src/utils/__tests__/use-page-scroll-lock.test.tsx +117 -0
- package/src/utils/capitalize.ts +1 -0
- package/src/utils/constants.ts +1 -0
- package/src/utils/disable-unsupported-props.ts +45 -0
- package/src/utils/forward-ref.ts +38 -0
- package/src/utils/get-name-initials.ts +15 -0
- package/src/utils/get-react-node-text-content.ts +36 -0
- package/src/utils/index.ts +92 -0
- package/src/utils/is-boolean.ts +3 -0
- package/src/utils/is-number.ts +3 -0
- package/src/utils/is-overflown.ts +20 -0
- package/src/utils/is-pointer-device.ts +9 -0
- package/src/utils/is-string.ts +3 -0
- package/src/utils/is-substring.ts +4 -0
- package/src/utils/kebab-to-camel-case.ts +7 -0
- package/src/utils/loader-palette.ts +9 -0
- package/src/utils/monads.ts +1 -0
- package/src/utils/noop.ts +1 -0
- package/src/utils/sum.ts +4 -0
- package/src/utils/test.tsx +372 -0
- package/src/utils/to-title-case.ts +14 -0
- package/src/utils/unsafe-error-log.ts +5 -0
- package/src/utils/use-combined-refs.ts +26 -0
- package/src/utils/use-deprecation-warnings.ts +56 -0
- package/src/utils/use-multiple-forward-refs.ts +37 -0
- package/src/utils/use-page-scroll-lock.ts +64 -0
- package/src/utils/use-safe-state.ts +25 -0
- package/src/utils/use-width-of.ts +26 -0
- package/src/utils/useBoolean/index.ts +1 -0
- package/src/utils/useBoolean/test.tsx +25 -0
- package/src/utils/useBoolean/use-boolean.ts +30 -0
- package/src/utils/useInterval/index.ts +1 -0
- package/src/utils/useInterval/test.ts +61 -0
- package/src/utils/useInterval/use-interval.ts +46 -0
- package/src/utils/useMouseEnter/index.ts +1 -0
- package/src/utils/useMouseEnter/test.ts +51 -0
- package/src/utils/useMouseEnter/use-mouse-enter.ts +30 -0
- package/src/utils/useOnScreen/index.ts +1 -0
- package/src/utils/useOnScreen/use-on-screen.ts +50 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { renderHook } from '@testing-library/react-hooks'
|
|
2
|
+
|
|
3
|
+
import useInterval from './use-interval'
|
|
4
|
+
|
|
5
|
+
jest.useFakeTimers()
|
|
6
|
+
|
|
7
|
+
describe('useInterval', () => {
|
|
8
|
+
it('calls the callback on each tick', () => {
|
|
9
|
+
const callback = jest.fn()
|
|
10
|
+
|
|
11
|
+
renderHook(() => useInterval({ callback, delay: 100 }))
|
|
12
|
+
jest.advanceTimersByTime(1000)
|
|
13
|
+
expect(callback).toHaveBeenCalledTimes(10)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
describe('when `isPause` parameter changes its state', () => {
|
|
17
|
+
it('pauses and resumes the interval', () => {
|
|
18
|
+
const callback = jest.fn()
|
|
19
|
+
const { rerender } = renderHook(props => useInterval(props), {
|
|
20
|
+
initialProps: { callback, delay: 100, isPaused: false },
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
jest.advanceTimersByTime(500)
|
|
24
|
+
expect(callback).toHaveBeenCalledTimes(5)
|
|
25
|
+
|
|
26
|
+
rerender({ callback, delay: 100, isPaused: true })
|
|
27
|
+
jest.advanceTimersByTime(500)
|
|
28
|
+
|
|
29
|
+
expect(callback).toHaveBeenCalledTimes(5)
|
|
30
|
+
|
|
31
|
+
rerender({ callback, delay: 100, isPaused: false })
|
|
32
|
+
jest.advanceTimersByTime(500)
|
|
33
|
+
|
|
34
|
+
expect(callback).toHaveBeenCalledTimes(10)
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
describe('component unmounts', () => {
|
|
38
|
+
it('cleans up the interval', () => {
|
|
39
|
+
const callback = jest.fn()
|
|
40
|
+
const { unmount } = renderHook(() =>
|
|
41
|
+
useInterval({ callback, delay: 100 })
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
jest.advanceTimersByTime(500)
|
|
45
|
+
unmount()
|
|
46
|
+
jest.advanceTimersByTime(500)
|
|
47
|
+
expect(callback).toHaveBeenCalledTimes(5)
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
describe('when initialized with `isPaused` set to true', () => {
|
|
52
|
+
it('does not call the callback when isPaused is true', () => {
|
|
53
|
+
const callback = jest.fn()
|
|
54
|
+
|
|
55
|
+
renderHook(() => useInterval({ callback, delay: 100, isPaused: true }))
|
|
56
|
+
|
|
57
|
+
jest.advanceTimersByTime(1000)
|
|
58
|
+
expect(callback).toHaveBeenCalledTimes(0)
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
})
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react'
|
|
2
|
+
|
|
3
|
+
interface UseIntervalOptions {
|
|
4
|
+
callback: () => void
|
|
5
|
+
delay: number
|
|
6
|
+
isPaused?: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
10
|
+
|
|
11
|
+
const useInterval = ({
|
|
12
|
+
callback,
|
|
13
|
+
delay,
|
|
14
|
+
isPaused = false,
|
|
15
|
+
}: UseIntervalOptions) => {
|
|
16
|
+
const intervalId = useRef<NodeJS.Timeout>()
|
|
17
|
+
|
|
18
|
+
const pauseInterval = useCallback(() => {
|
|
19
|
+
if (intervalId.current) {
|
|
20
|
+
clearInterval(intervalId.current!)
|
|
21
|
+
intervalId.current = undefined
|
|
22
|
+
}
|
|
23
|
+
}, [])
|
|
24
|
+
|
|
25
|
+
const resumeInterval = useCallback(() => {
|
|
26
|
+
if (!intervalId.current) {
|
|
27
|
+
intervalId.current = setInterval(callback, delay)
|
|
28
|
+
}
|
|
29
|
+
}, [callback, delay])
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (isPaused) {
|
|
33
|
+
pauseInterval()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!isPaused) {
|
|
37
|
+
resumeInterval()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return () => {
|
|
41
|
+
pauseInterval()
|
|
42
|
+
}
|
|
43
|
+
}, [isPaused, pauseInterval, resumeInterval])
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default useInterval
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './use-mouse-enter'
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { renderHook, act } from '@testing-library/react-hooks'
|
|
2
|
+
|
|
3
|
+
import useMouseEnter from './use-mouse-enter'
|
|
4
|
+
|
|
5
|
+
describe('useMouseOver', () => {
|
|
6
|
+
describe('when mouse enters and leaves element', () => {
|
|
7
|
+
it('should update isMouseOver state', () => {
|
|
8
|
+
const ref = { current: document.createElement('div') }
|
|
9
|
+
const { result } = renderHook(() => useMouseEnter(ref))
|
|
10
|
+
|
|
11
|
+
expect(result.current).toBe(false)
|
|
12
|
+
|
|
13
|
+
// Simulate mouse enter
|
|
14
|
+
act(() => {
|
|
15
|
+
ref.current.dispatchEvent(new MouseEvent('mouseenter'))
|
|
16
|
+
})
|
|
17
|
+
expect(result.current).toBe(true)
|
|
18
|
+
|
|
19
|
+
// Simulate mouse leave
|
|
20
|
+
act(() => {
|
|
21
|
+
ref.current.dispatchEvent(new MouseEvent('mouseleave'))
|
|
22
|
+
})
|
|
23
|
+
expect(result.current).toBe(false)
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
describe('when unmount is triggered', () => {
|
|
28
|
+
it('should remove event listeners', () => {
|
|
29
|
+
const ref = { current: document.createElement('div') }
|
|
30
|
+
const { result, unmount } = renderHook(() => useMouseEnter(ref))
|
|
31
|
+
|
|
32
|
+
expect(result.current).toBe(false)
|
|
33
|
+
|
|
34
|
+
// Simulate mouse enter
|
|
35
|
+
act(() => {
|
|
36
|
+
ref.current.dispatchEvent(new MouseEvent('mouseenter'))
|
|
37
|
+
})
|
|
38
|
+
expect(result.current).toBe(true)
|
|
39
|
+
|
|
40
|
+
// Unmount the hook
|
|
41
|
+
unmount()
|
|
42
|
+
|
|
43
|
+
// Simulate mouse leave
|
|
44
|
+
act(() => {
|
|
45
|
+
ref.current.dispatchEvent(new MouseEvent('mouseleave'))
|
|
46
|
+
})
|
|
47
|
+
// Expect isMouseOver to still be true, since event listeners should have been removed on unmount
|
|
48
|
+
expect(result.current).toBe(true)
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { RefObject } from 'react'
|
|
2
|
+
import { useEffect, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
const useMouseEnter = <T extends HTMLElement>(ref: RefObject<T>): boolean => {
|
|
5
|
+
const [isMouseOver, setIsMouseOver] = useState<boolean>(false)
|
|
6
|
+
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const handleMouseHover = (event: MouseEvent) => {
|
|
9
|
+
setIsMouseOver(event.type === 'mouseenter')
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const node = ref.current
|
|
13
|
+
|
|
14
|
+
if (node) {
|
|
15
|
+
node.addEventListener('mouseenter', handleMouseHover)
|
|
16
|
+
node.addEventListener('mouseleave', handleMouseHover)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return () => {
|
|
20
|
+
if (node) {
|
|
21
|
+
node.removeEventListener('mouseenter', handleMouseHover)
|
|
22
|
+
node.removeEventListener('mouseleave', handleMouseHover)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}, [ref])
|
|
26
|
+
|
|
27
|
+
return isMouseOver
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default useMouseEnter
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './use-on-screen'
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useEffect, useState, useMemo } from 'react'
|
|
2
|
+
|
|
3
|
+
interface UseOnScreenProps {
|
|
4
|
+
ref: React.RefObject<HTMLElement>
|
|
5
|
+
root?: React.RefObject<HTMLElement>
|
|
6
|
+
rootMargin?: string
|
|
7
|
+
threshold?: number | number[]
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const useOnScreen = ({
|
|
11
|
+
ref,
|
|
12
|
+
root,
|
|
13
|
+
rootMargin,
|
|
14
|
+
threshold,
|
|
15
|
+
}: UseOnScreenProps) => {
|
|
16
|
+
const [isIntersecting, setIntersecting] = useState(false)
|
|
17
|
+
|
|
18
|
+
const observer = useMemo(
|
|
19
|
+
() =>
|
|
20
|
+
new IntersectionObserver(
|
|
21
|
+
([entry]) => {
|
|
22
|
+
setIntersecting(entry.isIntersecting)
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
root: root?.current,
|
|
26
|
+
rootMargin,
|
|
27
|
+
threshold,
|
|
28
|
+
}
|
|
29
|
+
),
|
|
30
|
+
[root, rootMargin, threshold]
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
const element = ref.current
|
|
35
|
+
|
|
36
|
+
if (!element) {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
observer.observe(element)
|
|
41
|
+
|
|
42
|
+
return () => {
|
|
43
|
+
observer.unobserve(element)
|
|
44
|
+
}
|
|
45
|
+
}, [observer, ref])
|
|
46
|
+
|
|
47
|
+
return isIntersecting
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default useOnScreen
|