-
Notifications
You must be signed in to change notification settings - Fork 841
/
button.js
102 lines (87 loc) · 1.84 KB
/
button.js
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
95
96
97
98
99
100
101
102
import React, {
PropTypes,
} from 'react';
import classNames from 'classnames';
import {
ICON_TYPES,
KuiIcon,
} from '../icon';
const typeToClassNameMap = {
primary: 'kuiButton--primary',
secondary: 'kuiButton--secondary',
warning: 'kuiButton--warning',
danger: 'kuiButton--danger',
ghost: 'kuiButton--ghost',
};
export const TYPES = Object.keys(typeToClassNameMap);
const sizeToClassNameMap = {
small: 'kuiButton--small',
large: 'kuiButton--large',
};
export const SIZES = Object.keys(sizeToClassNameMap);
const iconSideToClassNameMap = {
left: '',
right: 'kuiButton--iconRight',
};
export const ICON_SIDES = Object.keys(iconSideToClassNameMap);
export const KuiButton = ({
children,
className,
iconType,
iconSide,
type,
size,
fill,
isDisabled,
...rest,
}) => {
const classes = classNames(
'kuiButton',
typeToClassNameMap[type],
sizeToClassNameMap[size],
iconSideToClassNameMap[iconSide],
className,
{
'kuiButton--fill': fill,
},
);
// Add an icon to the button if one exists.
let buttonIcon;
if (iconType) {
buttonIcon = (
<KuiIcon
className="kuiButton__icon"
type={iconType}
size="medium"
aria-hidden="true"
/>
);
}
return (
<button
disabled={isDisabled}
className={classes}
{...rest}
>
<span className="kuiButton__content">
{buttonIcon}
<span>{children}</span>
</span>
</button>
);
};
KuiButton.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
iconType: PropTypes.oneOf(ICON_TYPES),
iconSide: PropTypes.oneOf(ICON_SIDES),
fill: React.PropTypes.bool,
type: PropTypes.oneOf(TYPES),
size: PropTypes.oneOf(SIZES),
isDisabled: PropTypes.bool,
};
KuiButton.defaultProps = {
iconSide: 'left',
type: 'primary',
fill: false,
};