svg-dynamic-icon 1.0.3 → 1.0.4
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/index.js +101 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
@@ -1 +1,101 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __glob = (map) => (path) => {
|
9
|
+
var fn = map[path];
|
10
|
+
if (fn) return fn();
|
11
|
+
throw new Error("Module not found in bundle: " + path);
|
12
|
+
};
|
13
|
+
var __commonJS = (cb, mod) => function __require() {
|
14
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
15
|
+
};
|
16
|
+
var __export = (target, all) => {
|
17
|
+
for (var name in all)
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
19
|
+
};
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
22
|
+
for (let key of __getOwnPropNames(from))
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
25
|
+
}
|
26
|
+
return to;
|
27
|
+
};
|
28
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
29
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
30
|
+
// file that has been converted to a CommonJS file using a Babel-
|
31
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
32
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
33
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
34
|
+
mod
|
35
|
+
));
|
36
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
37
|
+
|
38
|
+
// assets/icons/Fallback.svg
|
39
|
+
var require_Fallback = __commonJS({
|
40
|
+
"assets/icons/Fallback.svg"(exports2, module2) {
|
41
|
+
module2.exports = "./assets/Fallback-R62GNTAJ.svg";
|
42
|
+
}
|
43
|
+
});
|
44
|
+
|
45
|
+
// index.ts
|
46
|
+
var index_exports = {};
|
47
|
+
__export(index_exports, {
|
48
|
+
DynamicIcon: () => DynamicIcon_default
|
49
|
+
});
|
50
|
+
module.exports = __toCommonJS(index_exports);
|
51
|
+
|
52
|
+
// src/DynamicIcon.tsx
|
53
|
+
var import_react = require("react");
|
54
|
+
var import_react_svg = require("react-svg");
|
55
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
56
|
+
|
57
|
+
// import("../assets/icons/**/*.svg") in src/DynamicIcon.tsx
|
58
|
+
var globImport_assets_icons_svg = __glob({
|
59
|
+
"../assets/icons/Fallback.svg": () => Promise.resolve().then(() => __toESM(require_Fallback()))
|
60
|
+
});
|
61
|
+
|
62
|
+
// src/DynamicIcon.tsx
|
63
|
+
var DynamicIcon = ({
|
64
|
+
iconName = "Fallback",
|
65
|
+
size = "25",
|
66
|
+
color = "black"
|
67
|
+
}) => {
|
68
|
+
const [iconUrl, setIconUrl] = (0, import_react.useState)(null);
|
69
|
+
(0, import_react.useEffect)(() => {
|
70
|
+
const importIcon = async () => {
|
71
|
+
try {
|
72
|
+
const icon = await globImport_assets_icons_svg(`../assets/icons/${iconName}.svg`);
|
73
|
+
setIconUrl(icon.default);
|
74
|
+
} catch (error) {
|
75
|
+
console.error(`Icon ${iconName} not found`);
|
76
|
+
setIconUrl(null);
|
77
|
+
}
|
78
|
+
};
|
79
|
+
importIcon();
|
80
|
+
}, [iconName]);
|
81
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
82
|
+
import_react_svg.ReactSVG,
|
83
|
+
{
|
84
|
+
src: iconUrl || "",
|
85
|
+
className: color,
|
86
|
+
beforeInjection: (svg) => {
|
87
|
+
svg.setAttribute("style", `width: ${size}px; height: ${size}px;`);
|
88
|
+
svg.setAttribute("fill", "currentColor");
|
89
|
+
svg.querySelectorAll("path").forEach((path) => {
|
90
|
+
path.setAttribute("fill", "currentColor");
|
91
|
+
});
|
92
|
+
}
|
93
|
+
}
|
94
|
+
);
|
95
|
+
};
|
96
|
+
var DynamicIcon_default = DynamicIcon;
|
97
|
+
// Annotate the CommonJS export names for ESM import in node:
|
98
|
+
0 && (module.exports = {
|
99
|
+
DynamicIcon
|
100
|
+
});
|
101
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "svg-dynamic-icon",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.4",
|
4
4
|
"main": "dist/index.js",
|
5
5
|
"types": "dist/index.d.ts",
|
6
6
|
"scripts": {
|
@@ -17,8 +17,8 @@
|
|
17
17
|
"typescript": "^5.8.3"
|
18
18
|
},
|
19
19
|
"peerDependencies": {
|
20
|
-
"react": "^17.0.0 || ^18.0.0",
|
21
|
-
"react-dom": "^17.0.0 || ^18.0.0",
|
20
|
+
"react": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
21
|
+
"react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0",
|
22
22
|
"react-svg": "^15.1.21"
|
23
23
|
}
|
24
24
|
}
|