-
Notifications
You must be signed in to change notification settings - Fork 5
/
svg-template.js
39 lines (37 loc) · 1.2 KB
/
svg-template.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* This template allows us to modify the generated React component template.
*/
function template(
{ template },
_,
{ imports, componentName, props, jsx, exports }
) {
jsx.openingElement.attributes = [
...jsx.openingElement.attributes,
{
type: 'JSXAttribute',
name: { type: 'JSXIdentifier', name: 'viewBox' },
value: { type: 'StringLiteral', value: '0 0 24 24' },
},
// Currently documentation folks at LifeOmic use `data-icon` to identify
// which icon is being used so they can import it in their app
{
type: 'JSXAttribute',
name: { type: 'JSXIdentifier', name: 'data-icon' },
value: { type: 'StringLiteral', value: componentName.name },
},
// For our generated React components, we think this makes sense
// to do by default: https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques/Using_the_aria-hidden_attribute
{
type: 'JSXAttribute',
name: { type: 'JSXIdentifier', name: 'aria-hidden' },
value: { type: 'StringLiteral', value: 'true' },
},
];
return template.ast`
${imports}
const ${componentName} = (${props}) => ${jsx}
${exports}
`;
}
module.exports = template;