@availity/mui-progress 0.1.0
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.
- package/CHANGELOG.md +14 -0
- package/README.md +61 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.js +97 -0
- package/dist/index.mjs +73 -0
- package/introduction.mdx +7 -0
- package/jest.config.js +7 -0
- package/package.json +52 -0
- package/project.json +42 -0
- package/src/index.ts +1 -0
- package/src/lib/CircularProgress.stories.tsx +17 -0
- package/src/lib/CircularProgress.test.tsx +54 -0
- package/src/lib/CircularProgress.tsx +88 -0
- package/tsconfig.json +5 -0
- package/tsconfig.spec.json +10 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
|
+
|
|
5
|
+
## 0.1.0 (2023-11-14)
|
|
6
|
+
|
|
7
|
+
### Dependency Updates
|
|
8
|
+
|
|
9
|
+
* `mui-icon` updated to version `0.7.2`
|
|
10
|
+
* `mui-typography` updated to version `0.1.4`
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* **mui-progress:** initial commit ([0012911](https://github.com/Availity/element/commit/00129117d2107d4bdf97a3767119d30ae2edb418))
|
package/README.md
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# @availity/mui-progress
|
|
2
|
+
|
|
3
|
+
> Availity MUI Progress component to be used with @availity/element design system.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@availity/mui-progress)
|
|
6
|
+
[](https://www.npmjs.com/package/@availity/mui-progress)
|
|
7
|
+
[](https://github.com/Availity/element/blob/main/packages/mui-progress/package.json)
|
|
8
|
+
|
|
9
|
+
## Documentation
|
|
10
|
+
|
|
11
|
+
This package extends the MUI Progress component: [MUI Progress Docs](https://mui.com/components/progress/)
|
|
12
|
+
|
|
13
|
+
Live demo and documentation in our [Storybook](https://availity.github.io/element/?path=/docs/components-progress-introduction--docs)
|
|
14
|
+
|
|
15
|
+
Availity standards for design and usage can be found in the [Availity Design Guide](https://zeroheight.com/2e36e50c7)
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### Import Through @availity/element (Recommended)
|
|
20
|
+
|
|
21
|
+
#### NPM
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @availity/element
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
#### Yarn
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
yarn add @availity/element
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Direct Import
|
|
34
|
+
|
|
35
|
+
#### NPM
|
|
36
|
+
|
|
37
|
+
_This package has a few peer dependencies. Add `@mui/material` & `@emotion/react` to your project if not already installed._
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install @availity/mui-progress
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
#### Yarn
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
yarn add @availity/mui-progress
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Usage
|
|
50
|
+
|
|
51
|
+
#### Import through @availity/element
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
import { Progress } from '@availity/element';
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### Direct import
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { Progress } from '@availity/mui-progress';
|
|
61
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CircularProgressProps as CircularProgressProps$1 } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
interface CircularProgressProps extends Omit<CircularProgressProps$1, 'disableShrink' | 'thickness' | 'variant'> {
|
|
4
|
+
/**@default 'primary' */
|
|
5
|
+
color?: 'primary' | 'inherit';
|
|
6
|
+
/** If `true` the the loading animation is replaced with Error Icon and the words "Loading error" display.
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
error?: boolean;
|
|
10
|
+
/** If `true` the the loading animation is replaced with Success Icon and the words "Loading successful" display. Note: This is overridden by the `error` prop.
|
|
11
|
+
* @default false
|
|
12
|
+
*/
|
|
13
|
+
success?: boolean;
|
|
14
|
+
/** If `true` the word "Loading" displays beneath the icon
|
|
15
|
+
* @default true
|
|
16
|
+
*/
|
|
17
|
+
loadingCaption?: boolean;
|
|
18
|
+
/** The size of the component.
|
|
19
|
+
* @default 'default'
|
|
20
|
+
*/
|
|
21
|
+
size?: 'default' | 'small';
|
|
22
|
+
}
|
|
23
|
+
type StatusIconProps = {
|
|
24
|
+
status: string;
|
|
25
|
+
size: 'default' | 'small';
|
|
26
|
+
};
|
|
27
|
+
declare const CircularProgress: ({ loadingCaption, error, success, size, ...props }: CircularProgressProps) => JSX.Element;
|
|
28
|
+
|
|
29
|
+
export { CircularProgress, CircularProgressProps, StatusIconProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
CircularProgress: () => CircularProgress
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(src_exports);
|
|
26
|
+
|
|
27
|
+
// src/lib/CircularProgress.tsx
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_material = require("@mui/material");
|
|
30
|
+
var import_mui_icon = require("@availity/mui-icon");
|
|
31
|
+
var import_mui_typography = require("@availity/mui-typography");
|
|
32
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
33
|
+
var StatusIcon = ({ status, size }) => {
|
|
34
|
+
const fontSize = size === "small" ? "medium" : "large";
|
|
35
|
+
switch (status) {
|
|
36
|
+
case "error":
|
|
37
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mui_icon.WarningCircleIcon, {
|
|
38
|
+
color: "error",
|
|
39
|
+
fontSize,
|
|
40
|
+
titleAccess: "loading error"
|
|
41
|
+
});
|
|
42
|
+
case "success":
|
|
43
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mui_icon.SuccessCircleIcon, {
|
|
44
|
+
color: "success",
|
|
45
|
+
fontSize,
|
|
46
|
+
titleAccess: "loading successful"
|
|
47
|
+
});
|
|
48
|
+
default:
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var getCaptionText = (status) => ({
|
|
53
|
+
loading: "Loading",
|
|
54
|
+
error: "Loading error",
|
|
55
|
+
success: "Loading successful"
|
|
56
|
+
})[status] || "";
|
|
57
|
+
var CircularProgress = ({
|
|
58
|
+
loadingCaption = true,
|
|
59
|
+
error = false,
|
|
60
|
+
success = false,
|
|
61
|
+
size = "default",
|
|
62
|
+
...props
|
|
63
|
+
}) => {
|
|
64
|
+
const [status, setStatus] = (0, import_react.useState)("loading");
|
|
65
|
+
(0, import_react.useEffect)(() => {
|
|
66
|
+
if (error) {
|
|
67
|
+
setStatus("error");
|
|
68
|
+
} else if (success) {
|
|
69
|
+
setStatus("success");
|
|
70
|
+
} else {
|
|
71
|
+
setStatus("loading");
|
|
72
|
+
}
|
|
73
|
+
}, [error, success]);
|
|
74
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_material.Stack, {
|
|
75
|
+
width: "fit-content",
|
|
76
|
+
alignItems: "center",
|
|
77
|
+
children: [
|
|
78
|
+
status === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_material.CircularProgress, {
|
|
79
|
+
...props,
|
|
80
|
+
size: size === "small" ? 24 : 40,
|
|
81
|
+
variant: "indeterminate"
|
|
82
|
+
}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusIcon, {
|
|
83
|
+
status,
|
|
84
|
+
size
|
|
85
|
+
}),
|
|
86
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_mui_typography.Typography, {
|
|
87
|
+
marginTop: "8px",
|
|
88
|
+
variant: "caption",
|
|
89
|
+
children: loadingCaption || error || success ? getCaptionText(status) : null
|
|
90
|
+
})
|
|
91
|
+
]
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
0 && (module.exports = {
|
|
96
|
+
CircularProgress
|
|
97
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/lib/CircularProgress.tsx
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import {
|
|
4
|
+
CircularProgress as MuiCircularProgress,
|
|
5
|
+
Stack
|
|
6
|
+
} from "@mui/material";
|
|
7
|
+
import { SuccessCircleIcon, WarningCircleIcon } from "@availity/mui-icon";
|
|
8
|
+
import { Typography } from "@availity/mui-typography";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
var StatusIcon = ({ status, size }) => {
|
|
11
|
+
const fontSize = size === "small" ? "medium" : "large";
|
|
12
|
+
switch (status) {
|
|
13
|
+
case "error":
|
|
14
|
+
return /* @__PURE__ */ jsx(WarningCircleIcon, {
|
|
15
|
+
color: "error",
|
|
16
|
+
fontSize,
|
|
17
|
+
titleAccess: "loading error"
|
|
18
|
+
});
|
|
19
|
+
case "success":
|
|
20
|
+
return /* @__PURE__ */ jsx(SuccessCircleIcon, {
|
|
21
|
+
color: "success",
|
|
22
|
+
fontSize,
|
|
23
|
+
titleAccess: "loading successful"
|
|
24
|
+
});
|
|
25
|
+
default:
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var getCaptionText = (status) => ({
|
|
30
|
+
loading: "Loading",
|
|
31
|
+
error: "Loading error",
|
|
32
|
+
success: "Loading successful"
|
|
33
|
+
})[status] || "";
|
|
34
|
+
var CircularProgress = ({
|
|
35
|
+
loadingCaption = true,
|
|
36
|
+
error = false,
|
|
37
|
+
success = false,
|
|
38
|
+
size = "default",
|
|
39
|
+
...props
|
|
40
|
+
}) => {
|
|
41
|
+
const [status, setStatus] = useState("loading");
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (error) {
|
|
44
|
+
setStatus("error");
|
|
45
|
+
} else if (success) {
|
|
46
|
+
setStatus("success");
|
|
47
|
+
} else {
|
|
48
|
+
setStatus("loading");
|
|
49
|
+
}
|
|
50
|
+
}, [error, success]);
|
|
51
|
+
return /* @__PURE__ */ jsxs(Stack, {
|
|
52
|
+
width: "fit-content",
|
|
53
|
+
alignItems: "center",
|
|
54
|
+
children: [
|
|
55
|
+
status === "loading" ? /* @__PURE__ */ jsx(MuiCircularProgress, {
|
|
56
|
+
...props,
|
|
57
|
+
size: size === "small" ? 24 : 40,
|
|
58
|
+
variant: "indeterminate"
|
|
59
|
+
}) : /* @__PURE__ */ jsx(StatusIcon, {
|
|
60
|
+
status,
|
|
61
|
+
size
|
|
62
|
+
}),
|
|
63
|
+
/* @__PURE__ */ jsx(Typography, {
|
|
64
|
+
marginTop: "8px",
|
|
65
|
+
variant: "caption",
|
|
66
|
+
children: loadingCaption || error || success ? getCaptionText(status) : null
|
|
67
|
+
})
|
|
68
|
+
]
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
export {
|
|
72
|
+
CircularProgress
|
|
73
|
+
};
|
package/introduction.mdx
ADDED
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@availity/mui-progress",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Availity MUI Progress Component - part of the @availity/element design system",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react",
|
|
7
|
+
"typescript",
|
|
8
|
+
"availity",
|
|
9
|
+
"mui"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://availity.github.io/element/?path=/docs/components-progress-introduction--docs",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/Availity/element/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/Availity/element.git",
|
|
18
|
+
"directory": "packages/progress"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "Availity Developers <AVOSS@availity.com>",
|
|
22
|
+
"browser": "./dist/index.js",
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"module": "./dist/index.mjs",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
28
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
29
|
+
"clean": "rm -rf dist",
|
|
30
|
+
"clean:nm": "rm -rf node_modules",
|
|
31
|
+
"publish": "yarn npm publish --tolerate-republish --access public",
|
|
32
|
+
"publish:canary": "yarn npm publish --access public --tag canary"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@mui/material": "^5.11.9",
|
|
36
|
+
"react": "18.2.0",
|
|
37
|
+
"react-dom": "18.2.0",
|
|
38
|
+
"tsup": "^5.12.7",
|
|
39
|
+
"typescript": "^4.6.4"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@mui/material": "^5.11.9",
|
|
43
|
+
"react": ">=16.3.0"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@availity/mui-icon": "^0.7.2",
|
|
50
|
+
"@availity/mui-typography": "^0.1.4"
|
|
51
|
+
}
|
|
52
|
+
}
|
package/project.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mui-progress",
|
|
3
|
+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "packages/progress/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"targets": {
|
|
8
|
+
"lint": {
|
|
9
|
+
"executor": "@nrwl/linter:eslint",
|
|
10
|
+
"options": {
|
|
11
|
+
"eslintConfig": ".eslintrc.json",
|
|
12
|
+
"lintFilePatterns": ["packages/progress/**/*.{js,ts}"],
|
|
13
|
+
"silent": false,
|
|
14
|
+
"fix": false,
|
|
15
|
+
"cache": true,
|
|
16
|
+
"cacheLocation": "./node_modules/.cache/progress/.eslintcache",
|
|
17
|
+
"maxWarnings": -1,
|
|
18
|
+
"quiet": false,
|
|
19
|
+
"noEslintrc": false,
|
|
20
|
+
"hasTypeAwareRules": true,
|
|
21
|
+
"cacheStrategy": "metadata"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"test": {
|
|
25
|
+
"executor": "@nrwl/jest:jest",
|
|
26
|
+
"outputs": ["coverage/progress"],
|
|
27
|
+
"options": {
|
|
28
|
+
"jestConfig": "packages/progress/jest.config.js",
|
|
29
|
+
"passWithNoTests": true
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"version": {
|
|
33
|
+
"executor": "@jscutlery/semver:version",
|
|
34
|
+
"options": {
|
|
35
|
+
"preset": "conventional",
|
|
36
|
+
"commitMessageFormat": "chore(${projectName}): release version ${version} [skip ci]",
|
|
37
|
+
"tagPrefix": "@availity/${projectName}@",
|
|
38
|
+
"trackDeps": true
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/CircularProgress';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Each exported component in the package should have its own stories file
|
|
2
|
+
|
|
3
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
4
|
+
import { CircularProgress, CircularProgressProps } from './CircularProgress';
|
|
5
|
+
|
|
6
|
+
const meta: Meta<typeof CircularProgress> = {
|
|
7
|
+
title: 'Components/Progress/Progress',
|
|
8
|
+
component: CircularProgress,
|
|
9
|
+
tags: ['autodocs'],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default meta;
|
|
13
|
+
|
|
14
|
+
export const _Progress: StoryObj<typeof CircularProgress> = {
|
|
15
|
+
render: (args: CircularProgressProps) => <CircularProgress {...args} />,
|
|
16
|
+
args: {},
|
|
17
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { render } from '@testing-library/react';
|
|
2
|
+
import { CircularProgress } from './CircularProgress';
|
|
3
|
+
|
|
4
|
+
describe('CircularProgress', () => {
|
|
5
|
+
test('should render loader successfully', () => {
|
|
6
|
+
const { getByText, getByRole } = render(<CircularProgress />);
|
|
7
|
+
expect(getByRole('progressbar')).toBeTruthy();
|
|
8
|
+
expect(getByText('Loading')).toBeTruthy();
|
|
9
|
+
});
|
|
10
|
+
describe('loadingCaption', () => {
|
|
11
|
+
test('should render loader successfully without Loading caption', () => {
|
|
12
|
+
const { queryByText } = render(<CircularProgress loadingCaption={false} />);
|
|
13
|
+
expect(queryByText('Loading')).not.toBeInTheDocument();
|
|
14
|
+
});
|
|
15
|
+
test('should render success but still have Loading successful caption', () => {
|
|
16
|
+
const { getByText } = render(<CircularProgress loadingCaption={false} success />);
|
|
17
|
+
expect(getByText('Loading successful')).toBeTruthy();
|
|
18
|
+
});
|
|
19
|
+
test('should render error but still have Loading successful caption', () => {
|
|
20
|
+
const { getByText } = render(<CircularProgress loadingCaption={false} error />);
|
|
21
|
+
expect(getByText('Loading error')).toBeTruthy();
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
describe('success', () => {
|
|
25
|
+
test('should render success icon successfully', () => {
|
|
26
|
+
const { queryByText, queryByRole, getByTitle, getByText } = render(<CircularProgress success />);
|
|
27
|
+
expect(queryByRole('progressbar')).not.toBeInTheDocument();
|
|
28
|
+
expect(queryByText('Loading')).not.toBeInTheDocument();
|
|
29
|
+
expect(getByTitle('loading successful')).toBeTruthy();
|
|
30
|
+
expect(getByText('Loading successful')).toBeTruthy();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
describe('error', () => {
|
|
34
|
+
test('should render error icon successfully', () => {
|
|
35
|
+
const { queryByText, queryByRole, getByTitle, getByText } = render(<CircularProgress error />);
|
|
36
|
+
expect(queryByRole('progressbar')).not.toBeInTheDocument();
|
|
37
|
+
expect(queryByText('Loading')).not.toBeInTheDocument();
|
|
38
|
+
expect(getByTitle('loading error')).toBeTruthy();
|
|
39
|
+
expect(getByText('Loading error')).toBeTruthy();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('should override success icon successfully', () => {
|
|
43
|
+
const { queryByText, queryByRole, queryByTitle, getByTitle, getByText } = render(
|
|
44
|
+
<CircularProgress success error />
|
|
45
|
+
);
|
|
46
|
+
expect(queryByRole('progressbar')).not.toBeInTheDocument();
|
|
47
|
+
expect(queryByText('Loading')).not.toBeInTheDocument();
|
|
48
|
+
expect(getByTitle('loading error')).toBeTruthy();
|
|
49
|
+
expect(getByText('Loading error')).toBeTruthy();
|
|
50
|
+
expect(queryByTitle('loading successful')).not.toBeInTheDocument();
|
|
51
|
+
expect(queryByText('Loading successful')).not.toBeInTheDocument();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
CircularProgress as MuiCircularProgress,
|
|
4
|
+
CircularProgressProps as MuiCircularProgressProps,
|
|
5
|
+
Stack,
|
|
6
|
+
} from '@mui/material';
|
|
7
|
+
import { SuccessCircleIcon, WarningCircleIcon } from '@availity/mui-icon';
|
|
8
|
+
import { Typography } from '@availity/mui-typography';
|
|
9
|
+
|
|
10
|
+
export interface CircularProgressProps
|
|
11
|
+
extends Omit<MuiCircularProgressProps, 'disableShrink' | 'thickness' | 'variant'> {
|
|
12
|
+
/**@default 'primary' */
|
|
13
|
+
color?: 'primary' | 'inherit';
|
|
14
|
+
/** If `true` the the loading animation is replaced with Error Icon and the words "Loading error" display.
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
17
|
+
error?: boolean;
|
|
18
|
+
/** If `true` the the loading animation is replaced with Success Icon and the words "Loading successful" display. Note: This is overridden by the `error` prop.
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
success?: boolean;
|
|
22
|
+
/** If `true` the word "Loading" displays beneath the icon
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
loadingCaption?: boolean;
|
|
26
|
+
/** The size of the component.
|
|
27
|
+
* @default 'default'
|
|
28
|
+
*/
|
|
29
|
+
size?: 'default' | 'small';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type StatusIconProps = {
|
|
33
|
+
status: string;
|
|
34
|
+
size: 'default' | 'small';
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const StatusIcon = ({ status, size }: StatusIconProps) => {
|
|
38
|
+
const fontSize = size === 'small' ? 'medium' : 'large';
|
|
39
|
+
|
|
40
|
+
switch (status) {
|
|
41
|
+
case 'error':
|
|
42
|
+
return <WarningCircleIcon color="error" fontSize={fontSize} titleAccess="loading error" />;
|
|
43
|
+
case 'success':
|
|
44
|
+
return <SuccessCircleIcon color="success" fontSize={fontSize} titleAccess="loading successful" />;
|
|
45
|
+
default:
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const getCaptionText = (status: string) =>
|
|
51
|
+
({
|
|
52
|
+
loading: 'Loading',
|
|
53
|
+
error: 'Loading error',
|
|
54
|
+
success: 'Loading successful',
|
|
55
|
+
}[status] || '');
|
|
56
|
+
|
|
57
|
+
export const CircularProgress = ({
|
|
58
|
+
loadingCaption = true,
|
|
59
|
+
error = false,
|
|
60
|
+
success = false,
|
|
61
|
+
size = 'default',
|
|
62
|
+
...props
|
|
63
|
+
}: CircularProgressProps): JSX.Element => {
|
|
64
|
+
const [status, setStatus] = useState('loading');
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (error) {
|
|
68
|
+
setStatus('error');
|
|
69
|
+
} else if (success) {
|
|
70
|
+
setStatus('success');
|
|
71
|
+
} else {
|
|
72
|
+
setStatus('loading');
|
|
73
|
+
}
|
|
74
|
+
}, [error, success]);
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<Stack width="fit-content" alignItems="center">
|
|
78
|
+
{status === 'loading' ? (
|
|
79
|
+
<MuiCircularProgress {...props} size={size === 'small' ? 24 : 40} variant="indeterminate" />
|
|
80
|
+
) : (
|
|
81
|
+
<StatusIcon status={status} size={size} />
|
|
82
|
+
)}
|
|
83
|
+
<Typography marginTop="8px" variant="caption">
|
|
84
|
+
{loadingCaption || error || success ? getCaptionText(status) : null}
|
|
85
|
+
</Typography>
|
|
86
|
+
</Stack>
|
|
87
|
+
);
|
|
88
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"module": "commonjs",
|
|
6
|
+
"types": ["jest", "node", "@testing-library/jest-dom"],
|
|
7
|
+
"allowJs": true
|
|
8
|
+
},
|
|
9
|
+
"include": ["**/*.test.js", "**/*.test.ts", "**/*.test.tsx", "**/*.d.ts"]
|
|
10
|
+
}
|