-
Notifications
You must be signed in to change notification settings - Fork 256
/
index.tsx
94 lines (76 loc) · 1.96 KB
/
index.tsx
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Libraries
import React, {Component} from 'react'
import classnames from 'classnames'
// Types
import {
ComponentStatus,
ComponentColor,
ComponentSize,
ButtonShape,
IconFont,
} from 'src/reusable_ui/types'
import {ErrorHandling} from 'src/shared/decorators/errors'
interface Props {
text: string
onClick?: () => void
color?: ComponentColor
size?: ComponentSize
shape?: ButtonShape
icon?: IconFont
status?: ComponentStatus
titleText?: string
}
@ErrorHandling
class Button extends Component<Props> {
public static defaultProps: Partial<Props> = {
color: ComponentColor.Default,
size: ComponentSize.Small,
shape: ButtonShape.Default,
status: ComponentStatus.Default,
}
public render() {
const {status, onClick, text, titleText} = this.props
return (
<button
className={this.className}
disabled={status === ComponentStatus.Disabled}
onClick={onClick}
title={titleText || text}
>
{this.icon}
{this.text}
{this.statusIndicator}
</button>
)
}
private get icon(): JSX.Element {
const {icon} = this.props
if (icon) {
return <span className={`button-icon icon ${icon}`} />
}
return null
}
private get text(): string {
const {text, shape} = this.props
if (shape === ButtonShape.Square) {
return null
}
return text
}
private get statusIndicator(): JSX.Element {
const {status, size} = this.props
if (status === ComponentStatus.Loading) {
return <div className={`button-spinner button-spinner--${size}`} />
}
return null
}
private get className(): string {
const {color, size, shape, status} = this.props
return classnames(`button button-${size} button-${color}`, {
'button-square': shape === ButtonShape.Square,
'button-stretch': shape === ButtonShape.StretchToFit,
'button--loading': status === ComponentStatus.Loading,
})
}
}
export default Button