@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,118 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
3
+ import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
4
+ import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
5
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
6
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
7
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
8
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
9
+ import * as React from 'react';
10
+ import { VIEWBOX_WIDTH, VIEWBOX_HEIGHT, VIEWBOX_HEIGHT_HALF, VIEWBOX_CENTER_X, VIEWBOX_CENTER_Y } from './constants';
11
+ import Path from './Path';
12
+ var CircularProgressbar = /*#__PURE__*/function (_React$Component) {
13
+ function CircularProgressbar() {
14
+ _classCallCheck(this, CircularProgressbar);
15
+ return _callSuper(this, CircularProgressbar, arguments);
16
+ }
17
+ _inherits(CircularProgressbar, _React$Component);
18
+ return _createClass(CircularProgressbar, [{
19
+ key: "getBackgroundPadding",
20
+ value: function getBackgroundPadding() {
21
+ if (!this.props.background) {
22
+ // Don't add padding if not displaying background
23
+ return 0;
24
+ }
25
+ return this.props.backgroundPadding;
26
+ }
27
+ }, {
28
+ key: "getPathRadius",
29
+ value: function getPathRadius() {
30
+ // The radius of the path is defined to be in the middle, so in order for the path to
31
+ // fit perfectly inside the 100x100 viewBox, need to subtract half the strokeWidth
32
+ return VIEWBOX_HEIGHT_HALF - this.props.strokeWidth / 2 - this.getBackgroundPadding();
33
+ }
34
+
35
+ // Ratio of path length to trail length, as a value between 0 and 1
36
+ }, {
37
+ key: "getPathRatio",
38
+ value: function getPathRatio() {
39
+ var _this$props = this.props,
40
+ value = _this$props.value,
41
+ minValue = _this$props.minValue,
42
+ maxValue = _this$props.maxValue;
43
+ var boundedValue = Math.min(Math.max(value, minValue), maxValue);
44
+ return (boundedValue - minValue) / (maxValue - minValue);
45
+ }
46
+ }, {
47
+ key: "render",
48
+ value: function render() {
49
+ var _this$props2 = this.props,
50
+ circleRatio = _this$props2.circleRatio,
51
+ className = _this$props2.className,
52
+ classes = _this$props2.classes,
53
+ counterClockwise = _this$props2.counterClockwise,
54
+ styles = _this$props2.styles,
55
+ strokeWidth = _this$props2.strokeWidth,
56
+ text = _this$props2.text;
57
+ var pathRadius = this.getPathRadius();
58
+ var pathRatio = this.getPathRatio();
59
+ return /*#__PURE__*/React.createElement("svg", {
60
+ className: "".concat(classes.root, " ").concat(className),
61
+ style: styles.root,
62
+ viewBox: "0 0 ".concat(VIEWBOX_WIDTH, " ").concat(VIEWBOX_HEIGHT),
63
+ "data-test-id": "CircularProgressbar"
64
+ }, this.props.background ? /*#__PURE__*/React.createElement("circle", {
65
+ className: classes.background,
66
+ style: styles.background,
67
+ cx: VIEWBOX_CENTER_X,
68
+ cy: VIEWBOX_CENTER_Y,
69
+ r: VIEWBOX_HEIGHT_HALF
70
+ }) : null, /*#__PURE__*/React.createElement(Path, {
71
+ className: classes.trail,
72
+ counterClockwise: counterClockwise,
73
+ dashRatio: circleRatio,
74
+ pathRadius: pathRadius,
75
+ strokeWidth: strokeWidth,
76
+ style: styles.trail
77
+ }), /*#__PURE__*/React.createElement(Path, {
78
+ className: classes.path,
79
+ counterClockwise: counterClockwise,
80
+ dashRatio: pathRatio * circleRatio,
81
+ pathRadius: pathRadius,
82
+ strokeWidth: strokeWidth,
83
+ style: styles.path
84
+ }), text ? /*#__PURE__*/React.createElement("text", {
85
+ className: classes.text,
86
+ style: styles.text,
87
+ x: VIEWBOX_CENTER_X,
88
+ y: VIEWBOX_CENTER_Y
89
+ }, text) : null);
90
+ }
91
+ }]);
92
+ }(React.Component);
93
+ _defineProperty(CircularProgressbar, "defaultProps", {
94
+ background: false,
95
+ backgroundPadding: 0,
96
+ circleRatio: 1,
97
+ classes: {
98
+ root: 'CircularProgressbar',
99
+ trail: 'CircularProgressbar-trail',
100
+ path: 'CircularProgressbar-path',
101
+ text: 'CircularProgressbar-text',
102
+ background: 'CircularProgressbar-background'
103
+ },
104
+ counterClockwise: false,
105
+ className: '',
106
+ maxValue: 100,
107
+ minValue: 0,
108
+ strokeWidth: 8,
109
+ styles: {
110
+ root: {},
111
+ trail: {},
112
+ path: {},
113
+ text: {},
114
+ background: {}
115
+ },
116
+ text: ''
117
+ });
118
+ 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,32 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ var _excluded = ["children"];
3
+ import * as React from 'react';
4
+ import CircularProgressbar from './CircularProgressbar';
5
+ // This is a wrapper around CircularProgressbar that allows passing children,
6
+ // which will be vertically and horizontally centered inside the progressbar automatically.
7
+ function CircularProgressbarWithChildren(props) {
8
+ var children = props.children,
9
+ circularProgressbarProps = _objectWithoutProperties(props, _excluded);
10
+ return /*#__PURE__*/React.createElement("div", {
11
+ "data-test-id": "CircularProgressbarWithChildren"
12
+ }, /*#__PURE__*/React.createElement("div", {
13
+ style: {
14
+ position: 'relative',
15
+ width: '100%',
16
+ height: '100%'
17
+ }
18
+ }, /*#__PURE__*/React.createElement(CircularProgressbar, circularProgressbarProps), props.children ? /*#__PURE__*/React.createElement("div", {
19
+ "data-test-id": "CircularProgressbarWithChildren__children",
20
+ style: {
21
+ position: 'absolute',
22
+ width: '100%',
23
+ height: '100%',
24
+ marginTop: '-100%',
25
+ display: 'flex',
26
+ flexDirection: 'column',
27
+ justifyContent: 'center',
28
+ alignItems: 'center'
29
+ }
30
+ }, props.children) : null));
31
+ }
32
+ 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,52 @@
1
+ import * as React from 'react';
2
+ import { VIEWBOX_CENTER_X, VIEWBOX_CENTER_Y } from './constants';
3
+ function Path(_ref) {
4
+ var className = _ref.className,
5
+ counterClockwise = _ref.counterClockwise,
6
+ dashRatio = _ref.dashRatio,
7
+ pathRadius = _ref.pathRadius,
8
+ strokeWidth = _ref.strokeWidth,
9
+ style = _ref.style;
10
+ return /*#__PURE__*/React.createElement("path", {
11
+ className: className,
12
+ style: Object.assign({}, style, getDashStyle({
13
+ pathRadius: pathRadius,
14
+ dashRatio: dashRatio,
15
+ counterClockwise: counterClockwise
16
+ })),
17
+ d: getPathDescription({
18
+ pathRadius: pathRadius,
19
+ counterClockwise: counterClockwise
20
+ }),
21
+ strokeWidth: strokeWidth,
22
+ fillOpacity: 0
23
+ });
24
+ }
25
+
26
+ // SVG path description specifies how the path should be drawn
27
+ function getPathDescription(_ref2) {
28
+ var pathRadius = _ref2.pathRadius,
29
+ counterClockwise = _ref2.counterClockwise;
30
+ var radius = pathRadius;
31
+ var rotation = counterClockwise ? 1 : 0;
32
+
33
+ // Move to center of canvas
34
+ // Relative move to top canvas
35
+ // Relative arc to bottom of canvas
36
+ // Relative arc to top of canvas
37
+ 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 ");
38
+ }
39
+ function getDashStyle(_ref3) {
40
+ var counterClockwise = _ref3.counterClockwise,
41
+ dashRatio = _ref3.dashRatio,
42
+ pathRadius = _ref3.pathRadius;
43
+ var diameter = Math.PI * 2 * pathRadius;
44
+ var gapLength = (1 - dashRatio) * diameter;
45
+ return {
46
+ // Have dash be full diameter, and gap be full diameter
47
+ strokeDasharray: "".concat(diameter, "px ").concat(diameter, "px"),
48
+ // Shift dash backward by gapLength, so gap starts appearing at correct distance
49
+ strokeDashoffset: "".concat(counterClockwise ? -gapLength : gapLength, "px")
50
+ };
51
+ }
52
+ 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,45 @@
1
+ export default function buildStyles(_ref) {
2
+ var rotation = _ref.rotation,
3
+ strokeLinecap = _ref.strokeLinecap,
4
+ textColor = _ref.textColor,
5
+ textSize = _ref.textSize,
6
+ pathColor = _ref.pathColor,
7
+ pathTransition = _ref.pathTransition,
8
+ pathTransitionDuration = _ref.pathTransitionDuration,
9
+ trailColor = _ref.trailColor,
10
+ backgroundColor = _ref.backgroundColor;
11
+ var rotationTransform = rotation == null ? undefined : "rotate(".concat(rotation, "turn)");
12
+ var rotationTransformOrigin = rotation == null ? undefined : 'center center';
13
+ return {
14
+ root: {},
15
+ path: removeUndefinedValues({
16
+ stroke: pathColor,
17
+ strokeLinecap: strokeLinecap,
18
+ transform: rotationTransform,
19
+ transformOrigin: rotationTransformOrigin,
20
+ transition: pathTransition,
21
+ transitionDuration: pathTransitionDuration == null ? undefined : "".concat(pathTransitionDuration, "s")
22
+ }),
23
+ trail: removeUndefinedValues({
24
+ stroke: trailColor,
25
+ strokeLinecap: strokeLinecap,
26
+ transform: rotationTransform,
27
+ transformOrigin: rotationTransformOrigin
28
+ }),
29
+ text: removeUndefinedValues({
30
+ fill: textColor,
31
+ fontSize: textSize
32
+ }),
33
+ background: removeUndefinedValues({
34
+ fill: backgroundColor
35
+ })
36
+ };
37
+ }
38
+ function removeUndefinedValues(obj) {
39
+ Object.keys(obj).forEach(function (key) {
40
+ if (obj[key] == null) {
41
+ delete obj[key];
42
+ }
43
+ });
44
+ return obj;
45
+ }
@@ -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,5 @@
1
+ export var VIEWBOX_WIDTH = 100;
2
+ export var VIEWBOX_HEIGHT = 100;
3
+ export var VIEWBOX_HEIGHT_HALF = 50;
4
+ export var VIEWBOX_CENTER_X = 50;
5
+ export var 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,4 @@
1
+ import CircularProgressBar from './CircularProgressbar';
2
+ import CircularProgress from './CircularProgressbarWithChildren';
3
+ import buildStyles from './buildStyles';
4
+ export { CircularProgressBar, CircularProgress, 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
+ };
@@ -0,0 +1 @@
1
+ export {};
package/esm/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';
package/esm/index.js CHANGED
@@ -12,6 +12,7 @@ export { default as Capacity } from './capacity';
12
12
  export { default as Card } from './card';
13
13
  export { default as Checkbox } from './checkbox';
14
14
  export { default as Code } from './code';
15
+ export { CircularProgress, buildStyles } from './CircularProgress';
15
16
  export { default as Collapse } from './collapse';
16
17
  export { default as Description } from './description';
17
18
  export { default as Display } from './display';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helpdice/ui",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "esm/index.d.ts",
6
6
  "unpkg": "dist/index.min.js",
@@ -94,7 +94,6 @@
94
94
  "yup": "^1.6.1"
95
95
  },
96
96
  "dependencies": {
97
- "@babel/runtime": "^7.26.7",
98
97
  "@helpdice/icons": "^1.0.8",
99
98
  "@types/hoist-non-react-statics": "^3.3.6",
100
99
  "@types/styled-components": "^5.1.34",