Skip to content
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
3 changes: 2 additions & 1 deletion config/jest/jest.unit.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = {
'<rootDir>/test/unit/setup.js',
],
moduleNameMapper: {
'^.+\\.svg$': 'jest-transform-stub'
'^.+\\.svg$': 'jest-transform-stub',
'^standalone/(.*)$': '<rootDir>/src/standalone/$1',
},
transformIgnorePatterns: ['/node_modules/(?!(sinon|react-syntax-highlighter|@asamuzakjp/css-color)/)'],
silent: true, // set to `false` to allow console.* calls to be printed
Expand Down
1 change: 1 addition & 0 deletions src/standalone/plugins/top-bar/assets/lightbulb-off.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 src/standalone/plugins/top-bar/assets/lightbulb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions src/standalone/plugins/top-bar/components/DarkModeToggle.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @prettier
*/
import React, { Component } from "react"

import LightBulb from "../assets/lightbulb.svg"
import LightBulbOff from "../assets/lightbulb-off.svg"

class DarkModeToggle extends Component {
constructor(props) {
super(props)
this.state = {
isDarkMode: false,
}
this.toggleIsDarkMode = this.toggleIsDarkMode.bind(this)
}

componentDidMount() {
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
document.documentElement.classList.add("dark-mode")
this.setState({ isDarkMode: true })
}
}

toggleIsDarkMode() {
document.documentElement.classList.toggle("dark-mode")
this.setState((prevState) => ({ isDarkMode: !prevState.isDarkMode }))
}

render() {
const { isDarkMode } = this.state

return (
<div className="dark-mode-toggle">
<button onClick={this.toggleIsDarkMode}>
{!isDarkMode ? (
<LightBulbOff height="24" />
) : (
<LightBulb height="24" />
)}
</button>
</div>
)
}
}

export default DarkModeToggle
2 changes: 2 additions & 0 deletions src/standalone/plugins/top-bar/components/TopBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class TopBar extends React.Component {
const Button = getComponent("Button")
const Link = getComponent("Link")
const Logo = getComponent("Logo")
const DarkModeToggle = getComponent("DarkModeToggle")

let isLoading = specSelectors.loadingStatus() === "loading"
let isFailed = specSelectors.loadingStatus() === "failed"
Expand Down Expand Up @@ -164,6 +165,7 @@ class TopBar extends React.Component {
<form className="download-url-wrapper" onSubmit={formOnSubmit}>
{control.map((el, i) => cloneElement(el, { key: i }))}
</form>
<DarkModeToggle />
</div>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/standalone/plugins/top-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
*/
import TopBar from "./components/TopBar"
import Logo from "./components/Logo"
import DarkModeToggle from "./components/DarkModeToggle"

const TopBarPlugin = () => ({
components: { Topbar: TopBar, Logo },
components: { Topbar: TopBar, Logo, DarkModeToggle },
})

export default TopBarPlugin
Loading