UNPKG

11.4 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _react = _interopRequireDefault(require("react"));
9
10var _propTypes = _interopRequireDefault(require("prop-types"));
11
12var _Loader = _interopRequireDefault(require("./Loader"));
13
14var _Shimmer = _interopRequireDefault(require("./Shimmer"));
15
16var _withStyles = require("../helpers/withStyles");
17
18var _reactWithStyles = require("react-with-styles");
19
20function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
22function _extends() { _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; }; return _extends.apply(this, arguments); }
23
24function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
25
26function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
27
28function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
29
30function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
31
32var propTypes = _objectSpread({}, _reactWithStyles.withStylesPropTypes, {
33 disabled: _propTypes.default.bool,
34 loading: _propTypes.default.bool,
35 fullWidth: _propTypes.default.bool,
36 block: _propTypes.default.bool,
37 compact: _propTypes.default.bool,
38 inverse: _propTypes.default.bool,
39 large: _propTypes.default.bool,
40 mono: _propTypes.default.bool,
41 noSpacing: _propTypes.default.bool,
42 soft: _propTypes.default.bool,
43 primary: _propTypes.default.bool,
44 rectangular: _propTypes.default.bool,
45 secondary: _propTypes.default.bool,
46 shade: _propTypes.default.bool,
47 shimmer: _propTypes.default.bool,
48 small: _propTypes.default.bool,
49 short: _propTypes.default.bool,
50 transparent: _propTypes.default.bool,
51 type: _propTypes.default.string,
52 underlined: _propTypes.default.bool,
53 noBorder: _propTypes.default.bool,
54 children: _propTypes.default.node
55});
56
57var defaultProps = {
58 type: 'button'
59};
60
61var Button = function Button(_ref) {
62 var styles = _ref.styles,
63 children = _ref.children,
64 disabled = _ref.disabled,
65 loading = _ref.loading,
66 fullWidth = _ref.fullWidth,
67 block = _ref.block,
68 compact = _ref.compact,
69 inverse = _ref.inverse,
70 grouped = _ref.grouped,
71 groupedFirst = _ref.groupedFirst,
72 groupedLast = _ref.groupedLast,
73 large = _ref.large,
74 mono = _ref.mono,
75 noSpacing = _ref.noSpacing,
76 shade = _ref.shade,
77 soft = _ref.soft,
78 primary = _ref.primary,
79 rectangular = _ref.rectangular,
80 secondary = _ref.secondary,
81 shimmer = _ref.shimmer,
82 short = _ref.short,
83 small = _ref.small,
84 transparent = _ref.transparent,
85 type = _ref.type,
86 underlined = _ref.underlined,
87 noBorder = _ref.noBorder,
88 theme = _ref.theme,
89 css = _ref.css,
90 href = _ref.href,
91 noWrap = _ref.noWrap,
92 shadowLevel = _ref.shadowLevel,
93 props = _objectWithoutProperties(_ref, ["styles", "children", "disabled", "loading", "fullWidth", "block", "compact", "inverse", "grouped", "groupedFirst", "groupedLast", "large", "mono", "noSpacing", "shade", "soft", "primary", "rectangular", "secondary", "shimmer", "short", "small", "transparent", "type", "underlined", "noBorder", "theme", "css", "href", "noWrap", "shadowLevel"]);
94
95 return _react.default.createElement("button", _extends({}, props, css(styles.button, loading && styles.button_loading, fullWidth && styles.button_fullWidth, block && styles.button_block, compact && styles.button_compact, disabled && styles.button_disabled, inverse && styles.button_inverse, grouped && styles.button_grouped, groupedFirst && styles.button_groupedFirst, groupedLast && styles.button_groupedLast, large && styles.button_large, mono && styles.button_mono, noSpacing && styles.button_noSpacing, soft && styles.button_soft, primary && styles.button_primary, rectangular && styles.button_rectangular, secondary && styles.button_secondary, shade && styles.button_shade, short && styles.button_short, small && styles.button_small, transparent && styles.button_transparent, underlined && styles.button_underlined, noBorder && styles.button_noBorder), {
96 disabled: disabled || loading,
97 type: type
98 }), loading && shimmer && _react.default.createElement("div", css(styles.shimmer), _react.default.createElement(_Shimmer.default, {
99 height: "100%",
100 width: "100%"
101 })), _react.default.createElement("div", css(styles.button__content, loading && styles.button__content_loading, fullWidth && styles.button__content_fullWidth), children), loading && _react.default.createElement("div", css(styles.button__loader, shimmer && styles.button__loader_shimmer), !shimmer && _react.default.createElement(_Loader.default, {
102 small: true,
103 primary: inverse && soft,
104 secondary: secondary,
105 mono: mono
106 })));
107};
108
109Button.propTypes = propTypes;
110Button.defaultProps = defaultProps;
111var ButtonWithStyles = (0, _withStyles.withStyles)(function (_ref2) {
112 var color = _ref2.color,
113 breakpoint = _ref2.breakpoint,
114 units = _ref2.units,
115 font = _ref2.font,
116 fontSize = _ref2.fontSize,
117 animation = _ref2.animation,
118 radius = _ref2.radius;
119 return {
120 button: {
121 appearance: 'none',
122 borderWidth: 0,
123 backgroundColor: color.secondary,
124 height: units(2.5),
125 //minWidth: units(2.5),
126 paddingTop: units(0.25),
127 paddingRight: units(1.25),
128 paddingBottom: units(0.25),
129 paddingLeft: units(1.25),
130 borderRadius: radius,
131 fontSize: units(0.95),
132 color: color.white,
133 outline: 0,
134 position: 'relative',
135 marginLeft: units(0.125),
136 marginRight: units(0.125),
137 marginBottom: units(0.5),
138 fontWeight: 500,
139 fontFamily: font.default,
140 cursor: 'pointer',
141 boxSizing: 'border-box',
142 overflow: 'hidden',
143 ':hover': {
144 backgroundColor: color.secondarySaturated
145 },
146 ':active': {
147 backgroundColor: color.secondaryDarker
148 }
149 },
150 button_soft: {
151 backgroundColor: color.blueGrayLighter,
152 color: color.primary,
153 ':hover': {
154 backgroundColor: color.blueGrayLight
155 },
156 ':active': {
157 backgroundColor: color.blueGray
158 }
159 },
160 button_fullWidth: {
161 width: '100%'
162 },
163 button_loading: {
164 opacity: 1,
165 pointerEvents: 'none'
166 },
167 button_block: {
168 width: '100%',
169 textAlign: 'left',
170 marginRight: 0,
171 marginLeft: 0
172 },
173 button_compact: {
174 paddingRight: units(0.75),
175 paddingLeft: units(0.75)
176 },
177 button_shade: {
178 background: color.shadowWeakest,
179 ':hover': {
180 background: color.shadowWeaker
181 },
182 ':active': {
183 background: color.shadowWeak
184 }
185 },
186 button_short: {
187 height: units(2)
188 },
189 button_underlined: {
190 borderBottomWidth: 1,
191 borderBottomColor: color.primary,
192 borderBottomStyle: 'solid'
193 },
194 button_grouped: {
195 marginRight: .5,
196 marginBottom: 0,
197 marginLeft: .5
198 },
199 button_groupedFirst: {
200 borderRadius: "".concat(radius, "px 0 0 ").concat(radius, "px"),
201 marginLeft: 0
202 },
203 button_groupedLast: {
204 borderRadius: "0 ".concat(radius, "px ").concat(radius, "px 0"),
205 marginRight: 0
206 },
207 button_disabled: {
208 opacity: .5,
209 pointerEvents: 'none'
210 },
211 button_mono: {
212 backgroundColor: color.transparent,
213 borderColor: color.black,
214 borderWidth: 1,
215 borderStyle: 'solid',
216 color: color.black,
217 ':hover': {
218 background: 'none'
219 },
220 ':active': {
221 backgroundColor: color.grayLighter
222 }
223 },
224 button_noSpacing: {
225 marginBottom: 0
226 },
227 button_primary: {
228 backgroundColor: color.primary,
229 ':hover': {
230 background: color.primarySaturated
231 },
232 ':active': {
233 background: color.primaryDarker
234 }
235 },
236 button_secondary: {
237 backgroundColor: color.transparent,
238 borderColor: color.secondary,
239 borderWidth: 1,
240 borderStyle: 'solid',
241 color: color.secondary,
242 ':hover': {
243 color: color.secondarySaturated,
244 backgroundColor: color.grayLightest
245 },
246 ':active': {
247 borderColor: color.secondaryDarker,
248 backgroundColor: color.grayLighter
249 }
250 },
251 button_inverse: {
252 backgroundColor: color.white,
253 color: color.primary,
254 borderWidth: 0,
255 ':hover': {
256 backgroundColor: color.blueGrayLight
257 },
258 ':active': {
259 backgroundColor: color.blueGray
260 }
261 },
262 button_transparent: {
263 backgroundColor: color.transparent,
264 color: color.primary,
265 ':hover': {
266 background: color.shadowWeakest
267 },
268 ':active': {
269 background: color.shadowWeaker
270 }
271 },
272 button_rectangular: {
273 borderRadius: 0
274 },
275 button_noBorder: {
276 border: 'none',
277 borderWidth: 0
278 },
279 button_small: _defineProperty({
280 fontSize: fontSize.small.small
281 }, breakpoint.large, {
282 fontSize: fontSize.large.small
283 }),
284 button_large: _defineProperty({
285 fontSize: fontSize.small.large
286 }, breakpoint.large, {
287 fontSize: fontSize.large.large
288 }),
289 button__content: {
290 display: 'flex',
291 alignItems: 'center',
292 justifyContent: 'flex-start',
293 opacity: 1,
294 transition: 'opacity .2s',
295 whiteSpace: 'nowrap',
296 userSelect: 'none'
297 },
298 button__content_loading: {
299 opacity: 0
300 },
301 button__content_fullWidth: {
302 justifyContent: 'center'
303 },
304 button__loader: {
305 position: 'absolute',
306 top: 0,
307 right: 0,
308 bottom: 0,
309 left: 0,
310 display: 'flex',
311 alignItems: 'center',
312 justifyContent: 'center'
313 },
314 shimmer: {
315 position: 'absolute',
316 width: '100%',
317 height: '100%',
318 top: 0,
319 right: 0,
320 bottom: 0,
321 left: 0
322 }
323 };
324})(Button);
325var _default = ButtonWithStyles;
326exports.default = _default;
\No newline at end of file