1 | import React, { Component } from 'react';
|
2 | import ReactDOM from 'react-dom';
|
3 | import PropTypes from 'prop-types';
|
4 | import classnames from 'classnames';
|
5 |
|
6 | const propTypes = {
|
7 | |
8 |
|
9 |
|
10 | size: PropTypes.oneOf(['sm', 'md', 'xg', 'lg']),
|
11 | |
12 |
|
13 |
|
14 | style: PropTypes.object,
|
15 | |
16 |
|
17 |
|
18 | shape: PropTypes.oneOf(['block', 'round','border', 'squared', 'floating', 'pillRight', 'pillLeft', 'icon']),
|
19 |
|
20 | bordered: PropTypes.bool,
|
21 | |
22 |
|
23 |
|
24 | colors: PropTypes.oneOf(['primary', 'secondary', 'accent', 'success', 'info', 'warning', 'danger', 'dark', 'light' , 'default']),
|
25 | |
26 |
|
27 |
|
28 |
|
29 | disabled: PropTypes.bool,
|
30 | |
31 |
|
32 |
|
33 |
|
34 | className: PropTypes.string,
|
35 |
|
36 | |
37 |
|
38 |
|
39 |
|
40 | htmlType: PropTypes.oneOf(['submit', 'button', 'reset']),
|
41 | isSubmit:PropTypes.bool
|
42 | }
|
43 |
|
44 | const defaultProps = {
|
45 | disabled: false,
|
46 | htmlType: 'button',
|
47 | clsPrefix: 'u-button',
|
48 | bordered: false,
|
49 | isSubmit:false
|
50 | }
|
51 |
|
52 | const sizeMap = {
|
53 | sm: 'sm',
|
54 | md: 'md',
|
55 | xg: 'xg',
|
56 | lg: 'lg'
|
57 | },
|
58 | colorsMap = {
|
59 | primary: 'primary',
|
60 | secondary: 'secondary',
|
61 | accent: 'accent',
|
62 | success: 'success',
|
63 | info: 'info',
|
64 | warning: 'warning',
|
65 | danger: 'danger',
|
66 | dark: 'dark',
|
67 | light: 'light'
|
68 | },
|
69 | shapeMap = {
|
70 | block: 'block',
|
71 | round: 'round',
|
72 | border: 'border',
|
73 | squared: 'squared',
|
74 | floating: 'floating',
|
75 | pillRight: 'pill-right',
|
76 | pillLeft: 'pill-left',
|
77 | icon: 'icon'
|
78 | };
|
79 |
|
80 |
|
81 | class Button extends Component {
|
82 | constructor(props) {
|
83 | super(props);
|
84 | }
|
85 | render() {
|
86 | let {colors,
|
87 | shape,
|
88 | disabled,
|
89 | className,
|
90 | size,
|
91 | bordered,
|
92 | children,
|
93 | htmlType,
|
94 | clsPrefix,
|
95 | isSubmit,
|
96 | ...others} = this.props;
|
97 | let clsObj = {};
|
98 | if (className) {
|
99 | clsObj[className] = true;
|
100 | }
|
101 | if (sizeMap[size]) {
|
102 | clsObj[`${clsPrefix}-${sizeMap[size]}`] = true;
|
103 | }
|
104 |
|
105 | if (shapeMap[shape]) {
|
106 | clsObj[`${clsPrefix}-${shapeMap[shape]}`] = true;
|
107 | }
|
108 | if (colorsMap[colors]) {
|
109 | clsObj[`${clsPrefix}-${colorsMap[colors]}`] = true;
|
110 | }
|
111 |
|
112 | let classes = classnames(clsPrefix, clsObj);
|
113 | return (
|
114 | <button
|
115 | type={htmlType}
|
116 | className={classes}
|
117 | disabled={disabled}
|
118 | {...others}>
|
119 | {this.props.children}
|
120 | </button>
|
121 | );
|
122 | }
|
123 | }
|
124 |
|
125 | Button.propTypes = propTypes;
|
126 | Button.defaultProps = defaultProps;
|
127 |
|
128 | export default Button;
|