diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2018-07-18 12:56:12 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-07-18 20:06:22 +0200 |
| commit | e6dc383704b1c7a6aff8abfad2bd5e2d948138cc (patch) | |
| tree | 0c2ffe951c376e0a0425119f99709945a92520f6 /app/components/AppButton.js | |
| parent | 9f0ed3cc4878edac9aa8ae67fae366cb1d0bf588 (diff) | |
| download | mullvadvpn-e6dc383704b1c7a6aff8abfad2bd5e2d948138cc.tar.xz mullvadvpn-e6dc383704b1c7a6aff8abfad2bd5e2d948138cc.zip | |
- Reintegrate components/styled into components
- Drop styled/Button, use RX.Button instead and reset cursor when needed
- Scope AppButton and Cell to avoid class clash for Label and SubText
- Add missing cursor: default
Diffstat (limited to 'app/components/AppButton.js')
| -rw-r--r-- | app/components/AppButton.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/app/components/AppButton.js b/app/components/AppButton.js new file mode 100644 index 0000000000..7419203472 --- /dev/null +++ b/app/components/AppButton.js @@ -0,0 +1,73 @@ +// @flow +import * as React from 'react'; +import { Button, Text, Component } from 'reactxp'; +import styles from './AppButtonStyles'; +import blurStyles from './BlurAppButtonStyles'; + +export class Label extends Text {} + +class BaseButton extends Component { + props: { + children?: React.Node, + disabled: boolean, + }; + + state = { hovered: false }; + + textStyle = () => (this.state.hovered ? styles.white80 : styles.white); + iconStyle = () => (this.state.hovered ? styles.white80 : 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.name === 'Label') { + updatedProps = { style: [styles.label, this.textStyle()] }; + } + + if (node.type.name === '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; +} |
