Skip to content

Commit

Permalink
New icons for theme button.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecao committed Sep 20, 2020
1 parent eb9f044 commit 92d1fdd
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 52 deletions.
1 change: 1 addition & 0 deletions assets/moon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/sun.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion assets/toggle-off.svg

This file was deleted.

1 change: 0 additions & 1 deletion assets/toggle-on.svg

This file was deleted.

38 changes: 30 additions & 8 deletions components/settings/ThemeButton.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
import React from 'react';
import { useTransition, animated } from 'react-spring';
import Button from 'components/common/Button';
import useTheme from 'hooks/useTheme';
import ToggleOn from 'assets/toggle-on.svg';
import ToggleOff from 'assets/toggle-off.svg';
import Sun from 'assets/sun.svg';
import Moon from 'assets/moon.svg';
import styles from './ThemeButton.module.css';
import Icon from '../common/Icon';

export default function ThemeButton() {
const [theme, setTheme] = useTheme();

const transitions = useTransition(theme, theme => theme, {
from: {
opacity: 0,
transform: `translateY(${theme === 'light' ? '-20px' : '20px'}) scale(0.5)`,
},
enter: { opacity: 1, transform: 'translateY(0px) scale(1)' },
leave: {
opacity: 0,
transform: `translateY(${theme === 'light' ? '20px' : '-20px'}) scale(0.5)`,
},
});

function handleClick() {
setTheme(theme === 'light' ? 'dark' : 'light');
}

return (
<Button
icon={theme === 'light' ? <ToggleOff /> : <ToggleOn />}
size="large"
variant="light"
onClick={handleClick}
/>
<Button className={styles.button} variant="light" onClick={handleClick}>
{transitions.map(({ item, key, props }) =>
item === 'light' ? (
<animated.div key={key} style={props}>
<Icon icon={<Sun />} />
</animated.div>
) : (
<animated.div key={key} style={props}>
<Icon icon={<Moon />} />
</animated.div>
),
)}
</Button>
);
}
42 changes: 1 addition & 41 deletions components/settings/ThemeButton.module.css
Original file line number Diff line number Diff line change
@@ -1,43 +1,3 @@
.icon {
.button svg {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
line-height: 16px;
}

.sun {
height: 16px;
width: 16px;
border-radius: 100%;
background: var(--gray900);
z-index: 1;
}

.moon {
height: 16px;
width: 16px;
border-radius: 100%;
background: var(--gray900);
}

.moon:before {
content: '';
position: absolute;
height: 13px;
width: 13px;
left: -2px;
top: 0;
bottom: 0;
margin: auto;
border-radius: 100%;
background: var(--gray50);
}

.light .moon {
display: none;
}

.dark .sun {
display: none;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "umami",
"version": "0.44.0",
"version": "0.45.0",
"description": "A simple, fast, website analytics alternative to Google Analytics. ",
"author": "Mike Cao <[email protected]>",
"license": "MIT",
Expand Down
4 changes: 4 additions & 0 deletions styles/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ main {
flex: 1;
}

svg {
shape-rendering: geometricPrecision;
}

#__next {
display: flex;
flex-direction: column;
Expand Down

0 comments on commit 92d1fdd

Please sign in to comment.