@helpdice/ui 1.1.0 → 1.1.1

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.
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ import { CircularProgressbarDefaultProps, CircularProgressbarProps } from './types';
3
+ declare class CircularProgressbar extends React.Component<CircularProgressbarProps> {
4
+ static defaultProps: CircularProgressbarDefaultProps;
5
+ getBackgroundPadding(): number;
6
+ getPathRadius(): number;
7
+ getPathRatio(): number;
8
+ render(): React.JSX.Element;
9
+ }
10
+ export default CircularProgressbar;
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import { CircularProgressbarWrapperProps } from './types';
3
+ type CircularProgressbarWithChildrenProps = CircularProgressbarWrapperProps & {
4
+ children?: React.ReactNode;
5
+ };
6
+ declare function CircularProgressbarWithChildren(props: CircularProgressbarWithChildrenProps): React.JSX.Element;
7
+ export default CircularProgressbarWithChildren;
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ declare function Path({ className, counterClockwise, dashRatio, pathRadius, strokeWidth, style, }: {
3
+ className?: string;
4
+ counterClockwise: boolean;
5
+ dashRatio: number;
6
+ pathRadius: number;
7
+ strokeWidth: number;
8
+ style?: object;
9
+ }): React.JSX.Element;
10
+ export default Path;
@@ -0,0 +1,12 @@
1
+ import { CircularProgressbarStyles } from './types';
2
+ export default function buildStyles({ rotation, strokeLinecap, textColor, textSize, pathColor, pathTransition, pathTransitionDuration, trailColor, backgroundColor, }: {
3
+ rotation?: number;
4
+ strokeLinecap?: any;
5
+ textColor?: string;
6
+ textSize?: string | number;
7
+ pathColor?: string;
8
+ pathTransition?: string;
9
+ pathTransitionDuration?: number;
10
+ trailColor?: string;
11
+ backgroundColor?: string;
12
+ }): CircularProgressbarStyles;
@@ -0,0 +1,5 @@
1
+ export declare const VIEWBOX_WIDTH = 100;
2
+ export declare const VIEWBOX_HEIGHT = 100;
3
+ export declare const VIEWBOX_HEIGHT_HALF = 50;
4
+ export declare const VIEWBOX_CENTER_X = 50;
5
+ export declare const VIEWBOX_CENTER_Y = 50;
@@ -0,0 +1,4 @@
1
+ import CircularProgressBar from './CircularProgressbar';
2
+ import CircularProgress from './CircularProgressbarWithChildren';
3
+ import buildStyles from './buildStyles';
4
+ export { CircularProgressBar, CircularProgress, buildStyles };
@@ -0,0 +1,363 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+
5
+ function _interopNamespaceDefault(e) {
6
+ var n = Object.create(null);
7
+ if (e) {
8
+ Object.keys(e).forEach(function (k) {
9
+ if (k !== 'default') {
10
+ var d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: function () { return e[k]; }
14
+ });
15
+ }
16
+ });
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
21
+
22
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
23
+
24
+ function _assertThisInitialized(e) {
25
+ if (undefined === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
26
+ return e;
27
+ }
28
+ function _callSuper(t, o, e) {
29
+ return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
30
+ }
31
+ function _classCallCheck(a, n) {
32
+ if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
33
+ }
34
+ function _defineProperties(e, r) {
35
+ for (var t = 0; t < r.length; t++) {
36
+ var o = r[t];
37
+ o.enumerable = o.enumerable || false, o.configurable = true, "value" in o && (o.writable = true), Object.defineProperty(e, _toPropertyKey(o.key), o);
38
+ }
39
+ }
40
+ function _createClass(e, r, t) {
41
+ return _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
42
+ writable: false
43
+ }), e;
44
+ }
45
+ function _defineProperty(e, r, t) {
46
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
47
+ value: t,
48
+ enumerable: true,
49
+ configurable: true,
50
+ writable: true
51
+ }) : e[r] = t, e;
52
+ }
53
+ function _getPrototypeOf(t) {
54
+ return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
55
+ return t.__proto__ || Object.getPrototypeOf(t);
56
+ }, _getPrototypeOf(t);
57
+ }
58
+ function _inherits(t, e) {
59
+ if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
60
+ t.prototype = Object.create(e && e.prototype, {
61
+ constructor: {
62
+ value: t,
63
+ writable: true,
64
+ configurable: true
65
+ }
66
+ }), Object.defineProperty(t, "prototype", {
67
+ writable: false
68
+ }), e && _setPrototypeOf(t, e);
69
+ }
70
+ function _isNativeReflectConstruct() {
71
+ try {
72
+ var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
73
+ } catch (t) {}
74
+ return (_isNativeReflectConstruct = function () {
75
+ return !!t;
76
+ })();
77
+ }
78
+ function _objectWithoutProperties(e, t) {
79
+ if (null == e) return {};
80
+ var o,
81
+ r,
82
+ i = _objectWithoutPropertiesLoose(e, t);
83
+ if (Object.getOwnPropertySymbols) {
84
+ var n = Object.getOwnPropertySymbols(e);
85
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
86
+ }
87
+ return i;
88
+ }
89
+ function _objectWithoutPropertiesLoose(r, e) {
90
+ if (null == r) return {};
91
+ var t = {};
92
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
93
+ if (-1 !== e.indexOf(n)) continue;
94
+ t[n] = r[n];
95
+ }
96
+ return t;
97
+ }
98
+ function _possibleConstructorReturn(t, e) {
99
+ if (e && ("object" == typeof e || "function" == typeof e)) return e;
100
+ if (undefined !== e) throw new TypeError("Derived constructors may only return object or undefined");
101
+ return _assertThisInitialized(t);
102
+ }
103
+ function _setPrototypeOf(t, e) {
104
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
105
+ return t.__proto__ = e, t;
106
+ }, _setPrototypeOf(t, e);
107
+ }
108
+ function _toPrimitive(t, r) {
109
+ if ("object" != typeof t || !t) return t;
110
+ var e = t[Symbol.toPrimitive];
111
+ if (undefined !== e) {
112
+ var i = e.call(t, r || "default");
113
+ if ("object" != typeof i) return i;
114
+ throw new TypeError("@@toPrimitive must return a primitive value.");
115
+ }
116
+ return ("string" === r ? String : Number)(t);
117
+ }
118
+ function _toPropertyKey(t) {
119
+ var i = _toPrimitive(t, "string");
120
+ return "symbol" == typeof i ? i : i + "";
121
+ }
122
+
123
+ var VIEWBOX_WIDTH = 100;
124
+ var VIEWBOX_HEIGHT = 100;
125
+ var VIEWBOX_HEIGHT_HALF = 50;
126
+ var VIEWBOX_CENTER_X = 50;
127
+ var VIEWBOX_CENTER_Y = 50;
128
+
129
+ function Path(_ref) {
130
+ var className = _ref.className,
131
+ counterClockwise = _ref.counterClockwise,
132
+ dashRatio = _ref.dashRatio,
133
+ pathRadius = _ref.pathRadius,
134
+ strokeWidth = _ref.strokeWidth,
135
+ style = _ref.style;
136
+ return /*#__PURE__*/React__namespace.createElement("path", {
137
+ className: className,
138
+ style: Object.assign({}, style, getDashStyle({
139
+ pathRadius: pathRadius,
140
+ dashRatio: dashRatio,
141
+ counterClockwise: counterClockwise
142
+ })),
143
+ d: getPathDescription({
144
+ pathRadius: pathRadius,
145
+ counterClockwise: counterClockwise
146
+ }),
147
+ strokeWidth: strokeWidth,
148
+ fillOpacity: 0
149
+ });
150
+ }
151
+
152
+ // SVG path description specifies how the path should be drawn
153
+ function getPathDescription(_ref2) {
154
+ var pathRadius = _ref2.pathRadius,
155
+ counterClockwise = _ref2.counterClockwise;
156
+ var radius = pathRadius;
157
+ var rotation = counterClockwise ? 1 : 0;
158
+
159
+ // Move to center of canvas
160
+ // Relative move to top canvas
161
+ // Relative arc to bottom of canvas
162
+ // Relative arc to top of canvas
163
+ return "\n M ".concat(VIEWBOX_CENTER_X, ",").concat(VIEWBOX_CENTER_Y, "\n m 0,-").concat(radius, "\n a ").concat(radius, ",").concat(radius, " ").concat(rotation, " 1 1 0,").concat(2 * radius, "\n a ").concat(radius, ",").concat(radius, " ").concat(rotation, " 1 1 0,-").concat(2 * radius, "\n ");
164
+ }
165
+ function getDashStyle(_ref3) {
166
+ var counterClockwise = _ref3.counterClockwise,
167
+ dashRatio = _ref3.dashRatio,
168
+ pathRadius = _ref3.pathRadius;
169
+ var diameter = Math.PI * 2 * pathRadius;
170
+ var gapLength = (1 - dashRatio) * diameter;
171
+ return {
172
+ // Have dash be full diameter, and gap be full diameter
173
+ strokeDasharray: "".concat(diameter, "px ").concat(diameter, "px"),
174
+ // Shift dash backward by gapLength, so gap starts appearing at correct distance
175
+ strokeDashoffset: "".concat(counterClockwise ? -gapLength : gapLength, "px")
176
+ };
177
+ }
178
+
179
+ var CircularProgressbar = /*#__PURE__*/function (_React$Component) {
180
+ function CircularProgressbar() {
181
+ _classCallCheck(this, CircularProgressbar);
182
+ return _callSuper(this, CircularProgressbar, arguments);
183
+ }
184
+ _inherits(CircularProgressbar, _React$Component);
185
+ return _createClass(CircularProgressbar, [{
186
+ key: "getBackgroundPadding",
187
+ value: function getBackgroundPadding() {
188
+ if (!this.props.background) {
189
+ // Don't add padding if not displaying background
190
+ return 0;
191
+ }
192
+ return this.props.backgroundPadding;
193
+ }
194
+ }, {
195
+ key: "getPathRadius",
196
+ value: function getPathRadius() {
197
+ // The radius of the path is defined to be in the middle, so in order for the path to
198
+ // fit perfectly inside the 100x100 viewBox, need to subtract half the strokeWidth
199
+ return VIEWBOX_HEIGHT_HALF - this.props.strokeWidth / 2 - this.getBackgroundPadding();
200
+ }
201
+
202
+ // Ratio of path length to trail length, as a value between 0 and 1
203
+ }, {
204
+ key: "getPathRatio",
205
+ value: function getPathRatio() {
206
+ var _this$props = this.props,
207
+ value = _this$props.value,
208
+ minValue = _this$props.minValue,
209
+ maxValue = _this$props.maxValue;
210
+ var boundedValue = Math.min(Math.max(value, minValue), maxValue);
211
+ return (boundedValue - minValue) / (maxValue - minValue);
212
+ }
213
+ }, {
214
+ key: "render",
215
+ value: function render() {
216
+ var _this$props2 = this.props,
217
+ circleRatio = _this$props2.circleRatio,
218
+ className = _this$props2.className,
219
+ classes = _this$props2.classes,
220
+ counterClockwise = _this$props2.counterClockwise,
221
+ styles = _this$props2.styles,
222
+ strokeWidth = _this$props2.strokeWidth,
223
+ text = _this$props2.text;
224
+ var pathRadius = this.getPathRadius();
225
+ var pathRatio = this.getPathRatio();
226
+ return /*#__PURE__*/React__namespace.createElement("svg", {
227
+ className: "".concat(classes.root, " ").concat(className),
228
+ style: styles.root,
229
+ viewBox: "0 0 ".concat(VIEWBOX_WIDTH, " ").concat(VIEWBOX_HEIGHT),
230
+ "data-test-id": "CircularProgressbar"
231
+ }, this.props.background ? /*#__PURE__*/React__namespace.createElement("circle", {
232
+ className: classes.background,
233
+ style: styles.background,
234
+ cx: VIEWBOX_CENTER_X,
235
+ cy: VIEWBOX_CENTER_Y,
236
+ r: VIEWBOX_HEIGHT_HALF
237
+ }) : null, /*#__PURE__*/React__namespace.createElement(Path, {
238
+ className: classes.trail,
239
+ counterClockwise: counterClockwise,
240
+ dashRatio: circleRatio,
241
+ pathRadius: pathRadius,
242
+ strokeWidth: strokeWidth,
243
+ style: styles.trail
244
+ }), /*#__PURE__*/React__namespace.createElement(Path, {
245
+ className: classes.path,
246
+ counterClockwise: counterClockwise,
247
+ dashRatio: pathRatio * circleRatio,
248
+ pathRadius: pathRadius,
249
+ strokeWidth: strokeWidth,
250
+ style: styles.path
251
+ }), text ? /*#__PURE__*/React__namespace.createElement("text", {
252
+ className: classes.text,
253
+ style: styles.text,
254
+ x: VIEWBOX_CENTER_X,
255
+ y: VIEWBOX_CENTER_Y
256
+ }, text) : null);
257
+ }
258
+ }]);
259
+ }(React__namespace.Component);
260
+ _defineProperty(CircularProgressbar, "defaultProps", {
261
+ background: false,
262
+ backgroundPadding: 0,
263
+ circleRatio: 1,
264
+ classes: {
265
+ root: 'CircularProgressbar',
266
+ trail: 'CircularProgressbar-trail',
267
+ path: 'CircularProgressbar-path',
268
+ text: 'CircularProgressbar-text',
269
+ background: 'CircularProgressbar-background'
270
+ },
271
+ counterClockwise: false,
272
+ className: '',
273
+ maxValue: 100,
274
+ minValue: 0,
275
+ strokeWidth: 8,
276
+ styles: {
277
+ root: {},
278
+ trail: {},
279
+ path: {},
280
+ text: {},
281
+ background: {}
282
+ },
283
+ text: ''
284
+ });
285
+
286
+ var _excluded = ["children"];
287
+ // This is a wrapper around CircularProgressbar that allows passing children,
288
+ // which will be vertically and horizontally centered inside the progressbar automatically.
289
+ function CircularProgressbarWithChildren(props) {
290
+ props.children;
291
+ var circularProgressbarProps = _objectWithoutProperties(props, _excluded);
292
+ return /*#__PURE__*/React__namespace.createElement("div", {
293
+ "data-test-id": "CircularProgressbarWithChildren"
294
+ }, /*#__PURE__*/React__namespace.createElement("div", {
295
+ style: {
296
+ position: 'relative',
297
+ width: '100%',
298
+ height: '100%'
299
+ }
300
+ }, /*#__PURE__*/React__namespace.createElement(CircularProgressbar, circularProgressbarProps), props.children ? /*#__PURE__*/React__namespace.createElement("div", {
301
+ "data-test-id": "CircularProgressbarWithChildren__children",
302
+ style: {
303
+ position: 'absolute',
304
+ width: '100%',
305
+ height: '100%',
306
+ marginTop: '-100%',
307
+ display: 'flex',
308
+ flexDirection: 'column',
309
+ justifyContent: 'center',
310
+ alignItems: 'center'
311
+ }
312
+ }, props.children) : null));
313
+ }
314
+
315
+ function buildStyles(_ref) {
316
+ var rotation = _ref.rotation,
317
+ strokeLinecap = _ref.strokeLinecap,
318
+ textColor = _ref.textColor,
319
+ textSize = _ref.textSize,
320
+ pathColor = _ref.pathColor,
321
+ pathTransition = _ref.pathTransition,
322
+ pathTransitionDuration = _ref.pathTransitionDuration,
323
+ trailColor = _ref.trailColor,
324
+ backgroundColor = _ref.backgroundColor;
325
+ var rotationTransform = rotation == null ? undefined : "rotate(".concat(rotation, "turn)");
326
+ var rotationTransformOrigin = rotation == null ? undefined : 'center center';
327
+ return {
328
+ root: {},
329
+ path: removeUndefinedValues({
330
+ stroke: pathColor,
331
+ strokeLinecap: strokeLinecap,
332
+ transform: rotationTransform,
333
+ transformOrigin: rotationTransformOrigin,
334
+ transition: pathTransition,
335
+ transitionDuration: pathTransitionDuration == null ? undefined : "".concat(pathTransitionDuration, "s")
336
+ }),
337
+ trail: removeUndefinedValues({
338
+ stroke: trailColor,
339
+ strokeLinecap: strokeLinecap,
340
+ transform: rotationTransform,
341
+ transformOrigin: rotationTransformOrigin
342
+ }),
343
+ text: removeUndefinedValues({
344
+ fill: textColor,
345
+ fontSize: textSize
346
+ }),
347
+ background: removeUndefinedValues({
348
+ fill: backgroundColor
349
+ })
350
+ };
351
+ }
352
+ function removeUndefinedValues(obj) {
353
+ Object.keys(obj).forEach(function (key) {
354
+ if (obj[key] == null) {
355
+ delete obj[key];
356
+ }
357
+ });
358
+ return obj;
359
+ }
360
+
361
+ exports.CircularProgress = CircularProgressbarWithChildren;
362
+ exports.CircularProgressBar = CircularProgressbar;
363
+ exports.buildStyles = buildStyles;
@@ -0,0 +1,50 @@
1
+ import * as React from 'react';
2
+ export type CircularProgressbarStyles = {
3
+ root?: React.CSSProperties;
4
+ trail?: React.CSSProperties;
5
+ path?: React.CSSProperties;
6
+ text?: React.CSSProperties;
7
+ background?: React.CSSProperties;
8
+ };
9
+ export type CircularProgressbarDefaultProps = {
10
+ background: boolean;
11
+ backgroundPadding: number;
12
+ circleRatio: number;
13
+ classes: {
14
+ root: string;
15
+ trail: string;
16
+ path: string;
17
+ text: string;
18
+ background: string;
19
+ };
20
+ className: string;
21
+ counterClockwise: boolean;
22
+ maxValue: number;
23
+ minValue: number;
24
+ strokeWidth: number;
25
+ styles: CircularProgressbarStyles;
26
+ text: string;
27
+ };
28
+ export type CircularProgressbarWrapperProps = {
29
+ background?: boolean;
30
+ backgroundPadding?: number;
31
+ circleRatio?: number;
32
+ classes?: {
33
+ root: string;
34
+ trail: string;
35
+ path: string;
36
+ text: string;
37
+ background: string;
38
+ };
39
+ className?: string;
40
+ counterClockwise?: boolean;
41
+ maxValue?: number;
42
+ minValue?: number;
43
+ strokeWidth?: number;
44
+ styles?: CircularProgressbarStyles;
45
+ text?: string;
46
+ value: number;
47
+ };
48
+ export type CircularProgressbarProps = CircularProgressbarDefaultProps & {
49
+ value: number;
50
+ };
package/dist/index.d.ts CHANGED
@@ -20,6 +20,7 @@ export { default as Checkbox } from './checkbox';
20
20
  export type { CheckboxProps, CheckboxGroupProps } from './checkbox';
21
21
  export { default as Code } from './code';
22
22
  export type { CodeProps } from './code';
23
+ export { CircularProgress, buildStyles } from './CircularProgress';
23
24
  export { default as Collapse } from './collapse';
24
25
  export type { CollapseProps, CollapseGroupProps } from './collapse';
25
26
  export { default as Description } from './description';