status-web/packages/icons/svgr.config.js

67 lines
1.5 KiB
JavaScript
Raw Normal View History

function transformImports(arr) {
arr.forEach(object => {
if (object.source && object.source.value === 'react-native-svg') {
2023-03-13 20:47:52 +00:00
object.specifiers.forEach((specifier, index) => {
if (specifier.type === 'ImportDefaultSpecifier') {
specifier.type = 'ImportSpecifier'
specifier.imported = specifier.local
}
2023-03-13 20:47:52 +00:00
if (specifier.imported.name === 'IconProps') {
object.specifiers.splice(index, 1)
}
})
}
})
2023-03-13 20:47:52 +00:00
}
function replaceSvgPropsWithIconProps(node) {
node[0].typeAnnotation.typeAnnotation.typeName.name = 'IconProps'
}
const template = (variables, { tpl }) => {
2023-03-13 20:47:52 +00:00
replaceSvgPropsWithIconProps(variables.props)
transformImports(variables.imports)
return tpl`
2023-03-13 20:47:52 +00:00
${variables.imports};
import { useTheme } from '@tamagui/core';
import { IconProps } from '../types';
${variables.interfaces};
const ${variables.componentName} = (${variables.props}) => {
2023-03-13 20:47:52 +00:00
const { color: token = '$neutral-100' } = props
const theme = useTheme();
2023-03-13 20:47:52 +00:00
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const color = theme[token]?.val ?? token
return (
${variables.jsx}
)
};
${variables.exports};
`
}
const COLORS = ['#09101C']
module.exports = {
typescript: true,
jsxRuntime: 'automatic',
native: true,
replaceAttrValues: {
...COLORS.reduce((acc, color) => {
acc[color] = '{color}'
return acc
}, {}),
},
outDir: '.',
filenameCase: 'kebab',
template,
}