@xplortech/apollo-icons 0.2.2 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # Apollo Icons
2
2
 
3
- Apollo's Icon package.
3
+ Apollo's Icon package with full TypeScript support.
4
4
 
5
5
  ## Installation
6
6
 
@@ -8,6 +8,228 @@ Apollo's Icon package.
8
8
  npm install @xplortech/apollo-icons@latest
9
9
  ```
10
10
 
11
- > Note: You will need to set up your NPM token in CI. [Check NPM's documentation on the topic][npm-ci-token].
11
+ ## Usage
12
12
 
13
- [npm-ci-token]: https://docs.npmjs.com/using-private-packages-in-a-ci-cd-workflow#set-the-token-as-an-environment-variable-on-the-cicd-server
13
+ ### Basic Usage
14
+
15
+ ```javascript
16
+ import octicons from '@xplortech/apollo-icons';
17
+
18
+ // Access an icon by name
19
+ const icon = octicons['calendar-refresh'];
20
+
21
+ // Generate SVG string
22
+ const svg = icon.toSVG();
23
+ // => '<svg version="1.1" width="16" height="16" viewBox="0 0 16 16" ...>...</svg>'
24
+ ```
25
+
26
+ ### TypeScript Support
27
+
28
+ The package includes full TypeScript definitions with autocomplete for all icon names:
29
+
30
+ ```typescript
31
+ import octicons, { Icon, IconName, SVGOptions } from '@xplortech/apollo-icons';
32
+
33
+ // Icon names are typed - you get autocomplete!
34
+ const icon = octicons['calendar-refresh']; // ✓ Type-safe
35
+
36
+ // TypeScript will catch typos
37
+ const invalid = octicons['calender-refresh']; // ✗ Error: not a valid IconName
38
+ ```
39
+
40
+ ### SVG Options
41
+
42
+ Customize the SVG output with options:
43
+
44
+ ```javascript
45
+ // Specify width (height scales proportionally)
46
+ icon.toSVG({ width: 24 });
47
+
48
+ // Specify height (width scales proportionally)
49
+ icon.toSVG({ height: 32 });
50
+
51
+ // Add custom CSS classes
52
+ icon.toSVG({ class: 'my-icon text-primary' });
53
+
54
+ // Add aria-label for accessibility (removes aria-hidden)
55
+ icon.toSVG({ 'aria-label': 'Refresh calendar' });
56
+ ```
57
+
58
+ ### Getting Icons by Name
59
+
60
+ Use `getIcon()` to safely retrieve an icon by name:
61
+
62
+ ```javascript
63
+ import octicons from '@xplortech/apollo-icons';
64
+
65
+ // Get an icon by name (returns Icon or undefined)
66
+ const icon = octicons.getIcon('calendar-refresh');
67
+ if (icon) {
68
+ console.log(icon.toSVG());
69
+ }
70
+
71
+ // Works with both direct access and getIcon()
72
+ const directIcon = octicons['calendar-refresh'];
73
+ const helperIcon = octicons.getIcon('calendar-refresh');
74
+ // Both return the same icon object
75
+ ```
76
+
77
+ ### Finding Icons by Tag
78
+
79
+ Use `getIconsByTag()` to find all icons that match a specific keyword/tag:
80
+
81
+ ```javascript
82
+ import octicons from '@xplortech/apollo-icons';
83
+
84
+ // Find all icons tagged with 'audio'
85
+ const audioIcons = octicons.getIconsByTag('audio');
86
+ // => [volume, headphones-4, microphone-3, ...]
87
+
88
+ // Iterate over matching icons
89
+ audioIcons.forEach(icon => {
90
+ console.log(icon.symbol); // Icon name
91
+ console.log(icon.toSVG({ width: 24 })); // SVG output
92
+ });
93
+
94
+ // Find icons for calendars
95
+ const calendarIcons = octicons.getIconsByTag('calendar');
96
+
97
+ // Find icons for navigation
98
+ const navIcons = octicons.getIconsByTag('arrow');
99
+ ```
100
+
101
+ ### Icon Properties
102
+
103
+ Each icon object has the following properties:
104
+
105
+ ```javascript
106
+ const icon = octicons['calendar-refresh'];
107
+
108
+ icon.symbol; // 'calendar-refresh' - the icon name
109
+ icon.keywords; // ['calendar-refresh', 'reload', 'sync', ...] - searchable tags
110
+ icon.heights; // { '16': {...}, '24': {...}, ... } - available sizes
111
+ icon.toSVG(); // Function to generate SVG string
112
+ ```
113
+
114
+ ### Available Heights
115
+
116
+ Icons are available in multiple sizes. The `toSVG()` method automatically selects the best size based on the requested dimensions:
117
+
118
+ ```javascript
119
+ // Request height 16 - uses 16px variant
120
+ icon.toSVG({ height: 16 });
121
+
122
+ // Request height 24 - uses 24px variant
123
+ icon.toSVG({ height: 24 });
124
+
125
+ // Request height 20 - uses closest available (16px scaled up)
126
+ icon.toSVG({ height: 20 });
127
+ ```
128
+
129
+ ## Icon Name Aliasing (Deprecation Notice)
130
+
131
+ Apollo Icons supports legacy icon names (called "apollo names") alongside the current naming convention (called "nucleo names"). **Apollo names are deprecated** and will be removed in the next major release.
132
+
133
+ ### Deprecation Warnings
134
+
135
+ When you access an icon using a deprecated apollo name, you'll see a console warning:
136
+
137
+ ```javascript
138
+ // Using a deprecated apollo name
139
+ const icon = octicons['ai'];
140
+ // Console warning: [octicons] Deprecation warning: Icon name "ai" is deprecated
141
+ // and will be removed in the next major release. Please use "add-magic" instead.
142
+
143
+ // Using the recommended nucleo name (no warning)
144
+ const icon = octicons['add-magic'];
145
+ ```
146
+
147
+ **Note:** Each deprecated name only warns once per session to avoid console spam.
148
+
149
+ ### Migrating from Apollo Names
150
+
151
+ If you're using deprecated apollo names, update them to nucleo names:
152
+
153
+ ```javascript
154
+ // ❌ Deprecated (apollo names)
155
+ octicons['ai'];
156
+ octicons['search'];
157
+ octicons['home'];
158
+ octicons['mail'];
159
+ octicons['edit'];
160
+
161
+ // ✅ Recommended (nucleo names)
162
+ octicons['add-magic'];
163
+ octicons['magnifier'];
164
+ octicons['house-4'];
165
+ octicons['envelope'];
166
+ octicons['compose-2'];
167
+ ```
168
+
169
+ ### Checking Icon Availability
170
+
171
+ Both naming conventions work with the `in` operator:
172
+
173
+ ```javascript
174
+ 'ai' in octicons; // true (but deprecated)
175
+ 'add-magic' in octicons; // true (recommended)
176
+ ```
177
+
178
+ ### Using getIcon() During Migration
179
+
180
+ The `getIcon()` helper supports both naming conventions and provides a safe way to check icon availability:
181
+
182
+ ```javascript
183
+ // Works with both naming conventions
184
+ const icon1 = octicons.getIcon('ai'); // Warns about deprecation
185
+ const icon2 = octicons.getIcon('add-magic'); // No warning
186
+
187
+ // Returns undefined for non-existent icons
188
+ const icon3 = octicons.getIcon('non-existent'); // undefined
189
+ ```
190
+
191
+ ## API Reference
192
+
193
+ ### `octicons[iconName]`
194
+
195
+ Access an icon by its name. Returns an `Icon` object.
196
+
197
+ ```javascript
198
+ const icon = octicons['calendar-refresh'];
199
+ ```
200
+
201
+ **Note:** Supports both nucleo names (recommended) and apollo names (deprecated with warnings).
202
+
203
+ ### `octicons.getIcon(name: string): Icon | undefined`
204
+
205
+ Get an icon by name with safe undefined handling. Returns the `Icon` object if found, or `undefined` if not found.
206
+
207
+ ```javascript
208
+ const icon = octicons.getIcon('calendar-refresh');
209
+ if (icon) {
210
+ console.log(icon.toSVG());
211
+ }
212
+ ```
213
+
214
+ **Note:** Supports both nucleo names (recommended) and apollo names (deprecated with warnings).
215
+
216
+ ### `octicons.getIconsByTag(tag: string): Icon[]`
217
+
218
+ Returns an array of all icons that include the specified tag in their keywords.
219
+
220
+ ```javascript
221
+ const audioIcons = octicons.getIconsByTag('audio');
222
+ ```
223
+
224
+ ### `Icon.toSVG(options?: SVGOptions): string`
225
+
226
+ Generates an SVG string for the icon.
227
+
228
+ **Options:**
229
+
230
+ | Option | Type | Description |
231
+ | ------------ | -------- | ---------------------------------------- |
232
+ | `width` | `number` | Width of the SVG in pixels |
233
+ | `height` | `number` | Height of the SVG in pixels |
234
+ | `class` | `string` | Additional CSS classes to add |
235
+ | `aria-label` | `string` | Accessible label (removes `aria-hidden`) |
package/build/build.css CHANGED
@@ -1,6 +1,6 @@
1
1
  .octicon {
2
2
  display: inline-block;
3
3
  vertical-align: text-top;
4
- fill: currentColor;
4
+ stroke: currentColor;
5
5
  overflow: visible;
6
6
  }