dioxus-iconify 0.4.2

CLI tool for importing/vendoring icons from [Iconify](https://icon-sets.iconify.design/) (material, lucid, heroicons,....) or from local SVG files in Dioxus projects
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# dioxus-iconify

> CLI tool for importing/vendoring icons from [Iconify]https://icon-sets.iconify.design/ (material, lucid, heroicons,....) or from local SVG files in Dioxus projects.

[![Crates.io](https://img.shields.io/crates/v/dioxus-iconify.svg)](https://crates.io/crates/dioxus-iconify)
[![License](https://img.shields.io/crates/l/dioxus-iconify)
](LICENSE)
![GitHub Downloads (all assets, all releases)](https://img.shields.io/github/downloads/davidB/dioxus-iconify/total)

Use any of the **275,000+ icons** from [Iconify](https://iconify.design) in your Dioxus applications with a simple CLI tool. Icons are generated at build time as Rust source code, eliminating runtime dependencies.

## ✨ Features

- 🎨 **275k+ Icons**: Access icons from Material Design, Heroicons, FontAwesome, Lucide, and [200+ other icon sets]https://icon-sets.iconify.design/
- πŸ“ **Local SVG Support**: Import your own SVG files or entire directories
- πŸ¦€ **Type-Safe**: Generated as Rust const values, checked at compile time
- πŸ“¦ **Zero Runtime Dependencies**: No need to depend on this crate at compile time and runtime - only Dioxus
- πŸ—‚οΈ **Well Organized**: Icons grouped by collection in separate files
- 🎯 **Fully Customizable**: Override any SVG attribute (size, color, stroke, etc.)
- πŸ’Ύ **Git-Friendly**: Generated code is committed to your repository
- ⚑ **CLI-Based**: Simple `add` command inspired by shadcn-ui and dioxus components

## πŸš€ Quick Start

### Installation

```bash
cargo install dioxus-iconify

# via cargo-binstall
cargo binstall dioxus-iconify

# brew (mac & linux)
brew install davidB/tap/dioxus-iconify

# via mise (cli or configuration file)
mise install "ubi:davidB/dioxus-iconify"

# curl + bash script
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/davidB/dioxus-iconify/releases/download/latest/dioxus-iconify-installer.sh | sh
```

### Usage

0. **Choose your icons** on [Iconify - home of open source icons]https://icon-sets.iconify.design/

1. **Add icons to your project**:

```bash
# Add icons from Iconify
dioxus-iconify add mdi:home

# Add multiple icons
dioxus-iconify add mdi:home mdi:account heroicons:arrow-left

# Add local SVG file
dioxus-iconify add ./assets/logo.svg

# Add all SVGs from a directory (recursively)
dioxus-iconify add ./assets/icons/

# Mix Iconify and local icons
dioxus-iconify add mdi:home ./custom/logo.svg heroicons:star

# Skip icons that already exist (don't overwrite)
dioxus-iconify add --skip-existing ./assets/icons/

# Specify custom output directory
dioxus-iconify --output src/components/icons add lucide:settings
```

2. **Use in your Dioxus Element**:

```rust
mod icons;
use crate::icons::{Icon, mdi};

use dioxus::prelude::*;

fn App() -> Element {
    rsx! {
        div {
            // Basic usage
            Icon { data: mdi::Home }

            // Custom size
            Icon {
                data: mdi::Home,
                size: "1.2em", // for same width & height
            }

            Icon {
                data: mdi::Home,
                width: 42,
                height: "24",
            }

            // Custom color and style
            Icon {
                data: mdi::Home,
                fill: "blue",
                class: "icon-class",
            }
        }
    }
}
```

<details>
<summary>(Optional) **Create your application iconset with aliases**</summary>
Advantages: Hide the name of external iconset / collection, ease maintainance, ease switching and mixing of collections.

Create a module to alias other `icons/app.rs`

```rust
// My application iconset
// - aliasing icon from other iconset to not expose other iconset outside
pub use super::heroicons::ArrowLeft;
pub use super::mdi::Home as House;
```

Only pub this module in `icons/mod.rs` (to redo after each `dioxus-iconify update`)

```rust
// ...
pub mod app;
mod heroicons;
mod mdi;
```

Use icons data from `icons::app::*`;

```rust
mod icons;
use crate::icons::{Icon, app};

use dioxus::prelude::*;

fn App() -> Element {
    rsx! {
        div {
            Icon { data: app::House }
            Icon { data: app::ArrowLeft }
        }
    }
}
```

</details>

## πŸ“š How It Works

### The Problem

Existing Dioxus icon libraries typically bundle all icons in the crate, leading to:

- Large dependency sizes
- Slower compile times
- Including icons you don't use

### The Solution

`dioxus-iconify` takes inspiration from [shadcn-ui](https://ui.shadcn.com/): instead of shipping icons as a dependency, it **generates the icon code directly in your project**.

### What Gets Generated

When you run `dioxus-iconify add mdi:home heroicons:arrow-left`, it creates:

```
src/icons/
β”œβ”€β”€ mod.rs         # Icon component + IconData struct + module declarations
β”œβ”€β”€ mdi.rs         # Material Design Icons: Home, ...
└── heroicons.rs   # Heroicons: ArrowLeft, ...
```

**src/icons/mod.rs**:

```rust
// Auto-generated by dioxus-iconify - DO NOT EDIT
use dioxus::prelude::*;

#[derive(Clone, Copy, PartialEq)]
pub struct IconData {
    pub name: &'static str,
    pub body: &'static str,
    pub view_box: &'static str,
    pub width: &'static str,
    pub height: &'static str,
}

#[component]
pub fn Icon(
    data: IconData,
    /// Optional size to set both width and height
    #[props(default, into)]
    size: String,
    /// Additional attributes to extend the svg element
    #[props(extends = SvgAttributes)]
    attributes: Vec<Attribute>,
) -> Element {
    let (width, height) = if size.is_empty() {
        (data.width, data.height)
    } else {
        (size.as_str(), size.as_str())
    };

    rsx! {
        svg {
            view_box: "{data.view_box}",
            width: "{width}",
            height: "{height}",
            dangerous_inner_html: "{data.body}",
            ..attributes,
        }
    }
}

pub mod heroicons;
pub mod mdi;
```

**src/icons/mdi.rs**:

```rust
// Auto-generated by dioxus-iconify - DO NOT EDIT
// Collection: mdi

use super::IconData;

pub const Home: IconData = IconData {
    name: "mdi:home",
    body: r#"<path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>"#,
    view_box: "0 0 24 24",
    width: "24",
    height: "24",
};
```

## 🎨 Icon Customization

The `Icon` component uses Dioxus 0.7's `extends = SvgAttributes` pattern, allowing you to override any SVG attribute:

```rust
Icon {
    data: mdi::Home,
    // Size
    width: "48",
    height: "48",

    // Color
    fill: "currentColor",
    stroke: "#000000",
    stroke_width: "2",

    // CSS
    class: "my-icon hover:text-blue-500",
    style: "margin: 1rem;",

    // Accessibility
    aria_label: "Home icon",
    role: "img",

    // Any other SVG attribute...
}
```

## πŸ” Finding Icons

Browse available icons at:

- [Iconify Icon Sets]https://icon-sets.iconify.design/
- [IcΓ΄nes]https://icones.js.org/

Icon names follow the format `collection:icon-name`:

- `mdi:home` - Material Design Icons
- `heroicons:arrow-left` - Heroicons
- `lucide:settings` - Lucide
- `fa:github` - Font Awesome
- `simple-icons:rust` - Simple Icons

## πŸ“– CLI Commands

### `add`

Add icons to your project from Iconify API or local SVG files:

```bash
dioxus-iconify add [OPTIONS] <ICONS>...

Options:
  --skip-existing    Skip icons that already exist (don't overwrite)

# Iconify API icons
dioxus-iconify add mdi:home
dioxus-iconify add mdi:home mdi:account heroicons:arrow-left

# Local SVG files
dioxus-iconify add ./logo.svg
dioxus-iconify add ./assets/icon1.svg ./assets/icon2.svg

# Local directories (scans recursively)
dioxus-iconify add ./assets/icons/
dioxus-iconify add ./icons/social/ ./icons/ui/

# Mix both sources
dioxus-iconify add mdi:home ./custom/logo.svg

# Don't overwrite existing icons
dioxus-iconify add --skip-existing ./assets/icons/

# Custom output directory
dioxus-iconify --output src/components/icons add lucide:settings
```

#### Local SVG Files

When adding local SVG files:

- **Single files**: Collection name is taken from the parent directory name
  - `./assets/logo.svg` β†’ collection: `assets`, icon: `logo`
- **Directories**: Collection name is the directory name, icons are scanned recursively
  - `./my-icons/home.svg` β†’ `my-icons:home`
  - `./my-icons/arrows/left.svg` β†’ `my-icons:arrows-left`
- **SVG processing**: Automatically extracts dimensions from `width`, `height`, and `viewBox` attributes
- **Missing dimensions**: Defaults to 24x24 if not specified in the SVG

### `init`

Initialize the icons directory (creates `mod.rs`):

```bash
dioxus-iconify init
```

### `list`

List all generated icons:

```bash
dioxus-iconify list
```

### `update`

Re-fetch and update all icons from Iconify API:

```bash
dioxus-iconify update
```

### Coming Soon

- `remove` - Remove icons from your project

## πŸ†š Comparison with Other Solutions

| Feature          | dioxus-iconify | Embedded Libraries | SVG Files |
| ---------------- | -------------- | ------------------ | --------- |
| Icon Count       | 275,000+       | Limited            | Manual    |
| Uptodate Icons   | βœ…             | Depends            | Manual    |
| Dependency Size  | 0 (CLI only)   | Large              | 0         |
| Type Safety      | Mixed          | βœ…                 | ❌        |
| Customization    | Full           | Limited            | Full      |
| Fixes/workaround | Full           | Take time          | Full      |
| Offline Support  | βœ… (committed) | βœ…                 | βœ…        |
| Updates          | CLI command    | Crate update       | Manual    |

Some Embedded libraries of icons for dioxus:
[dioxus-free-icons](https://crates.io/crates/dioxus-free-icons),
[dioxus-material-icons](https://crates.io/crates/dioxus-material-icons),
[dioxus-heroicons](https://crates.io/crates/dioxus-heroicons),
...

[Search Results for 'dioxus icons' - crates.io: Rust Package Registry](https://crates.io/search?q=dioxus%20icons)

## πŸ’‘ Tips

1. **Commit generated code**: The `src/icons/` directory should be committed to version control
2. **Customize the Icon component**: It's generated in your project, so modify it if needed
3. **Use with Tailwind**: Icon colors work with Tailwind's `text-*` classes via `currentColor`
4. **Organization**: Icons are automatically grouped by collection in separate files
5. **Local SVGs**: Use the `--skip-existing` flag when adding directories to avoid overwriting customized icons
6. **Nested directories**: Icons in subdirectories are automatically named with hyphens (e.g., `arrows/left.svg` becomes `arrows-left`)

## 🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## πŸ™ Acknowledgments

- [Dioxus]https://dioxuslabs.com/ - The amazing Rust UI framework
- [Iconify]https://iconify.design/ - For providing the amazing icon API and collections

### For inspiration

- [shadcn-ui]https://ui.shadcn.com/ - For inspiration on the CLI-based generation approach
- [Dioxus Components]https://dioxuslabs.com/components - Like shadcn but for dioxus
- [iconmate]https://github.com/Blankeos/iconmate - For similar ideas in the TypeScript ecosystem

## πŸ“š Resources

- [Iconify Documentation]https://iconify.design/docs/
- [Dioxus Documentation]https://dioxuslabs.com/learn/
- [Browse Icons]https://icon-sets.iconify.design/