1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
6 |
|
7 | var slicedToArray = require('./slicedToArray-ef426d0f.js');
|
8 | require('./unsupportedIterableToArray-8a00e599.js');
|
9 | var React = require('react');
|
10 | var React__default = _interopDefault(React);
|
11 | require('./_commonjsHelpers-72d386ba.js');
|
12 | var index = require('./index-b0606964.js');
|
13 | require('./defineProperty-0921a47c.js');
|
14 | require('./toConsumableArray-7f36359f.js');
|
15 | var _styled = require('styled-components');
|
16 | var _styled__default = _interopDefault(_styled);
|
17 | require('./getPrototypeOf-e2d1e599.js');
|
18 | require('./color.js');
|
19 | require('./components.js');
|
20 | require('./contains-component.js');
|
21 | var css = require('./css.js');
|
22 | require('./dayjs.min-aa59a48e.js');
|
23 | require('./date.js');
|
24 | require('./miscellaneous.js');
|
25 | var environment = require('./environment.js');
|
26 | require('./font.js');
|
27 | require('./math-ecfd5d91.js');
|
28 | require('./characters.js');
|
29 | require('./format.js');
|
30 | require('./keycodes.js');
|
31 | require('./url.js');
|
32 | require('./web3.js');
|
33 | var constants = require('./constants.js');
|
34 | require('./breakpoints.js');
|
35 | require('./springs.js');
|
36 | var textStyles = require('./text-styles.js');
|
37 | require('./theme-dark.js');
|
38 | require('./theme-light.js');
|
39 | var Theme = require('./Theme.js');
|
40 | var _extends = require('./extends-40571110.js');
|
41 | var objectWithoutProperties = require('./objectWithoutProperties-35db8ab0.js');
|
42 | var index$1 = require('./index-ecc57c9f.js');
|
43 | require('./isObject-52908731.js');
|
44 | require('./Viewport-fe2db97a.js');
|
45 | var Layout = require('./Layout.js');
|
46 | require('./FocusVisible.js');
|
47 | var ButtonBase = require('./ButtonBase.js');
|
48 |
|
49 |
|
50 |
|
51 | var SIZE_STYLES = {
|
52 | medium: {
|
53 | textStyleName: 'body2',
|
54 | height: 5 * constants.GU,
|
55 | padding: 3 * constants.GU,
|
56 | iconPadding: 2 * constants.GU,
|
57 | minWidth: 14.5 * constants.GU,
|
58 | middleSpace: 1 * constants.GU
|
59 | },
|
60 | small: {
|
61 | textStyleName: 'body2',
|
62 | height: 4 * constants.GU,
|
63 | padding: 2 * constants.GU,
|
64 | iconPadding: 1.5 * constants.GU,
|
65 | minWidth: 13 * constants.GU,
|
66 | middleSpace: 1 * constants.GU
|
67 | },
|
68 | mini: {
|
69 | textStyleName: 'body4',
|
70 | height: 3 * constants.GU,
|
71 | padding: 1.5 * constants.GU,
|
72 | iconPadding: 1 * constants.GU,
|
73 | minWidth: 9.25 * constants.GU,
|
74 | middleSpace: 0.5 * constants.GU
|
75 | }
|
76 | };
|
77 |
|
78 | function getPadding(size, displayIcon, displayLabel) {
|
79 | var _SIZE_STYLES$size = SIZE_STYLES[size],
|
80 | padding = _SIZE_STYLES$size.padding,
|
81 | iconPadding = _SIZE_STYLES$size.iconPadding;
|
82 |
|
83 | if (displayIcon && !displayLabel) {
|
84 | return '0';
|
85 | }
|
86 |
|
87 | if (displayIcon && displayLabel) {
|
88 | return "0 ".concat(padding, "px 0 ").concat(iconPadding, "px");
|
89 | }
|
90 |
|
91 | return "0 ".concat(padding, "px");
|
92 | }
|
93 |
|
94 | function getWidth(size, displayIconOnly, wide) {
|
95 | var height = SIZE_STYLES[size].height;
|
96 |
|
97 | if (wide) {
|
98 | return '100%';
|
99 | }
|
100 |
|
101 | if (displayIconOnly) {
|
102 | return "".concat(height, "px");
|
103 | }
|
104 |
|
105 | return 'auto';
|
106 | }
|
107 |
|
108 | function getMinWidth(size, displayLabelOnly) {
|
109 | var minWidth = SIZE_STYLES[size].minWidth;
|
110 | return displayLabelOnly ? "".concat(minWidth, "px") : '0';
|
111 | }
|
112 |
|
113 |
|
114 | function sizeStyles(size, wide, displayIcon, displayLabel) {
|
115 | var _SIZE_STYLES$size2 = SIZE_STYLES[size],
|
116 | height = _SIZE_STYLES$size2.height,
|
117 | textStyleName = _SIZE_STYLES$size2.textStyleName,
|
118 | middleSpace = _SIZE_STYLES$size2.middleSpace;
|
119 | return {
|
120 | height: "".concat(height, "px"),
|
121 | middleSpace: displayIcon && displayLabel ? "".concat(middleSpace, "px") : '0',
|
122 | minWidth: getMinWidth(size, !displayIcon && displayLabel),
|
123 | padding: getPadding(size, displayIcon, displayLabel),
|
124 | textStyleCss: textStyles.textStyle(textStyleName),
|
125 | width: getWidth(size, displayIcon && !displayLabel, wide)
|
126 | };
|
127 | }
|
128 |
|
129 |
|
130 | function modeStyles(theme, mode, disabled) {
|
131 | if (disabled) {
|
132 | return {
|
133 | background: theme.disabled,
|
134 | color: theme.disabledContent,
|
135 | iconColor: theme.disabledContent,
|
136 | border: '0'
|
137 | };
|
138 | }
|
139 |
|
140 | if (mode === 'strong') {
|
141 | return {
|
142 | background: "\n linear-gradient(\n 190deg,\n ".concat(theme.accentStart, " -100%,\n ").concat(theme.accentEnd, " 80%\n )\n "),
|
143 | color: theme.accentContent,
|
144 | iconColor: theme.accentContent,
|
145 | border: '0'
|
146 | };
|
147 | }
|
148 |
|
149 | if (mode === 'positive') {
|
150 | return {
|
151 | background: theme.positive,
|
152 | color: theme.positiveContent,
|
153 | iconColor: theme.positiveContent,
|
154 | border: '0'
|
155 | };
|
156 | }
|
157 |
|
158 | if (mode === 'negative') {
|
159 | return {
|
160 | background: theme.negative,
|
161 | color: theme.negativeContent,
|
162 | iconColor: theme.negativeContent,
|
163 | border: '0'
|
164 | };
|
165 | }
|
166 |
|
167 | return {
|
168 | background: theme.surfaceInteractive,
|
169 | color: theme.surfaceContent,
|
170 | iconColor: theme.surfaceIcon,
|
171 | border: "1px solid ".concat(theme.border)
|
172 | };
|
173 | }
|
174 |
|
175 | var _StyledButtonBase = _styled__default(ButtonBase.default).withConfig({
|
176 | displayName: "Button___StyledButtonBase",
|
177 | componentId: "sc-8npd5h-0"
|
178 | })(["display:", ";align-items:center;justify-content:center;width:", ";height:", ";min-width:", ";padding:", ";", ";", ";background:", ";color:", ";white-space:nowrap;border:", ";box-shadow:", ";transition-property:transform,box-shadow;transition-duration:50ms;transition-timing-function:ease-in-out;&:active{transform:", ";box-shadow:", ";}"], function (p) {
|
179 | return p._css;
|
180 | }, function (p) {
|
181 | return p._css2;
|
182 | }, function (p) {
|
183 | return p._css3;
|
184 | }, function (p) {
|
185 | return p._css4;
|
186 | }, function (p) {
|
187 | return p._css5;
|
188 | }, function (p) {
|
189 | return p._css6;
|
190 | }, css.unselectable, function (p) {
|
191 | return p._css7;
|
192 | }, function (p) {
|
193 | return p._css8;
|
194 | }, function (p) {
|
195 | return p._css9;
|
196 | }, function (p) {
|
197 | return p._css10;
|
198 | }, function (p) {
|
199 | return p._css11;
|
200 | }, function (p) {
|
201 | return p._css12;
|
202 | });
|
203 |
|
204 | var _StyledSpan = _styled__default("span").withConfig({
|
205 | displayName: "Button___StyledSpan",
|
206 | componentId: "sc-8npd5h-1"
|
207 | })(["position:relative;top:-1px;display:flex;color:", ";margin-right:", ";"], function (p) {
|
208 | return p._css13;
|
209 | }, function (p) {
|
210 | return p._css14;
|
211 | });
|
212 |
|
213 | function Button(_ref) {
|
214 | var children = _ref.children,
|
215 | disabled = _ref.disabled,
|
216 | display = _ref.display,
|
217 | icon = _ref.icon,
|
218 | iconOnly = _ref.iconOnly,
|
219 | innerRef = _ref.innerRef,
|
220 | label = _ref.label,
|
221 | mode = _ref.mode,
|
222 | size = _ref.size,
|
223 | wide = _ref.wide,
|
224 | props = objectWithoutProperties._objectWithoutProperties(_ref, ["children", "disabled", "display", "icon", "iconOnly", "innerRef", "label", "mode", "size", "wide"]);
|
225 |
|
226 |
|
227 | if (iconOnly) {
|
228 | environment.warnOnce('Button:iconOnly', 'Button: "iconOnly" is deprecated, please use "display".');
|
229 | display = 'icon';
|
230 | }
|
231 |
|
232 | if (mode === 'outline' || mode === 'secondary') {
|
233 | environment.warnOnce('Button:mode', "Button: the mode \"".concat(mode, "\" is deprecated, please use \"normal\"."));
|
234 | mode = 'normal';
|
235 | }
|
236 |
|
237 | if (size === 'normal' || size === 'large') {
|
238 | environment.warnOnce('Button:size', "Button: the size \"".concat(size, "\" is deprecated, please use \"medium\"."));
|
239 | size = 'medium';
|
240 | }
|
241 |
|
242 |
|
243 | if (display === 'icon' && !icon) {
|
244 | environment.warn('Button: the display "icon" was used without providing an icon.');
|
245 | }
|
246 |
|
247 | if (!children && !label) {
|
248 | environment.warn('Button: please provide a label.');
|
249 | }
|
250 |
|
251 | var theme = Theme.useTheme();
|
252 |
|
253 | var _useLayout = Layout.useLayout(),
|
254 | layoutName = _useLayout.layoutName;
|
255 |
|
256 | var _useInside = index$1.o('EmptyStateCard'),
|
257 | _useInside2 = slicedToArray._slicedToArray(_useInside, 1),
|
258 | insideEmptyStateCard = _useInside2[0];
|
259 |
|
260 | var _useInside3 = index$1.o('Header:secondary'),
|
261 | _useInside4 = slicedToArray._slicedToArray(_useInside3, 1),
|
262 | insideHeaderSecondary = _useInside4[0];
|
263 |
|
264 |
|
265 | if (insideEmptyStateCard) {
|
266 | mode = 'strong';
|
267 | wide = true;
|
268 | }
|
269 |
|
270 |
|
271 | if (insideHeaderSecondary && display === 'auto' && icon && label) {
|
272 | display = layoutName === 'small' ? 'icon' : 'label';
|
273 | }
|
274 |
|
275 |
|
276 | if (display === 'auto') {
|
277 | display = 'all';
|
278 | }
|
279 |
|
280 | var displayIcon = icon && (display === 'all' || display === 'icon');
|
281 | var displayLabel = label && (display === 'all' || display === 'label');
|
282 |
|
283 | var _useMemo = React.useMemo(function () {
|
284 | return modeStyles(theme, mode, disabled);
|
285 | }, [mode, theme, disabled]),
|
286 | background = _useMemo.background,
|
287 | color = _useMemo.color,
|
288 | iconColor = _useMemo.iconColor,
|
289 | border = _useMemo.border;
|
290 |
|
291 |
|
292 | var _useMemo2 = React.useMemo(function () {
|
293 | return sizeStyles(size, wide, displayIcon, displayLabel);
|
294 | }, [size, wide, displayIcon, displayLabel]),
|
295 | height = _useMemo2.height,
|
296 | middleSpace = _useMemo2.middleSpace,
|
297 | minWidth = _useMemo2.minWidth,
|
298 | padding = _useMemo2.padding,
|
299 | textStyleCss = _useMemo2.textStyleCss,
|
300 | width = _useMemo2.width;
|
301 |
|
302 |
|
303 | if (displayIcon && !displayLabel && label && typeof label === 'string') {
|
304 | props.title = label;
|
305 | }
|
306 |
|
307 | var insideData = {
|
308 | size: size
|
309 | };
|
310 | return React__default.createElement(_StyledButtonBase, _extends._extends({
|
311 | ref: innerRef,
|
312 | focusRingSpacing: border === '0' ? 0 : 1,
|
313 | focusRingRadius: constants.RADIUS,
|
314 | disabled: disabled
|
315 | }, props, {
|
316 | _css: wide ? 'flex' : 'inline-flex',
|
317 | _css2: width,
|
318 | _css3: height,
|
319 | _css4: minWidth,
|
320 | _css5: padding,
|
321 | _css6: textStyleCss,
|
322 | _css7: background,
|
323 | _css8: color,
|
324 | _css9: border,
|
325 | _css10: disabled ? 'none' : '0 1px 3px rgba(0, 0, 0, 0.1)',
|
326 | _css11: disabled ? 'none' : 'translateY(1px)',
|
327 | _css12: disabled ? 'none' : '0px 1px 2px rgba(0, 0, 0, 0.08)'
|
328 | }), React__default.createElement(index$1.i, {
|
329 | name: "Button",
|
330 | data: insideData
|
331 | }, children || React__default.createElement(React__default.Fragment, null, displayIcon && React__default.createElement(index$1.i, {
|
332 | name: "Button:icon",
|
333 | data: insideData
|
334 | }, React__default.createElement(_StyledSpan, {
|
335 | _css13: iconColor,
|
336 | _css14: middleSpace
|
337 | }, icon)), displayLabel && React__default.createElement(index$1.i, {
|
338 | name: "Button:label",
|
339 | data: insideData
|
340 | }, label))));
|
341 | }
|
342 |
|
343 | Button.propTypes = {
|
344 | children: index.PropTypes.node,
|
345 | disabled: index.PropTypes.bool,
|
346 | display: index.PropTypes.oneOf(['auto', 'all', 'icon', 'label']),
|
347 | icon: index.PropTypes.node,
|
348 | innerRef: index.PropTypes.any,
|
349 | label: index.PropTypes.string,
|
350 | mode: index.PropTypes.oneOf(['normal', 'strong', 'positive', 'negative',
|
351 | 'outline', 'secondary', 'text']),
|
352 | size: index.PropTypes.oneOf(['medium', 'small', 'mini',
|
353 | 'large', 'normal']),
|
354 | wide: index.PropTypes.bool,
|
355 |
|
356 | iconOnly: index.PropTypes.bool
|
357 | };
|
358 | Button.defaultProps = {
|
359 | disabled: false,
|
360 | display: 'auto',
|
361 | mode: 'normal',
|
362 | size: 'medium',
|
363 | wide: false
|
364 | };
|
365 | var ButtonWithRef = React__default.forwardRef(function (props, ref) {
|
366 | return React__default.createElement(Button, _extends._extends({
|
367 | innerRef: ref
|
368 | }, props));
|
369 | });
|
370 | ButtonWithRef.Anchor = React__default.forwardRef(function (props, ref) {
|
371 | environment.warnOnce('Button.Anchor', 'Button.Anchor is deprecated: please use Button with a href prop instead.');
|
372 | return React__default.createElement(ButtonWithRef, _extends._extends({
|
373 | ref: ref
|
374 | }, props));
|
375 | });
|
376 |
|
377 | exports.default = ButtonWithRef;
|
378 |
|