Skip to content

Commit 322c5a1

Browse files
authored
Merge pull request #20334 from dannon/fontawesome-standardization
Standardize FontAwesome usage
2 parents 3210592 + 83a3b63 commit 322c5a1

File tree

169 files changed

+715
-943
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+715
-943
lines changed

client/docs/headings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ Following properties allow for further styling the component:
4949
- `bold` - makes a heading bold
5050
- `inline` - displays the heading inline
5151
- `separator` - draws a separating line, to better distinguish sections
52-
- `icon="..."` - adds a font-awesome icon decoration to the left of the heading. Make sure to also load the icon with `library.add(...)`.
52+
- `icon={iconObject}` - adds an icon to the left of the heading. Import from FontAwesome (`@fortawesome/free-solid-svg-icons`) or Galaxy icons (`@/components/icons/galaxyIcons`).

client/gulpfile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ function stageLibs(callback) {
6666

6767
async function icons() {
6868
await buildIcons("./src/assets/icons.json");
69+
const generateIconsTypeScript = require("./icons/generate_ts_icons");
70+
generateIconsTypeScript();
6971
}
7072

7173
function cleanPlugins(callback) {

client/icons/all-icons.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
# Icons
22

3-
All custom icons available
3+
Galaxy custom icons
44

5-
This file is auto-generated by `build_icons.js`. Manual changes will be lost!
5+
Auto-generated by `build_icons.js`
6+
7+
## Usage
8+
9+
```vue
10+
<script setup>
11+
import { galaxyLogo } from "@/components/icons/galaxyIcons";
12+
</script>
13+
14+
<template>
15+
<FontAwesomeIcon :icon="galaxyLogo" />
16+
</template>
17+
```
618

719
---
820

9-
- `<FontAwesomeIcon :icon="['gxd', 'galaxyLogo']" />`
10-
- `<FontAwesomeIcon :icon="['gxd', 'textLarger']" />`
11-
- `<FontAwesomeIcon :icon="['gxd', 'textSmaller']" />`
21+
- **galaxyLogo**: `import { galaxyLogo } from "@/components/icons/galaxyIcons";`
22+
- **textLarger**: `import { textLarger } from "@/components/icons/galaxyIcons";`
23+
- **textSmaller**: `import { textSmaller } from "@/components/icons/galaxyIcons";`
1224

1325
---

client/icons/build_icons.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,21 @@ function findAllPaths(element) {
9696

9797
function makeMarkdown(iconDefinitions) {
9898
let content = "# Icons\n\n";
99-
content += "All custom icons available\n\n";
100-
content += "This file is auto-generated by `build_icons.js`. Manual changes will be lost!\n\n";
99+
content += "Galaxy custom icons\n\n";
100+
content += "Auto-generated by `build_icons.js`\n\n";
101+
content += "## Usage\n\n";
102+
content += "```vue\n";
103+
content += "<script setup>\n";
104+
content += 'import { galaxyLogo } from "@/components/icons/galaxyIcons";\n';
105+
content += "</script>\n\n";
106+
content += "<template>\n";
107+
content += ' <FontAwesomeIcon :icon="galaxyLogo" />\n';
108+
content += "</template>\n";
109+
content += "```\n\n";
101110
content += "---\n\n";
102111

103112
iconDefinitions.forEach((icon) => {
104-
content += `- \`<FontAwesomeIcon :icon="['${icon.prefix}', '${icon.iconName}']" />\`\n`;
113+
content += `- **${icon.iconName}**: \`import { ${icon.iconName} } from "@/components/icons/galaxyIcons";\`\n`;
105114
});
106115

107116
content += "\n---\n";

client/icons/generate_ts_icons.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
4+
/**
5+
* Generate TypeScript exports for Galaxy custom icons
6+
*/
7+
function generateIconsTypeScript() {
8+
// Read the generated icons JSON
9+
const iconsJsonPath = path.resolve(__dirname, "../src/assets/icons.json");
10+
const outputPath = path.resolve(__dirname, "../src/components/icons/galaxyIcons.ts");
11+
12+
if (!fs.existsSync(iconsJsonPath)) {
13+
console.error(`Icons JSON not found at ${iconsJsonPath}`);
14+
console.error("Run 'npm run icons' first to generate the icons JSON");
15+
return;
16+
}
17+
18+
const iconsJson = fs.readFileSync(iconsJsonPath, "utf8");
19+
const icons = JSON.parse(iconsJson);
20+
21+
// Generate TypeScript content
22+
let content = `import type { IconDefinition } from "@fortawesome/fontawesome-svg-core";
23+
24+
// Galaxy custom icons
25+
// Generated from: client/src/assets/icons.json
26+
// To regenerate: node icons/generate_ts_icons.js
27+
28+
// Matches FontAwesome's structure
29+
export interface GalaxyIconDefinition {
30+
iconName: string;
31+
prefix: string;
32+
icon: [number, number, never[], string, string | string[]];
33+
}
34+
35+
// Accepts both FA and Galaxy icons
36+
export type IconLike = IconDefinition | GalaxyIconDefinition;
37+
38+
`;
39+
40+
icons.forEach((icon) => {
41+
// Convert icon name to camelCase for JavaScript export
42+
const exportName = icon.iconName;
43+
44+
// Format the icon data manually to match the expected style
45+
const iconData = icon.icon;
46+
const formattedIcon = `{
47+
iconName: "${icon.iconName}",
48+
prefix: "${icon.prefix}",
49+
icon: [
50+
${iconData[0]},
51+
${iconData[1]},
52+
[],
53+
"",
54+
[
55+
${iconData[4].map((path) => `"${path}"`).join(",\n ")},
56+
],
57+
],
58+
};`;
59+
60+
content += `export const ${exportName}: GalaxyIconDefinition = ${formattedIcon}
61+
62+
`;
63+
});
64+
65+
// Write the TypeScript file
66+
fs.writeFileSync(outputPath, content.trimEnd() + "\n");
67+
console.log(`Generated Galaxy icons TypeScript exports at: ${outputPath}`);
68+
console.log(`Exported ${icons.length} icons: ${icons.map((i) => i.iconName).join(", ")}`);
69+
}
70+
71+
// Run if called directly
72+
if (require.main === module) {
73+
generateIconsTypeScript();
74+
}
75+
76+
module.exports = generateIconsTypeScript;

client/src/components/AboutGalaxy.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import { computed } from "vue";
66
import { RouterLink } from "vue-router";
77
8+
import { galaxyLogo } from "@/components/icons/galaxyIcons";
89
import { useConfig } from "@/composables/config";
910
import { getAppRoot } from "@/onload/loadConfig";
1011
@@ -29,7 +30,7 @@ const versionUserDocumentationUrl = computed(() => {
2930

3031
<template>
3132
<div v-if="isConfigLoaded" class="about-galaxy">
32-
<Heading h1 :icon="['gxd', 'galaxyLogo']" size="lg">Help and Support</Heading>
33+
<Heading h1 :icon="galaxyLogo" size="lg">Help and Support</Heading>
3334
<div class="p-2">
3435
<Heading h2 separator size="md">Support</Heading>
3536
<div v-if="config.wiki_url">

client/src/components/Citation/CitationItem.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<script setup lang="ts">
2-
import { library } from "@fortawesome/fontawesome-svg-core";
32
import { faExternalLinkAlt } from "@fortawesome/free-solid-svg-icons";
43
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
54
import { computed } from "vue";
65
76
import type { Citation } from ".";
87
9-
library.add(faExternalLinkAlt);
10-
118
interface Props {
129
citation: Citation;
1310
outputFormat?: string;

client/src/components/Collections/common/CellDiscardComponent.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
<script lang="ts">
22
/* cannot use a setup block and get params injection in Vue 2.7 I think */
33
4-
import { library } from "@fortawesome/fontawesome-svg-core";
54
import { faTimes } from "@fortawesome/free-solid-svg-icons";
65
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
76
import type { ICellRendererParams } from "ag-grid-community";
87
import { defineComponent } from "vue";
98
10-
library.add(faTimes);
11-
129
export default defineComponent({
1310
components: {
1411
FontAwesomeIcon,
1512
},
1613
data() {
1714
return {
1815
params: {} as ICellRendererParams,
16+
faTimes,
1917
};
2018
},
2119
computed: {},
@@ -28,7 +26,7 @@ export default defineComponent({
2826
</script>
2927
<template>
3028
<div>
31-
<FontAwesomeIcon size="2x" icon="fa-times" @click="onRemove" />
29+
<FontAwesomeIcon size="2x" :icon="faTimes" @click="onRemove" />
3230
</div>
3331
</template>
3432

client/src/components/Collections/common/CellStatusComponent.vue

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<script lang="ts">
22
/* cannot use a setup block and get params injection in Vue 2.7 I think */
33
4-
import { library } from "@fortawesome/fontawesome-svg-core";
54
import { faCheck, faExclamationTriangle } from "@fortawesome/free-solid-svg-icons";
65
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
76
import type { ICellRendererParams } from "ag-grid-community";
87
import { BPopover } from "bootstrap-vue";
98
import { defineComponent } from "vue";
109
11-
library.add(faCheck, faExclamationTriangle);
12-
1310
export default defineComponent({
1411
components: {
1512
BPopover,
@@ -18,6 +15,8 @@ export default defineComponent({
1815
data() {
1916
return {
2017
params: {} as ICellRendererParams,
18+
faCheck,
19+
faExclamationTriangle,
2120
};
2221
},
2322
computed: {
@@ -48,9 +47,9 @@ export default defineComponent({
4847
},
4948
icon() {
5049
if (this.isDuplicate || this.requiresPairing) {
51-
return "fa-exclamation-triangle";
50+
return this.faExclamationTriangle;
5251
} else {
53-
return "fa-check";
52+
return this.faCheck;
5453
}
5554
},
5655
},

client/src/components/Collections/common/CollectionEditView.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<script setup lang="ts">
2-
import { library } from "@fortawesome/fontawesome-svg-core";
3-
import { faBars, faCog, faDatabase, faSave, faTable, faUser } from "@fortawesome/free-solid-svg-icons";
2+
import { faBars, faCog, faDatabase, faSave, faTable } from "@fortawesome/free-solid-svg-icons";
43
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
54
import axios from "axios";
65
import { BAlert, BSpinner, BTab, BTabs } from "bootstrap-vue";
@@ -26,8 +25,6 @@ import Heading from "@/components/Common/Heading.vue";
2625
import FormDisplay from "@/components/Form/FormDisplay.vue";
2726
import LoadingSpan from "@/components/LoadingSpan.vue";
2827
29-
library.add(faBars, faCog, faDatabase, faSave, faTable, faUser);
30-
3128
interface Props {
3229
collectionId: string;
3330
}

0 commit comments

Comments
 (0)