Skip to content

Commit

Permalink
fix(ffe-symbols-react): legg til typings for symbol
Browse files Browse the repository at this point in the history
BREAKING CHANGE: I forrige versjon som ble feilmarkert som minor.
Endringen innebærer at symbolnavn settes via ikon-prop og ikke children-prop.
  • Loading branch information
HeleneKassandra committed Nov 3, 2023
1 parent 48137fe commit 2a93040
Show file tree
Hide file tree
Showing 4 changed files with 3,348 additions and 1 deletion.
18 changes: 18 additions & 0 deletions packages/ffe-symbols-react/scripts/fetchSymbolNames.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Fetches all the icon names by using the codepoints in the font */
const fetchSymbolNames = async () => {
let folderNames = [];
const url =
'https://raw.githubusercontent.com/google/material-design-icons/master/variablefont/MaterialSymbolsRounded%5BFILL%2CGRAD%2Copsz%2Cwght%5D.codepoints';
const response = await fetch(url);
const data = await response.text();

const lines = data.split('\n');
const names = lines
.filter(line => line.trim() !== '')
.map(line => `'${line.split(' ')[0]}'`);
folderNames = [...folderNames, ...names];

return folderNames;
};

module.exports = fetchSymbolNames;
29 changes: 29 additions & 0 deletions packages/ffe-symbols-react/scripts/generateSymbolTypings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
This function is manually triggered, and will fetch all the names of the symbols.
The names are then gathered in an array that is used for typescript typings in the symbols component.
Important to only run this when we update the icon-font files, as we might sometimes be out of sync with whats
the latest in material icons.
*/
const path = require('path');
const fs = require('fs').promises;
const fetchSymbolNames = require('./fetchSymbolNames');

const writeToFile = async (filePath, content) => {
try {
await fs.writeFile(filePath, content);
console.log('File written successfully');
} catch (error) {
console.error('Error writing file:', error);
}
};

const generateSymbolTypings = async () => {
const symbolNames = await fetchSymbolNames();
const fileContent = `export type SymbolName = ${symbolNames.join(' | ')}`;
const filePath = path.join(__dirname, '../src/typings/symbolNames.ts');

await writeToFile(filePath, fileContent);
};

generateSymbolTypings();
3 changes: 2 additions & 1 deletion packages/ffe-symbols-react/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { SymbolName } from './typings/symbolNames.ts';

export interface SymbolProps {
fill?: boolean;
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | '2xl';
weight?: 300 | 400 | 500;
icon: string;
icon: SymbolName;
className?: string;
ariaLabel?: string;
}
Expand Down
Loading

0 comments on commit 2a93040

Please sign in to comment.