-
Notifications
You must be signed in to change notification settings - Fork 71
Bumps svgr from v5 to v8 #3163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Bumps svgr from v5 to v8 #3163
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/** | ||
* LeafyGreen template transformation for SVGR-generated components | ||
* This replaces the previous inline regex with a more maintainable template approach | ||
*/ | ||
|
||
export function applyLeafyGreenTemplate( | ||
svgrOutput: string, | ||
componentName: string, | ||
): string { | ||
// This pattern matches the standard SVGR TypeScript output structure | ||
const svgrPattern = | ||
/import \* as React from "react";\nimport type \{ SVGProps \} from "react";\nconst (\w+) = \(props: SVGProps<SVGSVGElement>\) => (.*?);\nexport default \1;/s; | ||
|
||
const leafyGreenTemplate = `import * as React from 'react'; | ||
import { css, cx } from '@leafygreen-ui/emotion'; | ||
import { generateAccessibleProps, sizeMap } from '../glyphCommon'; | ||
import { LGGlyph } from '../types'; | ||
|
||
export interface $1Props extends LGGlyph.ComponentProps {} | ||
|
||
const $1 = ({ | ||
className, | ||
size = 16, | ||
title, | ||
'aria-label': ariaLabel, | ||
'aria-labelledby': ariaLabelledby, | ||
fill, | ||
role = 'img', | ||
...props | ||
}: $1Props) => { | ||
const fillStyle = css\` | ||
color: \${fill}; | ||
\`; | ||
|
||
const noFlexShrink = css\` | ||
flex-shrink: 0; | ||
\`; | ||
|
||
const accessibleProps = generateAccessibleProps(role, '${componentName}', { | ||
title, | ||
'aria-label': ariaLabel, | ||
'aria-labelledby': ariaLabelledby | ||
}); | ||
|
||
const svgElement = $2; | ||
|
||
return React.cloneElement(svgElement, { | ||
className: cx( | ||
{ | ||
[fillStyle]: fill != null, | ||
}, | ||
noFlexShrink, | ||
className, | ||
), | ||
height: typeof size === 'number' ? size : sizeMap[size], | ||
width: typeof size === 'number' ? size : sizeMap[size], | ||
role, | ||
...accessibleProps, | ||
...props, | ||
}); | ||
}; | ||
|
||
$1.displayName = '${componentName}'; | ||
$1.isGlyph = true; | ||
|
||
export default $1;`; | ||
|
||
return svgrOutput.replace(svgrPattern, leafyGreenTemplate); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this just moves the brittle string replacement to a separate file. We should use the transform
Config.template
propertyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed Cursor has difficulty doing this. There's a weird bug/quirk in the
tpl
function where it doesn't like when you concat words after interpolated var names.If you tell cursor to do that it works:
e.g. instead of
${variables.componentName}Props)
use${variables.componentName + "Props)"}