State.init({ theme: props.theme || "light", }); const dark = { bg: "#28282b", color: "#e6eaee", border: "#748094", button: { bg: "#39393c", }, }; const light = { bg: "#e3e8ef", color: "#4c5566", border: "#748094", button: { bg: "#eef2f6", }, }; const useTheme = (light, dark) => { return state.theme === "light" ? light : dark; }; const Button = styled.button` border-radius: 20px; padding-top: 5px; padding-bottom: 5px; display: flex; align-items: center; justify-content: center; border: 1px solid transparent; background-color: ${useTheme(light.bg, dark.bg)}; transition: background-color 0.1s ease-in-out; :hover { background-color: ${useTheme(light.button.bg, dark.button.bg)}; } `; const Moon = (width, height) => { const SVG = styled.svg` width: ${width} height: ${height} `; return ( <SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill={`${useTheme(light.color, dark.color)}`} > <path fillRule="evenodd" d="M7.455 2.004a.75.75 0 01.26.77 7 7 0 009.958 7.967.75.75 0 011.067.853A8.5 8.5 0 116.647 1.921a.75.75 0 01.808.083z" clipRule="evenodd" /> </SVG> ); }; const Sun = (width, height) => { const SVG = styled.svg` width: ${width} height: ${height} `; return ( <SVG xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth="1.5" stroke={`${useTheme(light.color, dark.color)}`} > <path strokeLinecap="round" strokeLinejoin="round" d="M12 3v2.25m6.364.386l-1.591 1.591M21 12h-2.25m-.386 6.364l-1.591-1.591M12 18.75V21m-4.773-4.227l-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0z" /> </SVG> ); }; return ( <> <Button onClick={props.switchTheme}> {useTheme( <Moon width={"20px"} height={"20px"} />, <Sun width={"25px"} height={"25px"} /> )} </Button> </> );