|
1 |
| -export const IconLoader = async () => ({ |
2 |
| - icons: { |
3 |
| - workflow: { |
4 |
| - medium: await import.meta.glob( |
5 |
| - "/node_modules/@adobe/spectrum-css-workflow-icons/dist/18/*.svg", |
| 1 | +import { cleanUiIconName, cleanWorkflowIconName } from "@spectrum-css/icon/stories/utilities.js"; |
| 2 | + |
| 3 | +/** |
| 4 | + * Loads all SVG files from both icon sets, and stores a string with the SVG markup. |
| 5 | + * |
| 6 | + * Excludes "22x20" workflow icons as they are not yet used within the design system. |
| 7 | + * |
| 8 | + * @see https://storybook.js.org/docs/writing-stories/loaders |
| 9 | + * @see https://vite.dev/guide/features#glob-import |
| 10 | + */ |
| 11 | +export const IconLoader = async () => { |
| 12 | + let iconData = { |
| 13 | + icons: { |
| 14 | + workflow: await import.meta.glob( |
| 15 | + [ |
| 16 | + "/node_modules/@adobe/spectrum-css-workflow-icons/dist/assets/svg/*.svg", |
| 17 | + "!/node_modules/@adobe/spectrum-css-workflow-icons/dist/assets/svg/*_22x20*.svg", |
| 18 | + ], |
6 | 19 | {
|
7 | 20 | eager: true,
|
8 | 21 | query: "?raw",
|
9 | 22 | import: "default",
|
10 | 23 | }
|
11 | 24 | ),
|
12 |
| - large: await import.meta.glob( |
13 |
| - "/node_modules/@adobe/spectrum-css-workflow-icons/dist/24/*.svg", |
| 25 | + ui: await import.meta.glob( |
| 26 | + "/node_modules/@spectrum-css/ui-icons/dist/svg/*.svg", |
14 | 27 | {
|
15 | 28 | eager: true,
|
16 | 29 | query: "?raw",
|
17 | 30 | import: "default",
|
18 | 31 | }
|
19 | 32 | ),
|
20 | 33 | },
|
21 |
| - ui: { |
22 |
| - medium: await import.meta.glob( |
23 |
| - "/node_modules/@spectrum-css/ui-icons/dist/medium/*.svg", |
24 |
| - { |
25 |
| - eager: true, |
26 |
| - query: "?raw", |
27 |
| - import: "default", |
28 |
| - } |
29 |
| - ), |
30 |
| - large: await import.meta.glob( |
31 |
| - "/node_modules/@spectrum-css/ui-icons/dist/large/*.svg", |
32 |
| - { |
33 |
| - eager: true, |
34 |
| - query: "?raw", |
35 |
| - import: "default", |
36 |
| - } |
37 |
| - ), |
38 |
| - }, |
39 |
| - }, |
40 |
| -}); |
| 34 | + }; |
| 35 | + |
| 36 | + /** |
| 37 | + * Changes all keys in the IconLoader object to be just the cleaned icon name used within our Storybook's Icon component, |
| 38 | + * instead of the full file name and directory that was loaded. |
| 39 | + * |
| 40 | + * E.g. "/node_modules/@adobe/spectrum-css-workflow-icons/dist/assets/svg/S2_Icon_3DAsset_20_N.svg" would become just "3DAsset". |
| 41 | + */ |
| 42 | + iconData.icons.workflow = Object.fromEntries( |
| 43 | + Object.entries(iconData.icons.workflow).map( |
| 44 | + ([key, value]) => [cleanWorkflowIconName(key.split("/").pop()), value] |
| 45 | + ) |
| 46 | + ); |
| 47 | + |
| 48 | + iconData.icons.ui = Object.fromEntries( |
| 49 | + Object.entries(iconData.icons.ui).map( |
| 50 | + ([key, value]) => [cleanUiIconName(key.split("/").pop()), value] |
| 51 | + ) |
| 52 | + ); |
| 53 | + |
| 54 | + return iconData; |
| 55 | +}; |
0 commit comments