dynamic-icons 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/LICENSE +21 -0
- package/README.md +50 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Carlos Torres Moral
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# dynamic-icons
|
|
2
|
+
|
|
3
|
+
A React component that morphs an SVG icon smoothly between named states, built on top of [`morphicons`](https://www.morphicons.com).
|
|
4
|
+
|
|
5
|
+
Not limited to two states — an icon can define as many named states as it needs (`"off" | "on"`, or `"idle" | "loading" | "success" | "error"`, etc.).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add dynamic-icons morphicons react
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`morphicons` and `react` are peer dependencies — you need them installed alongside this package.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
import { DynamicIcon, folderSearchIcon } from "dynamic-icons";
|
|
19
|
+
|
|
20
|
+
function NavIcon({ active }: { active: boolean }) {
|
|
21
|
+
return (
|
|
22
|
+
<DynamicIcon
|
|
23
|
+
icon={folderSearchIcon}
|
|
24
|
+
state={active ? "on" : "off"}
|
|
25
|
+
className="size-5"
|
|
26
|
+
aria-hidden="true"
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Icons included
|
|
33
|
+
|
|
34
|
+
- `folderSearchIcon` — `"off" | "on"`
|
|
35
|
+
- `clipboardListIcon` — `"off" | "on"`
|
|
36
|
+
- `settingsIcon` — `"off" | "on"`
|
|
37
|
+
|
|
38
|
+
## Defining your own icon
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import type { DynamicIconStates } from "dynamic-icons";
|
|
42
|
+
|
|
43
|
+
export const myIcon: DynamicIconStates<"idle" | "loading" | "done"> = {
|
|
44
|
+
idle: [/* morphicons IconInput */],
|
|
45
|
+
loading: [/* ... */],
|
|
46
|
+
done: [/* ... */],
|
|
47
|
+
};
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Any prop `MorphIcon` (from `morphicons/react`) accepts — `className`, `size`, `color`, `strokeWidth`, `label`, `spring`, `reducedMotion`, standard SVG attributes — is forwarded through `DynamicIcon`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { MorphIcon } from "morphicons/react";
|
|
3
|
+
import { IconInput } from "morphicons";
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
type DynamicIconStates<State extends string = string> = Record<State, IconInput>;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/DynamicIcon.d.ts
|
|
8
|
+
type Props<State extends string> = Omit<React.ComponentProps<typeof MorphIcon>, "icon" | "from" | "to"> & {
|
|
9
|
+
icon: DynamicIconStates<State>;
|
|
10
|
+
state: State;
|
|
11
|
+
};
|
|
12
|
+
export declare function DynamicIcon<State extends string>({ icon, state, ...props }: Props<State>): React.ReactElement;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/icons/folder-search.d.ts
|
|
15
|
+
export declare const folderSearchIcon: DynamicIconStates<"off" | "on">;
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/icons/clipboard-list.d.ts
|
|
18
|
+
export declare const clipboardListIcon: DynamicIconStates<"off" | "on">;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/icons/settings.d.ts
|
|
21
|
+
export declare const settingsIcon: DynamicIconStates<"off" | "on">;
|
|
22
|
+
//#endregion
|
|
23
|
+
export type { DynamicIconStates };
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import "react";
|
|
2
|
+
import { MorphIcon } from "morphicons/react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/DynamicIcon.tsx
|
|
5
|
+
function DynamicIcon({ icon, state, ...props }) {
|
|
6
|
+
return /* @__PURE__ */ jsx(MorphIcon, {
|
|
7
|
+
...props,
|
|
8
|
+
icon: icon[state]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/icons/folder-search.ts
|
|
13
|
+
const folderSearchIcon = {
|
|
14
|
+
off: [
|
|
15
|
+
["path", { d: "M10.7 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v4.1" }],
|
|
16
|
+
["path", { d: "m21 21-1.9-1.9" }],
|
|
17
|
+
["circle", {
|
|
18
|
+
cx: "17",
|
|
19
|
+
cy: "17",
|
|
20
|
+
r: "3"
|
|
21
|
+
}]
|
|
22
|
+
],
|
|
23
|
+
on: [
|
|
24
|
+
["path", { d: "M10.7 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v4.1" }],
|
|
25
|
+
["path", { d: "m21 21-1.9-1.9" }],
|
|
26
|
+
["circle", {
|
|
27
|
+
cx: "16",
|
|
28
|
+
cy: "16",
|
|
29
|
+
r: "4"
|
|
30
|
+
}]
|
|
31
|
+
]
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/icons/clipboard-list.ts
|
|
35
|
+
const clipboardListIcon = {
|
|
36
|
+
off: [
|
|
37
|
+
["rect", {
|
|
38
|
+
width: "8",
|
|
39
|
+
height: "4",
|
|
40
|
+
x: "8",
|
|
41
|
+
y: "2",
|
|
42
|
+
rx: "1",
|
|
43
|
+
ry: "1"
|
|
44
|
+
}],
|
|
45
|
+
["path", { d: "M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2" }],
|
|
46
|
+
["path", { d: "M8 11h4" }],
|
|
47
|
+
["path", { d: "M8 16h4" }],
|
|
48
|
+
["path", { d: "M8 11h.01" }],
|
|
49
|
+
["path", { d: "M8 16h.01" }]
|
|
50
|
+
],
|
|
51
|
+
on: [
|
|
52
|
+
["rect", {
|
|
53
|
+
width: "8",
|
|
54
|
+
height: "4",
|
|
55
|
+
x: "8",
|
|
56
|
+
y: "2",
|
|
57
|
+
rx: "1",
|
|
58
|
+
ry: "1"
|
|
59
|
+
}],
|
|
60
|
+
["path", { d: "M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2" }],
|
|
61
|
+
["path", { d: "M12 11h4" }],
|
|
62
|
+
["path", { d: "M12 16h4" }],
|
|
63
|
+
["path", { d: "M8 11h.01" }],
|
|
64
|
+
["path", { d: "M8 16h.01" }]
|
|
65
|
+
]
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/icons/settings.ts
|
|
69
|
+
const settingsIcon = {
|
|
70
|
+
off: [["path", { d: "M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915" }], ["circle", {
|
|
71
|
+
cx: "12",
|
|
72
|
+
cy: "12",
|
|
73
|
+
r: "3"
|
|
74
|
+
}]],
|
|
75
|
+
on: [["path", { d: "M 13.915 4.0251 a 2.34 2.34 30 0 1 4.0348 2.3295 a 2.34 2.34 30 0 0 1.9168 3.3179 a 2.34 2.34 30 0 1 0.0013 4.6577 a 2.34 2.34 30 0 0 -1.9155 3.3177 a 2.34 2.34 30 0 1 -4.0343 2.3277 a 2.34 2.34 30 0 0 -3.8318 -0.0011 a 2.34 2.34 30 0 1 -4.0348 -2.3295 a 2.34 2.34 30 0 0 -1.9177 -3.3184 a 2.34 2.34 30 0 1 -0.0013 -4.6577 a 2.34 2.34 30 0 0 1.9155 -3.3177 A 2.34 2.34 30 0 1 10.0815 4.023 a 2.34 2.34 30 0 0 3.8318 0.0011" }], ["circle", {
|
|
76
|
+
cx: "12",
|
|
77
|
+
cy: "12",
|
|
78
|
+
r: "3"
|
|
79
|
+
}]]
|
|
80
|
+
};
|
|
81
|
+
//#endregion
|
|
82
|
+
export { DynamicIcon, clipboardListIcon, folderSearchIcon, settingsIcon };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/DynamicIcon.tsx","../src/icons/folder-search.ts","../src/icons/clipboard-list.ts","../src/icons/settings.ts"],"sourcesContent":["import * as React from \"react\";\nimport { MorphIcon } from \"morphicons/react\";\nimport type { DynamicIconStates } from \"./types\";\n\ntype Props<State extends string> = Omit<\n React.ComponentProps<typeof MorphIcon>,\n \"icon\" | \"from\" | \"to\"\n> & {\n icon: DynamicIconStates<State>;\n state: State;\n};\n\nexport function DynamicIcon<State extends string>({\n icon,\n state,\n ...props\n}: Props<State>): React.ReactElement {\n return <MorphIcon {...props} icon={icon[state]} />;\n}\n","import type { DynamicIconStates } from \"../types\";\n\nexport const folderSearchIcon: DynamicIconStates<\"off\" | \"on\"> = {\n off: [\n [\n \"path\",\n {\n d: \"M10.7 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v4.1\",\n },\n ],\n [\"path\", { d: \"m21 21-1.9-1.9\" }],\n [\"circle\", { cx: \"17\", cy: \"17\", r: \"3\" }],\n ],\n on: [\n [\n \"path\",\n {\n d: \"M10.7 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v4.1\",\n },\n ],\n [\"path\", { d: \"m21 21-1.9-1.9\" }],\n [\"circle\", { cx: \"16\", cy: \"16\", r: \"4\" }],\n ],\n};\n","import type { DynamicIconStates } from \"../types\";\n\nexport const clipboardListIcon: DynamicIconStates<\"off\" | \"on\"> = {\n off: [\n [\"rect\", { width: \"8\", height: \"4\", x: \"8\", y: \"2\", rx: \"1\", ry: \"1\" }],\n [\n \"path\",\n { d: \"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2\" },\n ],\n [\"path\", { d: \"M8 11h4\" }],\n [\"path\", { d: \"M8 16h4\" }],\n [\"path\", { d: \"M8 11h.01\" }],\n [\"path\", { d: \"M8 16h.01\" }],\n ],\n on: [\n [\"rect\", { width: \"8\", height: \"4\", x: \"8\", y: \"2\", rx: \"1\", ry: \"1\" }],\n [\n \"path\",\n { d: \"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2\" },\n ],\n [\"path\", { d: \"M12 11h4\" }],\n [\"path\", { d: \"M12 16h4\" }],\n [\"path\", { d: \"M8 11h.01\" }],\n [\"path\", { d: \"M8 16h.01\" }],\n ],\n};\n","import type { DynamicIconStates } from \"../types\";\n\nexport const settingsIcon: DynamicIconStates<\"off\" | \"on\"> = {\n off: [\n [\n \"path\",\n {\n d: \"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915\",\n },\n ],\n [\"circle\", { cx: \"12\", cy: \"12\", r: \"3\" }],\n ],\n on: [\n [\n \"path\",\n {\n d: \"M 13.915 4.0251 a 2.34 2.34 30 0 1 4.0348 2.3295 a 2.34 2.34 30 0 0 1.9168 3.3179 a 2.34 2.34 30 0 1 0.0013 4.6577 a 2.34 2.34 30 0 0 -1.9155 3.3177 a 2.34 2.34 30 0 1 -4.0343 2.3277 a 2.34 2.34 30 0 0 -3.8318 -0.0011 a 2.34 2.34 30 0 1 -4.0348 -2.3295 a 2.34 2.34 30 0 0 -1.9177 -3.3184 a 2.34 2.34 30 0 1 -0.0013 -4.6577 a 2.34 2.34 30 0 0 1.9155 -3.3177 A 2.34 2.34 30 0 1 10.0815 4.023 a 2.34 2.34 30 0 0 3.8318 0.0011\",\n },\n ],\n [\"circle\", { cx: \"12\", cy: \"12\", r: \"3\" }],\n ],\n};\n"],"mappings":";;;;AAYA,SAAgB,YAAkC,EAChD,MACA,OACA,GAAG,SACgC;CACnC,OAAO,oBAAC,WAAD;EAAW,GAAI;EAAO,MAAM,KAAK;CAAS,CAAA;AACnD;;;AChBA,MAAa,mBAAoD;CAC/D,KAAK;EACH,CACE,QACA,EACE,GAAG,8GACL,CACF;EACA,CAAC,QAAQ,EAAE,GAAG,iBAAiB,CAAC;EAChC,CAAC,UAAU;GAAE,IAAI;GAAM,IAAI;GAAM,GAAG;EAAI,CAAC;CAC3C;CACA,IAAI;EACF,CACE,QACA,EACE,GAAG,8GACL,CACF;EACA,CAAC,QAAQ,EAAE,GAAG,iBAAiB,CAAC;EAChC,CAAC,UAAU;GAAE,IAAI;GAAM,IAAI;GAAM,GAAG;EAAI,CAAC;CAC3C;AACF;;;ACrBA,MAAa,oBAAqD;CAChE,KAAK;EACH,CAAC,QAAQ;GAAE,OAAO;GAAK,QAAQ;GAAK,GAAG;GAAK,GAAG;GAAK,IAAI;GAAK,IAAI;EAAI,CAAC;EACtE,CACE,QACA,EAAE,GAAG,2EAA2E,CAClF;EACA,CAAC,QAAQ,EAAE,GAAG,UAAU,CAAC;EACzB,CAAC,QAAQ,EAAE,GAAG,UAAU,CAAC;EACzB,CAAC,QAAQ,EAAE,GAAG,YAAY,CAAC;EAC3B,CAAC,QAAQ,EAAE,GAAG,YAAY,CAAC;CAC7B;CACA,IAAI;EACF,CAAC,QAAQ;GAAE,OAAO;GAAK,QAAQ;GAAK,GAAG;GAAK,GAAG;GAAK,IAAI;GAAK,IAAI;EAAI,CAAC;EACtE,CACE,QACA,EAAE,GAAG,2EAA2E,CAClF;EACA,CAAC,QAAQ,EAAE,GAAG,WAAW,CAAC;EAC1B,CAAC,QAAQ,EAAE,GAAG,WAAW,CAAC;EAC1B,CAAC,QAAQ,EAAE,GAAG,YAAY,CAAC;EAC3B,CAAC,QAAQ,EAAE,GAAG,YAAY,CAAC;CAC7B;AACF;;;ACvBA,MAAa,eAAgD;CAC3D,KAAK,CACH,CACE,QACA,EACE,GAAG,0UACL,CACF,GACA,CAAC,UAAU;EAAE,IAAI;EAAM,IAAI;EAAM,GAAG;CAAI,CAAC,CAC3C;CACA,IAAI,CACF,CACE,QACA,EACE,GAAG,yaACL,CACF,GACA,CAAC,UAAU;EAAE,IAAI;EAAM,IAAI;EAAM,GAAG;CAAI,CAAC,CAC3C;AACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dynamic-icons",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A React component that morphs an SVG icon between named states, built on morphicons.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Carlos Torres Moral",
|
|
7
|
+
"repository": { "type": "git", "url": "git+https://github.com/carlostxrres/dynamic-icons.git" },
|
|
8
|
+
"bugs": "https://github.com/carlostxrres/dynamic-icons/issues",
|
|
9
|
+
"homepage": "https://github.com/carlostxrres/dynamic-icons#readme",
|
|
10
|
+
"keywords": ["react", "icons", "svg", "morph", "morphicons", "animated-icons"],
|
|
11
|
+
"type": "module",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"files": ["dist"],
|
|
20
|
+
"engines": { "node": ">=20.19" },
|
|
21
|
+
"publishConfig": { "access": "public" },
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsdown",
|
|
24
|
+
"typecheck": "tsc",
|
|
25
|
+
"prepublishOnly": "npm run typecheck && npm run build"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"morphicons": "^1.7.1",
|
|
29
|
+
"react": ">=18"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/react": "^19.3.0",
|
|
33
|
+
"morphicons": "^1.7.1",
|
|
34
|
+
"react": "^19.3.0",
|
|
35
|
+
"tsdown": "^0.23.0",
|
|
36
|
+
"typescript": "^7.0.2"
|
|
37
|
+
}
|
|
38
|
+
}
|