Skip to content

Commit

Permalink
feat: Add dark mode toggle to the header
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Jun 23, 2020
1 parent 1aaa856 commit 670c726
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/components/FeatherIcon.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import PropTypes from 'prop-types';
import cx from 'classnames';
import styles from './FeatherIcon.module.scss';

const FeatherIcon = ({ className, name, size = '1em' }) => {
const FeatherIcon = ({ className, name, size = '1em', ...props }) => {
const paths = ICONS[name];

return paths ? (
<svg
{...props}
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
className={cx(styles.icon, className)}
Expand Down
9 changes: 9 additions & 0 deletions src/components/GlobalHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import { githubBaseUrl } from '../data/constants';
import NewRelicLogo from './NewRelicLogo';
import ExternalLink from './ExternalLink';
import FeatherIcon from './FeatherIcon';
import useDarkMode from 'use-dark-mode';

import styles from './GlobalHeader.module.scss';

const GlobalHeader = ({ className }) => {
const { fileRelativePath } = useContext(PageContext);
const darkMode = useDarkMode(false);

return (
<div className={cx(styles.globalHeaderContainer, className)}>
Expand Down Expand Up @@ -58,6 +60,13 @@ const GlobalHeader = ({ className }) => {
</div>

<ul className={styles.rightSideButtons}>
<li className={styles.rightSideButton}>
<FeatherIcon
name={darkMode.value ? 'sun' : 'moon'}
size="1rem"
onClick={darkMode.toggle}
/>
</li>
{fileRelativePath && (
<li className={styles.rightSideButton}>
<ExternalLink
Expand Down

0 comments on commit 670c726

Please sign in to comment.