UNPKG

8.96 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 active: _propTypes.default.bool,
34 disabled: _propTypes.default.bool,
35 loading: _propTypes.default.bool,
36 fullWidth: _propTypes.default.bool,
37 block: _propTypes.default.bool,
38 compact: _propTypes.default.bool,
39 inverse: _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 short: _propTypes.default.bool,
49 transparent: _propTypes.default.bool,
50 type: _propTypes.default.string,
51 underlined: _propTypes.default.bool,
52 noBorder: _propTypes.default.bool,
53 children: _propTypes.default.node
54});
55
56var defaultProps = {
57 type: 'button'
58};
59
60var TabButton = function TabButton(_ref) {
61 var styles = _ref.styles,
62 active = _ref.active,
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 mono = _ref.mono,
74 noSpacing = _ref.noSpacing,
75 shade = _ref.shade,
76 soft = _ref.soft,
77 primary = _ref.primary,
78 rectangular = _ref.rectangular,
79 secondary = _ref.secondary,
80 shimmer = _ref.shimmer,
81 short = _ref.short,
82 transparent = _ref.transparent,
83 type = _ref.type,
84 underlined = _ref.underlined,
85 noBorder = _ref.noBorder,
86 theme = _ref.theme,
87 css = _ref.css,
88 href = _ref.href,
89 large = _ref.large,
90 noWrap = _ref.noWrap,
91 shadowLevel = _ref.shadowLevel,
92 small = _ref.small,
93 props = _objectWithoutProperties(_ref, ["styles", "active", "children", "disabled", "loading", "fullWidth", "block", "compact", "inverse", "grouped", "groupedFirst", "groupedLast", "mono", "noSpacing", "shade", "soft", "primary", "rectangular", "secondary", "shimmer", "short", "transparent", "type", "underlined", "noBorder", "theme", "css", "href", "large", "noWrap", "shadowLevel", "small"]);
94
95 return _react.default.createElement("button", _extends({}, props, css(styles.button, active && styles.button_active, 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, 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, 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
109TabButton.propTypes = propTypes;
110TabButton.defaultProps = defaultProps;
111var TabButtonWithStyles = (0, _withStyles.withStyles)(function (_ref2) {
112 var color = _ref2.color,
113 units = _ref2.units,
114 font = _ref2.font;
115 return {
116 button: {
117 background: color.shadowWeaker,
118 color: color.primary,
119 appearance: 'none',
120 borderWidth: 0,
121 height: units(2.5),
122 //minWidth: units(2.5),
123 paddingTop: units(0.25),
124 paddingRight: units(1.25),
125 paddingBottom: units(0.25),
126 paddingLeft: units(1.25),
127 fontSize: units(0.95),
128 outline: 0,
129 position: 'relative',
130 marginRight: .5,
131 marginBottom: 0,
132 marginLeft: .5,
133 fontWeight: 500,
134 fontFamily: font.default,
135 boxSizing: 'border-box',
136 overflow: 'hidden',
137 cursor: 'pointer',
138 ':hover': {
139 background: color.shadowWeakest
140 }
141 },
142 button_fullWidth: {
143 width: '100%'
144 },
145 button_loading: {
146 opacity: 1,
147 pointerEvents: 'none'
148 },
149 button_underlined: {
150 borderBottomWidth: 1,
151 borderBottomColor: color.primary,
152 borderBottomStyle: 'solid'
153 },
154 button_disabled: {
155 opacity: .5,
156 pointerEvents: 'none'
157 },
158 button_mono: {
159 backgroundColor: color.transparent,
160 borderColor: color.black,
161 borderWidth: 1,
162 borderStyle: 'solid',
163 color: color.black
164 },
165 button_primary: {
166 backgroundColor: color.primary
167 },
168 button_secondary: {
169 backgroundColor: color.transparent,
170 borderColor: color.secondary,
171 borderWidth: 1,
172 borderStyle: 'solid',
173 color: color.secondary
174 },
175 button_inverse: {
176 backgroundColor: color.white,
177 color: color.primary,
178 borderWidth: 0
179 },
180 button_active: {
181 background: color.transparent,
182 cursor: 'default',
183 ':hover': {
184 background: color.transparent
185 }
186 },
187 button_noBorder: {
188 border: 'none',
189 borderWidth: 0
190 },
191 button__content: {
192 display: 'flex',
193 alignItems: 'center',
194 justifyContent: 'flex-start',
195 opacity: 1,
196 transition: 'opacity .2s',
197 whiteSpace: 'nowrap',
198 userSelect: 'none'
199 },
200 button__content_fullWidth: {
201 justifyContent: 'center'
202 },
203 button__content_loading: {
204 opacity: 0
205 },
206 button__loader: {
207 position: 'absolute',
208 top: 0,
209 right: 0,
210 bottom: 0,
211 left: 0,
212 display: 'flex',
213 alignItems: 'center',
214 justifyContent: 'center'
215 },
216 shimmer: {
217 position: 'absolute',
218 width: '100%',
219 height: '100%',
220 top: 0,
221 right: 0,
222 bottom: 0,
223 left: 0
224 }
225 };
226})(TabButton);
227var _default = TabButtonWithStyles;
228exports.default = _default;
\No newline at end of file