aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/components/ui/icon_button.tsx
blob: 9f469ec69d82fd560985fd145cce0726b7b398bc (plain) (blame)
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
import { colors, Styles } from '@0x/react-shared';
import * as _ from 'lodash';
import * as React from 'react';

export interface IconButtonProps {
    iconName: string;
    labelText?: string;
    onClick?: () => void;
    color?: string;
    display?: string;
}
interface IconButtonState {
    isHovering: boolean;
}
export class IconButton extends React.Component<IconButtonProps, IconButtonState> {
    public static defaultProps: Partial<IconButtonProps> = {
        labelText: '',
        color: colors.mediumBlue,
    };
    public constructor(props: IconButtonProps) {
        super(props);
        this.state = {
            isHovering: false,
        };
    }
    public render(): React.ReactNode {
        const styles: Styles = {
            root: {
                cursor: this.props.onClick ? 'pointer' : 'undefined',
                opacity: this.state.isHovering && this.props.onClick ? 0.5 : 1,
                display: this.props.display,
            },
            icon: {
                color: this.props.color,
                fontSize: 20,
            },
            label: {
                color: this.props.color,
                fontSize: 10,
            },
        };
        return (
            <div
                className="flex items-center py2"
                onClick={this.props.onClick}
                onMouseEnter={this._onToggleHover.bind(this, true)}
                onMouseLeave={this._onToggleHover.bind(this, false)}
                style={styles.root}
            >
                <i style={styles.icon} className={`zmdi ${this.props.iconName}`} />
                {!_.isEmpty(this.props.labelText) && (
                    <div className="pl1" style={styles.label}>
                        {this.props.labelText}
                    </div>
                )}
            </div>
        );
    }
    private _onToggleHover(isHovering: boolean): void {
        this.setState({
            isHovering,
        });
    }
}