-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1098 from prymitive/dark-mode
feat(ui): experimental dark theme
- Loading branch information
Showing
20 changed files
with
393 additions
and
62 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 was deleted.
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
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
57 changes: 57 additions & 0 deletions
57
ui/src/Components/MainModal/Configuration/ThemeConfiguration.js
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,57 @@ | ||
import React, { Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
import { action } from "mobx"; | ||
import { observer } from "mobx-react"; | ||
|
||
import { Settings } from "Stores/Settings"; | ||
|
||
const ThemeConfiguration = observer( | ||
class ThemeConfiguration extends Component { | ||
static propTypes = { | ||
settingsStore: PropTypes.instanceOf(Settings).isRequired | ||
}; | ||
|
||
onChange = action(event => { | ||
const { settingsStore } = this.props; | ||
settingsStore.themeConfig.config.darkTheme = event.target.checked; | ||
|
||
document.body.classList.toggle( | ||
"dark-theme", | ||
settingsStore.themeConfig.config.darkTheme | ||
); | ||
}); | ||
|
||
render() { | ||
const { settingsStore } = this.props; | ||
|
||
return ( | ||
<div className="form-group mb-0"> | ||
<div className="form-check form-check-inline"> | ||
<span className="custom-control custom-switch"> | ||
<input | ||
id="configuration-theme" | ||
className="custom-control-input" | ||
type="checkbox" | ||
value="" | ||
checked={settingsStore.themeConfig.config.darkTheme || false} | ||
onChange={this.onChange} | ||
/> | ||
<label | ||
className="custom-control-label cursor-pointer mr-3" | ||
htmlFor="configuration-theme" | ||
> | ||
Enable dark mode | ||
</label> | ||
<span className="ml-5 badge badge-danger align-text-bottom"> | ||
Experimental | ||
</span> | ||
</span> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
); | ||
|
||
export { ThemeConfiguration }; |
54 changes: 54 additions & 0 deletions
54
ui/src/Components/MainModal/Configuration/ThemeConfiguration.test.js
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,54 @@ | ||
import React from "react"; | ||
|
||
import { mount } from "enzyme"; | ||
|
||
import toDiffableHtml from "diffable-html"; | ||
|
||
import { Settings } from "Stores/Settings"; | ||
import { ThemeConfiguration } from "./ThemeConfiguration"; | ||
|
||
let settingsStore; | ||
beforeEach(() => { | ||
settingsStore = new Settings(); | ||
}); | ||
|
||
const FakeConfiguration = () => { | ||
return mount(<ThemeConfiguration settingsStore={settingsStore} />); | ||
}; | ||
|
||
describe("<ThemeConfiguration />", () => { | ||
it("matches snapshot with default values", () => { | ||
const tree = FakeConfiguration(); | ||
expect(toDiffableHtml(tree.html())).toMatchSnapshot(); | ||
}); | ||
|
||
it("darkTheme is 'false' by default", () => { | ||
expect(settingsStore.themeConfig.config.darkTheme).toBe(false); | ||
}); | ||
|
||
it("unchecking the checkbox sets stored darkTheme value to 'false'", done => { | ||
const tree = FakeConfiguration(); | ||
const checkbox = tree.find("#configuration-theme"); | ||
|
||
settingsStore.themeConfig.config.darkTheme = true; | ||
expect(settingsStore.themeConfig.config.darkTheme).toBe(true); | ||
checkbox.simulate("change", { target: { checked: false } }); | ||
setTimeout(() => { | ||
expect(settingsStore.themeConfig.config.darkTheme).toBe(false); | ||
done(); | ||
}, 200); | ||
}); | ||
|
||
it("checking the checkbox sets stored darkTheme value to 'true'", done => { | ||
const tree = FakeConfiguration(); | ||
const checkbox = tree.find("#configuration-theme"); | ||
|
||
settingsStore.themeConfig.config.darkTheme = false; | ||
expect(settingsStore.themeConfig.config.darkTheme).toBe(false); | ||
checkbox.simulate("change", { target: { checked: true } }); | ||
setTimeout(() => { | ||
expect(settingsStore.themeConfig.config.darkTheme).toBe(true); | ||
done(); | ||
}, 200); | ||
}); | ||
}); |
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
25 changes: 25 additions & 0 deletions
25
ui/src/Components/MainModal/Configuration/__snapshots__/ThemeConfiguration.test.js.snap
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,25 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<ThemeConfiguration /> matches snapshot with default values 1`] = ` | ||
" | ||
<div class=\\"form-group mb-0\\"> | ||
<div class=\\"form-check form-check-inline\\"> | ||
<span class=\\"custom-control custom-switch\\"> | ||
<input id=\\"configuration-theme\\" | ||
class=\\"custom-control-input\\" | ||
type=\\"checkbox\\" | ||
value | ||
> | ||
<label class=\\"custom-control-label cursor-pointer mr-3\\" | ||
for=\\"configuration-theme\\" | ||
> | ||
Enable dark mode | ||
</label> | ||
<span class=\\"ml-5 badge badge-danger align-text-bottom\\"> | ||
Experimental | ||
</span> | ||
</span> | ||
</div> | ||
</div> | ||
" | ||
`; |
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.