Skip to content

Commit

Permalink
fix(ffe-symbols-react): wip legg til typings for symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
HeleneKassandra committed Nov 1, 2023
1 parent 48137fe commit 180673a
Show file tree
Hide file tree
Showing 3 changed files with 1,046 additions and 1 deletion.
42 changes: 42 additions & 0 deletions packages/ffe-symbols-react/scripts/generateSymbolTypings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
This function is manually triggered, and will fetch all the names of the folders in the "symbols/web" folder
in the official material design icons repository.
The names are gathered in an array that is used for 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');

const fetchAllSymbolNames = () => {
const reqUrl =
'https://api.github.com/repos/google/material-design-icons/contents/symbols/web';

return fetch(reqUrl)
.then(response => {
if (response.ok) return response.json();
else {
throw new Error(
'Failed to fetch the content of the repository',
);
}
})
.then(data => {
const folderNames = data
.filter(item => item.type === 'dir')
.map(item => item.name);

let fileContent = `const symbolNames = ' + JSON.stringify(folderNames) + ' as const;
export type SymbolName = (typeof symbolNames)[number];`;
fs.writeFileSync(
'../src/typings/symbolNames.ts',
'export type SymbolName = ' + JSON.stringify(folderNames),
);

return folderNames;
})
.catch(error => console.error(error));
};

fetchAllSymbolNames();
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 180673a

Please sign in to comment.