-
Notifications
You must be signed in to change notification settings - Fork 127
/
Copy pathbutton.js
152 lines (145 loc) · 3 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import ButtonGroup from './components/button-group';
import Element from '../element';
import { normalizeStatus } from '../../services/normalizer';
const Button = ({
children,
className,
renderAs,
color,
size,
outlined,
inverted,
submit,
reset,
fullwidth,
status,
loading,
disabled,
remove,
isSelected,
isStatic,
rounded,
onClick,
text,
...props
}) => {
let otherProps = {};
if (submit) {
otherProps = {
type: 'submit',
renderAs: 'button',
};
}
if (reset) {
otherProps = {
type: 'reset',
renderAs: 'button',
};
}
if (isStatic) {
otherProps = {
renderAs: 'span',
};
}
return (
<Element
tabIndex={disabled ? -1 : 0}
renderAs={renderAs}
{...props}
{...otherProps}
disabled={disabled}
onClick={disabled ? undefined : onClick}
className={classnames(className, {
[`is-${color}`]: color,
[`is-${size}`]: size,
'is-selected': isSelected,
'is-static': isStatic,
'is-rounded': rounded,
'is-outlined': outlined,
'is-inverted': inverted,
'is-fullwidth': fullwidth,
[`is-${normalizeStatus(status)}`]: status,
'is-loading': loading,
'is-text': text,
delete: remove,
button: !remove,
})}
>
{children}
</Element>
);
};
Button.Group = ButtonGroup;
Button.propTypes = {
color: PropTypes.oneOfType([
PropTypes.oneOf([
'primary',
'link',
'info',
'success',
'warning',
'danger',
'dark',
'text',
'black-bis',
'black-ter',
'white-bis',
'white-ter',
'grey-darker',
'grey-dark',
'grey-light',
'grey-lighter',
]),
PropTypes.string,
]),
size: PropTypes.oneOfType([
PropTypes.oneOf(['small', 'medium', 'large']),
PropTypes.string,
]),
/**
* Whether Button should have an outline.
*/
outlined: PropTypes.bool,
/**
* Whether Button should have an inverted color scheme. Useful when button is used on colored background
*/
inverted: PropTypes.bool,
submit: PropTypes.bool,
reset: PropTypes.bool,
status: PropTypes.oneOf(['focus', 'hover', 'active']),
loading: PropTypes.bool,
/**
* Whether Button should occupy the full width of parent
*/
fullwidth: PropTypes.bool,
disabled: PropTypes.bool,
remove: PropTypes.bool,
/**
* Whether Button is selected. Useful in a Button.Group.
*/
isSelected: PropTypes.bool,
/**
* Whether Button is non-interactive/static.
*/
isStatic: PropTypes.bool,
/**
* Whether Button should have fully-rounded corners
*/
rounded: PropTypes.bool,
/**
* Whether Button is a text button.
*/
text: PropTypes.bool,
renderAs: PropTypes.oneOfType([
PropTypes.func,
PropTypes.string,
PropTypes.object,
]),
};
Button.defaultProps = {
renderAs: 'button',
};
export default Button;