1- import { css , cx } from "@emotion/css " ;
1+ import cx from "classnames " ;
22import { AnimationSegment } from "lottie-web" ;
33import * as React from "react" ;
44import LottiePlayerLight from "react-lottie-player/dist/LottiePlayerLight" ;
55
66import animationData from "./animationData.json" ;
7+ import styles from "./index.module.css" ;
78import { parseUnit } from "./parseUnit" ;
89
910export declare namespace DarkModeToggle {
@@ -68,11 +69,21 @@ export const DarkModeToggle = React.memo<DarkModeToggle.Props>(
6869 < button
6970 onClick = { onToggleClick }
7071 aria-hidden = "true"
71- className = { cx ( buttonStyles ( sizeValue , sizeUnit ) , className ) }
72+ style = { {
73+ width : `${ sizeValue } ${ sizeUnit } ` ,
74+ height : `${ sizeValue * 0.5 } ${ sizeUnit } ` ,
75+ } }
76+ className = { cx ( styles . button , className ) }
7277 id = { id }
7378 >
7479 < LottiePlayerLight
75- className = { playerStyles ( isLottiePlayerMounted , sizeValue , sizeUnit ) }
80+ className = { cx ( styles . player , { [ styles [ "player--loaded" ] ] : isLottiePlayerMounted } ) }
81+ style = { {
82+ marginTop : `${ sizeValue * - 0.575 } ${ sizeUnit } ` ,
83+ marginLeft : `${ sizeValue * - 0.32 } ${ sizeUnit } ` ,
84+ width : `${ sizeValue * 1.65 } ${ sizeUnit } ` ,
85+ height : `${ sizeValue * 1.65 } ${ sizeUnit } ` ,
86+ } }
7687 loop = { false }
7788 speed = { speed }
7889 play = { playAnimation }
@@ -98,28 +109,3 @@ function arePropsEqual(prevProps: DarkModeToggle.Props, nextProps: DarkModeToggl
98109 prevProps . id === nextProps . id
99110 ) ;
100111}
101-
102- function buttonStyles ( sizeValue : number , sizeUnit : string ) : string {
103- return css ( {
104- cursor : "pointer" ,
105- overflow : "hidden" ,
106- width : `${ sizeValue } ${ sizeUnit } ` ,
107- height : `${ sizeValue * 0.5 } ${ sizeUnit } ` ,
108- appearance : "none" ,
109- border : "none" ,
110- backgroundColor : "transparent" ,
111- padding : 0 ,
112- } ) ;
113- }
114-
115- function playerStyles ( isLoaded : boolean , sizeValue : number , sizeUnit : string ) : string {
116- return css ( {
117- display : isLoaded ? "flex" : "none" ,
118- alignItems : "center" ,
119- justifyContent : "center" ,
120- marginTop : `${ sizeValue * - 0.575 } ${ sizeUnit } ` ,
121- marginLeft : `${ sizeValue * - 0.32 } ${ sizeUnit } ` ,
122- width : `${ sizeValue * 1.65 } ${ sizeUnit } ` ,
123- height : `${ sizeValue * 1.65 } ${ sizeUnit } ` ,
124- } ) ;
125- }
0 commit comments