/
button.js
50 lines (46 loc) · 1.6 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
import React from 'react';
import PropTypes from 'prop-types';
import classNames from '../../utils/classnames';
/**
* Button usage:OK(primary)、Cancel(default)、Warn(warn).
*
*/
export default class Button extends React.Component {
static propTypes = {
disabled: PropTypes.bool,
/**
* Options: primary, default, warn, vcode
*
*/
type: PropTypes.string,
/**
* Options: normal, small
*
*/
size: PropTypes.string,
};
static defaultProps = {
disabled: false,
type: 'primary',
size: 'normal',
};
render() {
const { component, type, size, plain, className, children, ...others } = this.props;
const Component = component ? component : this.props.href || type === 'vcode' ? 'a' : 'button';
const cls = type === 'vcode' ? classNames('weui-vcode-btn', {[className]: className}) : classNames({
'weui-btn': true,
'weui-btn_mini': size === 'small',
'weui-btn_primary': type === 'primary' && !plain,
'weui-btn_default': type === 'default' && !plain,
'weui-btn_warn': type === 'warn',
'weui-btn_plain-primary': type === 'primary' && plain,
'weui-btn_plain-default': type === 'default' && plain,
'weui-btn_disabled': this.props.disabled && !plain,
'weui-btn_plain-disabled': this.props.disabled && plain,
[className]: className
});
return (
<Component { ...others } className={ cls }>{ children }</Component>
);
}
};