Skip to content

Commit 9a8efd4

Browse files
committed
update parse script to maintain set classname
1 parent a5ffaf6 commit 9a8efd4

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

packages/react-icons/scripts/parseRHIcons.mjs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ const ICON_TYPES = [
1818
// Add new types here as they become available in @rhds/icons
1919
];
2020

21+
const ICON_TYPE_CLASSES = {
22+
ui: '',
23+
standard: 'pf-v6-icon-rh-standard',
24+
// social: '',
25+
microns: ''
26+
};
27+
2128
const __dirname = path.dirname(fileURLToPath(import.meta.url));
2229
const require = createRequire(import.meta.url);
2330

@@ -106,10 +113,11 @@ async function processSvgFile(iconName, iconType) {
106113
/**
107114
* Formats an object as an ES module export with proper formatting.
108115
* @param {object} obj The object to format.
116+
* @param {string} iconType The set of the icon.
109117
* @param {number} indent The indentation level.
110118
* @returns {string} Formatted module string.
111119
*/
112-
function formatModule(obj, indent = 0) {
120+
function formatModule(obj, iconType, indent = 0) {
113121
const spaces = ' '.repeat(indent);
114122
const entries = Object.entries(obj);
115123
if (entries.length === 0) {
@@ -130,6 +138,11 @@ function formatModule(obj, indent = 0) {
130138
lines.push(`${spaces} width: ${value.width},`);
131139
lines.push(`${spaces} height: ${value.height},`);
132140

141+
// Handle set-specific svgClassName
142+
if (ICON_TYPE_CLASSES[iconType]) {
143+
lines.push(`${spaces} svgClassName: '${ICON_TYPE_CLASSES[iconType]}',`);
144+
}
145+
133146
// Handle svgPathData: string or array of objects
134147
if (Array.isArray(value.svgPathData)) {
135148
// Array of path objects with { path: string } structure
@@ -223,7 +236,7 @@ async function processSVGs() {
223236
// Capitalize first letter, and handle special case for 'ui' -> 'UI'
224237
const capitalizedType = iconType === 'ui' ? 'UI' : iconType.charAt(0).toUpperCase() + iconType.slice(1);
225238
const outputFile = path.join(OUTPUT_DIR, `rhIcons${capitalizedType}.mjs`);
226-
const moduleOutput = `export default ${formatModule(iconsObject)};\n`;
239+
const moduleOutput = `export default ${formatModule(iconsObject, iconType)};\n`;
227240
await fs.writeFile(outputFile, moduleOutput, 'utf-8');
228241
console.log(`Output written to: ${outputFile}`);
229242
}

0 commit comments

Comments
 (0)