1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
|
8 |
|
9 | var _react = require('react');
|
10 |
|
11 | var _react2 = _interopRequireDefault(_react);
|
12 |
|
13 | var _reactDom = require('react-dom');
|
14 |
|
15 | var _reactDom2 = _interopRequireDefault(_reactDom);
|
16 |
|
17 | var _propTypes = require('prop-types');
|
18 |
|
19 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
20 |
|
21 | var _classnames = require('classnames');
|
22 |
|
23 | var _classnames2 = _interopRequireDefault(_classnames);
|
24 |
|
25 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
26 |
|
27 | function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }
|
28 |
|
29 | function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
|
30 |
|
31 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
32 |
|
33 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
34 |
|
35 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
|
36 |
|
37 | var propTypes = {
|
38 | |
39 |
|
40 |
|
41 | size: _propTypes2["default"].oneOf(['sm', 'md', 'xg', 'lg']),
|
42 | |
43 |
|
44 |
|
45 | style: _propTypes2["default"].object,
|
46 | |
47 |
|
48 |
|
49 | shape: _propTypes2["default"].oneOf(['block', 'round', 'border', 'squared', 'floating', 'pillRight', 'pillLeft', 'icon']),
|
50 |
|
51 | bordered: _propTypes2["default"].bool,
|
52 | |
53 |
|
54 |
|
55 | colors: _propTypes2["default"].oneOf(['primary', 'secondary', 'accent', 'success', 'info', 'warning', 'danger', 'dark', 'light', 'default']),
|
56 | |
57 |
|
58 |
|
59 |
|
60 | disabled: _propTypes2["default"].bool,
|
61 | |
62 |
|
63 |
|
64 |
|
65 | className: _propTypes2["default"].string,
|
66 |
|
67 | |
68 |
|
69 |
|
70 |
|
71 | htmlType: _propTypes2["default"].oneOf(['submit', 'button', 'reset']),
|
72 | isSubmit: _propTypes2["default"].bool
|
73 | };
|
74 |
|
75 | var defaultProps = {
|
76 | disabled: false,
|
77 | htmlType: 'button',
|
78 | clsPrefix: 'u-button',
|
79 | bordered: false,
|
80 | isSubmit: false
|
81 | };
|
82 |
|
83 | var sizeMap = {
|
84 | sm: 'sm',
|
85 | md: 'md',
|
86 | xg: 'xg',
|
87 | lg: 'lg'
|
88 | },
|
89 | colorsMap = {
|
90 | primary: 'primary',
|
91 | secondary: 'secondary',
|
92 | accent: 'accent',
|
93 | success: 'success',
|
94 | info: 'info',
|
95 | warning: 'warning',
|
96 | danger: 'danger',
|
97 | dark: 'dark',
|
98 | light: 'light'
|
99 | },
|
100 | shapeMap = {
|
101 | block: 'block',
|
102 | round: 'round',
|
103 | border: 'border',
|
104 | squared: 'squared',
|
105 | floating: 'floating',
|
106 | pillRight: 'pill-right',
|
107 | pillLeft: 'pill-left',
|
108 | icon: 'icon'
|
109 | };
|
110 |
|
111 | var Button = function (_Component) {
|
112 | _inherits(Button, _Component);
|
113 |
|
114 | function Button(props) {
|
115 | _classCallCheck(this, Button);
|
116 |
|
117 | return _possibleConstructorReturn(this, _Component.call(this, props));
|
118 | }
|
119 |
|
120 | Button.prototype.render = function render() {
|
121 | var _props = this.props,
|
122 | colors = _props.colors,
|
123 | shape = _props.shape,
|
124 | disabled = _props.disabled,
|
125 | className = _props.className,
|
126 | size = _props.size,
|
127 | bordered = _props.bordered,
|
128 | children = _props.children,
|
129 | htmlType = _props.htmlType,
|
130 | clsPrefix = _props.clsPrefix,
|
131 | isSubmit = _props.isSubmit,
|
132 | others = _objectWithoutProperties(_props, ['colors', 'shape', 'disabled', 'className', 'size', 'bordered', 'children', 'htmlType', 'clsPrefix', 'isSubmit']);
|
133 |
|
134 | var clsObj = {};
|
135 | if (className) {
|
136 | clsObj[className] = true;
|
137 | }
|
138 | if (sizeMap[size]) {
|
139 | clsObj[clsPrefix + '-' + sizeMap[size]] = true;
|
140 | }
|
141 |
|
142 | if (shapeMap[shape]) {
|
143 | clsObj[clsPrefix + '-' + shapeMap[shape]] = true;
|
144 | }
|
145 | if (colorsMap[colors]) {
|
146 | clsObj[clsPrefix + '-' + colorsMap[colors]] = true;
|
147 | }
|
148 | if (bordered) {
|
149 | clsObj[clsPrefix + '-border'] = bordered;
|
150 | }
|
151 | var classes = (0, _classnames2["default"])(clsPrefix, clsObj);
|
152 | return _react2["default"].createElement(
|
153 | 'button',
|
154 | _extends({
|
155 | type: htmlType,
|
156 | className: classes,
|
157 | disabled: disabled
|
158 | }, others),
|
159 | this.props.children
|
160 | );
|
161 | };
|
162 |
|
163 | return Button;
|
164 | }(_react.Component);
|
165 |
|
166 | Button.propTypes = propTypes;
|
167 | Button.defaultProps = defaultProps;
|
168 |
|
169 | exports["default"] = Button;
|
170 | module.exports = exports['default']; |
\ | No newline at end of file |