-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add keywords to writings Add theme switch Add Layout component to add initial Helmet att Rename all scss modules with an underscore Added Storage module
- Loading branch information
Marvin Heilemann
committed
Jan 10, 2020
1 parent
f6ff65d
commit 05db231
Showing
36 changed files
with
714 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React from 'react' | ||
|
||
const Keywords = ({ list }) => ( | ||
<span className="keywords"> | ||
{list.map((item, i) => ( | ||
<span key={i}> | ||
{item} | ||
{list.length > i + 1 ? ', ' : ''} | ||
</span> | ||
))} | ||
</span> | ||
) | ||
|
||
export default Keywords |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useContext } from 'react' | ||
|
||
import { Theme } from '../store' | ||
import { modes } from '../store/theme' | ||
|
||
/** | ||
* @link https://codepen.io/muuvmuuv/pen/jOEzYLa?editors=0110 | ||
*/ | ||
const ThemeSwitch = () => { | ||
const themeState = useContext(Theme.State) | ||
|
||
const current = modes.findIndex((m) => m === themeState.mode) | ||
const index = current + 1 >= modes.length ? 0 : current + 1 | ||
const nextMode = modes[index] | ||
|
||
function toggleTheme(event) { | ||
const element = event.target | ||
element.classList.add('animating') | ||
themeState.toggle() | ||
} | ||
|
||
function onAnimationEnd(event) { | ||
const element = event.target | ||
element.classList.remove('animating') | ||
} | ||
|
||
return ( | ||
<button | ||
id="theme-switch" | ||
onKeyPress={toggleTheme} | ||
onClick={toggleTheme} | ||
mode={themeState.mode} | ||
theme={themeState.theme} | ||
onAnimationEnd={onAnimationEnd} | ||
aria-label={`Switch to ${nextMode} appearance`} | ||
title={`Switch to ${nextMode} appearance`} | ||
></button> | ||
) | ||
} | ||
|
||
export default ThemeSwitch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React, { useContext } from 'react' | ||
import { Helmet } from 'react-helmet-async' | ||
|
||
import { Theme } from '../store' | ||
|
||
const Layout = ({ children }) => { | ||
const themeState = useContext(Theme.State) | ||
|
||
return ( | ||
<> | ||
<Helmet | ||
htmlAttributes={{ | ||
theme: themeState.theme, | ||
}} | ||
/> | ||
|
||
{children} | ||
</> | ||
) | ||
} | ||
|
||
export default Layout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
function setItem(key, data) { | ||
return new Promise((resolve, reject) => { | ||
if (!key || !data) { | ||
reject('No key or data provided!') | ||
} | ||
localStorage.setItem(key, JSON.stringify(data)) | ||
resolve() | ||
}) | ||
} | ||
|
||
function getItem(key) { | ||
return new Promise((resolve, reject) => { | ||
if (!key) { | ||
reject('No key provided!') | ||
} | ||
let content = localStorage.getItem(key) | ||
content = JSON.parse(content) | ||
resolve(content) | ||
}) | ||
} | ||
|
||
function removeItem(key) { | ||
return new Promise((resolve, reject) => { | ||
if (!key) { | ||
reject('No key provided!') | ||
} | ||
localStorage.removeItem(key) | ||
resolve() | ||
}) | ||
} | ||
|
||
function clearAll() { | ||
return new Promise(resolve => { | ||
localStorage.clear() | ||
resolve() | ||
}) | ||
} | ||
|
||
const Storage = { setItem, getItem, removeItem, clearAll } | ||
export default Storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.