forked from USStateDept/State-TalentMAP
-
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.
Merge pull request #459 from MetaPhase-Consulting/feature/dark-mode
dark mode
- Loading branch information
Showing
23 changed files
with
258 additions
and
10 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
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,52 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { setDarkModePreference } from '../../actions/preferences'; | ||
import { EMPTY_FUNCTION } from '../../Constants/PropTypes'; | ||
|
||
class DarkModeToggle extends Component { | ||
|
||
constructor(props) { | ||
super(props); | ||
this.onClickUnset = this.onClickUnset.bind(this); | ||
this.onClickSet = this.onClickSet.bind(this); | ||
} | ||
|
||
onClickUnset() { | ||
this.props.set(false); | ||
} | ||
|
||
onClickSet() { | ||
this.props.set(true); | ||
} | ||
|
||
render() { | ||
const { isDarkMode, set, ...rest } = this.props; | ||
return ( | ||
isDarkMode ? | ||
<button className="unstyled-button" onClick={this.onClickUnset} {...rest}>Disable Dark Mode</button> | ||
: | ||
<button className="unstyled-button" onClick={this.onClickSet} {...rest}>Enable Dark Mode</button> | ||
); | ||
} | ||
} | ||
|
||
DarkModeToggle.propTypes = { | ||
isDarkMode: PropTypes.bool, | ||
set: PropTypes.func, | ||
}; | ||
|
||
DarkModeToggle.defaultProps = { | ||
isDarkMode: false, | ||
set: EMPTY_FUNCTION, | ||
}; | ||
|
||
const mapStateToProps = state => ({ | ||
isDarkMode: state.darkModePreference, | ||
}); | ||
|
||
export const mapDispatchToProps = dispatch => ({ | ||
set: bool => dispatch(setDarkModePreference(bool)), | ||
}); | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(DarkModeToggle); |
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,51 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { testDispatchFunctions } from '../../testUtilities/testUtilities'; | ||
import DarkModeToggle, { mapDispatchToProps } from './DarkModeToggle'; | ||
|
||
describe('DarkModeToggle', () => { | ||
const props = { | ||
isDarkMode: false, | ||
set: () => {}, | ||
}; | ||
|
||
it('is defined', () => { | ||
const wrapper = shallow( | ||
<DarkModeToggle.WrappedComponent {...props} />, | ||
); | ||
expect(wrapper).toBeDefined(); | ||
}); | ||
|
||
it('it displays "Disable" when isDarkMode === true', () => { | ||
const wrapper = shallow( | ||
<DarkModeToggle.WrappedComponent {...props} isDarkMode />, | ||
); | ||
expect(wrapper.find('button').text()).toBe('Disable Dark Mode'); | ||
}); | ||
|
||
it('it displays "Enable" when isDarkMode !== true', () => { | ||
const wrapper = shallow( | ||
<DarkModeToggle.WrappedComponent {...props} />, | ||
); | ||
expect(wrapper.find('button').text()).toBe('Enable Dark Mode'); | ||
}); | ||
|
||
it('calls the set function', () => { | ||
let val = true; | ||
const onClick = v => val = v; // eslint-disable-line | ||
const wrapper = shallow( | ||
<DarkModeToggle.WrappedComponent {...props} isDarkMode set={onClick} />, | ||
); | ||
const click = () => wrapper.find('button').simulate('click'); | ||
click(); | ||
expect(val).toBe(false); | ||
wrapper.setProps({ isDarkMode: false }); | ||
wrapper.update(); | ||
click(); | ||
expect(val).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('mapDispatchToProps', () => { | ||
testDispatchFunctions(mapDispatchToProps, { bool: [true] }); | ||
}); |
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,55 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { | ||
enable as enableDarkMode, | ||
disable as disableDarkMode, | ||
} from 'darkreader'; | ||
import { checkFlag } from '../../flags'; | ||
|
||
const getUseDarkMode = () => checkFlag('flags.personalization'); | ||
|
||
const setMode = (value) => { | ||
if (!value || !getUseDarkMode()) { | ||
disableDarkMode(); | ||
} else { | ||
enableDarkMode({ | ||
brightness: 100, | ||
contrast: 90, | ||
sepia: 10, | ||
}); | ||
} | ||
}; | ||
|
||
class DarkMode extends Component { | ||
|
||
componentWillMount() { | ||
const { isDarkMode } = this.props; | ||
setMode(isDarkMode); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
const { isDarkMode } = nextProps; | ||
setMode(isDarkMode); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div /> | ||
); | ||
} | ||
} | ||
|
||
DarkMode.propTypes = { | ||
isDarkMode: PropTypes.bool, | ||
}; | ||
|
||
DarkMode.defaultProps = { | ||
isDarkMode: false, | ||
}; | ||
|
||
const mapStateToProps = state => ({ | ||
isDarkMode: state.darkModePreference, | ||
}); | ||
|
||
export default connect(mapStateToProps)(DarkMode); |
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,16 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import DarkMode from './DarkMode'; | ||
|
||
describe('DarkMode', () => { | ||
const props = { | ||
isDarkMode: true, | ||
}; | ||
|
||
it('is defined', () => { | ||
const wrapper = shallow( | ||
<DarkMode.WrappedComponent {...props} />, | ||
); | ||
expect(wrapper).toBeDefined(); | ||
}); | ||
}); |
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 @@ | ||
export { default } from './DarkMode'; |
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
2 changes: 1 addition & 1 deletion
2
src/actions/sortPreferences.test.js → src/actions/preferences.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
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,3 @@ | ||
import preferences, { darkModePreference } from './preferences'; | ||
|
||
export default { preferences, darkModePreference }; |
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
4 changes: 2 additions & 2 deletions
4
...s/sortPreferences/sortPreferences.test.js → src/reducers/preferences/preferences.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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import sortPreferences from './sortPreferences'; | ||
import preferences from './preferences'; | ||
import { POSITION_SEARCH_SORTS_TYPE } from '../../Constants/Sort'; | ||
|
||
describe('reducers', () => { | ||
it('can set reducer SET_SORT_PREFERENCE', () => { | ||
expect(sortPreferences({}, { type: 'SET_SORT_PREFERENCE', key: POSITION_SEARCH_SORTS_TYPE, value: 'title' })) | ||
expect(preferences({}, { type: 'SET_SORT_PREFERENCE', key: POSITION_SEARCH_SORTS_TYPE, value: 'title' })) | ||
.toBeDefined(); | ||
}); | ||
}); |
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
Oops, something went wrong.