@ncds/ui-admin-icon 0.0.11 → 0.0.12
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/dist/cjs/index.js +39 -9
- package/dist/esm/index.js +40 -10
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -40,20 +40,50 @@ const react_1 = __importStar(require("react"));
|
|
|
40
40
|
const covertToPascalCase = (str) => {
|
|
41
41
|
return str.replace(/-([a-z0-9])/g, (_, char) => char.toUpperCase()).replace(/^[a-z]/, (char) => char.toUpperCase());
|
|
42
42
|
};
|
|
43
|
+
const viteLoader = (name) => {
|
|
44
|
+
const iconName = covertToPascalCase(name);
|
|
45
|
+
try {
|
|
46
|
+
return Promise.resolve(`${`./components/${iconName}`}`).then(s => __importStar(require(s))).then((module) => module.default);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return Promise.reject(new Error(`Icon ${name} not found`));
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const webpackLoader = (name) => {
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
const requireContext = require.context('./components', true, /\.(js|tsx)$/);
|
|
55
|
+
const iconName = covertToPascalCase(name);
|
|
56
|
+
try {
|
|
57
|
+
return Promise.resolve(requireContext(`./${iconName}`).default);
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return Promise.reject(new Error(`Icon ${name} not found`));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const getIconLoader = () => {
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
if (typeof require !== 'undefined' && typeof require.context === 'function') {
|
|
66
|
+
return webpackLoader;
|
|
67
|
+
}
|
|
68
|
+
return viteLoader;
|
|
69
|
+
};
|
|
70
|
+
const loadIcon = getIconLoader();
|
|
43
71
|
const Icon = ({ name, ...props }) => {
|
|
44
72
|
const iconRef = (0, react_1.useRef)(null);
|
|
45
|
-
const [
|
|
73
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(true);
|
|
46
74
|
(0, react_1.useEffect)(() => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
iconRef.current =
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
|
|
75
|
+
setIsLoading(true);
|
|
76
|
+
loadIcon(name)
|
|
77
|
+
.then((component) => {
|
|
78
|
+
iconRef.current = component;
|
|
79
|
+
setIsLoading(false);
|
|
80
|
+
})
|
|
81
|
+
.catch(() => {
|
|
82
|
+
setIsLoading(false);
|
|
83
|
+
});
|
|
54
84
|
}, [name]);
|
|
55
85
|
const IconComponent = iconRef.current;
|
|
56
|
-
if (
|
|
86
|
+
if (isLoading || !IconComponent)
|
|
57
87
|
return null;
|
|
58
88
|
return react_1.default.createElement(IconComponent, { ...props });
|
|
59
89
|
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,21 +1,51 @@
|
|
|
1
|
-
import React, { useEffect,
|
|
1
|
+
import React, { useEffect, useState, useRef } from 'react';
|
|
2
2
|
const covertToPascalCase = (str) => {
|
|
3
3
|
return str.replace(/-([a-z0-9])/g, (_, char) => char.toUpperCase()).replace(/^[a-z]/, (char) => char.toUpperCase());
|
|
4
4
|
};
|
|
5
|
+
const viteLoader = (name) => {
|
|
6
|
+
const iconName = covertToPascalCase(name);
|
|
7
|
+
try {
|
|
8
|
+
return import(/* @vite-ignore */ `./components/${iconName}`).then((module) => module.default);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return Promise.reject(new Error(`Icon ${name} not found`));
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const webpackLoader = (name) => {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
const requireContext = require.context('./components', true, /\.(js|tsx)$/);
|
|
17
|
+
const iconName = covertToPascalCase(name);
|
|
18
|
+
try {
|
|
19
|
+
return Promise.resolve(requireContext(`./${iconName}`).default);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return Promise.reject(new Error(`Icon ${name} not found`));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const getIconLoader = () => {
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
if (typeof require !== 'undefined' && typeof require.context === 'function') {
|
|
28
|
+
return webpackLoader;
|
|
29
|
+
}
|
|
30
|
+
return viteLoader;
|
|
31
|
+
};
|
|
32
|
+
const loadIcon = getIconLoader();
|
|
5
33
|
const Icon = ({ name, ...props }) => {
|
|
6
34
|
const iconRef = useRef(null);
|
|
7
|
-
const [
|
|
35
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
8
36
|
useEffect(() => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
iconRef.current =
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
37
|
+
setIsLoading(true);
|
|
38
|
+
loadIcon(name)
|
|
39
|
+
.then((component) => {
|
|
40
|
+
iconRef.current = component;
|
|
41
|
+
setIsLoading(false);
|
|
42
|
+
})
|
|
43
|
+
.catch(() => {
|
|
44
|
+
setIsLoading(false);
|
|
45
|
+
});
|
|
16
46
|
}, [name]);
|
|
17
47
|
const IconComponent = iconRef.current;
|
|
18
|
-
if (
|
|
48
|
+
if (isLoading || !IconComponent)
|
|
19
49
|
return null;
|
|
20
50
|
return React.createElement(IconComponent, { ...props });
|
|
21
51
|
};
|