-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow to transform SVG component name (#55)
* build: add `@svgr/babel-plugin-transform-svg-component` dependency * feat!: provide SVG component name transformer to SVG plugin * test: add tests for SVG component name transformations * docs: update `README.md` * chore: add changesets
- Loading branch information
Showing
33 changed files
with
592 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
'@tabula/forge': minor | ||
--- | ||
|
||
added support of transformation of SVG component name with `svgrComponentName` option. | ||
|
||
By default, SVGR uses `Svg<CamelCaseFileName>` name for components. You can override this behaviour through | ||
`svgrComponentName` options, which should be function of format `(svgrName: string) => string`. | ||
|
||
Example: | ||
|
||
```js | ||
export default { | ||
// ... | ||
svgrComponentName(name) { | ||
return `Ui${name.slice(3)}Icon`; | ||
}, | ||
// ... | ||
}; | ||
``` | ||
|
||
If you have a file `column.svg` then component name is `SvgColumn` by default. But with config from about the name | ||
will be `UiColumnIcon`. | ||
|
||
If you use memoization it looks like: | ||
|
||
```js | ||
import { memo } from 'react'; | ||
|
||
const UiColumnIcon = (props) => { | ||
// ... | ||
}; | ||
|
||
const Memo = memo(UiColumnIcon); | ||
|
||
export { Memo as ReactComponent }; | ||
``` | ||
|
||
This option doesn't affect named exports. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.