@ncds/ui-admin-icon 0.0.15 → 0.0.17
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/README.md +10 -3
- package/dist/cjs/index.js +22 -13
- package/dist/cjs/map.js +1549 -1549
- package/dist/esm/index.js +23 -14
- package/dist/esm/map.js +1549 -1549
- package/dist/types/map.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,18 +28,25 @@ The default export is a dynamic Icon component that loads icons on demand:
|
|
|
28
28
|
|
|
29
29
|
```jsx
|
|
30
30
|
import Icon from '@ncds/ui-admin-icon';
|
|
31
|
-
import type { IconName } '@ncds/ui-admin-icon';
|
|
32
31
|
|
|
33
32
|
function MyComponent() {
|
|
34
33
|
return (
|
|
35
34
|
<div>
|
|
36
35
|
<Icon name="plus" />
|
|
37
|
-
<Icon name="heart" width={24} height={24}
|
|
36
|
+
<Icon name="heart" width={24} height={24} color="red" />
|
|
38
37
|
</div>
|
|
39
38
|
);
|
|
40
39
|
}
|
|
41
40
|
```
|
|
42
41
|
|
|
42
|
+
The type of `name` is defined in the package, so you can use it for type checking:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import type { IconName } from '@ncds/ui-admin-icon';
|
|
46
|
+
|
|
47
|
+
const iconName: IconName = 'plus';
|
|
48
|
+
```
|
|
49
|
+
|
|
43
50
|
### Importing individual icons
|
|
44
51
|
|
|
45
52
|
For better performance, you can import specific icons directly:
|
|
@@ -51,7 +58,7 @@ function MyComponent() {
|
|
|
51
58
|
return (
|
|
52
59
|
<div>
|
|
53
60
|
<Plus />
|
|
54
|
-
<Heart width={24} height={24}
|
|
61
|
+
<Heart width={24} height={24} color="red" />
|
|
55
62
|
</div>
|
|
56
63
|
);
|
|
57
64
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -39,21 +39,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
const react_1 = __importStar(require("react"));
|
|
40
40
|
const map_1 = require("./map");
|
|
41
41
|
const Icon = ({ name, ...props }) => {
|
|
42
|
-
const
|
|
43
|
-
const [
|
|
42
|
+
const IconComponentRef = (0, react_1.useRef)(null);
|
|
43
|
+
const [, forceUpdate] = react_1.default.useState({});
|
|
44
44
|
(0, react_1.useEffect)(() => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
IconComponentRef.current = null;
|
|
46
|
+
let isMounted = true;
|
|
47
|
+
const iconImport = (0, map_1.getIcon)(name);
|
|
48
|
+
if (iconImport) {
|
|
49
|
+
iconImport()
|
|
50
|
+
.then((iconModule) => {
|
|
51
|
+
if (isMounted && iconModule?.default) {
|
|
52
|
+
IconComponentRef.current = iconModule.default;
|
|
53
|
+
forceUpdate({});
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
.catch((error) => {
|
|
57
|
+
console.error(`Error loading icon: ${name}`, error);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return () => {
|
|
61
|
+
isMounted = false;
|
|
62
|
+
};
|
|
54
63
|
}, [name]);
|
|
55
|
-
const IconComponent =
|
|
56
|
-
if (
|
|
64
|
+
const IconComponent = IconComponentRef.current;
|
|
65
|
+
if (!IconComponent)
|
|
57
66
|
return null;
|
|
58
67
|
return react_1.default.createElement(IconComponent, { ...props });
|
|
59
68
|
};
|