-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync WebUI: Move brave-ui paths to brave-core paths
- Loading branch information
1 parent
23c60db
commit 75a103c
Showing
43 changed files
with
209 additions
and
58 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
File renamed without changes
File renamed without changes
File renamed without changes
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
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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,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> | ||
) | ||
} | ||
} |
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,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); | ||
` |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.