@grucloud/bau-ui 0.66.0 → 0.67.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/lazy/index.d.ts +22 -0
- package/lazy/index.js +1 -0
- package/lazy/lazy.js +57 -0
- package/package.json +4 -4
package/lazy/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
declare module "@grucloud/bau-ui/lazy" {
|
|
2
|
+
type DefaultDesignProps = import("../constants").DefaultDesignProps;
|
|
3
|
+
type ComponentOption = import("../bau-ui").ComponentOption;
|
|
4
|
+
type Component = import("../bau-ui").Component<any>;
|
|
5
|
+
|
|
6
|
+
export type LazyOptions = {
|
|
7
|
+
loading?: Component;
|
|
8
|
+
error?: Component;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type LazyProps = {
|
|
12
|
+
getModule: () => any;
|
|
13
|
+
props?: any;
|
|
14
|
+
} & DefaultDesignProps;
|
|
15
|
+
|
|
16
|
+
type LazyComponent = import("../bau-ui").Component<LazyProps>;
|
|
17
|
+
|
|
18
|
+
export default function (
|
|
19
|
+
context: any,
|
|
20
|
+
option?: ComponentOption & LazyOptions
|
|
21
|
+
): LazyComponent;
|
|
22
|
+
}
|
package/lazy/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from "./lazy";
|
package/lazy/lazy.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import spinner from "../spinner";
|
|
2
|
+
import alert from "../alert";
|
|
3
|
+
|
|
4
|
+
export default function (context, options = {}) {
|
|
5
|
+
const { bau, css } = context;
|
|
6
|
+
const { div } = bau.tags;
|
|
7
|
+
|
|
8
|
+
const Spinner = spinner(context, { size: "lg" });
|
|
9
|
+
const Alert = alert(context, { color: "danger" });
|
|
10
|
+
|
|
11
|
+
const loadingDefault = () =>
|
|
12
|
+
div(
|
|
13
|
+
{
|
|
14
|
+
class: css`
|
|
15
|
+
height: 100%;
|
|
16
|
+
display: flex;
|
|
17
|
+
justify-content: center;
|
|
18
|
+
align-items: center;
|
|
19
|
+
`,
|
|
20
|
+
},
|
|
21
|
+
Spinner({ visibility: true })
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const errorDefault = (error) => Alert(error.message);
|
|
25
|
+
|
|
26
|
+
return function Lazy({
|
|
27
|
+
getModule,
|
|
28
|
+
loading = loadingDefault,
|
|
29
|
+
error = errorDefault,
|
|
30
|
+
props = {},
|
|
31
|
+
}) {
|
|
32
|
+
const componentState = bau.state(undefined);
|
|
33
|
+
const loadingState = bau.state(true);
|
|
34
|
+
const errorState = bau.state(false);
|
|
35
|
+
|
|
36
|
+
getModule()
|
|
37
|
+
.then((module) => {
|
|
38
|
+
componentState.val = module.default(context);
|
|
39
|
+
loadingState.val = false;
|
|
40
|
+
})
|
|
41
|
+
.catch((error) => {
|
|
42
|
+
errorState.val = error.message;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return div(() => {
|
|
46
|
+
if (errorState.val) {
|
|
47
|
+
return error({ message: errorState.val });
|
|
48
|
+
}
|
|
49
|
+
if (componentState.val) {
|
|
50
|
+
return componentState.val(props);
|
|
51
|
+
}
|
|
52
|
+
if (loadingState.val) {
|
|
53
|
+
return loading();
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grucloud/bau-ui",
|
|
3
3
|
"description": "Components library built with Bau",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.67.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "BSD",
|
|
7
7
|
"keywords": [
|
|
@@ -20,11 +20,11 @@
|
|
|
20
20
|
"directory": "bau-ui"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@grucloud/bau": "^0.
|
|
24
|
-
"@grucloud/bau-css": "^0.
|
|
23
|
+
"@grucloud/bau": "^0.67.0",
|
|
24
|
+
"@grucloud/bau-css": "^0.67.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"typedoc": "0.24.8"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "211dba67346ad04c11165a85291ec42fd856d0a2"
|
|
30
30
|
}
|