diff options
| author | anderklander <anderklander@gmail.com> | 2018-03-26 09:17:09 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-03-26 14:22:11 +0200 |
| commit | c1fd06c609ab5f99e01071c8a9e790950ede9981 (patch) | |
| tree | 0cfc25ca91f13b15a507c0af4071066ea0b6218d | |
| parent | 767b0dc6e8eba9bb3acc8345d459333f4f690ce1 (diff) | |
| download | mullvadvpn-c1fd06c609ab5f99e01071c8a9e790950ede9981.tar.xz mullvadvpn-c1fd06c609ab5f99e01071c8a9e790950ede9981.zip | |
Separate hovering of Img
| -rw-r--r-- | app/components/Img.js | 31 | ||||
| -rw-r--r-- | app/components/Login.js | 7 | ||||
| -rw-r--r-- | app/components/LoginStyles.js | 9 |
3 files changed, 35 insertions, 12 deletions
diff --git a/app/components/Img.js b/app/components/Img.js index c4fb7637d5..821dd2c290 100644 --- a/app/components/Img.js +++ b/app/components/Img.js @@ -1,15 +1,29 @@ // @flow -import React from 'react'; -import { View, Component } from 'reactxp'; +import * as React from 'react'; +import { View, Component, Styles } from 'reactxp'; -export default class Img extends Component { - props: { +type ImgProps = { source: string, - tintColor?: string + tintColor?: string, + hoverColor?: string, + disabled?: boolean, }; +type State = { hovered: boolean }; + +export default class Img extends Component<ImgProps, State> { + + state = { hovered: false }; + + hoverColorStyle = Styles.createViewStyle({color: this.props.hoverColor}, false); + + onHoverStart = () => !this.props.disabled ? this.setState({ hovered: true }) : null; + onHoverEnd = () => !this.props.disabled ? this.setState({ hovered: false }) : null; + + getHoverStyle = () => (this.state.hovered && this.props.hoverColor) ? this.hoverColorStyle : null; + render() { - const { source, ...otherProps } = this.props; + const { source, disabled, style, onMouseEnter, onMouseLeave, ...otherProps } = this.props; const tintColor = this.props.tintColor; const url = './assets/images/' + source + '.svg'; let image; @@ -34,7 +48,10 @@ export default class Img extends Component { } return ( - <View { ...otherProps }> + <View { ...otherProps } + onMouseEnter={onMouseEnter || this.onHoverStart} + onMouseLeave={onMouseLeave || this.onHoverEnd} + style={[style, this.getHoverStyle()]}> { image } </View>); } diff --git a/app/components/Login.js b/app/components/Login.js index 239156af5b..1450f5adeb 100644 --- a/app/components/Login.js +++ b/app/components/Login.js @@ -396,7 +396,12 @@ class AccountDropdownItem extends React.Component<AccountDropdownItemProps> { <Label style={styles.account_dropdown__label} hoverStyle={ styles.account_dropdown__label_hover } onPress={ () => this.props.onSelect(this.props.value) }> { this.props.label } </Label> - <Img style={styles.account_dropdown__remove} hoverStyle={ styles.account_dropdown__remove_hover } source='icon-close-sml' height='16' width='16' onPress={ () => this.props.onRemove(this.props.value) }/> + <Img style={styles.account_dropdown__remove} + hoverStyle={ styles.account_dropdown__remove_cell_hover } + hoverColor={ styles.account_dropdown__remove_hover } + source='icon-close-sml' + height='16' width='16' + onPress={ () => this.props.onRemove(this.props.value) }/> </CellButton> ); } diff --git a/app/components/LoginStyles.js b/app/components/LoginStyles.js index 757ace7317..a3c998c9a0 100644 --- a/app/components/LoginStyles.js +++ b/app/components/LoginStyles.js @@ -93,10 +93,10 @@ export default { }, account_dropdown__remove: { justifyContent: 'center', - color: colors.blue60, + color: colors.blue40, }, - account_dropdown__remove_hover: { - color: colors.blue, + account_dropdown__remove_cell_hover: { + color: colors.blue60, }, account_dropdown__label_hover: { color: colors.blue, @@ -156,5 +156,6 @@ export default { border: 0, textAlign: 'left', }, - }) + }), + account_dropdown__remove_hover: colors.blue, }; |
