diff options
| author | anderklander <anderklander@gmail.com> | 2018-02-15 08:47:11 +0100 |
|---|---|---|
| committer | anderklander <anderklander@gmail.com> | 2018-02-15 16:02:03 +0100 |
| commit | 1e9aa9bbeb6be8bd880946a27dc5672b9c668d33 (patch) | |
| tree | ffc7302aea91b851bfd09c3f02acbe6bbcd725c1 /app/components/styled/CellButton.js | |
| parent | 86a28e957d2facd1f31daf072644c06de8bb05ee (diff) | |
| download | mullvadvpn-1e9aa9bbeb6be8bd880946a27dc5672b9c668d33.tar.xz mullvadvpn-1e9aa9bbeb6be8bd880946a27dc5672b9c668d33.zip | |
CellButton rework
Diffstat (limited to 'app/components/styled/CellButton.js')
| -rw-r--r-- | app/components/styled/CellButton.js | 101 |
1 files changed, 54 insertions, 47 deletions
diff --git a/app/components/styled/CellButton.js b/app/components/styled/CellButton.js index f805c089c4..5a50955747 100644 --- a/app/components/styled/CellButton.js +++ b/app/components/styled/CellButton.js @@ -2,6 +2,9 @@ import React from 'react'; import { Text, Component } from 'reactxp'; import { Button } from './Button'; +import { Label } from './Label'; +import { Icon } from './Icon'; +import { SubText } from './SubText'; import Img from '../Img'; import { colors } from '../../config'; @@ -10,7 +13,6 @@ import { createViewStyles, createTextStyles } from '../../lib/styles'; const styles = { ...createViewStyles({ cell:{ - backgroundColor: colors.blue, paddingTop: 15, paddingBottom: 15, paddingLeft: 24, @@ -19,75 +21,80 @@ const styles = { flex: 1, flexDirection: 'row', alignItems: 'center', + alignContent: 'center', justifyContent: 'space-between' }, - hover:{ - backgroundColor: colors.blue80 + blue:{ + backgroundColor: colors.blue80, }, - icon:{ - marginLeft: 8, - width: 16, - height: 16, - flexGrow: 0, - flexShrink: 0, - flexBasis: 'auto', - alignItems: 'flex-end', + blueHover:{ + backgroundColor: colors.blue60, + }, + white40:{ + color: colors.white40, + }, + white60:{ + color: colors.white60, + }, + white80:{ color: colors.white80, }, - }), - ...createTextStyles({ - label:{ - fontFamily: 'DINPro', - fontSize: 20, - fontWeight: '900', - lineHeight: 26, + white: { color: colors.white, - flexGrow: 1, - flexShrink: 0, - flexBasis: 'auto', }, - subtext:{ - fontFamily: 'Open Sans', - fontSize: 13, - fontWeight: '800', - color: colors.white80, - flexGrow: 0, - textAlign: 'right', + relative: { + position: 'relative', + alignSelf: 'center', }, - }) + }), }; export default class CellButton extends Component { props: { - icon?: string, - iconStyle?: string, - hoverStyle?: string, - subtextStyle?: string, - text: string, - subtext?: string, - tintColor?: string, - style?: string + children: React.Element<*>, + disabled: boolean, }; state = { hovered: false }; - render() { - const { style, tintColor, hoverStyle, text, subtext, subtextStyle, icon, iconStyle, ...otherProps } = this.props; + textStyle = () => this.state.hovered ? styles.white80 : styles.white; + iconStyle = () => this.state.hovered ? styles.white80 : styles.white; + subtextStyle = () => this.state.hovered ? styles.white40 : styles.white60; + backgroundStyle = () => this.state.hovered ? styles.blueHover : styles.blue; + 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.cell, style, this.state.hovered ? [styles.hover, hoverStyle] : null ]} - onHoverStart={() => this.setState({ hovered: true })} - onHoverEnd={() => this.setState({ hovered: false })} + <Button style={[ styles.cell, this.backgroundStyle() ]} + onHoverStart={this.onHoverStart} + onHoverEnd={this.onHoverEnd} {...otherProps}> + { + React.Children.map(children, (node) => { + if (React.isValidElement(node)){ + let updatedProps = {}; - <Text style={ styles.label }>{ text }</Text> + if(node.type.name === 'Label') { + updatedProps = { style: [this.textStyle(), node.props.style]}; + } - { subtext ? <Text style={[ styles.subtext, subtextStyle ]}>{ subtext }</Text> : null } + if(node.type.name === 'Icon') { + updatedProps = { style: [this.iconStyle(), styles.relative, node.props.style]}; + } - <Img style={[ styles.icon, iconStyle ]} - source={ icon } - tintColor={ tintColor }/> + if(node.type.name === 'SubText') { + updatedProps = { style: [this.subtextStyle(), node.props.style]}; + } + return React.cloneElement(node, updatedProps); + } else { + return <Label style={this.textStyle()}>{children}</Label>; + } + }) + } </Button> ); } |
