@stillwind/plugin-iconify 0.1.0 → 0.3.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/README.md +6 -228
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @stillwind/plugin-iconify
|
|
2
2
|
|
|
3
|
-
Stillwind compiles Tailwind CSS v4 utilities into component props and static CSS.
|
|
3
|
+
[Stillwind](https://stillwind.dev/) compiles Tailwind CSS v4 utilities into component props and static CSS.
|
|
4
4
|
|
|
5
5
|
`@stillwind/plugin-iconify` adds Iconify icons as Stillwind utilities. Only the icons
|
|
6
6
|
you use are included in your CSS.
|
|
@@ -20,236 +20,14 @@ Load the plugin in the project stylesheet:
|
|
|
20
20
|
@plugin "@stillwind/plugin-iconify";
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
Set up the stylesheet and build integration with the
|
|
24
|
-
[Getting started](https://stillwind.dev/docs) guide.
|
|
23
|
+
Set up the stylesheet and build integration with the [Getting started](https://stillwind.dev/docs) guide.
|
|
25
24
|
|
|
26
|
-
Use `icon-<set>--<icon>` or `icon-[<set>--<icon>]` to select an icon. Variants apply as
|
|
27
|
-
|
|
25
|
+
Use `icon-<set>--<icon>` or `icon-[<set>--<icon>]` to select an icon. Variants apply as usual.
|
|
26
|
+
The `prefer-canonical-utilities` lint suggests the form without brackets:
|
|
28
27
|
|
|
29
28
|
```tsx
|
|
30
29
|
<span {...style("icon-mdi--close", "hover:icon-[mdi--close-circle]")} />
|
|
31
30
|
```
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
An icon is `1em` high by default, and its width keeps the icon's aspect ratio. A size utility
|
|
36
|
-
sets the height of the icon on the same element:
|
|
37
|
-
|
|
38
|
-
- `icon-<name>` uses the `--icon-size-<name>` theme token.
|
|
39
|
-
- `icon-full` uses `100%` of the parent's height.
|
|
40
|
-
- `icon-[<length>]`, `icon-[<percentage>]`, and `icon-(<custom-property>)` use the given value.
|
|
41
|
-
|
|
42
|
-
```css
|
|
43
|
-
@theme {
|
|
44
|
-
--icon-size-lg: 1.5rem;
|
|
45
|
-
}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
```tsx
|
|
49
|
-
<span {...style("icon-mdi--close icon-lg")} />
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
`icon-full` needs a parent with a definite height. In a parent whose height depends on its
|
|
53
|
-
content, the icon is 0 high. To size an icon by its width instead, override the height:
|
|
54
|
-
`icon-mdi--close w-full h-auto` fills the parent's width and keeps the icon's aspect ratio.
|
|
55
|
-
When other utilities, such as `size-full` or `max-w-full`, change the box, the SVG keeps its
|
|
56
|
-
aspect ratio and stays centered in the box.
|
|
57
|
-
|
|
58
|
-
The size does not reach descendants or the element's `::before` and `::after` boxes. Apply the
|
|
59
|
-
size with the same variant as the icon, such as `before:icon-mdi--close before:icon-lg`.
|
|
60
|
-
Use lengths or percentages for `--icon-size-*` values. These property names stay the
|
|
61
|
-
same when you customize the utility `prefix`.
|
|
62
|
-
|
|
63
|
-
Size values follow lint policies configured for `height`. For example,
|
|
64
|
-
`no-restricted-length-units` with `properties: ["height"]` checks their units, and
|
|
65
|
-
`no-arbitrary-spacing` with `properties: ["height"]` reports arbitrary sizes. Named
|
|
66
|
-
sizes such as `icon-lg` remain theme-token selections.
|
|
67
|
-
|
|
68
|
-
## Icon sets
|
|
69
|
-
|
|
70
|
-
The plugin finds a set in this order:
|
|
71
|
-
|
|
72
|
-
1. The `collections` option of a configured instance.
|
|
73
|
-
2. The `@iconify-json/<set>` package.
|
|
74
|
-
3. The `@iconify/json` package, which contains every Iconify set.
|
|
75
|
-
|
|
76
|
-
Install icon set packages in the project that contains your stylesheet. Changes to a
|
|
77
|
-
set's JSON file update its icons automatically. Editors complete the icons of configured sets
|
|
78
|
-
and of the `@iconify-json/*` packages listed in the project's `package.json` dependencies.
|
|
79
|
-
When `@iconify/json` is installed, editors also complete its set names, such as `icon-mdi--`,
|
|
80
|
-
and list the icons of a set after the input names it.
|
|
81
|
-
|
|
82
|
-
### License notices
|
|
83
|
-
|
|
84
|
-
The CSS output starts with a license notice for each icon set whose icons it contains, such as
|
|
85
|
-
`/*! Material Design Icons | Pictogrammers | Apache 2.0 | ... */`. The notice contains the set's
|
|
86
|
-
name, author, and license from the set's metadata. A `@iconify-json/<set>` package supplies the
|
|
87
|
-
metadata in its `info.json` file. The `@iconify/json` package and custom JSON sets supply it in
|
|
88
|
-
their `info` field.
|
|
89
|
-
|
|
90
|
-
A custom set without metadata adds no notice. It does not use the metadata of an installed set
|
|
91
|
-
with the same name. Pass the `info` option to `svgDirectory()` to add a notice for a set of SVG
|
|
92
|
-
files.
|
|
93
|
-
|
|
94
|
-
## Options
|
|
95
|
-
|
|
96
|
-
The options block of the statement sets these options:
|
|
97
|
-
|
|
98
|
-
```css
|
|
99
|
-
@plugin "@stillwind/plugin-iconify" {
|
|
100
|
-
prefix: i;
|
|
101
|
-
syntax: bracket;
|
|
102
|
-
scale: 1.2;
|
|
103
|
-
mode: mask;
|
|
104
|
-
hash-length: 4;
|
|
105
|
-
}
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
- `prefix`: utility prefix without the trailing hyphen, such as `icon` or `i`. Defaults to `icon`.
|
|
109
|
-
- `syntax`: spellings that select an icon. `named` accepts `icon-mdi--close`, `bracket` accepts
|
|
110
|
-
`icon-[mdi--close]`, and `both`, the default, accepts both.
|
|
111
|
-
- `scale`: icon height in `em` when no size utility applies. Defaults to `1`.
|
|
112
|
-
- `mode`: `mask` paints the text color through the icon's shape, and `background` paints the
|
|
113
|
-
icon's own colors. `auto`, the default, selects `mask` for icons whose SVG uses
|
|
114
|
-
`currentColor`.
|
|
115
|
-
- `hash-length`: base36 hash length in generated CSS variable names. Accepts integers
|
|
116
|
-
from `1` to `7` and defaults to `4`. Increase it when using many icons to reduce collisions.
|
|
117
|
-
|
|
118
|
-
For custom icon sets or TypeScript options, add `iconify(...)` to your project's
|
|
119
|
-
`plugins` list. Icon sets can be data, absolute JSON file paths, functions that
|
|
120
|
-
return data, or SVG directories. Keep `@plugin "@stillwind/plugin-iconify";` in your stylesheet:
|
|
121
|
-
|
|
122
|
-
```ts
|
|
123
|
-
import { iconify } from "@stillwind/plugin-iconify";
|
|
124
|
-
import { defineConfig } from "stillwind/config";
|
|
125
|
-
|
|
126
|
-
export default defineConfig({
|
|
127
|
-
projects: [
|
|
128
|
-
{
|
|
129
|
-
css: "src/stillwind.css",
|
|
130
|
-
files: ["src/**/*.{ts,tsx}"],
|
|
131
|
-
plugins: [
|
|
132
|
-
iconify({
|
|
133
|
-
collections: {
|
|
134
|
-
brand: "/abs/path/brand.json",
|
|
135
|
-
},
|
|
136
|
-
}),
|
|
137
|
-
],
|
|
138
|
-
},
|
|
139
|
-
],
|
|
140
|
-
});
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
> [!NOTE]
|
|
144
|
-
> Options in the stylesheet's `@plugin` block override the TypeScript options. Use
|
|
145
|
-
> `hashLength` for the `hash-length` option in TypeScript, such as `iconify({ hashLength: 6 })`.
|
|
146
|
-
> The stylesheet cannot set `collections` or `svgo` (described below).
|
|
147
|
-
|
|
148
|
-
### Custom icon set format
|
|
149
|
-
|
|
150
|
-
A custom icon set uses the Iconify JSON format, which the `IconifyJSON` type of
|
|
151
|
-
`@iconify/types` describes. This is the same format as the `icons.json` file of an
|
|
152
|
-
`@iconify-json/*` package:
|
|
153
|
-
|
|
154
|
-
```json
|
|
155
|
-
{
|
|
156
|
-
"prefix": "brand",
|
|
157
|
-
"width": 24,
|
|
158
|
-
"height": 24,
|
|
159
|
-
"icons": {
|
|
160
|
-
"logo": {
|
|
161
|
-
"body": "<path fill=\"currentColor\" d=\"M4 4h16v16H4z\"/>"
|
|
162
|
-
},
|
|
163
|
-
"badge": {
|
|
164
|
-
"body": "<circle cx=\"12\" cy=\"12\" r=\"10\" fill=\"#e11d48\"/>",
|
|
165
|
-
"width": 32,
|
|
166
|
-
"height": 32
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
"aliases": {
|
|
170
|
-
"logo-flipped": {
|
|
171
|
-
"parent": "logo",
|
|
172
|
-
"hFlip": true
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
- `icons` maps each icon name to its SVG content. `body` contains the elements inside the
|
|
179
|
-
`<svg>` element, without the `<svg>` element itself.
|
|
180
|
-
- `left`, `top`, `width`, and `height` define the icon's `viewBox`. An icon can set them, and
|
|
181
|
-
the top level sets the default values for every icon. Missing values default to `0`, `0`,
|
|
182
|
-
`16`, and `16`.
|
|
183
|
-
- `aliases` maps additional names to an existing icon in `parent`. An alias can override the
|
|
184
|
-
`viewBox` values and add `rotate` (quarter turns), `hFlip`, and `vFlip` transformations.
|
|
185
|
-
- The key in `collections` sets the set name in utilities, such as `icon-brand--logo`. The
|
|
186
|
-
plugin does not use the `prefix` field to find the set.
|
|
187
|
-
|
|
188
|
-
Set names and icon names must consist of lowercase letters and digits, separated by single
|
|
189
|
-
hyphens. Utilities cannot select other names, such as `Logo` or `logo_dark`.
|
|
190
|
-
|
|
191
|
-
With the default `mode: auto`, an icon whose `body` contains `currentColor` paints the text
|
|
192
|
-
color, and the other icons keep their own colors. In the example, `logo` follows the text
|
|
193
|
-
color and `badge` stays red.
|
|
194
|
-
|
|
195
|
-
The plugin does not validate the data. A JSON file must contain valid JSON, but the plugin
|
|
196
|
-
treats an icon that it cannot find in the data as an unknown utility.
|
|
197
|
-
|
|
198
|
-
### Icon sets from SVG files
|
|
199
|
-
|
|
200
|
-
`svgDirectory()` creates an icon set from the SVG files in a directory. Each file becomes one
|
|
201
|
-
icon, and the file name without `.svg` becomes the icon name:
|
|
202
|
-
|
|
203
|
-
```ts
|
|
204
|
-
import { iconify, svgDirectory } from "@stillwind/plugin-iconify";
|
|
205
|
-
|
|
206
|
-
iconify({
|
|
207
|
-
collections: {
|
|
208
|
-
brand: svgDirectory("src/icons/brand"),
|
|
209
|
-
ui: svgDirectory("src/icons/ui", {
|
|
210
|
-
recursive: true,
|
|
211
|
-
transform: (svg) => svg.replaceAll('fill="#000"', 'fill="currentColor"'),
|
|
212
|
-
}),
|
|
213
|
-
},
|
|
214
|
-
});
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
The directory can be an absolute path or a path relative to the project directory. Each file
|
|
218
|
-
must contain an `<svg>` element with a `viewBox` attribute, which sets the icon's dimensions.
|
|
219
|
-
The plugin keeps the `style` attribute of the `<svg>` element and its attributes whose names
|
|
220
|
-
start with `fill` or `stroke`, such as `fill-rule`. It drops the other attributes of the
|
|
221
|
-
`<svg>` element.
|
|
222
|
-
|
|
223
|
-
- `recursive`: reads subdirectories. The default icon name joins the path segments with `-`,
|
|
224
|
-
such as `arrows-left` for `arrows/left.svg`. Defaults to `false`.
|
|
225
|
-
- `name`: maps the file path relative to the directory, without `.svg` and with `/` separators,
|
|
226
|
-
to an icon name. Returning `undefined` skips the file.
|
|
227
|
-
- `transform`: rewrites the SVG text of each file before the plugin parses it.
|
|
228
|
-
- `info`: the set's name, author, and license in the format of the Iconify `info` field. The
|
|
229
|
-
plugin uses it for the [license notice](#license-notices).
|
|
230
|
-
|
|
231
|
-
Loading fails when an icon name is invalid, two files have the same icon name, or a file has
|
|
232
|
-
no `viewBox`. The error names the file. Adding, removing, or editing an SVG file reloads the
|
|
233
|
-
icons while a development server or build watcher runs.
|
|
234
|
-
|
|
235
|
-
A function in `collections` receives the set name and the host's `read`, `list`, and `watch`
|
|
236
|
-
operations, so you can write similar loaders. Watch each file and directory that the function
|
|
237
|
-
reads, such as `context.watch(file)` and `context.watch(directory, "directory")`.
|
|
238
|
-
|
|
239
|
-
### SVG minification
|
|
240
|
-
|
|
241
|
-
The plugin minifies the SVG of each icon with [SVGO](https://svgo.dev/) before it embeds the
|
|
242
|
-
SVG in CSS. The `svgo` TypeScript option controls this:
|
|
243
|
-
|
|
244
|
-
- `true`, the default, uses `preset-default` with `multipass` enabled.
|
|
245
|
-
- An SVGO configuration object replaces that default configuration.
|
|
246
|
-
- `false` embeds the SVG without minification.
|
|
247
|
-
|
|
248
|
-
```ts
|
|
249
|
-
iconify({
|
|
250
|
-
svgo: {
|
|
251
|
-
multipass: true,
|
|
252
|
-
plugins: ["preset-default", "removeDimensions"],
|
|
253
|
-
},
|
|
254
|
-
});
|
|
255
|
-
```
|
|
32
|
+
See [Iconify icons](https://stillwind.dev/docs/plugins/iconify) for sizes, icon sets,
|
|
33
|
+
options, custom icon sets, and SVG minification.
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stillwind/plugin-iconify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Iconify icons as Stillwind utilities",
|
|
5
|
-
"homepage": "https://stillwind.dev
|
|
5
|
+
"homepage": "https://stillwind.dev",
|
|
6
6
|
"bugs": {
|
|
7
7
|
"url": "https://github.com/SegaraRai/stillwind/issues"
|
|
8
8
|
},
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@iconify/types": "^2.0.0",
|
|
31
31
|
"@iconify/utils": "^3.1.7",
|
|
32
|
-
"@stillwind/config": "0.
|
|
32
|
+
"@stillwind/config": "0.3.0",
|
|
33
33
|
"svgo": "^4.1.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@stillwind-internal/tools-workspace": "0.0.0",
|
|
37
|
-
"@stillwind/host": "0.
|
|
38
|
-
"@stillwind/native": "0.
|
|
39
|
-
"@types/node": "^26.6.
|
|
40
|
-
"stillwind": "0.
|
|
37
|
+
"@stillwind/host": "0.3.0",
|
|
38
|
+
"@stillwind/native": "0.3.0",
|
|
39
|
+
"@types/node": "^26.6.6",
|
|
40
|
+
"stillwind": "0.3.0",
|
|
41
41
|
"typescript": "^6.0.3",
|
|
42
42
|
"vite-plus": "1.4.0"
|
|
43
43
|
}
|