-
Notifications
You must be signed in to change notification settings - Fork 862
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 #2668 from brave/toggle-background-ntp
Change Background Settings for New Tabs Page
- Loading branch information
Showing
16 changed files
with
213 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
58 changes: 58 additions & 0 deletions
58
components/brave_new_tab_ui/components/newTab/settings.tsx
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,58 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import * as React from 'react' | ||
|
||
import { SettingsMenu, SettingsRow, SettingsText, SettingsTitle, SettingsWrapper } from 'brave-ui/features/newTab/default' | ||
|
||
import { Toggle } from 'brave-ui/features/newTab/toggle' | ||
|
||
import { getLocale } from '../../../common/locale' | ||
|
||
export interface Props { | ||
onClickOutside: () => void | ||
toggleShowBackgroundImage: () => void | ||
showBackgroundImage: boolean | ||
} | ||
|
||
export default class Settings extends React.PureComponent<Props, {}> { | ||
settingsMenuRef: React.RefObject<any> | ||
constructor (props: Props) { | ||
super(props) | ||
this.settingsMenuRef = React.createRef() | ||
} | ||
|
||
handleClickOutside = (event: Event) => { | ||
if (this.settingsMenuRef && !this.settingsMenuRef.current.contains(event.target)) { | ||
this.props.onClickOutside() | ||
} | ||
} | ||
|
||
componentDidMount () { | ||
document.addEventListener('mousedown', this.handleClickOutside) | ||
} | ||
|
||
componentWillUnmount () { | ||
document.removeEventListener('mousedown', this.handleClickOutside) | ||
} | ||
|
||
render () { | ||
const { toggleShowBackgroundImage, showBackgroundImage } = this.props | ||
return ( | ||
<SettingsWrapper> | ||
<SettingsMenu innerRef={this.settingsMenuRef}> | ||
<SettingsTitle>{getLocale('dashboardSettingsTitle')}</SettingsTitle> | ||
<SettingsRow> | ||
<SettingsText>{getLocale('showBackgroundImage')}</SettingsText> | ||
<Toggle | ||
onChange={toggleShowBackgroundImage} | ||
checked={showBackgroundImage} | ||
size='small' | ||
/> | ||
</SettingsRow> | ||
</SettingsMenu> | ||
</SettingsWrapper> | ||
) | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
components/test/brave_new_tab_ui/components/settings_test.tsx
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,22 @@ | ||
import * as React from 'react' | ||
import { shallow } from 'enzyme' | ||
import { SettingsMenu, SettingsWrapper } from 'brave-ui/features/newTab/default' | ||
import Settings, { Props } from '../../../../components/brave_new_tab_ui/components/newTab/settings' | ||
|
||
describe('settings component tests', () => { | ||
const mockProps: Props = { | ||
onClickOutside: () => null, | ||
toggleShowBackgroundImage: () => null, | ||
showBackgroundImage: true | ||
} | ||
it('should render the component properly', () => { | ||
const wrapper = shallow( | ||
<Settings | ||
onClickOutside={mockProps.onClickOutside} | ||
toggleShowBackgroundImage={mockProps.toggleShowBackgroundImage} | ||
showBackgroundImage={mockProps.showBackgroundImage} | ||
/>) | ||
expect(wrapper.find(SettingsMenu)).toHaveLength(1) | ||
expect(wrapper.find(SettingsWrapper)).toHaveLength(1) | ||
}) | ||
}) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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