@sit-onyx/icons 1.0.0-beta.7 → 1.0.0-beta.8
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/dist/index.js +52 -0
- package/dist/metadata.json +2796 -0
- package/dist/types.js +1 -0
- package/package.json +8 -4
- package/src/assets/cloud-files.svg +1 -0
- package/src/assets/folder-file.svg +1 -0
- package/src/metadata.json +8 -0
package/dist/index.js
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
export {
|
2
|
+
/**
|
3
|
+
* Metadata for all available onyx icons.
|
4
|
+
*/
|
5
|
+
default as ICON_METADATA, } from "./metadata.json";
|
6
|
+
/**
|
7
|
+
* Groups all available icon metadata by category.
|
8
|
+
* Categories and icons will be sorted alphabetically.
|
9
|
+
*/
|
10
|
+
export const groupIconsByCategory = (iconMetadata) => {
|
11
|
+
const categories = Object.entries(iconMetadata).reduce((categories, [iconName, metadata]) => {
|
12
|
+
const icons = categories[metadata.category] ?? [];
|
13
|
+
icons.push({ iconName, metadata });
|
14
|
+
categories[metadata.category] = icons;
|
15
|
+
return categories;
|
16
|
+
}, {});
|
17
|
+
const sortedCategories = {};
|
18
|
+
Object.keys(categories)
|
19
|
+
.sort()
|
20
|
+
.forEach((category) => {
|
21
|
+
const sortedMetadata = categories[category].slice().sort((a, b) => {
|
22
|
+
return a.iconName.localeCompare(b.iconName);
|
23
|
+
});
|
24
|
+
sortedCategories[category] = sortedMetadata;
|
25
|
+
});
|
26
|
+
return sortedCategories;
|
27
|
+
};
|
28
|
+
/**
|
29
|
+
* Transform an icon name to its corresponding JavaScript import name.
|
30
|
+
*
|
31
|
+
* @example
|
32
|
+
* ```ts
|
33
|
+
* "bell-disabled" => "bellDisabled"
|
34
|
+
* // e.g. used as 'import bellDisabled from "@sit-onyx/icons/bell-disabled.svg?raw"'
|
35
|
+
* ```
|
36
|
+
*/
|
37
|
+
export const getIconImportName = (iconName) => {
|
38
|
+
return iconName
|
39
|
+
.split("-")
|
40
|
+
.map((word, index) => {
|
41
|
+
if (index === 0)
|
42
|
+
return word;
|
43
|
+
return capitalize(word);
|
44
|
+
})
|
45
|
+
.join("");
|
46
|
+
};
|
47
|
+
/**
|
48
|
+
* Capitalizes the first character of the given string.
|
49
|
+
*/
|
50
|
+
export const capitalize = (value) => {
|
51
|
+
return value.charAt(0).toUpperCase() + value.slice(1);
|
52
|
+
};
|