Skip to content

Commit

Permalink
Sync WebUI: Move brave-ui paths to brave-core paths
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Aug 1, 2019
1 parent 23c60db commit 75a103c
Show file tree
Hide file tree
Showing 43 changed files with 209 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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 styled from '../../../theme'
import styled from 'brave-ui/theme'

export const SectionBlock = styled<{}, 'section'>('section')`
margin: 15px 0 40px;
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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 styled from '../../../theme'
import styled from 'brave-ui/theme'

import StartImageUrl from './start_icon.svg'
import DefaultImageUrl from './default_icon.svg'
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ export {
ThreeColumnButtonGridCol1,
ThreeColumnButtonGridCol2
} from './modal'
export { Toggle } from './toggle'
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

import * as React from 'react'
import styled from '../../../theme'
import { Card } from '../../../components'
import { CardProps } from '../../../components/layout/card'
import styled from 'brave-ui/theme'
import Card, { CardProps } from 'brave-ui/components/layout/card'

export const DisabledContent = styled<{}, 'div'>('div')`
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* 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 styled from '../../../theme'
import Heading from '../../../components/text/heading'
import styled from 'brave-ui/theme'
import Heading from 'brave-ui/components/text/heading'

export const ModalHeader = styled<{}, 'header'>('header')`
margin-bottom: 8px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* 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 styled from '../../../theme'
import Heading from '../../../components/text/heading'
import styled from 'brave-ui/theme'
import Heading from 'brave-ui/components/text/heading'

export const Title = styled(Heading)`
font-weight: 600;
Expand Down
80 changes: 80 additions & 0 deletions components/brave_sync/ui/components/toggle/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/* 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 { StyledWrapper, StyledSlider, StyledBullet, StyleToggle, StyledCheckbox } from './style'

export interface Props {
testId?: string
checked?: boolean
disabled?: boolean
onChange?: (e: any) => void
id?: string
readOnly?: boolean
autoFocus?: boolean
size: 'large' | 'small'
colorType?: 'dark' | 'light' | 'default'
}

export interface ToggleState {
checked?: boolean
}

export class Toggle extends React.PureComponent<Props, ToggleState> {
static defaultProps = {
checked: false,
size: 'small',
type: 'default',
disabled: false
}

constructor (props: Props) {
super(props)
this.state = { checked: props.checked }
this.handleChange = this.handleChange.bind(this)
}

componentWillReceiveProps (nextProps: Props) {
if ('checked' in nextProps) {
this.setState({ checked: nextProps.checked })
}
}

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

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

render () {
const { id, testId, readOnly, disabled, autoFocus, size, colorType } = this.props
const { checked } = this.state

return (
<StyledWrapper checked={checked} data-test-id={testId} size={size}>
<StyledCheckbox
type='checkbox'
id={id}
readOnly={readOnly}
disabled={disabled}
checked={checked}
onChange={this.handleChange}
autoFocus={autoFocus}
/>
<StyleToggle size={size}>
<StyledSlider htmlFor={id} checked={checked} size={size} disabled={disabled} />
<StyledBullet htmlFor={id} checked={checked} size={size} disabled={disabled} colorType={colorType} />
</StyleToggle>
</StyledWrapper>
)
}
}
77 changes: 77 additions & 0 deletions components/brave_sync/ui/components/toggle/style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/* 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 styled, { css } from 'brave-ui/theme'
import { Props } from './index'
import palette from 'brave-ui/theme/colors'

export const StyledCheckbox = styled<{}, 'input'>('input')`
-webkit-appearance: none;
position: absolute;
z-index: 99999999;
width: 100%;
height: 100%;
top: 0;
left: 0;
outline-offset: -3px;
outline-color: ${palette.orange400};
outline-width: 2px;
`

export const StyledWrapper = styled<Props, 'div'>('div')`
box-sizing: border-box;
display: flex;
position: relative;
`

export const StyleToggle = styled<Props, 'div'>('div')`
box-sizing: border-box;
position: relative;
display: block;
height: ${(p) => p.size === 'small' ? '16px' : '24px'};
width: ${(p) => p.size === 'small' ? '28px' : '40px'};
${(p) => p.disabled
? css`
pointer-events: none;
animation: none;
` : ''
};
`

export const StyledSlider = styled<Props, 'label'>('label')`
box-sizing: border-box;
background: ${(p) => p.disabled ? 'rgba(246,246,250,0.1)' : '#C4C7C9'};
height: ${(p) => p.size === 'small' ? '6px' : '8px'};
margin-top: ${(p) => p.size === 'small' ? '5px' : '8px'};
width: 100%;
border-radius: 3px;
display: block;
`

const transform = (p: Props) => {
let x = p.size === 'small' ? '12px' : '20px'
let y = p.size === 'small' ? '3px' : '4px'

if (!p.checked) {
x = '-1px'
}

return { x, y }
}

const transformBullet = (p: Props) => `${transform(p).x}, calc(-50% - ${transform(p).y})`

export const StyledBullet = styled<Props, 'label'>('label')`
box-sizing: border-box;
position: relative;
border-radius: 50%;
transition: all .4s ease;
transform: ${p => `translate(${transformBullet(p)})`};
width: ${p => p.size === 'small' ? '16px' : '20px'};
height: ${p => p.size === 'small' ? '16px' : '20px'};
background-color: ${p => p.disabled && 'rgba(235,236,240,0.8)' || p.checked ? '#fb542b' : '#ebecf0'};
display: block;
box-shadow: 0 3px 3px rgba(0,0,0,0.05);
`
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as React from 'react'
import { AlertBox } from 'brave-ui'

// Feature-specific components
import { Title } from 'brave-ui/features/sync'
import { Title } from '../../components'

// Utils
import { getLocale } from '../../../../common/locale'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as React from 'react'
import { AlertBox } from 'brave-ui'

// Feature-specific components
import { Title, Paragraph } from 'brave-ui/features/sync'
import { Title, Paragraph } from '../../components'

// Utils
import { getLocale } from '../../../../common/locale'
Expand Down
4 changes: 2 additions & 2 deletions components/brave_sync/ui/containers/disabledContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
SyncCard,
SyncCardContent,
DisabledContent
} from 'brave-ui/features/sync'
} from '../components'

import { SyncStartIcon } from 'brave-ui/features/sync/images'
import { SyncStartIcon } from '../components/images'

// Modals
import DeviceTypeModal from './modals/deviceType'
Expand Down
4 changes: 2 additions & 2 deletions components/brave_sync/ui/containers/enabledContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import * as React from 'react'
import { Button, AlertBox } from 'brave-ui'
import { CloseCircleIcon } from 'brave-ui/components/icons'
import Table, { Cell, Row } from 'brave-ui/components/dataTables/table'
import { Toggle } from 'brave-ui/features/shields'

// Feature-specific components
import {
Expand All @@ -25,8 +24,9 @@ import {
TableButtonGrid,
EnabledContent,
SyncCardContent,
Toggle,
SyncCard
} from 'brave-ui/features/sync'
} from '../components'

// Modals
import RemoveDeviceModal from './modals/removeDevice'
Expand Down
4 changes: 2 additions & 2 deletions components/brave_sync/ui/containers/modals/deviceType.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
DeviceGrid,
DeviceContainer,
ModalSubTitle
} from 'brave-ui/features/sync'
} from '../../components'

// Modals
import ViewSyncCode from './viewSyncCode'
Expand All @@ -26,7 +26,7 @@ import ScanCode from './scanCode'
import { getLocale } from '../../../../common/locale'

// Images
import { SyncDesktopIcon, SyncMobileIcon } from 'brave-ui/features/sync/images'
import { SyncDesktopIcon, SyncMobileIcon } from '../../components/images'

interface Props {
syncData: Sync.State
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
OneColumnButtonGrid,
Title,
SubTitle
} from 'brave-ui/features/sync'
} from '../../components'

// Icons
import { LoaderIcon } from 'brave-ui/components/icons'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
ModalContent,
TwoColumnButtonGrid,
OneColumnButtonGrid
} from 'brave-ui/features/sync'
} from '../../components'

// Icons
import { LoaderIcon } from 'brave-ui/components/icons'
Expand Down
2 changes: 1 addition & 1 deletion components/brave_sync/ui/containers/modals/resetSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
TwoColumnButtonGrid,
OneColumnButtonGrid,
Paragraph
} from 'brave-ui/features/sync'
} from '../../components'

// Icons
import { LoaderIcon } from 'brave-ui/components/icons'
Expand Down
4 changes: 2 additions & 2 deletions components/brave_sync/ui/containers/modals/scanCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
ScanGrid,
ThreeColumnButtonGrid,
Link
} from 'brave-ui/features/sync'
} from '../../components'

// Dialogs
import CancelDeviceSyncingDialog from '../commonDialogs/cancelDeviceSyncing'
Expand All @@ -26,7 +26,7 @@ import CancelDeviceSyncingDialog from '../commonDialogs/cancelDeviceSyncing'
import { getLocale } from '../../../../common/locale'

// Images
import { SyncMobilePicture, QRCode } from 'brave-ui/features/sync/images'
import { SyncMobilePicture, QRCode } from '../../components/images'

interface Props {
syncData: Sync.State
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ThreeColumnButtonGrid,
Bold,
Link
} from 'brave-ui/features/sync'
} from '../../components'

// Dialogs
import CancelDeviceSyncingDialog from '../commonDialogs/cancelDeviceSyncing'
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import * as React from 'react'

// Components
import { Button } from '../../../src/components'
import { Button } from 'brave-ui'

// Component-specific components
import {
Expand All @@ -17,14 +17,14 @@ import {
DisabledContentButtonGrid,
TableGrid,
Paragraph
} from '../../../src/features/sync'
} from '../components'

// Modals
import DeviceType from './modals/deviceType'
import EnterSyncCode from './modals/enterSyncCode'

// Images
import { SyncStartIcon } from '../../../src/features/sync/images'
import { SyncStartIcon } from '../components/images'

// Utils
import { getLocale } from './page/fakeLocale'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import * as React from 'react'

// Components
import { Toggle } from '../../../src/features/shields'
import Button from '../../../src/components/buttonsIndicators/button'
import { CloseCircleOIcon } from '../../../src/components/icons'
import Table, { Cell, Row } from '../../../src/components/dataTables/table'
import { Button } from 'brave-ui'
import { CloseCircleOIcon } from 'brave-ui/components/icons'
import Table, { Cell, Row } from 'brave-ui/components/dataTables/table'

// Feature-specific components
import {
Expand All @@ -23,8 +22,9 @@ import {
TableRowRemoveButton,
TableGrid,
TableButtonGrid,
TableRowToggleButton
} from '../../../src/features/sync'
TableRowToggleButton,
Toggle
} from '../components'

// Modals
import RemoveMainDevice from './modals/removeMainDevice'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const doNothing = () => {
console.log('nothing')
}

storiesOf('Feature Components/Sync/Popups and Modals', module)
storiesOf('Sync/Popups and Modals', module)
.add('Reset Sync', () => <ResetSyncModal onClose={doNothing} mainDeviceName={data.device1.name} />)
.add('Device Type', () => <DeviceTypeModal onClose={doNothing} />)
.add('Scan Code', () => <ScanCodeModal onClose={doNothing} />)
Expand Down
Loading

0 comments on commit 75a103c

Please sign in to comment.