Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = {
},
plugins: [
'gatsby-plugin-catch-links',
'gatsby-plugin-dark-mode',
'gatsby-transformer-yaml',
'gatsby-plugin-react-helmet',
{
Expand Down
45,004 changes: 17,028 additions & 27,976 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"dependencies": {
"@mdx-js/mdx": "^1.6.18",
"@mdx-js/react": "^1.6.18",
"@smotaal.io/dark-mode-controller": "<0.5",
"@storybook/addon-actions": "^6.2.2",
"@storybook/addon-links": "^6.2.2",
"@storybook/addons": "^6.2.2",
Expand All @@ -22,13 +21,14 @@
"gatsby": "2.24.85",
"gatsby-plugin-canonical-urls": "^2.2.3",
"gatsby-plugin-catch-links": "^2.2.1",
"gatsby-plugin-manifest": "^2.4.0",
"gatsby-plugin-dark-mode": "^1.1.2",
"gatsby-plugin-manifest": "^2.12.1",
"gatsby-plugin-mdx": "^1.2.40",
"gatsby-plugin-meta-redirect": "^1.1.1",
"gatsby-plugin-offline": "^3.1.2",
"gatsby-plugin-react-helmet": "^3.2.4",
"gatsby-plugin-sass": "2.3.1",
"gatsby-plugin-sharp": "2.6.36",
"gatsby-plugin-sharp": "^2.6.36",
"gatsby-plugin-sitemap": "^2.0.5",
"gatsby-plugin-typescript": "^2.3.5",
"gatsby-remark-autolink-headers": "^2.2.1",
Expand Down Expand Up @@ -110,6 +110,9 @@
"type": "git",
"url": "https://github.com/nodejs/nodejs.dev"
},
"resolutions": {
"sharp": "0.27.2"
},
Comment on lines +113 to +115

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having a lot of trouble running locally, specifically because of the sharp dependency shared between gatsby-plugin-manifest and gatsby-plugin-sharp. One would get the wrong version and I couldnt run the project locally. I added this so installing will force the correct version of sharp

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which version of node are you using? Are you using npm or yarn?
i haven’t see this issue before. Have you tried using the latest Node LTS? 14.x

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried both 10.x when I run nvm use and the latest Node LTS. Before I added this, the gatsby-plugin-sharp was downloading sharp version 0.25.6 which was incompatible. I also tried nuking package lock and node modules to no avail.

One thing I will say is that I didnt see this issue at all after upgrading gatsby and all the associated plugins to 3.x, so if this is merged I think we can remove it in your upgrade PR here

"jest": {
"transform": {
"^.+\\.(ts|tsx|js)$": "<rootDir>/test-preprocessor.js"
Expand Down
4 changes: 2 additions & 2 deletions src/components/DownloadReleases/DownloadTable.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
padding: var(--space-16) var(--space-16);
border-bottom: 1px solid #e2e3e7;

.dark-mode & {
.dark & {
border-bottom: 1px solid var(--color-border-primary);
}
}
Expand All @@ -38,7 +38,7 @@
background: var(--brand10);
}

.dark-mode &:hover {
.dark &:hover {
background: var(--brand9);
}
}
Expand Down
69 changes: 45 additions & 24 deletions src/components/Header/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { Link } from 'gatsby';
import React, { KeyboardEvent } from 'react';
import React, { MouseEvent, KeyboardEvent } from 'react';
import { ThemeToggler } from 'gatsby-plugin-dark-mode';
import logoLight from '../../images/logos/nodejs-logo-light-mode.svg';
import logoDark from '../../images/logos/nodejs-logo-dark-mode.svg';
import defaultDarkModeController from '../../util/darkModeController';
import { useMediaQuery } from '../../hooks/useMediaQuery';

interface Props {
darkModeController?: typeof defaultDarkModeController;
}

const Header = ({
darkModeController = defaultDarkModeController,
}: Props): JSX.Element => {
const Header = (): JSX.Element => {
const isMobile = useMediaQuery('(max-width: 870px)');

const keyPressDarkModeHandler: (
e: KeyboardEvent<HTMLButtonElement>
) => void = e => {
if (e.charCode === 13 || e.charCode === 32) darkModeController.toggle();
const handleThemeOnClick = (
e: MouseEvent<HTMLButtonElement, Event> | KeyboardEvent<HTMLButtonElement>,
// eslint-disable-next-line @typescript-eslint/ban-types
toggleTheme: Function,
isKeyPress = false
): void => {
if (isKeyPress) {
return;
}
const target = e.target as HTMLElement;
const toggle = target.innerText.includes('nights_stay') ? 'dark' : 'light';
toggleTheme(toggle);
};

return (
Expand Down Expand Up @@ -86,17 +88,36 @@ const Header = ({
<div className="nav__endwrapper">
<ul className="right-container">
<li className="nav__tabs nav__tabs--right">
<button
type="button"
className="dark-mode-toggle"
onKeyPress={keyPressDarkModeHandler}
onMouseDown={darkModeController.handleEvent}
onMouseUp={darkModeController.handleEvent}
>
<span className="sr-only">Toggle Dark Mode</span>
<i className="material-icons light-mode-only">nights_stay</i>
<i className="material-icons dark-mode-only">wb_sunny</i>
</button>
<ThemeToggler>
Comment thread
benhalverson marked this conversation as resolved.
{({
theme,
toggleTheme,
}: {
theme: string | null;
// eslint-disable-next-line @typescript-eslint/ban-types
toggleTheme: Function;
}): JSX.Element | null => {
if (theme === null) {
return null;
}
return (
<button
type="button"
onClick={(e): void => handleThemeOnClick(e, toggleTheme)}
className="dark-mode-toggle"
onKeyPress={(e): void =>
handleThemeOnClick(e, toggleTheme, true)
}
>
<span className="sr-only">Toggle Dark Mode</span>
<i className="material-icons light-mode-only">
nights_stay
</i>
<i className="material-icons dark-mode-only">wb_sunny</i>
</button>
);
}}
</ThemeToggler>
</li>

<li className="nav__tabs">
Expand Down
6 changes: 3 additions & 3 deletions src/components/Hero/Hero.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@
border: var(--brand7) var(--space-02) solid;
}

.dark-mode &.inverse {
.dark &.inverse {
color: var(--black0);
}

.light-mode &.inverse {
.light &.inverse {
color: var(--brand6);
}

.light-mode &.inverse:hover {
.light &.inverse:hover {
color: var(--black0);
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/components/Layout/centered.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ import '../../styles/centered-layout.scss';
import '../../styles/mobile.scss';
import SEO from '../Seo';

// NOTE: Quickly restores dark-mode state to mitigate onload flash
import darkModeController from '../../util/darkModeController';

interface Props {
children: React.ReactNode;
title?: string;
Expand All @@ -32,7 +29,7 @@ const CenteredLayout = ({
return (
<>
<SEO title={title} description={description} img={img} />
<Header darkModeController={darkModeController} />
<Header />
<main className="main__centered">{children}</main>
{showFooter && <Footer />}
</>
Expand Down
5 changes: 1 addition & 4 deletions src/components/Layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import '../../styles/layout.scss';
import '../../styles/mobile.scss';
import SEO from '../Seo';

// NOTE: Quickly restores dark-mode state to mitigate onload flash
import darkModeController from '../../util/darkModeController';

interface Props {
children: React.ReactNode;
title?: string;
Expand Down Expand Up @@ -38,7 +35,7 @@ const Layout = ({
img={img}
/>
<div className="layout-container">
<Header darkModeController={darkModeController} />
<Header />
{children}
{showFooter && <Footer />}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/styles/docs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
}
}

.dark-mode .api-key__section {
.dark .api-key__section {
background: var(--black9);

.api-key__item {
Expand Down
6 changes: 3 additions & 3 deletions src/styles/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ input {
color: var(--color-text-primary);
}

body:not(.dark-mode) .dark-mode-only,
.dark-mode .light-mode-only {
body:not(.dark) .dark-mode-only,
Comment thread
benhalverson marked this conversation as resolved.
.dark .light-mode-only {
display: none;
}

Expand Down Expand Up @@ -281,7 +281,7 @@ select {
justify-content: flex-end;
}

.dark-mode .nav {
.dark .nav {
border: none;
}

Expand Down
3 changes: 1 addition & 2 deletions src/styles/tokens.scss
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ body {
--space-128: 12.8rem;
--space-160: 16rem;
}

.dark-mode {
.dark {
/* Colors */
--color-brand-primary: var(--brand5);
--color-text-primary: var(--black4);
Expand Down
1 change: 1 addition & 0 deletions src/types/gatsby-plugin-dark-mode.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'gatsby-plugin-dark-mode';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can be convinced to put this in a separate place. Im not sure whats best, to put it next to where its used or in this types folder.

18 changes: 0 additions & 18 deletions src/util/darkModeController.ts

This file was deleted.