1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2025-01-03 10:25:00 +01:00

improve default dark mode loading experience

This commit is contained in:
Matthias Kretschmann 2018-05-10 20:56:58 +02:00
parent c2f62634bc
commit f61f4fda95
Signed by: m
GPG Key ID: 606EEEF3C479A91F
6 changed files with 72 additions and 54 deletions

View File

@ -15,6 +15,7 @@
padding: $spacer / 4; padding: $spacer / 4;
text-align: center; text-align: center;
background: rgba(#fff, .15); background: rgba(#fff, .15);
border-radius: .25rem;
color: $brand-grey-light; color: $brand-grey-light;
margin-left: $spacer / 2; margin-left: $spacer / 2;
margin-bottom: $spacer / 2; margin-bottom: $spacer / 2;

View File

@ -1,4 +1,5 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { FadeIn } from '../atoms/Animations'
import { ReactComponent as Day } from '../../images/day.svg' import { ReactComponent as Day } from '../../images/day.svg'
import { ReactComponent as Night } from '../../images/night.svg' import { ReactComponent as Night } from '../../images/night.svg'
import './ThemeSwitch.scss' import './ThemeSwitch.scss'
@ -10,13 +11,15 @@ class ThemeSwitch extends Component {
this.state = { dark: false } this.state = { dark: false }
} }
componentDidMount() { componentWillMount() {
const now = new Date().getHours() const now = new Date().getHours()
if (now >= 19 || now <= 7) { if (now >= 19 || now <= 7) {
this.setState({ dark: true }) this.setState({ dark: true })
} }
}
componentDidMount() {
this.toggleTheme() this.toggleTheme()
} }
@ -31,33 +34,35 @@ class ThemeSwitch extends Component {
} }
toggleTheme = () => { toggleTheme = () => {
document.body.classList.toggle('dark', this.state.dark) document.getElementsByClassName('app')[0].classList.toggle('dark', this.state.dark)
} }
render() { render() {
return ( return (
<aside className="themeswitch"> <FadeIn>
<label className="checkbox"> <aside className="themeswitch">
<span className="checkbox__label">Toggle Night Mode</span> <label className="checkbox">
<input <span className="checkbox__label">Toggle Night Mode</span>
onChange={this.handleChange} <input
type="checkbox" onChange={this.handleChange}
name="toggle" type="checkbox"
value="toggle" name="toggle"
aria-describedby="toggle" value="toggle"
checked={this.state.dark} aria-describedby="toggle"
/> checked={this.state.dark}
<span />
id="toggle" <span
className="checkbox__faux-container" id="toggle"
aria-live="assertive" className="checkbox__faux-container"
> aria-live="assertive"
<Day className={this.state.dark ? 'icon' : 'icon active'} /> >
<span className="checkbox__faux" /> <Day className={this.state.dark ? 'icon' : 'icon active'} />
<Night className={this.state.dark ? 'icon active' : 'icon'} /> <span className="checkbox__faux" />
</span> <Night className={this.state.dark ? 'icon active' : 'icon'} />
</label> </span>
</aside> </label>
</aside>
</FadeIn>
) )
} }
} }

View File

@ -5,15 +5,11 @@
top: $spacer / 2; top: $spacer / 2;
right: $spacer; right: $spacer;
z-index: 10; z-index: 10;
opacity: .6;
.dark & {
opacity: .8;
}
.icon { .icon {
width: .8rem; width: .8rem;
height: .8rem; height: .8rem;
margin-top: -.05rem;
fill: $brand-grey-light; fill: $brand-grey-light;
&:last-child { &:last-child {
@ -22,16 +18,8 @@
height: .7rem; height: .7rem;
} }
&.active {
fill: $brand-grey;
}
.dark & { .dark & {
fill: $brand-grey; fill: $brand-grey;
&.active {
fill: $brand-grey-light;
}
} }
} }
} }
@ -41,12 +29,15 @@
align-items: center; align-items: center;
} }
$knob-size: 8px;
$knob-space: 1px;
.checkbox__faux { .checkbox__faux {
display: block; display: block;
position: relative; position: relative;
width: 1.15rem; width: ($knob-size + ($knob-space * 2)) * 2;
height: .61rem; height: $knob-size + ($knob-space * 4);
border: .05rem solid $brand-grey-light; border: 1px solid $brand-grey-light;
border-radius: 15rem; border-radius: 15rem;
margin-left: $spacer / 3; margin-left: $spacer / 3;
margin-right: $spacer / 3; margin-right: $spacer / 3;
@ -54,20 +45,33 @@
&::after { &::after {
content: ''; content: '';
position: absolute; position: absolute;
top: .025rem; top: $knob-space;
left: .05rem; left: $knob-space;
width: .5rem; width: $knob-size;
height: .5rem; height: $knob-size;
background-color: $brand-grey; background-color: $brand-grey-light;
border-radius: 15rem; border-radius: 15rem;
transition: transform .2s $easing; transition: transform .2s $easing;
transform: translate3d(0, 0, 0); transform: translate3d(0, 0, 0);
} }
.dark & {
border-color: $brand-grey;
&::after {
background-color: $brand-grey;
}
}
} }
.checkbox { .checkbox {
position: relative; position: relative;
cursor: pointer; cursor: pointer;
opacity: .6;
.dark & {
opacity: .8;
}
[type="checkbox"], [type="checkbox"],
.checkbox__label { .checkbox__label {

View File

@ -24,9 +24,15 @@ const Main = ({ children }) => <main className="screen">{children}</main>
const TemplateWrapper = ({ data, location, children }) => { const TemplateWrapper = ({ data, location, children }) => {
const meta = data.dataYaml const meta = data.dataYaml
const isHomepage = location.pathname === '/' const isHomepage = location.pathname === '/'
const now = new Date().getHours()
let classes = 'app'
if (now >= 19 || now <= 7) {
classes += ' dark'
}
return ( return (
<div className="app"> <div className={classes}>
<Head meta={meta} location={location} /> <Head meta={meta} location={location} />
<Header meta={meta} isHomepage={isHomepage} /> <Header meta={meta} isHomepage={isHomepage} />

View File

@ -19,7 +19,6 @@ html {
} }
body { body {
background: $body-background-color;
font-family: $font-family-base; font-family: $font-family-base;
font-weight: $font-weight-base; font-weight: $font-weight-base;
font-size: $font-size-base; font-size: $font-size-base;
@ -29,12 +28,6 @@ body {
font-feature-settings: 'liga', 'kern'; font-feature-settings: 'liga', 'kern';
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
transition: background .2s ease-out;
&.dark {
background: $body-background-color--dark;
color: $text-color--dark;
}
} }
p, p,
@ -118,6 +111,13 @@ svg {
display: flex; display: flex;
min-height: 100vh; min-height: 100vh;
flex-direction: column; flex-direction: column;
background: $body-background-color;
transition: background .2s ease-out;
&.dark {
background: $body-background-color--dark;
color: $text-color--dark;
}
} }
.screen { .screen {

View File

@ -7,6 +7,7 @@ $easing: cubic-bezier(.75, 0, .08, 1);
$brand-main: #015565; $brand-main: #015565;
$brand-cyan: #43a699; $brand-cyan: #43a699;
$brand-main-light: #88bec8;
$brand-light: #e7eef4; $brand-light: #e7eef4;
$brand-grey: #6b7f88; $brand-grey: #6b7f88;
@ -33,6 +34,7 @@ $text-color-light--dark: $brand-grey;
// Typography // Typography
///////////////////////////////////// /////////////////////////////////////
$font-size-root : 18px; $font-size-root : 18px;
$font-size-base : 1rem; $font-size-base : 1rem;
@ -61,7 +63,7 @@ $font-weight-headings : 400;
$line-height-headings : 1.1; $line-height-headings : 1.1;
$color-headings: $brand-main; $color-headings: $brand-main;
$color-headings--dark: lighten($color-headings, 10%); $color-headings--dark: $brand-main-light;
// Components spacing // Components spacing
///////////////////////////////////// /////////////////////////////////////