-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract transition code in a separate hook. Add documentation.
- Loading branch information
Alexandru Bereghici
committed
Feb 2, 2024
1 parent
6fd7b86
commit 57c2998
Showing
6 changed files
with
75 additions
and
34 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
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,19 +1,23 @@ | ||
[data-theme='dark'] { | ||
background-color: #000; | ||
color: white; | ||
transition: background-color 2s ease; | ||
} | ||
|
||
[data-theme='light'] { | ||
background-color: #f2f2f2; | ||
color: black; | ||
transition: background-color 2s ease; | ||
} | ||
|
||
.dark { | ||
background-color: #000; | ||
color: white; | ||
transition: background-color 2s ease; | ||
} | ||
|
||
.light { | ||
background-color: #f2f2f2; | ||
color: black; | ||
transition: background-color 2s ease; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import {useCallback} from 'react' | ||
|
||
function withoutTransition(callback: Function) { | ||
const css = document.createElement('style') | ||
css.appendChild( | ||
document.createTextNode( | ||
`* { | ||
-webkit-transition: none !important; | ||
-moz-transition: none !important; | ||
-o-transition: none !important; | ||
-ms-transition: none !important; | ||
transition: none !important; | ||
}`, | ||
), | ||
) | ||
document.head.appendChild(css) | ||
|
||
callback() | ||
|
||
setTimeout(() => { | ||
// Calling getComputedStyle forces the browser to redraw | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const _ = window.getComputedStyle(css).transition | ||
document.head.removeChild(css) | ||
}, 0) | ||
} | ||
|
||
export function useCorrectCssTransition({ | ||
disableTransitions = false, | ||
}: {disableTransitions?: boolean} = {}) { | ||
return useCallback( | ||
(callback: Function) => { | ||
if (disableTransitions) { | ||
withoutTransition(() => { | ||
callback() | ||
}) | ||
} else { | ||
callback() | ||
} | ||
}, | ||
[disableTransitions], | ||
) | ||
} |
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 |
---|---|---|
|
@@ -1514,7 +1514,7 @@ | |
source-map-support "^0.5.21" | ||
stream-slice "^0.1.2" | ||
|
||
"@remix-run/react@latest": | ||
"@remix-run/react@1.12.0", "@remix-run/react@latest": | ||
version "1.12.0" | ||
resolved "https://registry.yarnpkg.com/@remix-run/react/-/react-1.12.0.tgz#7ad27e7d152b0980ef09ac851f849cc445a9e51f" | ||
integrity sha512-BokbMOILGJvUvwOsTXAUrucvfFz/SBKVgSHke2+89DZIU7H2Z1UWe5t8wRTfjQnfnSH2tAXCF0QxmVpo1GQ3dg== | ||
|
@@ -1538,7 +1538,7 @@ | |
express "^4.17.1" | ||
morgan "^1.10.0" | ||
|
||
"@remix-run/[email protected]", "@remix-run/server-runtime@latest": | ||
"@remix-run/[email protected]": | ||
version "1.12.0" | ||
resolved "https://registry.yarnpkg.com/@remix-run/server-runtime/-/server-runtime-1.12.0.tgz#a2072c2e88b948b2a657993574cad01d42cf8cd4" | ||
integrity sha512-7I0165Ns/ffPfCEfuiqD58lMderTn2s/sew1xJ34ONa21mG/7+5T7diHIgxKST8rS3816JPmlwSqUaHgwbmO6Q== | ||
|