blob: f54bd18024e6971fc6b5d49ddcd19ca7bacad52a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// @flow
import * as React from 'react';
import { Text, Component } from 'reactxp';
import { Button } from './Button';
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;
}
|