@typeolymp/ui-components 1.9.10 → 1.9.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,7 @@ export declare type PropsType = {
10
10
  href?: string;
11
11
  asAnchor?: boolean;
12
12
  onClick?(): void;
13
+ onClickAsync?(resolve: any): void;
13
14
  };
14
15
  declare const Button: React.ForwardRefExoticComponent<PropsType & React.RefAttributes<HTMLButtonElement | HTMLAnchorElement>>;
15
16
  export default Button;
@@ -1,3 +1,4 @@
1
1
  export declare const StyledButton: any;
2
2
  export declare const DisabledButton: any;
3
3
  export declare const GhostButton: any;
4
+ export declare const LoaderWrapper: any;
package/build/index.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import React, { forwardRef, useRef, useState, useEffect, createElement, useImperativeHandle } from 'react';
3
- import styled, { keyframes } from 'styled-components';
4
3
  import BeatLoader from 'react-spinners/BeatLoader';
4
+ import styled, { keyframes } from 'styled-components';
5
5
  import parse from 'html-react-parser';
6
6
 
7
7
  var theme = {
@@ -174,6 +174,18 @@ var __assign = function() {
174
174
  return __assign.apply(this, arguments);
175
175
  };
176
176
 
177
+ function __rest(s, e) {
178
+ var t = {};
179
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
180
+ t[p] = s[p];
181
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
182
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
183
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
184
+ t[p[i]] = s[p[i]];
185
+ }
186
+ return t;
187
+ }
188
+
177
189
  function __spreadArray(to, from, pack) {
178
190
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
179
191
  if (ar || !(i in from)) {
@@ -259,17 +271,47 @@ var GhostButton = styled(StyledButton)(templateObject_3$a || (templateObject_3$a
259
271
  ? theme.button.medium.marginTopActive
260
272
  : theme.button[size].marginTopActive;
261
273
  });
262
- var templateObject_1$N, templateObject_2$t, templateObject_3$a;
274
+ var LoaderWrapper = styled.div(templateObject_4$7 || (templateObject_4$7 = __makeTemplateObject(["\n width: ", ";\n margin-top: ", ";\n"], ["\n width: ", ";\n margin-top: ", ";\n"])), function (_a) {
275
+ var width = _a.width;
276
+ return "".concat(width, "px");
277
+ }, function (_a) {
278
+ var size = _a.size;
279
+ return (size === "small" ? "3px" : "");
280
+ });
281
+ var templateObject_1$N, templateObject_2$t, templateObject_3$a, templateObject_4$7;
263
282
 
264
283
  var Button = forwardRef(function (_a, ref) {
265
- var label = _a.label, color = _a.color, size = _a.size, fluid = _a.fluid, disabled = _a.disabled, type = _a.type, tabIndex = _a.tabIndex, href = _a.href, asAnchor = _a.asAnchor, onClick = _a.onClick;
284
+ var label = _a.label, color = _a.color, size = _a.size, fluid = _a.fluid, disabled = _a.disabled, type = _a.type, tabIndex = _a.tabIndex, href = _a.href, asAnchor = _a.asAnchor, props = __rest(_a, ["label", "color", "size", "fluid", "disabled", "type", "tabIndex", "href", "asAnchor"]);
285
+ var buttonRef = useRef(null);
286
+ var _b = useState(false), isLoading = _b[0], setIsLoading = _b[1];
266
287
  var as = href || asAnchor ? "a" : "button";
288
+ var onClick = function () {
289
+ if (props.onClickAsync) {
290
+ setIsLoading(true);
291
+ new Promise(function (resolve) {
292
+ props.onClickAsync(resolve);
293
+ }).then(function () { return setIsLoading(false); });
294
+ }
295
+ else if (props.onClick) {
296
+ props.onClick();
297
+ }
298
+ };
299
+ var Loader = function (_a) {
300
+ var _b;
301
+ var dark = _a.dark;
302
+ var width = ((_b = buttonRef.current) === null || _b === void 0 ? void 0 : _b.clientWidth) - 40;
303
+ if (dark)
304
+ width = width + 4;
305
+ return (jsx(LoaderWrapper, __assign({ width: width, size: size }, { children: jsx(BeatLoader, { size: 10, color: dark
306
+ ? theme.colors.lightGray.darker
307
+ : theme.colors.lightGray.light, speedMultiplier: 0.5 }) })));
308
+ };
267
309
  if (disabled) {
268
- return (jsx(DisabledButton, __assign({ color: color, size: size, fluid: fluid, type: type, tabIndex: tabIndex, as: as, href: href, ref: ref }, { children: jsx("span", { children: label }) })));
310
+ return (jsx(DisabledButton, __assign({ color: color, size: size, fluid: fluid, type: type, tabIndex: tabIndex, as: as, href: href, ref: ref ? ref : buttonRef }, { children: jsx("span", { children: label }) })));
269
311
  }
270
312
  if (color === "white")
271
- return (jsx(GhostButton, __assign({ color: color, size: size, fluid: fluid, type: type, tabIndex: tabIndex, as: as, href: href, ref: ref, onClick: onClick }, { children: jsx("span", { children: label }) })));
272
- return (jsx(StyledButton, __assign({ color: color, size: size, fluid: fluid, type: type, tabIndex: tabIndex, as: as, href: href, ref: ref, onClick: onClick }, { children: jsx("span", { children: label }) })));
313
+ return (jsx(GhostButton, __assign({ color: color, size: size, fluid: fluid, type: type, tabIndex: tabIndex, as: as, href: href, ref: ref ? ref : buttonRef, onClick: onClick }, { children: isLoading ? jsx(Loader, { dark: true }) : jsx("span", { children: label }) })));
314
+ return (jsx(StyledButton, __assign({ color: color, size: size, fluid: fluid, type: type, tabIndex: tabIndex, as: as, href: href, ref: ref ? ref : buttonRef, onClick: onClick }, { children: isLoading ? jsx(Loader, {}) : jsx("span", { children: label }) })));
273
315
  });
274
316
 
275
317
  var StyledCheckbox = styled.div(templateObject_1$M || (templateObject_1$M = __makeTemplateObject(["\n min-height: 25px;\n max-height: 25px;\n min-width: 25px;\n max-width: 25px;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n border-width: 1px;\n border-style: solid;\n border-color: ", ";\n cursor: ", ";\n background-color: ", ";\n\n svg {\n margin-left: -1px;\n fill: ", ";\n }\n\n input {\n display: none;\n }\n\n :focus {\n outline: 0;\n border-color: ", ";\n box-shadow: ", ";\n }\n"], ["\n min-height: 25px;\n max-height: 25px;\n min-width: 25px;\n max-width: 25px;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 4px;\n border-width: 1px;\n border-style: solid;\n border-color: ", ";\n cursor: ", ";\n background-color: ", ";\n\n svg {\n margin-left: -1px;\n fill: ", ";\n }\n\n input {\n display: none;\n }\n\n :focus {\n outline: 0;\n border-color: ", ";\n box-shadow: ", ";\n }\n"])), function (_a) {