-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
468 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,12 @@ jobs: | |
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit | ||
fetch-depth: 0 # a full history is required for pull request analysis | ||
ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit | ||
fetch-depth: 0 # a full history is required for pull request analysis | ||
- name: 'Qodana Scan' | ||
uses: JetBrains/[email protected] | ||
with: | ||
pr-mode: false | ||
env: | ||
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN_1824326538 }} | ||
QODANA_ENDPOINT: 'https://qodana.cloud' | ||
QODANA_ENDPOINT: 'https://qodana.cloud' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
const useBodyScrollLock = () => { | ||
React.useLayoutEffect(() => { | ||
const originalStyle = window.getComputedStyle(document.body).overflow; | ||
document.body.style.overflow = 'hidden'; | ||
return () => (document.body.style.overflow = originalStyle); | ||
}, []); | ||
}; | ||
const originalStyle = window.getComputedStyle(document.body).overflow | ||
document.body.style.overflow = 'hidden' | ||
return () => (document.body.style.overflow = originalStyle) | ||
}, []) | ||
} | ||
|
||
export default useBodyScrollLock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useState, useEffect, RefObject } from 'react' | ||
Check warning on line 1 in src/components/hooks/useElementViewportPosition/index.jsx
|
||
|
||
const useElementViewportPosition = (ref = null, offset = 0) => { | ||
const [position, setPosition] = useState([0, 0]) | ||
|
||
useEffect(() => { | ||
const update = () => { | ||
if (!ref || !ref.current) return | ||
const pageHeight = document.body.scrollHeight | ||
const start = ref.current.offsetTop | ||
const end = start + ref.current.offsetHeight | ||
|
||
setPosition([(start + offset) / pageHeight, (end + offset) / pageHeight]) | ||
} | ||
|
||
update() | ||
|
||
document.addEventListener('resize', update) | ||
|
||
return () => { | ||
document.removeEventListener('resize', update) | ||
} | ||
}, [offset, ref]) | ||
|
||
return { position } | ||
} | ||
|
||
export default useElementViewportPosition |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,44 @@ | ||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
const useInViewport = (triggerOnce = false, threshold = 0, rootMargin="0px" ) => { | ||
const inViewRef = useRef(null); | ||
const [inViewport, setInViewport] = useState(false); | ||
const observer = useRef(null); | ||
import { useEffect, useRef, useState } from 'react' | ||
|
||
const useInViewport = (triggerOnce = false, threshold = 0, rootMargin = '0px') => { | ||
const inViewRef = useRef(null) | ||
const [inViewport, setInViewport] = useState(false) | ||
const observer = useRef(null) | ||
|
||
useEffect(() => { | ||
const targetElement = elementRef.current; | ||
if (!targetElement) return; | ||
observer.current = new IntersectionObserver((entries) => { | ||
const targetElement = elementRef.current | ||
if (!targetElement) return | ||
observer.current = new IntersectionObserver( | ||
(entries) => { | ||
entries.forEach((entry) => { | ||
if (entry.isIntersecting && entry.intersectionRatio >= threshold) { | ||
setInViewport(true); | ||
if (triggerOnce) { | ||
observer.current.disconnect() | ||
} | ||
} else { | ||
setInViewport(false); | ||
if (entry.isIntersecting && entry.intersectionRatio >= threshold) { | ||
setInViewport(true) | ||
if (triggerOnce) { | ||
observer.current.disconnect() | ||
} | ||
}); | ||
}, {threshold, rootMargin}); | ||
} else { | ||
setInViewport(false) | ||
} | ||
}) | ||
}, | ||
{ threshold, rootMargin } | ||
) | ||
|
||
if (inViewRef.current) { | ||
observer.current.observe(inViewRef.current); | ||
observer.current.observe(inViewRef.current) | ||
} | ||
|
||
return () => { | ||
if (inViewRef.current) { | ||
observer.current.unobserve(inViewRef.current); | ||
} | ||
}; | ||
}, [threshold, triggerOnce, rootMargin]); | ||
if (inViewRef.current) { | ||
observer.current.unobserve(inViewRef.current) | ||
} | ||
} | ||
}, [threshold, triggerOnce, rootMargin]) | ||
|
||
return { | ||
inViewRef, | ||
inViewport | ||
}; | ||
}; | ||
return { | ||
inViewRef, | ||
inViewport, | ||
} | ||
} | ||
|
||
export default useInViewport; | ||
export default useInViewport |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
const useKeyPress = targetKey => { | ||
const [keyPressed, setKeyPressed] = React.useState(false); | ||
const useKeyPress = (targetKey) => { | ||
const [keyPressed, setKeyPressed] = React.useState(false) | ||
|
||
const downHandler = ({ key }) => { | ||
if (key === targetKey) setKeyPressed(true); | ||
}; | ||
if (key === targetKey) setKeyPressed(true) | ||
} | ||
|
||
const upHandler = ({ key }) => { | ||
if (key === targetKey) setKeyPressed(false); | ||
}; | ||
if (key === targetKey) setKeyPressed(false) | ||
} | ||
|
||
React.useEffect(() => { | ||
window.addEventListener('keydown', downHandler); | ||
window.addEventListener('keyup', upHandler); | ||
window.addEventListener('keydown', downHandler) | ||
window.addEventListener('keyup', upHandler) | ||
|
||
return () => { | ||
window.removeEventListener('keydown', downHandler); | ||
window.removeEventListener('keyup', upHandler); | ||
}; | ||
}, []); | ||
window.removeEventListener('keydown', downHandler) | ||
window.removeEventListener('keyup', upHandler) | ||
} | ||
}, []) | ||
|
||
return keyPressed; | ||
}; | ||
return keyPressed | ||
} | ||
|
||
export default useKeyPress |
Oops, something went wrong.