diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-07-18 20:07:12 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-07-18 20:07:12 +0200 |
| commit | ec6248d4a431c91c6a437e5a4897911d4701347b (patch) | |
| tree | 2809d5ba60811a2bdbbad56a4e6106d0f8f583b5 /app/components/AppButton.js | |
| parent | 9f0ed3cc4878edac9aa8ae67fae366cb1d0bf588 (diff) | |
| parent | 75adfa317377a7150955ece2f59379ca3d89321f (diff) | |
| download | mullvadvpn-ec6248d4a431c91c6a437e5a4897911d4701347b.tar.xz mullvadvpn-ec6248d4a431c91c6a437e5a4897911d4701347b.zip | |
Merge branch 'reintegrate-styled-classes'
Diffstat (limited to 'app/components/AppButton.js')
| -rw-r--r-- | app/components/AppButton.js | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/app/components/AppButton.js b/app/components/AppButton.js new file mode 100644 index 0000000000..1b8f50cad2 --- /dev/null +++ b/app/components/AppButton.js @@ -0,0 +1,74 @@ +// @flow +import * as React from 'react'; +import { Button, Text, Component } from 'reactxp'; +import styles from './AppButtonStyles'; +import blurStyles from './BlurAppButtonStyles'; +import Img from './Img'; + +export class Label extends Text {} + +class BaseButton extends Component { + props: { + children?: React.Node, + disabled: boolean, + }; + + state = { hovered: false }; + + textStyle = () => styles.white; + iconStyle = () => styles.white; + backgroundStyle = () => (this.state.hovered ? styles.white80 : styles.white); + + onHoverStart = () => (!this.props.disabled ? this.setState({ hovered: true }) : null); + onHoverEnd = () => (!this.props.disabled ? this.setState({ hovered: false }) : null); + render() { + const { children, ...otherProps } = this.props; + return ( + <Button + style={[styles.common, this.backgroundStyle()]} + onHoverStart={this.onHoverStart} + onHoverEnd={this.onHoverEnd} + {...otherProps}> + {React.Children.map(children, (node) => { + if (React.isValidElement(node)) { + let updatedProps = {}; + + if (node.type === Label) { + updatedProps = { style: [styles.label, this.textStyle()] }; + } + + if (node.type === Img) { + updatedProps = { tintColor: 'currentColor', style: [styles.icon, this.iconStyle()] }; + } + + return React.cloneElement(node, updatedProps); + } else { + return <Label style={[styles.label, this.textStyle()]}>{children}</Label>; + } + })} + </Button> + ); + } +} + +export class RedButton extends BaseButton { + backgroundStyle = () => (this.state.hovered ? styles.redHover : styles.red); +} + +export class GreenButton extends BaseButton { + backgroundStyle = () => (this.state.hovered ? styles.greenHover : styles.green); +} + +export class BlueButton extends BaseButton { + backgroundStyle = () => (this.state.hovered ? styles.blueHover : styles.blue); +} + +export class TransparentButton extends BaseButton { + backgroundStyle = () => + this.state.hovered ? blurStyles.transparentHover : blurStyles.transparent; +} + +export class RedTransparentButton extends BaseButton { + backgroundStyle = () => + this.state.hovered ? blurStyles.redTransparentHover : blurStyles.redTransparent; +} |
