Skip to content

Commit

Permalink
ui-icons: add union of icons, remove generic type
Browse files Browse the repository at this point in the history
  • Loading branch information
ElysaSrc committed Feb 5, 2024
1 parent d5f773a commit 0a5ebc6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
13 changes: 7 additions & 6 deletions ui-icons/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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<IconReplaceNameProps>'

let file = componentTemplate
.replace(
Expand All @@ -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`
)

5 changes: 3 additions & 2 deletions ui-icons/src/components/_template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const iconData: IconData = {}

//ReplaceWithTypes

const IconReplaceName: React.FC<IconReplaceNameProps> = ({ 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.`)
Expand All @@ -31,4 +31,5 @@ const IconReplaceName: React.FC<IconReplaceNameProps> = ({ variant = 'base', siz
)
}

export default IconReplaceName;
export { IconReplaceName }
export default IconReplaceName
5 changes: 0 additions & 5 deletions ui-icons/src/types/generic-icon-type.ts

This file was deleted.

0 comments on commit 0a5ebc6

Please sign in to comment.