Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make NTP setting menu keyboard accessible #2814

Merged
merged 2 commits into from
Jul 22, 2019
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: 1 addition & 2 deletions .storybook/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { withBackgrounds } from '@storybook/addon-backgrounds'
import 'emptykit.css'
import { configure, addDecorator, addParameters } from '@storybook/react'
import { withOptions } from '@storybook/addon-options'
import { initLocale } from 'brave-ui/helpers'
import locale from './locale'
import { withThemesProvider } from 'storybook-addon-styled-component-theme'
Expand Down
6 changes: 2 additions & 4 deletions components/brave_new_tab_ui/actions/new_tab_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ export const gridSitesUpdated = (gridSites: NewTab.Site[]) => action(types.NEW_T

export const statsUpdated = () => action(types.NEW_TAB_STATS_UPDATED)

export const textDirectionUpdated = (textDirection: string) => action(types.NEW_TAB_TEXT_DIRECTION_UPDATED, textDirection)

export const changePrivateSearchEngine = (shouldUse: boolean) => action(types.NEW_TAB_USE_ALTERNATIVE_PRIVATE_SEARCH_ENGINE, {
shouldUse
})

export const showSettingsMenu = () => action(types.NEW_TAB_SHOW_SETTINGS_MENU)

export const closeSettingsMenu = () => action(types.NEW_TAB_CLOSE_SETTINGS_MENU)

export const preferencesUpdated = (preferences: Preferences) => action(types.NEW_TAB_PREFERENCES_UPDATED, {
preferences
})
7 changes: 7 additions & 0 deletions components/brave_new_tab_ui/brave_new_tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import '../fonts/poppins.css'
import '../fonts/muli.css'

async function initialize () {
getTextDirection()
render(
<Provider store={store}>
<ThemeProvider theme={Theme}>
Expand All @@ -42,6 +43,12 @@ async function updatePreferences () {
actions.preferencesUpdated(preferences)
}

function getTextDirection () {
const actions = dataFetchAPI.getActions()
const textDirection = window.loadTimeData.getString('textdirection')
actions.textDirectionUpdated(textDirection)
}

function updateStats () {
const actions = dataFetchAPI.getActions()
actions.statsUpdated()
Expand Down
4 changes: 0 additions & 4 deletions components/brave_new_tab_ui/components/default/grid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ export const Footer = styled<{}, 'footer'>('footer')`
grid-template-areas:
"credits actions";
> *:first-child {
text-align: left;
}
> *:nth-child(2) {
justify-content: flex-end;
}
Expand Down
3 changes: 2 additions & 1 deletion components/brave_new_tab_ui/components/default/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import { StatsContainer, StatsItem } from './stats'
import { Page, DynamicBackground, Gradient, Link, Navigation, IconLink, PhotoName } from './page'
import { Page, DynamicBackground, Gradient, Link, Navigation, IconLink, IconButton, PhotoName } from './page'
import { Header, Main, Footer } from './grid'
import { SettingsMenu, SettingsRow, SettingsText, SettingsTitle, SettingsWrapper } from './settings'
import { List, ListWidget, Tile, TileActionsContainer, TileAction, TileFavicon } from './topSites'
Expand All @@ -21,6 +21,7 @@ export {
Link,
Navigation,
IconLink,
IconButton,
PhotoName,
Header,
Main,
Expand Down
25 changes: 21 additions & 4 deletions components/brave_new_tab_ui/components/default/page/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,11 @@ export const Navigation = styled<{}, 'nav'>('nav')`
display: flex;
`

interface IconLinkProps {
disabled?: boolean
interface IconButtonProps {
clickDisabled?: boolean
}

export const IconLink = styled<IconLinkProps, 'a'>('a')`
pointer-events: ${p => p.disabled && 'none'};
export const IconLink = styled<{}, 'a'>('a')`
display: flex;
width: 24px;
height: 24px;
Expand All @@ -109,3 +108,21 @@ export const IconLink = styled<IconLinkProps, 'a'>('a')`
opacity: 0.95;
}
`

export const IconButton = styled<IconButtonProps, 'button'>('button')`
pointer-events: ${p => p.clickDisabled && 'none'};
display: flex;
width: 24px;
height: 24px;
padding: 0;
border: none;
margin: 12px;
cursor: pointer;
color: #ffffff;
background-color: transparent;
opacity: 0.7;
transition: opacity 0.15s ease, filter 0.15s ease;
&:hover {
opacity: 0.95;
}
`
19 changes: 10 additions & 9 deletions components/brave_new_tab_ui/components/default/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@

import styled from 'styled-components'

export const SettingsMenu = styled<{}, 'div'>('div')`
interface Props {
textDirection: string
}

export const SettingsMenu = styled<Props, 'div'>('div')`
bottom: 48px;
width: auto;
position: absolute;
${p => p.textDirection && (p.textDirection === 'rtl') ? `left: 12px` : `right: 12px`}
background-color: ${p => p.theme.color.contextMenuBackground};
color: ${p => p.theme.color.contextMenuForeground};
border-radius: 8px;
Expand Down Expand Up @@ -38,14 +46,7 @@ export const SettingsText = styled<{}, 'span'>('span')`
`

export const SettingsWrapper = styled<{}, 'div'>('div')`
position: absolute;
bottom: 118px;
padding: 0 222px;
position: relative;
display: flex;
width: 100%;
justify-content: flex-end;
@media screen and (max-width: 1150px) {
padding: 0 192px;
}
`
8 changes: 4 additions & 4 deletions components/brave_new_tab_ui/components/toggle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface Props {
testId?: string
checked?: boolean
disabled?: boolean
onChange?: (e: any) => void
onChange?: (event: any) => void
id?: string
readOnly?: boolean
autoFocus?: boolean
Expand Down Expand Up @@ -41,17 +41,17 @@ export class Toggle extends React.PureComponent<Props, ToggleState> {
}
}

handleChange (e: any) {
handleChange (event: any) {
const { props } = this
if (props.disabled) {
return
}
if (!('checked' in props)) {
this.setState({ checked: e.target.checked })
this.setState({ checked: event.target.checked })
}

if (props.onChange) {
props.onChange({ target: { checked: e.target.checked } })
props.onChange({ target: { checked: event.target.checked } })
}
}

Expand Down
5 changes: 2 additions & 3 deletions components/brave_new_tab_ui/constants/new_tab_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const enum types {
NEW_TAB_GRID_SITES_UPDATED = '@@newtab/NEW_TAB_GRID_SITES_UPDATED',
NEW_TAB_STATS_UPDATED = '@@newtab/NEW_TAB_STATS_UPDATED',
NEW_TAB_USE_ALTERNATIVE_PRIVATE_SEARCH_ENGINE = '@@newtab/NEW_TAB_USE_ALTERNATIVE_PRIVATE_SEARCH_ENGINE',
NEW_TAB_SHOW_SETTINGS_MENU = '@@newtab/NEW_TAB_SHOW_SETTINGS_MENU',
NEW_TAB_CLOSE_SETTINGS_MENU = '@@newtab/NEW_TAB_CLOSE_SETTINGS_MENU',
NEW_TAB_PREFERENCES_UPDATED = '@@newtab/NEW_TAB_PREFERENCES_UPDATED'
NEW_TAB_PREFERENCES_UPDATED = '@@newtab/NEW_TAB_PREFERENCES_UPDATED',
NEW_TAB_TEXT_DIRECTION_UPDATED = '@@newtab/NEW_TAB_TEXT_DIRECTION_UPDATED'
}
73 changes: 51 additions & 22 deletions components/brave_new_tab_ui/containers/newTab/footerInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,75 @@ import * as React from 'react'
import { Link, Navigation, IconLink, PhotoName } from '../../components/default'

// Icons
import { SettingsAdvancedIcon, BookmarkBook, HistoryIcon, SettingsIcon } from 'brave-ui/components/icons'
import { SettingsAdvancedIcon, BookmarkBook, HistoryIcon } from 'brave-ui/components/icons'

// Helpers
import { getLocale } from '../../../common/locale'
import Settings from './settings'

interface Props {
backgroundImageInfo: NewTab.Image | undefined
textDirection: string
onClickOutside: () => void
backgroundImageInfo: any
onClickSettings: () => void
isSettingsMenuOpen: boolean
showSettingsMenu: boolean
showPhotoInfo: boolean
toggleShowBackgroundImage: () => void
toggleShowClock: () => void
toggleShowStats: () => void
toggleShowTopSites: () => void
showBackgroundImage: boolean
showClock: boolean
showStats: boolean
showTopSites: boolean
}

export default class FooterInfo extends React.Component<Props, {}> {
export default class FooterInfo extends React.PureComponent<Props, {}> {

render () {
const {
textDirection,
backgroundImageInfo,
onClickSettings,
isSettingsMenuOpen,
showPhotoInfo
showSettingsMenu,
showPhotoInfo,
onClickOutside,
toggleShowBackgroundImage,
toggleShowClock,
toggleShowStats,
toggleShowTopSites,
showBackgroundImage,
showClock,
showStats,
showTopSites
} = this.props

if (!backgroundImageInfo) {
return null
}

return (
<>
<div>
{showPhotoInfo &&
<PhotoName>
{`${getLocale('photoBy')} `}
<Link href={backgroundImageInfo.link} rel='noreferrer noopener' target='_blank'>
{backgroundImageInfo.author}
</Link>
</PhotoName>}
</div>
<div>
{showPhotoInfo &&
<PhotoName>
{`${getLocale('photoBy')} `}
<Link href={backgroundImageInfo.link} rel='noreferrer noopener' target='_blank'>
{backgroundImageInfo.author}
</Link>
</PhotoName>}
</div>
<Navigation>
<IconLink title={getLocale('dashboardSettingsTitle')} onClick={onClickSettings} disabled={isSettingsMenuOpen}>
<SettingsIcon />
</IconLink>
<Settings
textDirection={textDirection}
showSettingsMenu={showSettingsMenu}
onClickOutside={onClickOutside}
onClick={onClickSettings}
toggleShowBackgroundImage={toggleShowBackgroundImage}
toggleShowClock={toggleShowClock}
toggleShowStats={toggleShowStats}
toggleShowTopSites={toggleShowTopSites}
showBackgroundImage={showBackgroundImage}
showClock={showClock}
showStats={showStats}
showTopSites={showTopSites}
/>
<IconLink title={getLocale('preferencesPageTitle')} href='chrome://settings'>
<SettingsAdvancedIcon />
</IconLink>
Expand Down
39 changes: 22 additions & 17 deletions components/brave_new_tab_ui/containers/newTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
} from '../../components/default'

// Components
import Settings from './settings'
import Stats from './stats'
import Block from './block'
import FooterInfo from './footerInfo'
Expand All @@ -32,7 +31,16 @@ interface Props {
saveShowStats: (value: boolean) => void
}

class NewTabPage extends React.Component<Props, {}> {
interface State {
showSettingsMenu: boolean
}

class NewTabPage extends React.Component<Props, State> {
constructor (props: Props) {
super(props)
this.state = { showSettingsMenu: false }
}

componentDidMount () {
// if a notification is open at component mounting time, close it
this.props.actions.onHideSiteRemovalNotification()
Expand Down Expand Up @@ -90,16 +98,17 @@ class NewTabPage extends React.Component<Props, {}> {
)
}

showSettings = () => {
this.props.actions.showSettingsMenu()
closeSettings = () => {
this.setState({ showSettingsMenu: false })
}

closeSettings = () => {
this.props.actions.closeSettingsMenu()
toggleSettings = () => {
this.setState({ showSettingsMenu: !this.state.showSettingsMenu })
}

render () {
const { newTabData, actions } = this.props
const { showSettingsMenu } = this.state

if (!newTabData || !newTabData.backgroundImage) {
return null
Expand Down Expand Up @@ -141,10 +150,14 @@ class NewTabPage extends React.Component<Props, {}> {
}
</Main>
</Header>
{
newTabData.showSettings &&
<Settings
<Footer>
<FooterInfo
textDirection={newTabData.textDirection}
onClickOutside={this.closeSettings}
backgroundImageInfo={newTabData.backgroundImage}
onClickSettings={this.toggleSettings}
showSettingsMenu={showSettingsMenu}
showPhotoInfo={newTabData.showBackgroundImage}
toggleShowBackgroundImage={this.toggleShowBackgroundImage}
toggleShowClock={this.toggleShowClock}
toggleShowStats={this.toggleShowStats}
Expand All @@ -154,14 +167,6 @@ class NewTabPage extends React.Component<Props, {}> {
showStats={newTabData.showStats}
showTopSites={newTabData.showTopSites}
/>
}
<Footer>
<FooterInfo
backgroundImageInfo={newTabData.backgroundImage}
onClickSettings={this.showSettings}
isSettingsMenuOpen={newTabData.showSettings}
showPhotoInfo={newTabData.showBackgroundImage}
/>
</Footer>
</Page>
</DynamicBackground>
Expand Down
Loading