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
75
76
77
78
79
|
// @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 {}
type Props = {
children?: React.Node,
style?: Object,
disabled: boolean,
};
type State = {
hovered: boolean,
};
class BaseButton extends Component<Props, State> {
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, style, ...otherProps } = this.props;
return (
<Button
{...otherProps}
style={[styles.common, this.backgroundStyle(), style]}
onHoverStart={this.onHoverStart}
onHoverEnd={this.onHoverEnd}>
{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;
}
|