1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | import { __assign, __extends, __rest } from "tslib";
|
17 | import classNames from "classnames";
|
18 | import * as React from "react";
|
19 | import { AbstractPureComponent, Classes } from "../../common";
|
20 | import { SPINNER_WARN_CLASSES_SIZE } from "../../common/errors";
|
21 | import { DISPLAYNAME_PREFIX } from "../../common/props";
|
22 | import { clamp } from "../../common/utils";
|
23 | export var SpinnerSize;
|
24 | (function (SpinnerSize) {
|
25 | SpinnerSize[SpinnerSize["SMALL"] = 20] = "SMALL";
|
26 | SpinnerSize[SpinnerSize["STANDARD"] = 50] = "STANDARD";
|
27 | SpinnerSize[SpinnerSize["LARGE"] = 100] = "LARGE";
|
28 | })(SpinnerSize || (SpinnerSize = {}));
|
29 |
|
30 | var R = 45;
|
31 | var SPINNER_TRACK = "M 50,50 m 0,-".concat(R, " a ").concat(R, ",").concat(R, " 0 1 1 0,").concat(R * 2, " a ").concat(R, ",").concat(R, " 0 1 1 0,-").concat(R * 2);
|
32 |
|
33 |
|
34 |
|
35 | var PATH_LENGTH = 280;
|
36 | var MIN_SIZE = 10;
|
37 | var STROKE_WIDTH = 4;
|
38 | var MIN_STROKE_WIDTH = 16;
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | var Spinner = (function (_super) {
|
45 | __extends(Spinner, _super);
|
46 | function Spinner() {
|
47 | return _super !== null && _super.apply(this, arguments) || this;
|
48 | }
|
49 | Spinner.prototype.componentDidUpdate = function (prevProps) {
|
50 | if (prevProps.value !== this.props.value) {
|
51 |
|
52 | this.forceUpdate();
|
53 | }
|
54 | };
|
55 | Spinner.prototype.render = function () {
|
56 | var _a;
|
57 | var _b = this.props, className = _b.className, intent = _b.intent, value = _b.value, _c = _b.tagName, tagName = _c === void 0 ? "div" : _c, htmlProps = __rest(_b, ["className", "intent", "value", "tagName"]);
|
58 | var size = this.getSize();
|
59 | var classes = classNames(Classes.SPINNER, Classes.intentClass(intent), (_a = {}, _a[Classes.SPINNER_NO_SPIN] = value != null, _a), className);
|
60 |
|
61 | var strokeWidth = Math.min(MIN_STROKE_WIDTH, (STROKE_WIDTH * SpinnerSize.LARGE) / size);
|
62 | var strokeOffset = PATH_LENGTH - PATH_LENGTH * (value == null ? 0.25 : clamp(value, 0, 1));
|
63 |
|
64 |
|
65 |
|
66 | return React.createElement(tagName, __assign({ "aria-label": "loading", "aria-valuemax": 100, "aria-valuemin": 0, "aria-valuenow": value === undefined ? undefined : value * 100, className: classes, role: "progressbar" }, htmlProps), React.createElement(tagName, { className: Classes.SPINNER_ANIMATION }, React.createElement("svg", { width: size, height: size, strokeWidth: strokeWidth.toFixed(2), viewBox: this.getViewBox(strokeWidth) },
|
67 | React.createElement("path", { className: Classes.SPINNER_TRACK, d: SPINNER_TRACK }),
|
68 | React.createElement("path", { className: Classes.SPINNER_HEAD, d: SPINNER_TRACK, pathLength: PATH_LENGTH, strokeDasharray: "".concat(PATH_LENGTH, " ").concat(PATH_LENGTH), strokeDashoffset: strokeOffset }))));
|
69 | };
|
70 | Spinner.prototype.validateProps = function (_a) {
|
71 | var _b = _a.className, className = _b === void 0 ? "" : _b, size = _a.size;
|
72 | if (size != null && (className.indexOf(Classes.SMALL) >= 0 || className.indexOf(Classes.LARGE) >= 0)) {
|
73 | console.warn(SPINNER_WARN_CLASSES_SIZE);
|
74 | }
|
75 | };
|
76 | |
77 |
|
78 |
|
79 |
|
80 | Spinner.prototype.getSize = function () {
|
81 | var _a = this.props, _b = _a.className, className = _b === void 0 ? "" : _b, size = _a.size;
|
82 | if (size == null) {
|
83 |
|
84 | if (className.indexOf(Classes.SMALL) >= 0) {
|
85 | return SpinnerSize.SMALL;
|
86 | }
|
87 | else if (className.indexOf(Classes.LARGE) >= 0) {
|
88 | return SpinnerSize.LARGE;
|
89 | }
|
90 | return SpinnerSize.STANDARD;
|
91 | }
|
92 | return Math.max(MIN_SIZE, size);
|
93 | };
|
94 |
|
95 | Spinner.prototype.getViewBox = function (strokeWidth) {
|
96 | var radius = R + strokeWidth / 2;
|
97 | var viewBoxX = (50 - radius).toFixed(2);
|
98 | var viewBoxWidth = (radius * 2).toFixed(2);
|
99 | return "".concat(viewBoxX, " ").concat(viewBoxX, " ").concat(viewBoxWidth, " ").concat(viewBoxWidth);
|
100 | };
|
101 | Spinner.displayName = "".concat(DISPLAYNAME_PREFIX, ".Spinner");
|
102 | return Spinner;
|
103 | }(AbstractPureComponent));
|
104 | export { Spinner };
|
105 |
|
\ | No newline at end of file |