@bevelo/icons 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +137 -2
- package/dist/index.cjs +224 -0
- package/dist/index.d.cts +119 -0
- package/dist/index.d.ts +119 -0
- package/dist/index.js +220 -0
- package/package.json +35 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bevelo contributors
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,138 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @bevelo/icons
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Iconography as data. An icon is a name and some 24x24 SVG path data; `icon("check")`
|
|
4
|
+
turns it into the same render description a component returns, so the button that
|
|
5
|
+
takes an `icon` prop has something to put in it.
|
|
6
|
+
|
|
7
|
+
There is no JSX, no component, no build step and no dependency. The output is a
|
|
8
|
+
plain object, which is why the same call feeds the web adapter, the React adapter,
|
|
9
|
+
and a test that only reads the description.
|
|
10
|
+
|
|
11
|
+
Stability: `@stable`. The API and the icon names follow semver.
|
|
12
|
+
|
|
13
|
+
## Files
|
|
14
|
+
|
|
15
|
+
| file | what it is |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `src/paths.ts` | The icon data: a name to path-data record, plus the geometry rules the set follows. No imports. |
|
|
18
|
+
| `src/index.ts` | The public surface: `icons`, `IconName`, `icon()`, `iconNames()`, `hasIcon()`. |
|
|
19
|
+
| `test/icons.test.ts` | The path tokeniser, the canvas check, and the `icon()` attribute contract. |
|
|
20
|
+
|
|
21
|
+
## Using it
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { icon } from "@bevelo/icons";
|
|
25
|
+
|
|
26
|
+
button({ icon: icon("plus") });
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
A description is an `svg` tree with `viewBox="0 0 24 24"`, sized 16px, stroked in
|
|
30
|
+
`currentColor` at 1.75, with round caps and joins. The icon inherits colour from
|
|
31
|
+
the element it lands in and needs no theming.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
icon("trash", { size: 20, strokeWidth: 2 }); // a toolbar glyph
|
|
35
|
+
icon("warning", { label: "Connection lost" }); // exposed as role="img"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`label` is the difference between an image and a decoration. Without it the svg is
|
|
39
|
+
`aria-hidden="true"`: correct beside text, wrong as the only content of a button,
|
|
40
|
+
because the control would then have no accessible name.
|
|
41
|
+
|
|
42
|
+
When a name comes from data, narrow it before calling:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { hasIcon, icon } from "@bevelo/icons";
|
|
46
|
+
|
|
47
|
+
if (hasIcon(row.icon)) {
|
|
48
|
+
render(icon(row.icon));
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### The API
|
|
53
|
+
|
|
54
|
+
| export | what it is |
|
|
55
|
+
|---|---|
|
|
56
|
+
| `icons` | `readonly IconName[]`: every name, frozen, in declaration order, so a picker renders a stable list. |
|
|
57
|
+
| `iconNames()` | The same frozen array, for a caller that prefers a call. |
|
|
58
|
+
| `hasIcon(name)` | Runtime guard narrowing a `string` to `IconName`. Own keys only, so `"toString"` is not an icon. |
|
|
59
|
+
| `icon(name, options?)` | The description. Options: `size` (16), `strokeWidth` (1.75), `label` (none). |
|
|
60
|
+
| `IconName` | The union of names, derived from the data. |
|
|
61
|
+
| `IconDescription`, `IconOptions`, `IconPath` | The types a caller may need to name. |
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
type IconName =
|
|
65
|
+
| "check" | "chevron-down" | "chevron-up" | "chevron-left" | "chevron-right"
|
|
66
|
+
| "chevrons-left" | "chevrons-right" | "close" | "plus" | "minus" | "search"
|
|
67
|
+
| "menu" | "more-horizontal" | "more-vertical" | "arrow-left" | "arrow-right"
|
|
68
|
+
| "arrow-up" | "arrow-down" | "arrow-up-right" | "star" | "star-filled"
|
|
69
|
+
| "heart" | "info" | "warning" | "error" | "success" | "calendar" | "clock"
|
|
70
|
+
| "trash" | "edit" | "copy" | "download" | "upload" | "external-link" | "eye"
|
|
71
|
+
| "eye-off" | "lock" | "unlock" | "user" | "users" | "settings" | "filter"
|
|
72
|
+
| "sort-asc" | "sort-desc" | "grip-vertical" | "play" | "pause" | "folder"
|
|
73
|
+
| "file" | "refresh" | "spinner" | "sun" | "moon" | "monitor";
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## The data
|
|
77
|
+
|
|
78
|
+
An icon is a list of paths, so an icon that needs a second stroke (a search circle
|
|
79
|
+
plus its handle, a copy badge plus its sheet) says so instead of merging the shapes
|
|
80
|
+
into one `d`:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
"external-link": ["M15 3h6v6", "M10 14 21 3", "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"],
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
A path is either its data string or `{ d, fill: true }`. The object form is used
|
|
87
|
+
once, by `star-filled`, where "filled" is a solid body rather than a closed
|
|
88
|
+
outline: the path paints `fill="currentColor"` in addition to its stroke, and the
|
|
89
|
+
other 53 icons are unaffected.
|
|
90
|
+
|
|
91
|
+
Geometry conventions: the canvas is 24x24, the artwork stays inside 2..22 so a
|
|
92
|
+
stroke never clips, a symmetric shape is symmetric about x=12 or y=12, and the
|
|
93
|
+
data is a centre line for a 1.75px stroke — never an outline of the painted shape.
|
|
94
|
+
|
|
95
|
+
## Design decisions
|
|
96
|
+
|
|
97
|
+
- **The description type is declared locally, not imported from `@bevelo/core`.**
|
|
98
|
+
`icon()` returns a value assignable to `Child`: `IconDescription` is
|
|
99
|
+
structurally `Child`'s `Description` arm, so a component typed
|
|
100
|
+
`icon?: Child` accepts the value. A type-only import would have cost nothing at
|
|
101
|
+
runtime, but it would make this package depend on core, and core (or the
|
|
102
|
+
adapters) depend on icons as soon as a component ships a default glyph — a
|
|
103
|
+
package cycle for a type alias. Declaring the shape keeps the package a leaf.
|
|
104
|
+
The alternative, importing `Child`, was rejected for that reason.
|
|
105
|
+
- **`star-filled` carries a per-path `fill` flag.** The svg sets
|
|
106
|
+
`fill="none"`, which a solid star cannot honour. The flag paints one
|
|
107
|
+
path and leaves the svg's paint rules alone; the alternative — a second
|
|
108
|
+
top-level attribute or a name-suffix rule — would have made one special case
|
|
109
|
+
leak into every icon.
|
|
110
|
+
- **A blank `label` is decorative.** `label: " "` is treated as no label: a
|
|
111
|
+
trimmed-to-empty `aria-label` names nothing and is worse than `aria-hidden`.
|
|
112
|
+
Labels are trimmed before they reach the description.
|
|
113
|
+
- **`settings` is drawn as sliders, not a cog.** A cog at 16px needs twelve or
|
|
114
|
+
more teeth to read as a cog and collides with `sun` (a circle with rays); two
|
|
115
|
+
slider rows with round knobs is distinguishable at the size the kit renders and
|
|
116
|
+
is the same metaphor `filter` does not use (that one is a funnel).
|
|
117
|
+
- **`error` / `success` are circle-plus-glyph, not bare glyphs.** They read as
|
|
118
|
+
status at the same weight as `info` and `warning`, and a bare `×` would be
|
|
119
|
+
`close` under another name.
|
|
120
|
+
|
|
121
|
+
## Not in this package
|
|
122
|
+
|
|
123
|
+
A component, a sprite, a font, runtime search, or a loader for arbitrary icon
|
|
124
|
+
packs. `icon()` produces the description; wiring colour and size is the host's
|
|
125
|
+
job, and the host does it by passing `size`, `strokeWidth` and CSS colour.
|
|
126
|
+
|
|
127
|
+
## Checking it
|
|
128
|
+
|
|
129
|
+
```sh
|
|
130
|
+
pnpm --filter @bevelo/icons typecheck
|
|
131
|
+
pnpm --filter @bevelo/icons test
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The test tokenises every `d` with a real parser rather than trusting the data:
|
|
135
|
+
commands must be SVG's list, each must carry a whole number of argument groups,
|
|
136
|
+
arc flags must be 0 or 1, and every resolved point must stay on the 24 canvas.
|
|
137
|
+
That is the check that catches a copied path with a missing coordinate before a
|
|
138
|
+
browser silently drops it.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
// src/paths.ts
|
|
3
|
+
/** The icon data. Keys are the public names; the order is the order `icons`
|
|
4
|
+
* exposes, so a picker that renders the whole set is stable between calls. */
|
|
5
|
+
const ICON_PATHS = {
|
|
6
|
+
check: ["M4 12.5l5 5L20 6.5"],
|
|
7
|
+
"chevron-down": ["M6 9l6 6 6-6"],
|
|
8
|
+
"chevron-up": ["M6 15l6-6 6 6"],
|
|
9
|
+
"chevron-left": ["M15 6l-6 6 6 6"],
|
|
10
|
+
"chevron-right": ["M9 6l6 6-6 6"],
|
|
11
|
+
"chevrons-left": ["M11 7l-5 5 5 5", "M18 7l-5 5 5 5"],
|
|
12
|
+
"chevrons-right": ["M6 7l5 5-5 5", "M13 7l5 5-5 5"],
|
|
13
|
+
close: ["M6 6l12 12", "M18 6l-12 12"],
|
|
14
|
+
plus: ["M12 5v14", "M5 12h14"],
|
|
15
|
+
minus: ["M5 12h14"],
|
|
16
|
+
search: ["M3 11a8 8 0 1 0 16 0 8 8 0 1 0-16 0", "M21 21l-4.3-4.3"],
|
|
17
|
+
menu: [
|
|
18
|
+
"M4 7h16",
|
|
19
|
+
"M4 12h16",
|
|
20
|
+
"M4 17h16"
|
|
21
|
+
],
|
|
22
|
+
"more-horizontal": [
|
|
23
|
+
"M5 12h.01",
|
|
24
|
+
"M12 12h.01",
|
|
25
|
+
"M19 12h.01"
|
|
26
|
+
],
|
|
27
|
+
"more-vertical": [
|
|
28
|
+
"M12 5h.01",
|
|
29
|
+
"M12 12h.01",
|
|
30
|
+
"M12 19h.01"
|
|
31
|
+
],
|
|
32
|
+
"arrow-left": ["M19 12H5", "M12 19l-7-7 7-7"],
|
|
33
|
+
"arrow-right": ["M5 12h14", "M12 5l7 7-7 7"],
|
|
34
|
+
"arrow-up": ["M12 19V5", "M5 12l7-7 7 7"],
|
|
35
|
+
"arrow-down": ["M12 5v14", "M19 12l-7 7-7-7"],
|
|
36
|
+
"arrow-up-right": ["M7 17 17 7", "M8 7h9v9"],
|
|
37
|
+
star: ["M12 3.2l2.7 5.5 6.1.9-4.4 4.3 1 6.1-5.4-2.9-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"],
|
|
38
|
+
"star-filled": [{
|
|
39
|
+
d: "M12 3.2l2.7 5.5 6.1.9-4.4 4.3 1 6.1-5.4-2.9-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z",
|
|
40
|
+
fill: true
|
|
41
|
+
}],
|
|
42
|
+
heart: ["M20.3 5.7a5 5 0 0 0-7.1 0L12 6.9l-1.2-1.2a5 5 0 0 0-7.1 7.1L12 21l8.3-8.2a5 5 0 0 0 0-7.1z"],
|
|
43
|
+
info: [
|
|
44
|
+
"M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0",
|
|
45
|
+
"M12 11v5",
|
|
46
|
+
"M12 7.5h.01"
|
|
47
|
+
],
|
|
48
|
+
warning: [
|
|
49
|
+
"M12 3.5l9 16H3z",
|
|
50
|
+
"M12 10v4",
|
|
51
|
+
"M12 17h.01"
|
|
52
|
+
],
|
|
53
|
+
error: [
|
|
54
|
+
"M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0",
|
|
55
|
+
"M9 9l6 6",
|
|
56
|
+
"M15 9l-6 6"
|
|
57
|
+
],
|
|
58
|
+
success: ["M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0", "M8 12.5l2.5 2.5 5.5-6"],
|
|
59
|
+
calendar: [
|
|
60
|
+
"M4 5h16v15H4z",
|
|
61
|
+
"M8 3v4",
|
|
62
|
+
"M16 3v4",
|
|
63
|
+
"M4 10h16"
|
|
64
|
+
],
|
|
65
|
+
clock: ["M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0", "M12 7v5l3.5 2"],
|
|
66
|
+
trash: [
|
|
67
|
+
"M3 6h18",
|
|
68
|
+
"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",
|
|
69
|
+
"M5 6v14a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6",
|
|
70
|
+
"M10 11v6",
|
|
71
|
+
"M14 11v6"
|
|
72
|
+
],
|
|
73
|
+
edit: ["M15.5 4.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z", "M14 6l4 4"],
|
|
74
|
+
copy: ["M8 8V5a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1h-3", "M4 8h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z"],
|
|
75
|
+
download: [
|
|
76
|
+
"M12 3v12",
|
|
77
|
+
"M7 10l5 5 5-5",
|
|
78
|
+
"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"
|
|
79
|
+
],
|
|
80
|
+
upload: [
|
|
81
|
+
"M12 15V3",
|
|
82
|
+
"M7 8l5-5 5 5",
|
|
83
|
+
"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"
|
|
84
|
+
],
|
|
85
|
+
"external-link": [
|
|
86
|
+
"M15 3h6v6",
|
|
87
|
+
"M10 14 21 3",
|
|
88
|
+
"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"
|
|
89
|
+
],
|
|
90
|
+
eye: ["M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7-10-7-10-7z", "M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0"],
|
|
91
|
+
"eye-off": [
|
|
92
|
+
"M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7-10-7-10-7z",
|
|
93
|
+
"M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0",
|
|
94
|
+
"M4 4l16 16"
|
|
95
|
+
],
|
|
96
|
+
lock: ["M5 11h14a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1z", "M8 11V8a4 4 0 0 1 8 0v3"],
|
|
97
|
+
unlock: ["M5 11h14a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1z", "M8 11V8a4 4 0 0 1 7.6-1.8"],
|
|
98
|
+
user: ["M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2", "M16 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0"],
|
|
99
|
+
users: [
|
|
100
|
+
"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",
|
|
101
|
+
"M13 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0",
|
|
102
|
+
"M17 3.5a4 4 0 0 1 0 7.5",
|
|
103
|
+
"M22 21v-2a4 4 0 0 0-3-3.9"
|
|
104
|
+
],
|
|
105
|
+
settings: [
|
|
106
|
+
"M4 7h4",
|
|
107
|
+
"M12 7h8",
|
|
108
|
+
"M12 7a2 2 0 1 1-4 0 2 2 0 0 1 4 0",
|
|
109
|
+
"M4 17h6",
|
|
110
|
+
"M14 17h6",
|
|
111
|
+
"M14 17a2 2 0 1 1-4 0 2 2 0 0 1 4 0"
|
|
112
|
+
],
|
|
113
|
+
filter: ["M4 5h16l-6 7v6l-4 2v-8z"],
|
|
114
|
+
"sort-asc": [
|
|
115
|
+
"M4 6h9",
|
|
116
|
+
"M4 12h6",
|
|
117
|
+
"M4 18h3",
|
|
118
|
+
"M17 19V5",
|
|
119
|
+
"M14 8l3-3 3 3"
|
|
120
|
+
],
|
|
121
|
+
"sort-desc": [
|
|
122
|
+
"M4 6h3",
|
|
123
|
+
"M4 12h6",
|
|
124
|
+
"M4 18h9",
|
|
125
|
+
"M17 5v14",
|
|
126
|
+
"M14 16l3 3 3-3"
|
|
127
|
+
],
|
|
128
|
+
"grip-vertical": [
|
|
129
|
+
"M9 5h.01",
|
|
130
|
+
"M9 12h.01",
|
|
131
|
+
"M9 19h.01",
|
|
132
|
+
"M15 5h.01",
|
|
133
|
+
"M15 12h.01",
|
|
134
|
+
"M15 19h.01"
|
|
135
|
+
],
|
|
136
|
+
play: ["M7 5v14l13-7z"],
|
|
137
|
+
pause: ["M9 5v14", "M15 5v14"],
|
|
138
|
+
folder: ["M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"],
|
|
139
|
+
file: ["M6 3h7l7 7v9a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z", "M13 3v4a2 2 0 0 0 2 2h5"],
|
|
140
|
+
refresh: ["M21 12a9 9 0 1 1-9-9c2.5 0 4.9 1 6.7 2.7L21 8", "M21 3v5h-5"],
|
|
141
|
+
spinner: ["M21 12a9 9 0 1 1-9-9"],
|
|
142
|
+
sun: [
|
|
143
|
+
"M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8",
|
|
144
|
+
"M12 2v2",
|
|
145
|
+
"M12 20v2",
|
|
146
|
+
"M4.2 4.2l1.4 1.4",
|
|
147
|
+
"M18.4 18.4l1.4 1.4",
|
|
148
|
+
"M2 12h2",
|
|
149
|
+
"M20 12h2",
|
|
150
|
+
"M4.2 19.8l1.4-1.4",
|
|
151
|
+
"M18.4 5.6l1.4-1.4"
|
|
152
|
+
],
|
|
153
|
+
moon: ["M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9z"],
|
|
154
|
+
monitor: [
|
|
155
|
+
"M5 4h14a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z",
|
|
156
|
+
"M9 21h6",
|
|
157
|
+
"M12 17v4"
|
|
158
|
+
]
|
|
159
|
+
};
|
|
160
|
+
// src/index.ts
|
|
161
|
+
const DEFAULT_SIZE = 16;
|
|
162
|
+
const DEFAULT_STROKE_WIDTH = 1.75;
|
|
163
|
+
/** Every icon name, in the order paths.ts declares them.
|
|
164
|
+
*
|
|
165
|
+
* Frozen and ordered so a picker can render the whole set without sorting it, and
|
|
166
|
+
* so a caller cannot make the exported list disagree with the data. */
|
|
167
|
+
const icons = Object.freeze(Object.keys(ICON_PATHS));
|
|
168
|
+
/** The icon names, for a caller that wants a call rather than the constant.
|
|
169
|
+
*
|
|
170
|
+
* Returns the same frozen array `icons` holds, not a copy. */
|
|
171
|
+
function iconNames() {
|
|
172
|
+
return icons;
|
|
173
|
+
}
|
|
174
|
+
/** Whether a runtime string is one of the names.
|
|
175
|
+
*
|
|
176
|
+
* The guard to reach for when a name arrives from data (`<Button icon={row.icon}>`):
|
|
177
|
+
* `icon()` accepts only `IconName`, and this is what narrows a `string` to it.
|
|
178
|
+
* `hasOwnProperty` rather than `in`, so `"toString"` is not an icon. */
|
|
179
|
+
function hasIcon(name) {
|
|
180
|
+
return Object.hasOwn(ICON_PATHS, name);
|
|
181
|
+
}
|
|
182
|
+
/** One icon as a render description.
|
|
183
|
+
*
|
|
184
|
+
* `icon("check")` is decorative by default: `aria-hidden="true"`, no role, current
|
|
185
|
+
* colour for both stroke and fill. Pass `label` when the icon is the only content
|
|
186
|
+
* of a control — it switches to `role="img"` plus `aria-label`, because an
|
|
187
|
+
* `aria-hidden` image inside a control with no text leaves the control unnamed. */
|
|
188
|
+
function icon(name, options = {}) {
|
|
189
|
+
const paths = ICON_PATHS[name];
|
|
190
|
+
if (paths === void 0) throw new Error(`Unknown icon "${String(name)}": call hasIcon() before passing a runtime name.`);
|
|
191
|
+
const { size = DEFAULT_SIZE, strokeWidth = DEFAULT_STROKE_WIDTH } = options;
|
|
192
|
+
const label = options.label?.trim() ?? "";
|
|
193
|
+
const attrs = {
|
|
194
|
+
viewBox: "0 0 24 24",
|
|
195
|
+
width: size,
|
|
196
|
+
height: size,
|
|
197
|
+
fill: "none",
|
|
198
|
+
stroke: "currentColor",
|
|
199
|
+
"stroke-width": strokeWidth,
|
|
200
|
+
"stroke-linecap": "round",
|
|
201
|
+
"stroke-linejoin": "round"
|
|
202
|
+
};
|
|
203
|
+
if (label === "") attrs["aria-hidden"] = "true";
|
|
204
|
+
else {
|
|
205
|
+
attrs.role = "img";
|
|
206
|
+
attrs["aria-label"] = label;
|
|
207
|
+
}
|
|
208
|
+
return {
|
|
209
|
+
tag: "svg",
|
|
210
|
+
attrs,
|
|
211
|
+
children: paths.map((path) => {
|
|
212
|
+
const pathAttrs = { d: typeof path === "string" ? path : path.d };
|
|
213
|
+
if (typeof path !== "string" && path.fill) pathAttrs.fill = "currentColor";
|
|
214
|
+
return {
|
|
215
|
+
tag: "path",
|
|
216
|
+
attrs: pathAttrs
|
|
217
|
+
};
|
|
218
|
+
})
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
exports.hasIcon = hasIcon;
|
|
222
|
+
exports.icon = icon;
|
|
223
|
+
exports.iconNames = iconNames;
|
|
224
|
+
exports.icons = icons;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/** One subpath of an icon: SVG path data, and whether it also paints a fill.
|
|
2
|
+
*
|
|
3
|
+
* Plain data is the common case. The object form exists for `star-filled`, whose
|
|
4
|
+
* "filled" meaning is a solid body rather than a closed outline; a per-path flag
|
|
5
|
+
* is the smallest way to say that without changing the paint rules for all 53
|
|
6
|
+
* other icons. */
|
|
7
|
+
type IconPath = string | {
|
|
8
|
+
readonly d: string;
|
|
9
|
+
readonly fill: true;
|
|
10
|
+
};
|
|
11
|
+
/** The icon data. Keys are the public names; the order is the order `icons`
|
|
12
|
+
* exposes, so a picker that renders the whole set is stable between calls. */
|
|
13
|
+
declare const ICON_PATHS: {
|
|
14
|
+
readonly check: readonly ["M4 12.5l5 5L20 6.5"];
|
|
15
|
+
readonly "chevron-down": readonly ["M6 9l6 6 6-6"];
|
|
16
|
+
readonly "chevron-up": readonly ["M6 15l6-6 6 6"];
|
|
17
|
+
readonly "chevron-left": readonly ["M15 6l-6 6 6 6"];
|
|
18
|
+
readonly "chevron-right": readonly ["M9 6l6 6-6 6"];
|
|
19
|
+
readonly "chevrons-left": readonly ["M11 7l-5 5 5 5", "M18 7l-5 5 5 5"];
|
|
20
|
+
readonly "chevrons-right": readonly ["M6 7l5 5-5 5", "M13 7l5 5-5 5"];
|
|
21
|
+
readonly close: readonly ["M6 6l12 12", "M18 6l-12 12"];
|
|
22
|
+
readonly plus: readonly ["M12 5v14", "M5 12h14"];
|
|
23
|
+
readonly minus: readonly ["M5 12h14"];
|
|
24
|
+
readonly search: readonly ["M3 11a8 8 0 1 0 16 0 8 8 0 1 0-16 0", "M21 21l-4.3-4.3"];
|
|
25
|
+
readonly menu: readonly ["M4 7h16", "M4 12h16", "M4 17h16"];
|
|
26
|
+
readonly "more-horizontal": readonly ["M5 12h.01", "M12 12h.01", "M19 12h.01"];
|
|
27
|
+
readonly "more-vertical": readonly ["M12 5h.01", "M12 12h.01", "M12 19h.01"];
|
|
28
|
+
readonly "arrow-left": readonly ["M19 12H5", "M12 19l-7-7 7-7"];
|
|
29
|
+
readonly "arrow-right": readonly ["M5 12h14", "M12 5l7 7-7 7"];
|
|
30
|
+
readonly "arrow-up": readonly ["M12 19V5", "M5 12l7-7 7 7"];
|
|
31
|
+
readonly "arrow-down": readonly ["M12 5v14", "M19 12l-7 7-7-7"];
|
|
32
|
+
readonly "arrow-up-right": readonly ["M7 17 17 7", "M8 7h9v9"];
|
|
33
|
+
readonly star: readonly ["M12 3.2l2.7 5.5 6.1.9-4.4 4.3 1 6.1-5.4-2.9-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"];
|
|
34
|
+
readonly "star-filled": readonly [{
|
|
35
|
+
readonly d: "M12 3.2l2.7 5.5 6.1.9-4.4 4.3 1 6.1-5.4-2.9-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z";
|
|
36
|
+
readonly fill: true;
|
|
37
|
+
}];
|
|
38
|
+
readonly heart: readonly ["M20.3 5.7a5 5 0 0 0-7.1 0L12 6.9l-1.2-1.2a5 5 0 0 0-7.1 7.1L12 21l8.3-8.2a5 5 0 0 0 0-7.1z"];
|
|
39
|
+
readonly info: readonly ["M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0", "M12 11v5", "M12 7.5h.01"];
|
|
40
|
+
readonly warning: readonly ["M12 3.5l9 16H3z", "M12 10v4", "M12 17h.01"];
|
|
41
|
+
readonly error: readonly ["M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0", "M9 9l6 6", "M15 9l-6 6"];
|
|
42
|
+
readonly success: readonly ["M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0", "M8 12.5l2.5 2.5 5.5-6"];
|
|
43
|
+
readonly calendar: readonly ["M4 5h16v15H4z", "M8 3v4", "M16 3v4", "M4 10h16"];
|
|
44
|
+
readonly clock: readonly ["M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0", "M12 7v5l3.5 2"];
|
|
45
|
+
readonly trash: readonly ["M3 6h18", "M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2", "M5 6v14a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6", "M10 11v6", "M14 11v6"];
|
|
46
|
+
readonly edit: readonly ["M15.5 4.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z", "M14 6l4 4"];
|
|
47
|
+
readonly copy: readonly ["M8 8V5a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1h-3", "M4 8h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z"];
|
|
48
|
+
readonly download: readonly ["M12 3v12", "M7 10l5 5 5-5", "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"];
|
|
49
|
+
readonly upload: readonly ["M12 15V3", "M7 8l5-5 5 5", "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"];
|
|
50
|
+
readonly "external-link": readonly ["M15 3h6v6", "M10 14 21 3", "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"];
|
|
51
|
+
readonly eye: readonly ["M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7-10-7-10-7z", "M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0"];
|
|
52
|
+
readonly "eye-off": readonly ["M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7-10-7-10-7z", "M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0", "M4 4l16 16"];
|
|
53
|
+
readonly lock: readonly ["M5 11h14a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1z", "M8 11V8a4 4 0 0 1 8 0v3"];
|
|
54
|
+
readonly unlock: readonly ["M5 11h14a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1z", "M8 11V8a4 4 0 0 1 7.6-1.8"];
|
|
55
|
+
readonly user: readonly ["M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2", "M16 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0"];
|
|
56
|
+
readonly users: readonly ["M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2", "M13 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0", "M17 3.5a4 4 0 0 1 0 7.5", "M22 21v-2a4 4 0 0 0-3-3.9"];
|
|
57
|
+
readonly settings: readonly ["M4 7h4", "M12 7h8", "M12 7a2 2 0 1 1-4 0 2 2 0 0 1 4 0", "M4 17h6", "M14 17h6", "M14 17a2 2 0 1 1-4 0 2 2 0 0 1 4 0"];
|
|
58
|
+
readonly filter: readonly ["M4 5h16l-6 7v6l-4 2v-8z"];
|
|
59
|
+
readonly "sort-asc": readonly ["M4 6h9", "M4 12h6", "M4 18h3", "M17 19V5", "M14 8l3-3 3 3"];
|
|
60
|
+
readonly "sort-desc": readonly ["M4 6h3", "M4 12h6", "M4 18h9", "M17 5v14", "M14 16l3 3 3-3"];
|
|
61
|
+
readonly "grip-vertical": readonly ["M9 5h.01", "M9 12h.01", "M9 19h.01", "M15 5h.01", "M15 12h.01", "M15 19h.01"];
|
|
62
|
+
readonly play: readonly ["M7 5v14l13-7z"];
|
|
63
|
+
readonly pause: readonly ["M9 5v14", "M15 5v14"];
|
|
64
|
+
readonly folder: readonly ["M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"];
|
|
65
|
+
readonly file: readonly ["M6 3h7l7 7v9a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z", "M13 3v4a2 2 0 0 0 2 2h5"];
|
|
66
|
+
readonly refresh: readonly ["M21 12a9 9 0 1 1-9-9c2.5 0 4.9 1 6.7 2.7L21 8", "M21 3v5h-5"];
|
|
67
|
+
readonly spinner: readonly ["M21 12a9 9 0 1 1-9-9"];
|
|
68
|
+
readonly sun: readonly ["M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8", "M12 2v2", "M12 20v2", "M4.2 4.2l1.4 1.4", "M18.4 18.4l1.4 1.4", "M2 12h2", "M20 12h2", "M4.2 19.8l1.4-1.4", "M18.4 5.6l1.4-1.4"];
|
|
69
|
+
readonly moon: readonly ["M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9z"];
|
|
70
|
+
readonly monitor: readonly ["M5 4h14a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z", "M9 21h6", "M12 17v4"];
|
|
71
|
+
};
|
|
72
|
+
/** Every name the set has. Derived from the data so the two cannot drift. */
|
|
73
|
+
type IconName = keyof typeof ICON_PATHS;
|
|
74
|
+
/** An element description: the same shape as core's `Description`, which is one
|
|
75
|
+
* arm of its `Child`. Declared here so the package imports nothing.
|
|
76
|
+
*
|
|
77
|
+
* `attrs` is a plain record and `children` is a list of the same thing, so this
|
|
78
|
+
* is assignable to `Child` in both adapters and can be inspected in a test
|
|
79
|
+
* without a DOM. */
|
|
80
|
+
export interface IconDescription {
|
|
81
|
+
readonly tag: string;
|
|
82
|
+
readonly attrs: Readonly<Record<string, string | number>>;
|
|
83
|
+
readonly children?: readonly IconDescription[];
|
|
84
|
+
}
|
|
85
|
+
/** What a caller may change about one icon.
|
|
86
|
+
*
|
|
87
|
+
* Everything is optional because a default exists for all of it: an icon with no
|
|
88
|
+
* options is the 16px decorative glyph a component wants inline with text. */
|
|
89
|
+
export interface IconOptions {
|
|
90
|
+
/** Rendered width and height in px. Default 16. */
|
|
91
|
+
size?: number;
|
|
92
|
+
/** Accessible name. Present turns a decorative glyph into a labelled image. */
|
|
93
|
+
label?: string;
|
|
94
|
+
/** Stroke width in px. Default 1.75, the weight the path data is drawn for. */
|
|
95
|
+
strokeWidth?: number;
|
|
96
|
+
}
|
|
97
|
+
/** Every icon name, in the order paths.ts declares them.
|
|
98
|
+
*
|
|
99
|
+
* Frozen and ordered so a picker can render the whole set without sorting it, and
|
|
100
|
+
* so a caller cannot make the exported list disagree with the data. */
|
|
101
|
+
export declare const icons: readonly IconName[];
|
|
102
|
+
/** The icon names, for a caller that wants a call rather than the constant.
|
|
103
|
+
*
|
|
104
|
+
* Returns the same frozen array `icons` holds, not a copy. */
|
|
105
|
+
export declare function iconNames(): readonly IconName[];
|
|
106
|
+
/** Whether a runtime string is one of the names.
|
|
107
|
+
*
|
|
108
|
+
* The guard to reach for when a name arrives from data (`<Button icon={row.icon}>`):
|
|
109
|
+
* `icon()` accepts only `IconName`, and this is what narrows a `string` to it.
|
|
110
|
+
* `hasOwnProperty` rather than `in`, so `"toString"` is not an icon. */
|
|
111
|
+
export declare function hasIcon(name: string): name is IconName;
|
|
112
|
+
/** One icon as a render description.
|
|
113
|
+
*
|
|
114
|
+
* `icon("check")` is decorative by default: `aria-hidden="true"`, no role, current
|
|
115
|
+
* colour for both stroke and fill. Pass `label` when the icon is the only content
|
|
116
|
+
* of a control — it switches to `role="img"` plus `aria-label`, because an
|
|
117
|
+
* `aria-hidden` image inside a control with no text leaves the control unnamed. */
|
|
118
|
+
export declare function icon(name: IconName, options?: IconOptions): IconDescription;
|
|
119
|
+
export type { IconName, IconPath };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/** One subpath of an icon: SVG path data, and whether it also paints a fill.
|
|
2
|
+
*
|
|
3
|
+
* Plain data is the common case. The object form exists for `star-filled`, whose
|
|
4
|
+
* "filled" meaning is a solid body rather than a closed outline; a per-path flag
|
|
5
|
+
* is the smallest way to say that without changing the paint rules for all 53
|
|
6
|
+
* other icons. */
|
|
7
|
+
type IconPath = string | {
|
|
8
|
+
readonly d: string;
|
|
9
|
+
readonly fill: true;
|
|
10
|
+
};
|
|
11
|
+
/** The icon data. Keys are the public names; the order is the order `icons`
|
|
12
|
+
* exposes, so a picker that renders the whole set is stable between calls. */
|
|
13
|
+
declare const ICON_PATHS: {
|
|
14
|
+
readonly check: readonly ["M4 12.5l5 5L20 6.5"];
|
|
15
|
+
readonly "chevron-down": readonly ["M6 9l6 6 6-6"];
|
|
16
|
+
readonly "chevron-up": readonly ["M6 15l6-6 6 6"];
|
|
17
|
+
readonly "chevron-left": readonly ["M15 6l-6 6 6 6"];
|
|
18
|
+
readonly "chevron-right": readonly ["M9 6l6 6-6 6"];
|
|
19
|
+
readonly "chevrons-left": readonly ["M11 7l-5 5 5 5", "M18 7l-5 5 5 5"];
|
|
20
|
+
readonly "chevrons-right": readonly ["M6 7l5 5-5 5", "M13 7l5 5-5 5"];
|
|
21
|
+
readonly close: readonly ["M6 6l12 12", "M18 6l-12 12"];
|
|
22
|
+
readonly plus: readonly ["M12 5v14", "M5 12h14"];
|
|
23
|
+
readonly minus: readonly ["M5 12h14"];
|
|
24
|
+
readonly search: readonly ["M3 11a8 8 0 1 0 16 0 8 8 0 1 0-16 0", "M21 21l-4.3-4.3"];
|
|
25
|
+
readonly menu: readonly ["M4 7h16", "M4 12h16", "M4 17h16"];
|
|
26
|
+
readonly "more-horizontal": readonly ["M5 12h.01", "M12 12h.01", "M19 12h.01"];
|
|
27
|
+
readonly "more-vertical": readonly ["M12 5h.01", "M12 12h.01", "M12 19h.01"];
|
|
28
|
+
readonly "arrow-left": readonly ["M19 12H5", "M12 19l-7-7 7-7"];
|
|
29
|
+
readonly "arrow-right": readonly ["M5 12h14", "M12 5l7 7-7 7"];
|
|
30
|
+
readonly "arrow-up": readonly ["M12 19V5", "M5 12l7-7 7 7"];
|
|
31
|
+
readonly "arrow-down": readonly ["M12 5v14", "M19 12l-7 7-7-7"];
|
|
32
|
+
readonly "arrow-up-right": readonly ["M7 17 17 7", "M8 7h9v9"];
|
|
33
|
+
readonly star: readonly ["M12 3.2l2.7 5.5 6.1.9-4.4 4.3 1 6.1-5.4-2.9-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"];
|
|
34
|
+
readonly "star-filled": readonly [{
|
|
35
|
+
readonly d: "M12 3.2l2.7 5.5 6.1.9-4.4 4.3 1 6.1-5.4-2.9-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z";
|
|
36
|
+
readonly fill: true;
|
|
37
|
+
}];
|
|
38
|
+
readonly heart: readonly ["M20.3 5.7a5 5 0 0 0-7.1 0L12 6.9l-1.2-1.2a5 5 0 0 0-7.1 7.1L12 21l8.3-8.2a5 5 0 0 0 0-7.1z"];
|
|
39
|
+
readonly info: readonly ["M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0", "M12 11v5", "M12 7.5h.01"];
|
|
40
|
+
readonly warning: readonly ["M12 3.5l9 16H3z", "M12 10v4", "M12 17h.01"];
|
|
41
|
+
readonly error: readonly ["M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0", "M9 9l6 6", "M15 9l-6 6"];
|
|
42
|
+
readonly success: readonly ["M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0", "M8 12.5l2.5 2.5 5.5-6"];
|
|
43
|
+
readonly calendar: readonly ["M4 5h16v15H4z", "M8 3v4", "M16 3v4", "M4 10h16"];
|
|
44
|
+
readonly clock: readonly ["M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0", "M12 7v5l3.5 2"];
|
|
45
|
+
readonly trash: readonly ["M3 6h18", "M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2", "M5 6v14a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6", "M10 11v6", "M14 11v6"];
|
|
46
|
+
readonly edit: readonly ["M15.5 4.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z", "M14 6l4 4"];
|
|
47
|
+
readonly copy: readonly ["M8 8V5a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1h-3", "M4 8h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z"];
|
|
48
|
+
readonly download: readonly ["M12 3v12", "M7 10l5 5 5-5", "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"];
|
|
49
|
+
readonly upload: readonly ["M12 15V3", "M7 8l5-5 5 5", "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"];
|
|
50
|
+
readonly "external-link": readonly ["M15 3h6v6", "M10 14 21 3", "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"];
|
|
51
|
+
readonly eye: readonly ["M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7-10-7-10-7z", "M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0"];
|
|
52
|
+
readonly "eye-off": readonly ["M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7-10-7-10-7z", "M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0", "M4 4l16 16"];
|
|
53
|
+
readonly lock: readonly ["M5 11h14a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1z", "M8 11V8a4 4 0 0 1 8 0v3"];
|
|
54
|
+
readonly unlock: readonly ["M5 11h14a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1z", "M8 11V8a4 4 0 0 1 7.6-1.8"];
|
|
55
|
+
readonly user: readonly ["M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2", "M16 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0"];
|
|
56
|
+
readonly users: readonly ["M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2", "M13 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0", "M17 3.5a4 4 0 0 1 0 7.5", "M22 21v-2a4 4 0 0 0-3-3.9"];
|
|
57
|
+
readonly settings: readonly ["M4 7h4", "M12 7h8", "M12 7a2 2 0 1 1-4 0 2 2 0 0 1 4 0", "M4 17h6", "M14 17h6", "M14 17a2 2 0 1 1-4 0 2 2 0 0 1 4 0"];
|
|
58
|
+
readonly filter: readonly ["M4 5h16l-6 7v6l-4 2v-8z"];
|
|
59
|
+
readonly "sort-asc": readonly ["M4 6h9", "M4 12h6", "M4 18h3", "M17 19V5", "M14 8l3-3 3 3"];
|
|
60
|
+
readonly "sort-desc": readonly ["M4 6h3", "M4 12h6", "M4 18h9", "M17 5v14", "M14 16l3 3 3-3"];
|
|
61
|
+
readonly "grip-vertical": readonly ["M9 5h.01", "M9 12h.01", "M9 19h.01", "M15 5h.01", "M15 12h.01", "M15 19h.01"];
|
|
62
|
+
readonly play: readonly ["M7 5v14l13-7z"];
|
|
63
|
+
readonly pause: readonly ["M9 5v14", "M15 5v14"];
|
|
64
|
+
readonly folder: readonly ["M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"];
|
|
65
|
+
readonly file: readonly ["M6 3h7l7 7v9a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z", "M13 3v4a2 2 0 0 0 2 2h5"];
|
|
66
|
+
readonly refresh: readonly ["M21 12a9 9 0 1 1-9-9c2.5 0 4.9 1 6.7 2.7L21 8", "M21 3v5h-5"];
|
|
67
|
+
readonly spinner: readonly ["M21 12a9 9 0 1 1-9-9"];
|
|
68
|
+
readonly sun: readonly ["M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8", "M12 2v2", "M12 20v2", "M4.2 4.2l1.4 1.4", "M18.4 18.4l1.4 1.4", "M2 12h2", "M20 12h2", "M4.2 19.8l1.4-1.4", "M18.4 5.6l1.4-1.4"];
|
|
69
|
+
readonly moon: readonly ["M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9z"];
|
|
70
|
+
readonly monitor: readonly ["M5 4h14a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z", "M9 21h6", "M12 17v4"];
|
|
71
|
+
};
|
|
72
|
+
/** Every name the set has. Derived from the data so the two cannot drift. */
|
|
73
|
+
type IconName = keyof typeof ICON_PATHS;
|
|
74
|
+
/** An element description: the same shape as core's `Description`, which is one
|
|
75
|
+
* arm of its `Child`. Declared here so the package imports nothing.
|
|
76
|
+
*
|
|
77
|
+
* `attrs` is a plain record and `children` is a list of the same thing, so this
|
|
78
|
+
* is assignable to `Child` in both adapters and can be inspected in a test
|
|
79
|
+
* without a DOM. */
|
|
80
|
+
export interface IconDescription {
|
|
81
|
+
readonly tag: string;
|
|
82
|
+
readonly attrs: Readonly<Record<string, string | number>>;
|
|
83
|
+
readonly children?: readonly IconDescription[];
|
|
84
|
+
}
|
|
85
|
+
/** What a caller may change about one icon.
|
|
86
|
+
*
|
|
87
|
+
* Everything is optional because a default exists for all of it: an icon with no
|
|
88
|
+
* options is the 16px decorative glyph a component wants inline with text. */
|
|
89
|
+
export interface IconOptions {
|
|
90
|
+
/** Rendered width and height in px. Default 16. */
|
|
91
|
+
size?: number;
|
|
92
|
+
/** Accessible name. Present turns a decorative glyph into a labelled image. */
|
|
93
|
+
label?: string;
|
|
94
|
+
/** Stroke width in px. Default 1.75, the weight the path data is drawn for. */
|
|
95
|
+
strokeWidth?: number;
|
|
96
|
+
}
|
|
97
|
+
/** Every icon name, in the order paths.ts declares them.
|
|
98
|
+
*
|
|
99
|
+
* Frozen and ordered so a picker can render the whole set without sorting it, and
|
|
100
|
+
* so a caller cannot make the exported list disagree with the data. */
|
|
101
|
+
export declare const icons: readonly IconName[];
|
|
102
|
+
/** The icon names, for a caller that wants a call rather than the constant.
|
|
103
|
+
*
|
|
104
|
+
* Returns the same frozen array `icons` holds, not a copy. */
|
|
105
|
+
export declare function iconNames(): readonly IconName[];
|
|
106
|
+
/** Whether a runtime string is one of the names.
|
|
107
|
+
*
|
|
108
|
+
* The guard to reach for when a name arrives from data (`<Button icon={row.icon}>`):
|
|
109
|
+
* `icon()` accepts only `IconName`, and this is what narrows a `string` to it.
|
|
110
|
+
* `hasOwnProperty` rather than `in`, so `"toString"` is not an icon. */
|
|
111
|
+
export declare function hasIcon(name: string): name is IconName;
|
|
112
|
+
/** One icon as a render description.
|
|
113
|
+
*
|
|
114
|
+
* `icon("check")` is decorative by default: `aria-hidden="true"`, no role, current
|
|
115
|
+
* colour for both stroke and fill. Pass `label` when the icon is the only content
|
|
116
|
+
* of a control — it switches to `role="img"` plus `aria-label`, because an
|
|
117
|
+
* `aria-hidden` image inside a control with no text leaves the control unnamed. */
|
|
118
|
+
export declare function icon(name: IconName, options?: IconOptions): IconDescription;
|
|
119
|
+
export type { IconName, IconPath };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// src/paths.ts
|
|
2
|
+
/** The icon data. Keys are the public names; the order is the order `icons`
|
|
3
|
+
* exposes, so a picker that renders the whole set is stable between calls. */
|
|
4
|
+
const ICON_PATHS = {
|
|
5
|
+
check: ["M4 12.5l5 5L20 6.5"],
|
|
6
|
+
"chevron-down": ["M6 9l6 6 6-6"],
|
|
7
|
+
"chevron-up": ["M6 15l6-6 6 6"],
|
|
8
|
+
"chevron-left": ["M15 6l-6 6 6 6"],
|
|
9
|
+
"chevron-right": ["M9 6l6 6-6 6"],
|
|
10
|
+
"chevrons-left": ["M11 7l-5 5 5 5", "M18 7l-5 5 5 5"],
|
|
11
|
+
"chevrons-right": ["M6 7l5 5-5 5", "M13 7l5 5-5 5"],
|
|
12
|
+
close: ["M6 6l12 12", "M18 6l-12 12"],
|
|
13
|
+
plus: ["M12 5v14", "M5 12h14"],
|
|
14
|
+
minus: ["M5 12h14"],
|
|
15
|
+
search: ["M3 11a8 8 0 1 0 16 0 8 8 0 1 0-16 0", "M21 21l-4.3-4.3"],
|
|
16
|
+
menu: [
|
|
17
|
+
"M4 7h16",
|
|
18
|
+
"M4 12h16",
|
|
19
|
+
"M4 17h16"
|
|
20
|
+
],
|
|
21
|
+
"more-horizontal": [
|
|
22
|
+
"M5 12h.01",
|
|
23
|
+
"M12 12h.01",
|
|
24
|
+
"M19 12h.01"
|
|
25
|
+
],
|
|
26
|
+
"more-vertical": [
|
|
27
|
+
"M12 5h.01",
|
|
28
|
+
"M12 12h.01",
|
|
29
|
+
"M12 19h.01"
|
|
30
|
+
],
|
|
31
|
+
"arrow-left": ["M19 12H5", "M12 19l-7-7 7-7"],
|
|
32
|
+
"arrow-right": ["M5 12h14", "M12 5l7 7-7 7"],
|
|
33
|
+
"arrow-up": ["M12 19V5", "M5 12l7-7 7 7"],
|
|
34
|
+
"arrow-down": ["M12 5v14", "M19 12l-7 7-7-7"],
|
|
35
|
+
"arrow-up-right": ["M7 17 17 7", "M8 7h9v9"],
|
|
36
|
+
star: ["M12 3.2l2.7 5.5 6.1.9-4.4 4.3 1 6.1-5.4-2.9-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z"],
|
|
37
|
+
"star-filled": [{
|
|
38
|
+
d: "M12 3.2l2.7 5.5 6.1.9-4.4 4.3 1 6.1-5.4-2.9-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z",
|
|
39
|
+
fill: true
|
|
40
|
+
}],
|
|
41
|
+
heart: ["M20.3 5.7a5 5 0 0 0-7.1 0L12 6.9l-1.2-1.2a5 5 0 0 0-7.1 7.1L12 21l8.3-8.2a5 5 0 0 0 0-7.1z"],
|
|
42
|
+
info: [
|
|
43
|
+
"M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0",
|
|
44
|
+
"M12 11v5",
|
|
45
|
+
"M12 7.5h.01"
|
|
46
|
+
],
|
|
47
|
+
warning: [
|
|
48
|
+
"M12 3.5l9 16H3z",
|
|
49
|
+
"M12 10v4",
|
|
50
|
+
"M12 17h.01"
|
|
51
|
+
],
|
|
52
|
+
error: [
|
|
53
|
+
"M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0",
|
|
54
|
+
"M9 9l6 6",
|
|
55
|
+
"M15 9l-6 6"
|
|
56
|
+
],
|
|
57
|
+
success: ["M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0", "M8 12.5l2.5 2.5 5.5-6"],
|
|
58
|
+
calendar: [
|
|
59
|
+
"M4 5h16v15H4z",
|
|
60
|
+
"M8 3v4",
|
|
61
|
+
"M16 3v4",
|
|
62
|
+
"M4 10h16"
|
|
63
|
+
],
|
|
64
|
+
clock: ["M3 12a9 9 0 1 0 18 0 9 9 0 1 0-18 0", "M12 7v5l3.5 2"],
|
|
65
|
+
trash: [
|
|
66
|
+
"M3 6h18",
|
|
67
|
+
"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",
|
|
68
|
+
"M5 6v14a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V6",
|
|
69
|
+
"M10 11v6",
|
|
70
|
+
"M14 11v6"
|
|
71
|
+
],
|
|
72
|
+
edit: ["M15.5 4.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z", "M14 6l4 4"],
|
|
73
|
+
copy: ["M8 8V5a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1h-3", "M4 8h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V9a1 1 0 0 1 1-1z"],
|
|
74
|
+
download: [
|
|
75
|
+
"M12 3v12",
|
|
76
|
+
"M7 10l5 5 5-5",
|
|
77
|
+
"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"
|
|
78
|
+
],
|
|
79
|
+
upload: [
|
|
80
|
+
"M12 15V3",
|
|
81
|
+
"M7 8l5-5 5 5",
|
|
82
|
+
"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"
|
|
83
|
+
],
|
|
84
|
+
"external-link": [
|
|
85
|
+
"M15 3h6v6",
|
|
86
|
+
"M10 14 21 3",
|
|
87
|
+
"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"
|
|
88
|
+
],
|
|
89
|
+
eye: ["M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7-10-7-10-7z", "M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0"],
|
|
90
|
+
"eye-off": [
|
|
91
|
+
"M2 12s3.6-7 10-7 10 7 10 7-3.6 7-10 7-10-7-10-7z",
|
|
92
|
+
"M15 12a3 3 0 1 1-6 0 3 3 0 0 1 6 0",
|
|
93
|
+
"M4 4l16 16"
|
|
94
|
+
],
|
|
95
|
+
lock: ["M5 11h14a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1z", "M8 11V8a4 4 0 0 1 8 0v3"],
|
|
96
|
+
unlock: ["M5 11h14a1 1 0 0 1 1 1v7a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-7a1 1 0 0 1 1-1z", "M8 11V8a4 4 0 0 1 7.6-1.8"],
|
|
97
|
+
user: ["M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2", "M16 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0"],
|
|
98
|
+
users: [
|
|
99
|
+
"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",
|
|
100
|
+
"M13 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0",
|
|
101
|
+
"M17 3.5a4 4 0 0 1 0 7.5",
|
|
102
|
+
"M22 21v-2a4 4 0 0 0-3-3.9"
|
|
103
|
+
],
|
|
104
|
+
settings: [
|
|
105
|
+
"M4 7h4",
|
|
106
|
+
"M12 7h8",
|
|
107
|
+
"M12 7a2 2 0 1 1-4 0 2 2 0 0 1 4 0",
|
|
108
|
+
"M4 17h6",
|
|
109
|
+
"M14 17h6",
|
|
110
|
+
"M14 17a2 2 0 1 1-4 0 2 2 0 0 1 4 0"
|
|
111
|
+
],
|
|
112
|
+
filter: ["M4 5h16l-6 7v6l-4 2v-8z"],
|
|
113
|
+
"sort-asc": [
|
|
114
|
+
"M4 6h9",
|
|
115
|
+
"M4 12h6",
|
|
116
|
+
"M4 18h3",
|
|
117
|
+
"M17 19V5",
|
|
118
|
+
"M14 8l3-3 3 3"
|
|
119
|
+
],
|
|
120
|
+
"sort-desc": [
|
|
121
|
+
"M4 6h3",
|
|
122
|
+
"M4 12h6",
|
|
123
|
+
"M4 18h9",
|
|
124
|
+
"M17 5v14",
|
|
125
|
+
"M14 16l3 3 3-3"
|
|
126
|
+
],
|
|
127
|
+
"grip-vertical": [
|
|
128
|
+
"M9 5h.01",
|
|
129
|
+
"M9 12h.01",
|
|
130
|
+
"M9 19h.01",
|
|
131
|
+
"M15 5h.01",
|
|
132
|
+
"M15 12h.01",
|
|
133
|
+
"M15 19h.01"
|
|
134
|
+
],
|
|
135
|
+
play: ["M7 5v14l13-7z"],
|
|
136
|
+
pause: ["M9 5v14", "M15 5v14"],
|
|
137
|
+
folder: ["M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"],
|
|
138
|
+
file: ["M6 3h7l7 7v9a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z", "M13 3v4a2 2 0 0 0 2 2h5"],
|
|
139
|
+
refresh: ["M21 12a9 9 0 1 1-9-9c2.5 0 4.9 1 6.7 2.7L21 8", "M21 3v5h-5"],
|
|
140
|
+
spinner: ["M21 12a9 9 0 1 1-9-9"],
|
|
141
|
+
sun: [
|
|
142
|
+
"M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8",
|
|
143
|
+
"M12 2v2",
|
|
144
|
+
"M12 20v2",
|
|
145
|
+
"M4.2 4.2l1.4 1.4",
|
|
146
|
+
"M18.4 18.4l1.4 1.4",
|
|
147
|
+
"M2 12h2",
|
|
148
|
+
"M20 12h2",
|
|
149
|
+
"M4.2 19.8l1.4-1.4",
|
|
150
|
+
"M18.4 5.6l1.4-1.4"
|
|
151
|
+
],
|
|
152
|
+
moon: ["M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9z"],
|
|
153
|
+
monitor: [
|
|
154
|
+
"M5 4h14a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z",
|
|
155
|
+
"M9 21h6",
|
|
156
|
+
"M12 17v4"
|
|
157
|
+
]
|
|
158
|
+
};
|
|
159
|
+
// src/index.ts
|
|
160
|
+
const DEFAULT_SIZE = 16;
|
|
161
|
+
const DEFAULT_STROKE_WIDTH = 1.75;
|
|
162
|
+
/** Every icon name, in the order paths.ts declares them.
|
|
163
|
+
*
|
|
164
|
+
* Frozen and ordered so a picker can render the whole set without sorting it, and
|
|
165
|
+
* so a caller cannot make the exported list disagree with the data. */
|
|
166
|
+
const icons = Object.freeze(Object.keys(ICON_PATHS));
|
|
167
|
+
/** The icon names, for a caller that wants a call rather than the constant.
|
|
168
|
+
*
|
|
169
|
+
* Returns the same frozen array `icons` holds, not a copy. */
|
|
170
|
+
function iconNames() {
|
|
171
|
+
return icons;
|
|
172
|
+
}
|
|
173
|
+
/** Whether a runtime string is one of the names.
|
|
174
|
+
*
|
|
175
|
+
* The guard to reach for when a name arrives from data (`<Button icon={row.icon}>`):
|
|
176
|
+
* `icon()` accepts only `IconName`, and this is what narrows a `string` to it.
|
|
177
|
+
* `hasOwnProperty` rather than `in`, so `"toString"` is not an icon. */
|
|
178
|
+
function hasIcon(name) {
|
|
179
|
+
return Object.hasOwn(ICON_PATHS, name);
|
|
180
|
+
}
|
|
181
|
+
/** One icon as a render description.
|
|
182
|
+
*
|
|
183
|
+
* `icon("check")` is decorative by default: `aria-hidden="true"`, no role, current
|
|
184
|
+
* colour for both stroke and fill. Pass `label` when the icon is the only content
|
|
185
|
+
* of a control — it switches to `role="img"` plus `aria-label`, because an
|
|
186
|
+
* `aria-hidden` image inside a control with no text leaves the control unnamed. */
|
|
187
|
+
function icon(name, options = {}) {
|
|
188
|
+
const paths = ICON_PATHS[name];
|
|
189
|
+
if (paths === void 0) throw new Error(`Unknown icon "${String(name)}": call hasIcon() before passing a runtime name.`);
|
|
190
|
+
const { size = DEFAULT_SIZE, strokeWidth = DEFAULT_STROKE_WIDTH } = options;
|
|
191
|
+
const label = options.label?.trim() ?? "";
|
|
192
|
+
const attrs = {
|
|
193
|
+
viewBox: "0 0 24 24",
|
|
194
|
+
width: size,
|
|
195
|
+
height: size,
|
|
196
|
+
fill: "none",
|
|
197
|
+
stroke: "currentColor",
|
|
198
|
+
"stroke-width": strokeWidth,
|
|
199
|
+
"stroke-linecap": "round",
|
|
200
|
+
"stroke-linejoin": "round"
|
|
201
|
+
};
|
|
202
|
+
if (label === "") attrs["aria-hidden"] = "true";
|
|
203
|
+
else {
|
|
204
|
+
attrs.role = "img";
|
|
205
|
+
attrs["aria-label"] = label;
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
tag: "svg",
|
|
209
|
+
attrs,
|
|
210
|
+
children: paths.map((path) => {
|
|
211
|
+
const pathAttrs = { d: typeof path === "string" ? path : path.d };
|
|
212
|
+
if (typeof path !== "string" && path.fill) pathAttrs.fill = "currentColor";
|
|
213
|
+
return {
|
|
214
|
+
tag: "path",
|
|
215
|
+
attrs: pathAttrs
|
|
216
|
+
};
|
|
217
|
+
})
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
export { hasIcon, icon, iconNames, icons };
|
package/package.json
CHANGED
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bevelo/icons",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Iconography as data: named 24x24 path descriptions an adapter turns into an svg.",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://github.com/bevelo/bevelo#readme",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/bevelo/bevelo/issues"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/bevelo/bevelo.git",
|
|
28
|
+
"directory": "packages/icons"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "vp pack",
|
|
35
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
36
|
+
"test": "vp test run"
|
|
37
|
+
}
|
|
6
38
|
}
|