-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch component and fix i18n in client (#1108)
* [#780] Switch Component * Update Switch in Moments/Strategies form * Remove react-intl and use i18n-js * Add i18n to TODOs in client * Make Codeclimate happy * Remove build-i18n from test build * Quick fixes * CSS updates * Letter spacing
- Loading branch information
1 parent
01ec097
commit ed1a17d
Showing
41 changed files
with
370 additions
and
269 deletions.
There are no files selected for viewing
This file was deleted.
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
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 was deleted.
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
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,88 @@ | ||
// @flow | ||
import React from 'react'; | ||
import { Utils } from '../../utils'; | ||
import { Input } from './index'; | ||
import css from './InputSwitch.scss'; | ||
import { I18n } from '../../libs/i18n'; | ||
|
||
export type Props = { | ||
id: string, | ||
name: string, | ||
label: string, | ||
value?: any, | ||
checked?: boolean, | ||
uncheckedValue?: any, | ||
}; | ||
|
||
export type State = { | ||
checked: boolean, | ||
key?: string, | ||
}; | ||
|
||
export class InputSwitch extends React.Component<Props, State> { | ||
constructor(props: Props) { | ||
super(props); | ||
this.state = { checked: !!props.checked }; | ||
} | ||
|
||
toggleChecked = () => { | ||
this.setState((prevState: State) => ({ | ||
checked: !prevState.checked, | ||
key: Utils.randomString(), | ||
})); | ||
}; | ||
|
||
onKeyPress = (e: SyntheticKeyboardEvent<HTMLInputElement>) => { | ||
if (e.key === 'Enter') { | ||
this.toggleChecked(); | ||
} | ||
}; | ||
|
||
displaySwitchHidden = () => { | ||
const { | ||
id, name, label, value, uncheckedValue, | ||
} = this.props; | ||
const { checked, key } = this.state; | ||
return ( | ||
<div className={css.switchHidden}> | ||
<Input | ||
id={id} | ||
key={key} | ||
type="checkbox" | ||
name={name} | ||
label={label} | ||
value={value} | ||
uncheckedValue={uncheckedValue} | ||
checked={checked} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
render() { | ||
const { id } = this.props; | ||
const { checked } = this.state; | ||
return ( | ||
<div className={css.switch}> | ||
<div | ||
className={`${css.switchWrapper} ${ | ||
checked ? css.switchOn : css.switchOff | ||
}`} | ||
> | ||
<div | ||
id={`${id}_switch`} | ||
className={`switchToggle ${css.switchToggle}`} | ||
onClick={this.toggleChecked} | ||
onKeyPress={this.onKeyPress} | ||
role="switch" | ||
aria-checked={checked} | ||
tabIndex={0} | ||
> | ||
{checked ? I18n.t('true') : I18n.t('false')} | ||
</div> | ||
</div> | ||
{this.displaySwitchHidden()} | ||
</div> | ||
); | ||
} | ||
} |
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,39 @@ | ||
@import "../../styles/_global.scss"; | ||
|
||
.switch { | ||
@include setFontSize($size-16); | ||
display: inline-block; | ||
min-width: 120px; | ||
letter-spacing: 0.095em; | ||
|
||
&Wrapper { | ||
display: flex; | ||
flex-direction: row; | ||
border-radius: $size-4; | ||
padding: $size-4; | ||
} | ||
|
||
&On { | ||
@include linearTransition(0.5s); | ||
background: $key-lime; | ||
justify-content: flex-end; | ||
} | ||
|
||
&Off { | ||
@include linearTransition(0.5s); | ||
background: $mulberry-70; | ||
} | ||
|
||
&Toggle { | ||
background: $white-70; | ||
padding: $size-8 $size-16; | ||
border-radius: $size-4; | ||
color: $mulberry-80; | ||
cursor: pointer; | ||
text-transform: uppercase; | ||
} | ||
|
||
&Hidden { | ||
display: none; | ||
} | ||
} |
Oops, something went wrong.