Skip to content

Commit d751132

Browse files
committed
Polish README
1 parent ccb2712 commit d751132

1 file changed

Lines changed: 117 additions & 80 deletions

File tree

README.md

Lines changed: 117 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,38 @@
11
# PhoenixIconify
22

3-
Phoenix components for [Iconify](https://iconify.design) icons with compile-time discovery.
3+
[![Hex.pm](https://img.shields.io/hexpm/v/phoenix_iconify.svg)](https://hex.pm/packages/phoenix_iconify) [![Documentation](https://img.shields.io/badge/documentation-gray)](https://hexdocs.pm/phoenix_iconify)
44

5-
Access 200,000+ icons from 150+ icon sets. Browse available icons at [icon-sets.iconify.design](https://icon-sets.iconify.design).
5+
Inline [Iconify](https://iconify.design) SVGs for Phoenix and LiveView. Write a normal Phoenix component, let the compiler discover the icons you use, and ship only those icons with your app.
66

7-
## Features
7+
```heex
8+
<.icon name="lucide:settings" class="size-5" />
9+
```
10+
11+
PhoenixIconify gives Phoenix apps access to 200,000+ icons from 150+ icon sets without a client-side icon runtime. Browse icons at [icon-sets.iconify.design](https://icon-sets.iconify.design).
12+
13+
## Why PhoenixIconify
14+
15+
Most Iconify integrations load icons in JavaScript. PhoenixIconify keeps icons on the server:
16+
17+
- Icons are discovered from HEEx at compile time
18+
- Only icons you use are fetched and stored
19+
- Rendering is plain inline SVG
20+
- No browser-side icon loader
21+
- Works with LiveView diffs and `phx-*` attributes
22+
- Dynamic icons can be pre-registered in config
823

9-
- **Compile-time discovery** - Icons are automatically detected from your templates
10-
- **On-demand fetching** - Only icons you use are downloaded
11-
- **Zero runtime overhead** - Icons are embedded at compile time
12-
- **LiveView optimized** - Minimal diffs, only attributes change
24+
It pairs naturally with Tailwind and Volt-powered Phoenix projects:
25+
26+
```heex
27+
<button class="inline-flex items-center gap-2">
28+
<.icon name="lucide:settings" class="size-4" />
29+
Settings
30+
</button>
31+
```
1332

1433
## Installation
1534

16-
Add `phoenix_iconify` to your list of dependencies in `mix.exs`:
35+
Add the dependency:
1736

1837
```elixir
1938
def deps do
@@ -23,74 +42,90 @@ def deps do
2342
end
2443
```
2544

26-
Add the compiler to your project:
45+
Add the compiler:
2746

2847
```elixir
2948
def project do
3049
[
31-
compilers: Mix.compilers() ++ [:phoenix_iconify],
32-
# ...
50+
compilers: Mix.compilers() ++ [:phoenix_iconify]
3351
]
3452
end
3553
```
3654

37-
## Usage
38-
39-
Import the component in your web module (`lib/my_app_web.ex`):
55+
Import the component in your web module:
4056

4157
```elixir
58+
# lib/my_app_web.ex
4259
defp html_helpers do
4360
quote do
4461
import PhoenixIconify, only: [icon: 1]
45-
# ...
4662
end
4763
end
4864
```
4965

50-
Use icons in your templates:
66+
Now use icons in HEEx:
5167

5268
```heex
5369
<.icon name="lucide:settings" class="size-5" />
54-
<.icon name="hero-user" class="size-6 text-zinc-500" />
55-
<.icon name="mdi:account" label="Account" />
56-
<.icon name="lucide:x" phx-click="close" />
5770
```
5871

59-
The component renders inline SVG and forwards global attributes, including `phx-*`, `data-*`, and `aria-*` attributes.
72+
## Usage
73+
74+
Use Iconify's standard `prefix:name` format:
75+
76+
```heex
77+
<.icon name="lucide:home" class="size-5" />
78+
<.icon name="mdi:account" class="size-6 text-blue-600" />
79+
<.icon name="heroicons:check" class="size-4" />
80+
```
81+
82+
Phoenix-style Heroicons names are supported too:
83+
84+
```heex
85+
<.icon name="hero-user" class="size-6" />
86+
<.icon name="hero-sun-mini" class="size-5" />
87+
<.icon name="hero-sun-micro" class="size-4" />
88+
```
6089

61-
## How It Works
90+
Global attributes are forwarded to the SVG, including `phx-*`, `data-*`, and `aria-*`:
6291

63-
1. You use `<.icon name="heroicons:user" />` in your templates
64-
2. During compilation, the compiler scans for icon component calls
65-
3. It extracts literal icon names from the `name` attribute
66-
4. Missing icons are fetched from the Iconify API
67-
5. Icons are cached in `priv/iconify/manifest.etf`
68-
6. At runtime, icons are loaded from the manifest
92+
```heex
93+
<.icon name="lucide:x" class="size-4" phx-click="close" data-testid="close" />
94+
```
6995

70-
## Component API
96+
## Accessibility
7197

72-
Decorative icons are hidden from assistive technology by default:
98+
Icons are decorative by default and render with `aria-hidden="true"`:
7399

74100
```heex
75101
<.icon name="lucide:settings" class="size-5" />
76102
```
77103

78-
Use `label` or `title` for meaningful icons:
104+
For meaningful icons, provide `label` or `title`:
79105

80106
```heex
81107
<.icon name="lucide:settings" label="Settings" />
82108
<.icon name="lucide:settings" title="Settings" />
83109
```
84110

85-
Set dimensions with Tailwind classes, `size`, or explicit `width`/`height`:
111+
## Sizing
112+
113+
Use Tailwind's `size-*` utilities when possible:
86114

87115
```heex
88116
<.icon name="lucide:settings" class="size-5" />
117+
```
118+
119+
Or set SVG dimensions directly:
120+
121+
```heex
89122
<.icon name="lucide:settings" size="20" />
90123
<.icon name="lucide:settings" width="1em" height="1em" />
91124
```
92125

93-
Iconify transformations are supported for aliases and at render time:
126+
## Transformations
127+
128+
Iconify aliases can include transformations, and you can transform at render time:
94129

95130
```heex
96131
<.icon name="lucide:arrow-right" rotate={1} />
@@ -99,84 +134,86 @@ Iconify transformations are supported for aliases and at render time:
99134
<.icon name="lucide:arrow-right" v_flip />
100135
```
101136

102-
## Icon Names
137+
## How it works
103138

104-
Icons use the format `prefix:icon-name`:
139+
1. You write `<.icon name="lucide:settings" />`
140+
2. The `:phoenix_iconify` compiler scans HEEx and `~H` sigils
141+
3. Literal icon names are collected
142+
4. Missing icons are fetched through Iconify
143+
5. A JSON manifest is written to `priv/iconify/manifest.json`
144+
6. At runtime, the component reads icons from the manifest and renders inline SVG
105145

106-
- `heroicons:user` - Heroicons user icon
107-
- `heroicons:user-solid` - Heroicons solid user
108-
- `lucide:home` - Lucide home icon
109-
- `mdi:account` - Material Design Icons account
146+
There is no client-side icon runtime and no JavaScript bundle impact.
110147

111-
Browse all icons at [icon-sets.iconify.design](https://icon-sets.iconify.design).
148+
## Dynamic icons
112149

113-
## Configuration
150+
Compile-time discovery only works for literal names. If an icon name comes from assigns, a database, or user configuration, register the possible values:
114151

115152
```elixir
116153
# config/config.exs
117154
config :phoenix_iconify,
118-
# Pre-register icons for dynamic usage (e.g., icons from database)
119-
extra_icons: ["heroicons:check", "heroicons:x-mark"],
120-
121-
# Fallback icon when requested icon is not found
122-
fallback: "heroicons:question-mark-circle",
123-
124-
# Log warnings when icons are not found (default: true)
125-
warn_on_missing: true
155+
extra_icons: [
156+
"lucide:check",
157+
"lucide:x",
158+
"lucide:alert-triangle"
159+
]
126160
```
127161

128-
## Caching
162+
Then dynamic usage works at runtime:
129163

130-
Icon sets are cached locally in `priv/iconify/sets/` to avoid repeated downloads.
164+
```heex
165+
<.icon name={@status_icon} class="size-4" />
166+
```
131167

132-
```bash
133-
# Pre-fetch icon sets for faster subsequent compiles
134-
mix phoenix_iconify.cache fetch
168+
## Configuration
135169

136-
# List cached sets
137-
mix phoenix_iconify.cache list
170+
```elixir
171+
config :phoenix_iconify,
172+
extra_icons: ["lucide:check", "lucide:x"],
173+
fallback: "lucide:circle-help",
174+
warn_on_missing: true
175+
```
138176

139-
# Clear cache
140-
mix phoenix_iconify.cache clear
177+
Options:
141178

142-
# Show statistics
143-
mix phoenix_iconify.stats
144-
```
179+
- `:extra_icons` - icons to include even when they are not found by static discovery
180+
- `:fallback` - icon to render when a requested icon is missing
181+
- `:warn_on_missing` - log missing icon warnings, enabled by default
145182

146-
## Dynamic Icons
183+
## Cache and manifest
147184

148-
For icons that can't be discovered at compile time (e.g., from database):
185+
PhoenixIconify stores:
149186

150-
```elixir
151-
config :phoenix_iconify,
152-
extra_icons: [
153-
"heroicons:check",
154-
"heroicons:x-mark",
155-
"heroicons:exclamation-triangle"
156-
]
187+
- `priv/iconify/manifest.json` - icons used by your app
188+
- `priv/iconify/sets/*.json` - cached icon sets
189+
190+
Useful tasks:
191+
192+
```bash
193+
mix phoenix_iconify.prefetch # scan and fetch discovered icons
194+
mix phoenix_iconify.audit # report discovered icons missing from the manifest
195+
mix phoenix_iconify.clean # remove manifest icons no longer used
196+
mix phoenix_iconify.list # list manifest icons
197+
mix phoenix_iconify.stats # show manifest and cache stats
157198
```
158199

159-
## Mix Tasks
200+
Cache tasks:
160201

161202
```bash
162-
mix phoenix_iconify # Show help
163-
mix phoenix_iconify.stats # Show statistics
164-
mix phoenix_iconify.list # List icons in manifest
165-
mix phoenix_iconify.cache # Cache management
166-
mix phoenix_iconify.prefetch # Scan and fetch discovered icons
167-
mix phoenix_iconify.audit # Report missing discovered icons
168-
mix phoenix_iconify.clean # Remove unused manifest icons
203+
mix phoenix_iconify.cache fetch
204+
mix phoenix_iconify.cache list
205+
mix phoenix_iconify.cache clear
169206
```
170207

171-
## Volt Projects
208+
## Volt projects
172209

173-
For projects created with Volt, use `phoenix_iconify` when you want server-rendered, compile-time embedded SVGs:
210+
For projects created with [Volt](https://hex.pm/packages/volt), PhoenixIconify is the server-rendered option:
174211

175212
```heex
176213
<.icon name="lucide:settings" class="size-5" />
177214
```
178215

179-
This does not use Volt's JavaScript pipeline. If you want client-side Iconify components instead, use the official npm packages (`iconify-icon`, `@iconify/react`, `@iconify/vue`, etc.) through Volt's normal package handling.
216+
It does not use Volt's JavaScript pipeline. If you want client-side icon components instead, use the official npm packages (`iconify-icon`, `@iconify/react`, `@iconify/vue`, etc.) through Volt's normal package handling.
180217

181218
## License
182219

0 commit comments

Comments
 (0)