diff --git a/ui-icons/scripts/build.js b/ui-icons/scripts/build.js index 6322389d..0703fa0b 100755 --- a/ui-icons/scripts/build.js +++ b/ui-icons/scripts/build.js @@ -123,6 +123,7 @@ const sizesContent = `export default ${JSON.stringify(sizes)}` writeFileSync(sizesFile, sizesContent) // Loop over the representation to generate React component files for each icon +let typeNames = [] for (const [name, currentData] of Object.entries(representation)) { const supportedVariants = Object.keys(currentData) @@ -141,7 +142,8 @@ for (const [name, currentData] of Object.entries(representation)) { }) const iconPropsContent = definitions.map(([name, content]) => `${content}\n`).join('\n') const iconsPropsTypeUnion = definitions.map(([name]) => name).join(' | ') - const iconPropsExport = `export type IconReplaceNameProps = ${iconsPropsTypeUnion}` + const iconPropsExport = `export type IconReplaceNameProps = ${iconsPropsTypeUnion}` + '\n' + + 'export type IconReplaceNameIcon = React.FC' let file = componentTemplate .replace( @@ -159,13 +161,12 @@ for (const [name, currentData] of Object.entries(representation)) { // Append the current icon's export statement to the index file appendFileSync( indexFile, - `export { default as ${name} } from './components/${name}'\n` + `export { ${name} } from './components/${name}'\n` + + `import type { ${name}Icon } from './components/${name}'\n` ) + typeNames.push(`${name}Icon`) } - -// Add generic icon type appendFileSync( indexFile, - `export type { GenericIconType } from './types/generic-icon-type'\n` + `export type UiIcon = ${typeNames.join(' | ')}\n` ) - diff --git a/ui-icons/src/components/_template.tsx b/ui-icons/src/components/_template.tsx index dda99b6c..8b4a4d9b 100644 --- a/ui-icons/src/components/_template.tsx +++ b/ui-icons/src/components/_template.tsx @@ -6,7 +6,7 @@ const iconData: IconData = {} //ReplaceWithTypes -const IconReplaceName: React.FC = ({ variant = 'base', size = 'sm', title }) => { +const IconReplaceName: IconReplaceNameIcon = ({ variant = 'base', size = 'sm', title }) => { const currentSize = sizes[size] if (!iconData[variant]) { throw new Error(`IconReplaceName: variant ${variant} not found.`) @@ -31,4 +31,5 @@ const IconReplaceName: React.FC = ({ variant = 'base', siz ) } -export default IconReplaceName; +export { IconReplaceName } +export default IconReplaceName diff --git a/ui-icons/src/types/generic-icon-type.ts b/ui-icons/src/types/generic-icon-type.ts deleted file mode 100644 index 95af3b5f..00000000 --- a/ui-icons/src/types/generic-icon-type.ts +++ /dev/null @@ -1,5 +0,0 @@ -export type GenericIconType = (props: { - variant?: string; - size?: string; - title?: string; -}) => JSX.Element;