-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
270 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
import { SwitchTag, SwitchInputTag, SwitchApperanceTag, SwitchLabelTag } from './Switch.theme'; | ||
|
||
type SwitchProps = { | ||
label?: string, | ||
name?: string, | ||
value: boolean, | ||
onChange?: (boolean, SyntheticInputEvent<HTMLInputElement>) => void, | ||
}; | ||
|
||
class Switch extends React.Component<SwitchProps> { | ||
onChange = (e: SyntheticInputEvent<HTMLInputElement>) => { | ||
const { onChange } = this.props; | ||
|
||
if (typeof onChange === 'function') { | ||
onChange(e.target.checked, e); | ||
} | ||
}; | ||
|
||
render() { | ||
const { label, value, name, onChange, ...rest } = this.props; | ||
|
||
return ( | ||
<SwitchTag tagName="label" { ...rest }> | ||
<SwitchInputTag tagName="input" type="checkbox" name={ name } checked={ value } onChange={ this.onChange } /> | ||
<SwitchApperanceTag value={ value } /> | ||
{ label && <SwitchLabelTag>{ label }</SwitchLabelTag> } | ||
</SwitchTag> | ||
); | ||
} | ||
} | ||
|
||
export { Switch }; |
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,15 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
|
||
export default (asStory: *) => { | ||
asStory('ATOMS/DATA ENTRY/Switch', module, (story, { Switch, Column }) => { | ||
story | ||
.add('with label', () => ( | ||
<Column> | ||
<Switch label="Switch Label" value={ false } /> | ||
<Switch label="Switch Label" value /> | ||
</Column> | ||
)); | ||
}); | ||
}; |
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,53 @@ | ||
// @flow | ||
|
||
import { createStyledTag, createTheme } from '../../../utils'; | ||
|
||
const name = 'Switch'; | ||
|
||
const theme = createTheme(name, { | ||
modifiers: {}, | ||
defaults: {}, | ||
}); | ||
|
||
const SwitchTag = createStyledTag(name, { | ||
display: 'flex', | ||
alignItems: 'center', | ||
height: '4rem', | ||
cursor: 'pointer', | ||
}); | ||
|
||
const SwitchInputTag = createStyledTag(name, { | ||
display: 'none', | ||
}); | ||
|
||
const SwitchApperanceTag = createStyledTag(name, props => ({ | ||
display: 'flex', | ||
height: '2.6rem', | ||
width: '5.2rem', | ||
borderRadius: '2.6rem', | ||
backgroundColor: props.theme.COLORS[props.value ? 'LIGHT_BLUE' : 'LIGHT_GRAY1'], | ||
position: 'relative', | ||
|
||
'&:before': { | ||
content: '\'\'', | ||
position: 'absolute', | ||
width: '2rem', | ||
height: '2rem', | ||
borderRadius: '2rem', | ||
backgroundColor: '#fff', | ||
left: `${props.value ? 29 : 3}px`, | ||
top: '3px', | ||
zIndex: 1, | ||
transition: '.4s', | ||
}, | ||
})); | ||
|
||
const SwitchLabelTag = createStyledTag(name, props => ({ | ||
fontFamily: 'Poppins', | ||
fontSize: '1.2rem', | ||
marginLeft: '1rem', | ||
userSelect: 'none', | ||
color: props.theme.COLORS.GRAY1, | ||
})); | ||
|
||
export { theme, SwitchTag, SwitchInputTag, SwitchApperanceTag, SwitchLabelTag }; |
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 @@ | ||
// @flow | ||
export { Switch } from './Switch'; | ||
export { theme } from './Switch.theme'; |
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