File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change 1
1
import { Show , onMount } from 'solid-js'
2
- import { useDark } from '@/hooks'
2
+ import { useDark , useDisableTransition } from '@/hooks'
3
3
4
4
export default ( ) => {
5
5
const [ isDark , setIsDark ] = useDark ( )
6
+ const { disableTransition, removeDisableTransition } = useDisableTransition ( )
6
7
7
8
onMount ( ( ) => {
8
9
document . querySelector ( 'meta[name="theme-color"]' ) ?. setAttribute ( 'content' , isDark ( ) ? '#222222' : '#fafafa' )
9
10
} )
10
11
11
12
const handleDarkChanged = ( ) => {
13
+ disableTransition ( )
12
14
const dark = ! isDark ( )
13
15
document . querySelector ( 'meta[name="theme-color"]' ) ?. setAttribute ( 'content' , dark ? '#222222' : '#fafafa' )
14
16
setIsDark ( dark )
17
+ removeDisableTransition ( )
15
18
}
16
19
17
20
return (
Original file line number Diff line number Diff line change @@ -3,3 +3,4 @@ export * from './useCopy'
3
3
export * from './useClickOutside'
4
4
export * from './useLargeScreen'
5
5
export * from './useMobileScreen'
6
+ export * from './useDisableTransition'
Original file line number Diff line number Diff line change
1
+ export const useDisableTransition = ( ) => {
2
+ // https://paco.me/writing/disable-theme-transitions
3
+ const css = document . createElement ( 'style' )
4
+ const disableTransition = ( ) => {
5
+ css . type = 'text/css'
6
+ css . appendChild (
7
+ document . createTextNode (
8
+ `* {
9
+ -webkit-transition: none !important;
10
+ -moz-transition: none !important;
11
+ -o-transition: none !important;
12
+ -ms-transition: none !important;
13
+ transition: none !important;
14
+ }` ,
15
+ ) ,
16
+ )
17
+ document . head . appendChild ( css )
18
+ }
19
+
20
+ // Calling getComputedStyle forces the browser to redraw
21
+ const removeDisableTransition = ( ) => {
22
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
23
+ const _ = window . getComputedStyle ( css ) . opacity
24
+ document . head . removeChild ( css )
25
+ }
26
+
27
+ return {
28
+ css,
29
+ disableTransition,
30
+ removeDisableTransition,
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments