@heartpace/icons 0.1.1
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 +22 -0
- package/README.md +184 -0
- package/dist/index.d.mts +903 -0
- package/dist/index.d.ts +903 -0
- package/dist/index.js +478 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +232 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +60 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Heartpace
|
|
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.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
# Heartpace Icons
|
|
2
|
+
|
|
3
|
+
A TypeScript/React icon library with recursive SVG autogeneration. Automatically converts SVG files from nested folders into unique React components using SVGR and tsup.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- 🔄 **Recursive SVG Processing**: Automatically scans nested folders in `src/icons`
|
|
8
|
+
- 🎯 **Unique Component Names**: Generates globally unique component names based on folder structure
|
|
9
|
+
- 📁 **Nested Folder Support**: Organize your icons in any folder structure you want
|
|
10
|
+
- 🔀 **Duplicate File Name Handling**: SVG files can have the same name in different folders
|
|
11
|
+
- ⚡ **TypeScript Support**: Full TypeScript definitions included
|
|
12
|
+
- 📦 **Tree-shakeable**: Built with tsup for optimal bundle size
|
|
13
|
+
- 🎨 **SVGR Integration**: Uses SVGR to convert SVGs to optimized React components
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
### Adding Icons
|
|
24
|
+
|
|
25
|
+
Place your SVG files in the `src/icons` directory. You can organize them in any nested folder structure:
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
src/icons/
|
|
29
|
+
├── icon.svg
|
|
30
|
+
├── ui/
|
|
31
|
+
│ ├── button/
|
|
32
|
+
│ │ └── icon.svg
|
|
33
|
+
│ └── icon.svg
|
|
34
|
+
└── actions/
|
|
35
|
+
├── icon.svg
|
|
36
|
+
└── save.svg
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Generating Components
|
|
40
|
+
|
|
41
|
+
Run the generation script to convert SVGs to React components:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm run generate
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
This will:
|
|
48
|
+
1. Recursively scan `src/icons` for all SVG files
|
|
49
|
+
2. Generate unique component names based on folder structure
|
|
50
|
+
3. Convert SVGs to React components using SVGR
|
|
51
|
+
4. Create TypeScript component files in `src/generated/`
|
|
52
|
+
5. Update `src/index.ts` with all exports
|
|
53
|
+
|
|
54
|
+
### Building
|
|
55
|
+
|
|
56
|
+
Build the library for production:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm run build
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
This runs the generation step and then builds with tsup, outputting:
|
|
63
|
+
- CommonJS: `dist/index.js`
|
|
64
|
+
- ES Modules: `dist/index.mjs`
|
|
65
|
+
- TypeScript definitions: `dist/index.d.ts`
|
|
66
|
+
|
|
67
|
+
### Development
|
|
68
|
+
|
|
69
|
+
Watch mode for development:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm run dev
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Component Naming
|
|
76
|
+
|
|
77
|
+
Component names are automatically generated from the folder structure and file name:
|
|
78
|
+
|
|
79
|
+
- **Path**: `src/icons/ui/button/icon.svg` → **Component**: `UiButtonIcon`
|
|
80
|
+
- **Path**: `src/icons/actions/save.svg` → **Component**: `ActionsSave`
|
|
81
|
+
- **Path**: `src/icons/icon.svg` → **Component**: `Icon`
|
|
82
|
+
|
|
83
|
+
### Naming Rules
|
|
84
|
+
|
|
85
|
+
1. Each folder and file name is converted to PascalCase
|
|
86
|
+
2. All parts are joined together (no separators)
|
|
87
|
+
3. The `.svg` extension is removed
|
|
88
|
+
4. If duplicate names would occur, numbers are appended (e.g., `Icon2`, `Icon3`)
|
|
89
|
+
|
|
90
|
+
### Examples
|
|
91
|
+
|
|
92
|
+
| File Path | Component Name |
|
|
93
|
+
|-----------|----------------|
|
|
94
|
+
| `icon.svg` | `Icon` |
|
|
95
|
+
| `ui/icon.svg` | `UiIcon` |
|
|
96
|
+
| `ui/button/icon.svg` | `UiButtonIcon` |
|
|
97
|
+
| `actions/save.svg` | `ActionsSave` |
|
|
98
|
+
| `arrows/icon/arrow/swap.svg` | `ArrowsIconArrowSwap` |
|
|
99
|
+
|
|
100
|
+
## Using the Icons
|
|
101
|
+
|
|
102
|
+
After building, import icons from the package:
|
|
103
|
+
|
|
104
|
+
```tsx
|
|
105
|
+
import { Icon, UiButtonIcon, ActionsSave } from 'heartpace-icons';
|
|
106
|
+
|
|
107
|
+
function MyComponent() {
|
|
108
|
+
return (
|
|
109
|
+
<div>
|
|
110
|
+
<Icon className="w-6 h-6" />
|
|
111
|
+
<UiButtonIcon width={24} height={24} fill="currentColor" />
|
|
112
|
+
<ActionsSave stroke="blue" />
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
All icons accept standard React SVG props (`className`, `width`, `height`, `fill`, `stroke`, etc.).
|
|
119
|
+
|
|
120
|
+
## Tree-shaking Support
|
|
121
|
+
|
|
122
|
+
This library is fully optimized for tree-shaking! Only the icons you import will be included in your final bundle.
|
|
123
|
+
|
|
124
|
+
### ✅ Best Practices
|
|
125
|
+
|
|
126
|
+
```tsx
|
|
127
|
+
// ✅ GOOD: Named imports (tree-shakeable)
|
|
128
|
+
import { ArrowsIconArrowUp, FlagsFrance } from 'heartpace-icons';
|
|
129
|
+
|
|
130
|
+
// ❌ BAD: Namespace import (imports everything)
|
|
131
|
+
import * as Icons from 'heartpace-icons';
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### 📊 Bundle Size Impact
|
|
135
|
+
|
|
136
|
+
- **Total library size**: ~240 KB (all 225 icons)
|
|
137
|
+
- **Single icon**: ~1-2 KB
|
|
138
|
+
- **With tree-shaking**: Only imported icons are bundled
|
|
139
|
+
|
|
140
|
+
Example: Importing 5 icons = ~5-10 KB instead of 240 KB! 🎉
|
|
141
|
+
|
|
142
|
+
For more details, see [TREE_SHAKING.md](./TREE_SHAKING.md).
|
|
143
|
+
|
|
144
|
+
## Project Structure
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
heartpace-icons/
|
|
148
|
+
├── src/
|
|
149
|
+
│ ├── icons/ # Place your SVG files here (any nested structure)
|
|
150
|
+
│ ├── generated/ # Auto-generated React components (gitignored)
|
|
151
|
+
│ └── index.ts # Auto-generated exports (gitignored)
|
|
152
|
+
├── dist/ # Build output (gitignored)
|
|
153
|
+
├── scripts/
|
|
154
|
+
│ └── generate.js # SVG to React component generator
|
|
155
|
+
├── package.json
|
|
156
|
+
├── tsconfig.json
|
|
157
|
+
├── tsup.config.ts
|
|
158
|
+
└── README.md
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Scripts
|
|
162
|
+
|
|
163
|
+
- `npm run generate` - Generate React components from SVG files
|
|
164
|
+
- `npm run build` - Generate components and build the library
|
|
165
|
+
- `npm run dev` - Generate components and watch for changes
|
|
166
|
+
|
|
167
|
+
## How It Works
|
|
168
|
+
|
|
169
|
+
1. **Discovery**: The generator recursively scans `src/icons` for all `.svg` files
|
|
170
|
+
2. **Naming**: Component names are generated from the full folder path + filename
|
|
171
|
+
3. **Conversion**: Each SVG is converted to a React component using SVGR
|
|
172
|
+
4. **Generation**: TypeScript component files are created in `src/generated/`
|
|
173
|
+
5. **Export**: All components are exported from `src/index.ts`
|
|
174
|
+
6. **Build**: tsup bundles everything into distributable formats
|
|
175
|
+
|
|
176
|
+
## Requirements
|
|
177
|
+
|
|
178
|
+
- Node.js 18+
|
|
179
|
+
- React 18+ (peer dependency)
|
|
180
|
+
|
|
181
|
+
## License
|
|
182
|
+
|
|
183
|
+
MIT
|
|
184
|
+
|