diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2017-12-21 13:15:40 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2017-12-22 13:30:33 +0100 |
| commit | 0822ed3ea1bb595c69f414f6363018c970f2f199 (patch) | |
| tree | 03ba2479700613156969d3b45ddeb0cd0cb4ac97 | |
| parent | 41d50449196fb9028850720b919221ffca456508 (diff) | |
| download | mullvadvpn-0822ed3ea1bb595c69f414f6363018c970f2f199.tar.xz mullvadvpn-0822ed3ea1bb595c69f414f6363018c970f2f199.zip | |
Add tint color to Img component
| -rw-r--r-- | app/components/Img.js | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/app/components/Img.js b/app/components/Img.js index 0c687ff654..9511a4ecb3 100644 --- a/app/components/Img.js +++ b/app/components/Img.js @@ -3,11 +3,37 @@ import React from 'react'; import { View, Component } from 'reactxp'; export default class Img extends Component { + props: { + source: string, + tintColor?: string + }; + render() { - const url = './assets/images/' + this.props.source + '.svg'; + const { source, tintColor, ...otherProps } = this.props; + const url = './assets/images/' + source + '.svg'; + let image; - const style = this.props.style; + if(tintColor) { + image = ( + <div style={{ + WebkitMaskImage: `url('${url}')`, + WebkitMaskRepeat: 'no-repeat', + backgroundColor: tintColor, + }}> + <img src={ url } style={{ + visibility: 'hidden', + }} /> + </div> + ); + } else { + image = ( + <img src={ url } /> + ); + } - return (<View style={ style }> <img src={ url } /> </View>); + return ( + <View { ...otherProps }> + { image } + </View>); } } |
