grafana/packages/grafana-icons/templates/icon.cjs
Ashley Harrison 47f8717149
React: Use new JSX transform (#88802)
* update eslint, tsconfig + esbuild to handle new jsx transform

* remove thing that breaks the new jsx transform

* remove react imports

* adjust grafana-icons build

* is this the correct syntax?

* try this

* well this was much easier than expected...

* change grafana-plugin-configs webpack config

* fixes

* fix lockfile

* fix 2 more violations

* use path.resolve instead of require.resolve

* remove react import

* fix react imports

* more fixes

* remove React import

* remove import React from docs

* remove another react import
2024-06-25 12:43:47 +01:00

47 lines
954 B
JavaScript

/**
* Modify the JSX to use the IconBase component as a wrapper
*/
const modifyJSX = (jsx) => {
jsx.openingElement.name.name = 'IconBase';
jsx.openingElement.attributes = [
...jsx.openingElement.attributes,
{
type: 'JSXSpreadAttribute',
argument: {
type: 'Identifier',
name: 'props',
},
},
];
jsx.closingElement.name.name = 'IconBase';
return jsx;
};
const comments = `
// This is an auto-generated file, created by svgr-cli.
// Do not edit this file manually.
// To update the component, modify the template in templates/icon.js.
// Run "yarn generate" to update.
`;
const imports = `
import { memo } from 'react';
import { IconBase, IconProps } from '../IconBase';
`;
const template = ({ exports, jsx, componentName }, { tpl }) => {
return tpl`
${comments}
${imports}
const ${componentName} = (props: IconProps) => (
${modifyJSX(jsx)}
);
${exports};
`;
};
module.exports = template;