1- import { IconButton , IconButtonProps } from "@mui/material" ;
1+ import { GlobalStyles , IconButton , IconButtonProps } from "@mui/material" ;
22import { useColorScheme } from "@mui/material/styles" ;
33import LightModeIcon from "@mui/icons-material/LightMode" ;
44import BedtimeIcon from "@mui/icons-material/Bedtime" ;
@@ -7,30 +7,51 @@ export const ColourSchemeButton = (props: IconButtonProps) => {
77 const { mode, systemMode, setMode } = useColorScheme ( ) ;
88
99 const resolvedMode = mode === "system" ? systemMode : mode ;
10+ const isReady = resolvedMode === "light" || resolvedMode === "dark" ;
1011 const isDark = resolvedMode === "dark" ;
1112
1213 return (
13- < IconButton
14- aria-label = { `Colour scheme switcher: ${ resolvedMode ?? "unknown" } ` }
15- { ...props }
16- onClick = { ( event ) => {
17- setMode ( isDark ? "light" : "dark" ) ;
18- props . onClick ?.( event ) ;
19- } }
20- sx = { ( theme ) => ( {
21- ml : 1 ,
22- width : 32 ,
23- height : 32 ,
24- borderRadius : 1 ,
25- backgroundColor : theme . palette . surface . strong ,
26- color : theme . palette . text . primary ,
27- "&:hover" : {
14+ < >
15+ < GlobalStyles
16+ styles = { `
17+ html.ds-mode-changing *,
18+ html.ds-mode-changing *::before,
19+ html.ds-mode-changing *::after {
20+ transition: none !important;
21+ animation: none !important;
22+ }
23+ ` }
24+ />
25+
26+ < IconButton
27+ aria-label = { `Colour scheme switcher: ${ resolvedMode ?? "unknown" } ` }
28+ { ...props }
29+ onClick = { ( event ) => {
30+ document . documentElement . classList . add ( "ds-mode-changing" ) ;
31+
32+ setMode ( isDark ? "light" : "dark" ) ;
33+
34+ window . setTimeout ( ( ) => {
35+ document . documentElement . classList . remove ( "ds-mode-changing" ) ;
36+ } , 250 ) ;
37+
38+ props . onClick ?.( event ) ;
39+ } }
40+ sx = { ( theme ) => ( {
41+ ml : 1 ,
42+ width : 32 ,
43+ height : 32 ,
44+ borderRadius : 1 ,
2845 backgroundColor : theme . palette . surface . strong ,
29- borderColor : theme . palette . border . subtle ,
30- } ,
31- } ) }
32- >
33- { isDark ? < LightModeIcon /> : < BedtimeIcon /> }
34- </ IconButton >
46+ color : theme . palette . text . primary ,
47+ "&:hover" : {
48+ backgroundColor : theme . palette . surface . strong ,
49+ borderColor : theme . palette . border . subtle ,
50+ } ,
51+ } ) }
52+ >
53+ { isReady ? isDark ? < LightModeIcon /> : < BedtimeIcon /> : null }
54+ </ IconButton >
55+ </ >
3556 ) ;
3657} ;
0 commit comments