Skip to content

Commit 6c49b2b

Browse files
committed
v0.3.0 + Add Tabler Icon Support
1 parent 1edd3ce commit 6c49b2b

File tree

3 files changed

+217
-257
lines changed

3 files changed

+217
-257
lines changed

README.md

Lines changed: 113 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -4,109 +4,106 @@
44

55
<div align="center">
66

7-
<h1>React Zero Icon Sprite</h1>
8-
<h2>The most performant way to do icons in React</h2>
7+
<h1>React Zero Icon Sprite - Zero Runtime SVG Icons</h1>
8+
<h2>The most performant way to use icons in React</h2>
9+
10+
<legend><b>Use over 6,800+</b> Lucide & Tabler <code>&lt;Icon /&gt;</code> in development. </br> Ship <b>one SVG sprite</b> in production - only the icons you used.</legend>
11+
12+
<br/>
13+
14+
<table align="center">
15+
<tr>
16+
<td align="center" width="33%">
17+
🚀 <b>Zero Runtime</b><br/>Compiles to native <code>&lt;use&gt;</code> tags
18+
</td>
19+
<td align="center" width="33%">
20+
📦 <b>~300% Smaller</b><br/>No HTML bloat or JS overhead
21+
</td>
22+
<td align="center" width="33%">
23+
🎨 <b>6,800+ Icons</b><br/>Full Lucide & Tabler support
24+
</td>
25+
</tr>
26+
<tr>
27+
<td align="center" width="33%">
28+
🛠️ <b>DX First</b><br/>Full component DX in Dev
29+
</td>
30+
<td align="center" width="33%">
31+
⚡ <b>Any Framework</b><br/>Next.js, Vite, Remix, Webpack
32+
</td>
33+
<td align="center" width="33%">
34+
🧩 <b>Custom Icons</b><br/>First-class support for your SVGs
35+
</td>
36+
</tr>
37+
</table>
938

10-
<legend><b>Use over 1,600</b> Lucide <code>&lt;Icon /&gt;</code> in development. </br> Ship <b>one SVG sprite</b> in production - only the icons you used.</legend>
11-
<small>Average 300% Decrease in HTML Size. <a target="_blank" href="https://zero-ui.dev/icon-sprite">See the Demo ↗︎</a></small>
12-
13-
<p/>
14-
<p/>
15-
<p>
16-
🔹 Zero runtime 🔹 Tree-shaken & deduped 🔹 Lucide + your custom SVGs 🔹 Long-cacheable sprite 🔹 SSR-safe
17-
</p>
1839
</div>
1940

41+
---
2042

21-
```jsx
22-
// Development (DX)
23-
import { Icon } from "@react-zero-ui/icon-sprite";
43+
## Contents
2444

25-
<ArrowRight props="..."/>;
26-
```
27-
Automaitcally generates:
28-
```html
29-
<!-- Production output (zero runtime) -->
30-
<svg props="...">
31-
<use href="/icon.svg#arrow-right" />;
32-
</svg>
45+
- [Why This Library?](#why-this-library)
46+
- [Benchmarks](#-benchmarks-150-icons)
47+
- [Quick Start](#quick-start)
48+
- [Usage](#usage)
49+
- [How It Works](#how-it-works-under-the-hood)
3350

34-
```
51+
---
3552

36-
Quick Start
53+
## Why This Library?
3754

38-
```
39-
npm install @react-zero-ui/icon-sprite
55+
SVG sprites are still the most performant way to deliver flat icons on the web. They are significantly smaller than React components and can be cached aggressively by the browser.
4056

41-
```
57+
**However, using sprites in development is a pain.**
58+
Browsers cache sprites so aggressively that you often have to close the tab and reopen it just to see a new icon, even with cache disabled in DevTools.
4259

43-
44-
45-
Part of the [React Zero-UI](https://github.com/react-zero-ui) ecosystem.
46-
47-
60+
**This library solves that problem:**
61+
1. **In Development:** It uses standard React components. No caching issues, instant HMR (Hot Module Replacement), and full prop support.
62+
2. **In Production:** It compiles everything into a single, highly optimized SVG sprite that is loaded once and cached forever.
4863

49-
---
64+
You get the **Developer Experience** of a component library with the **Performance** of a handwritten sprite.
5065

51-
5266
> [!NOTE]
53-
>**Live Demo ~270% Smaller HTML**
54-
>**See the difference:** [View Demo](https://zero-ui.dev/icon-sprite)
55-
56-
67+
> **See the difference for yourself:** [View Live Demo ↗](https://zero-ui.dev/icon-sprite)
5768
5869
---
5970

71+
## ⚡ Benchmarks (150 Icons)
6072

61-
## What This Library Does
62-
63-
1. **Full Lucide-React DX in development**
64-
Easy imports, hot reload, JSX props - import icons from `@react-zero-ui/icon-sprite` instead of `lucide-react`.
73+
| Library | HTML Size |
74+
|---------|-----------|
75+
| **Lucide React** | 19.5kb |
76+
| **@react-zero-ui** | **7.5kb** |
6577

66-
2. **Zero-runtime in production**
67-
Every icon becomes `<use href="/icons.svg#id" />` at build time.
78+
---
6879

69-
3. **Smallest possible sprite**
70-
Only icons actually used in your app are included.
80+
## Quick Start
7181

72-
## Custom Icon Support
73-
Drop SVGs into **`/public/zero-ui-icons/`**, then use `<CustomIcon />` with the filename (no `.svg`).
82+
### 1. Install
7483

75-
> [!TIP]
76-
>```txt
77-
>📁/public
78-
> └──📁/zero-ui-icons/
79-
> └──dog.svg
80-
> ```
81-
> ```tsx
82-
>import { CustomIcon } from "@react-zero-ui/icon-sprite";
83-
>//❗The name MUST matcb the file name (no .svg extension).
84-
><CustomIcon name="dog" size={24} />
85-
>```
86-
87-
> [!NOTE]
88-
> In dev you may see a brief FOUC using custom icons; this is removed in production.
84+
```bash
85+
npm install @react-zero-ui/icon-sprite
86+
```
8987

90-
---
88+
### 2. Use Icons
9189

92-
## Installation
90+
```tsx
91+
import { ArrowRight, Mail } from "@react-zero-ui/icon-sprite";
9392

94-
```bash
95-
npm install @react-zero-ui/icon-sprite
93+
<ArrowRight size={24} className="text-gray-600" />
94+
<Mail width={24} height={24} />
9695
```
9796

98-
---
97+
### 3. Build for Production
9998

100-
## Build Command
10199
> [!CAUTION]
102-
> Run this before your app build so the sprite exists.
103-
>```bash
104-
>npx zero-icons
105-
>```
100+
> Run this **before** your app build so the sprite exists.
106101
107-
This command builds the icons sprite for production.
102+
```bash
103+
npx zero-icons
104+
```
108105

109-
Or add this to your `package.json` scripts:
106+
Or add it to your `package.json`:
110107
```json
111108
{
112109
"scripts": {
@@ -115,17 +112,14 @@ Or add this to your `package.json` scripts:
115112
}
116113
}
117114
```
118-
That's it! You can now use the icons in your app.
115+
116+
That's it! Your icons are now optimized for production.
119117

120118
---
121119

122120
## Usage
123121

124-
> [!WARNING]
125-
> **Pass `size`, or both `width` and `height`, to ensure identical dev/prod rendering.**
126-
> Dev defaults (Lucide 24×24) differ from sprite viewBoxes in production. Missing these props will **very likely** change the visual size in prod.
127-
128-
### For Lucide Icons:
122+
### Lucide Icons
129123

130124
```tsx
131125
import { ArrowRight, Mail } from "@react-zero-ui/icon-sprite";
@@ -134,19 +128,42 @@ import { ArrowRight, Mail } from "@react-zero-ui/icon-sprite";
134128
<Mail width={24} height={24} />
135129
```
136130

137-
### Custom Icons:
131+
### Tabler Icons
138132

139-
Drop SVGs into **`/public/zero-ui-icons/`**, then use `<CustomIcon />` with the filename (no `.svg`).
140133
```tsx
141-
import { CustomIcon } from "@react-zero-ui/icon-sprite";
142-
//❗The name MUST match the name of the file name (without .svg).
143-
<CustomIcon name="dog" size={32} />
134+
import { IconBrandGithub, IconHeart } from "@react-zero-ui/icon-sprite";
135+
136+
<IconBrandGithub size={24} className="text-gray-600" />
137+
<IconHeart width={24} height={24} />
144138
```
145139

140+
### Custom Icons
141+
142+
Drop your own SVGs into **`/public/zero-ui-icons/`**, then use `<CustomIcon />`:
143+
144+
> [!TIP]
145+
>```txt
146+
>📁/public
147+
> └──📁/zero-ui-icons/
148+
> └──dog.svg
149+
>```
150+
>```tsx
151+
>import { CustomIcon } from "@react-zero-ui/icon-sprite";
152+
>
153+
><CustomIcon name="dog" size={24} />
154+
>```
155+
> The `name` prop **must match** the file name (without `.svg`).
156+
157+
> [!NOTE]
158+
> In dev you may see a brief FOUC using custom icons; this is removed in production.
159+
146160
---
147161
148162
## How It Works (Under the Hood)
149163
164+
<details>
165+
<summary><b>🔍 Click to see how we handle Dev vs. Prod</b></summary>
166+
150167
### Development: DX First
151168
152169
In dev, each icon wrapper looks like this:
@@ -166,78 +183,31 @@ export const ArrowRight = (props) =>
166183
167184
This ensures:
168185

169-
* Dev uses Lucide's real React components (`lucide-react`)
186+
* Dev uses real React components
170187
* Full props support (e.g. `strokeWidth`, `className`)
171188
* No caching issues from SVG sprites
172189
* No FOUC (Flash of Unstyled Content)
173190

174-
### ⚙️ Production Mode: Minimal Runtime, Maximum Speed
191+
### Production Mode: Minimal Runtime, Maximum Speed
175192

176193
At build time:
177194

178195
1. We scan your codebase for all icons statically using Babel + AST traversal
179196
2. We generate a single SVG sprite sheet (`public/icons.svg`)
180197
3. The wrapper components switch to `<use href="/icons.svg#icon-id" />`
181198

182-
---
183-
184-
## Tooling
185-
186-
To generate everything:
187-
188-
```bash
189-
npx zero-icons
190-
```
191-
192-
This runs the full pipeline:
199+
### The Build Pipeline (`npx zero-icons`)
193200

194201
| Script | Purpose |
195202
| --- | --- |
196203
| `scan-icons.js` | Parse your codebase for used icons (`Icon` usage or named imports) |
197204
| `used-icons.js` | Collects a list of unique icon names |
198-
| `build-sprite.js` | Uses [`svgstore`](https://github.com/DIYgod/svgstore) to generate `icons.svg` from used Lucide + custom SVGs |
199-
200-
201-
---
202-
203-
## Why This Beats Icon Libraries Everywhere
204-
205-
* **DX-first in dev**: No flicker. No sprite caching. Live updates.
206-
* **Zero-runtime in production**: Sprites are native, fast, lightweight & highly Cached.
207-
* **Only ships the icons you actually use** - smallest possible sprite.
208-
* **Custom icon support**: Drop SVGs into `/public/zero-ui-icons/` and use `<CustomIcon />`
209-
210-
211-
Made with ❤️ for the React community by [@austin1serb](https://github.com/austin1serb)
212-
213-
214-
<!--
215-
📂 icon-sprite/
216-
├── 📂 node_modules
217-
│ └── 📂 lucide-static
218-
│ │ └── 📂 icons
219-
│ │ └── *icon-name*.svg
220-
├── 📂 dist
221-
│ │── config.js
222-
│ │── index.js
223-
│ │── used-icons.js
224-
│ │── utils.js
225-
│ └── icons.svg
226-
│── 📂 scripts
227-
│ │── build-sprite.js
228-
│ │── gen-dist.js
229-
│ │── gen-wrappers.js
230-
│ │── index.js
231-
│ │── scan-icons.js
232-
│ └── used-icons.js
233-
│── 📂 src
234-
│ │── 📂 icons
235-
│ │ │── *IconName*.tsx
236-
│ │── config.ts
237-
│ └── utils.ts
238-
│── README.md
239-
│── package-lock.json
240-
│── package.json
241-
│── react-zero-ui-icon-sprite-0.1.3.tgz
242-
└── tsconfig.json
243-
-->
205+
| `build-sprite.js` | Uses [`svgstore`](https://github.com/DIYgod/svgstore) to generate `icons.svg` from used Lucide + Tabler + custom SVGs |
206+
207+
</details>
208+
209+
---
210+
211+
Part of the [React Zero-UI](https://github.com/react-zero-ui) ecosystem.
212+
213+
Made with ❤️ for the React community by [@austinserb](https://www.austinserb.com/)

0 commit comments

Comments
 (0)