Skip to content

Commit

Permalink
Custom icon and SVG handling (#20)
Browse files Browse the repository at this point in the history
Adds custom highlight icon
Defines types for SVG imports
Configures SVG Mocking in Jest
Injects custom SVG loader into Storybook config

---------

Co-authored-by: jackson <Jackson Hyde>
  • Loading branch information
jacksonhyde authored Jul 11, 2024
1 parent a2f67bb commit 8560ed9
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 36,542 deletions.
28 changes: 28 additions & 0 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,34 @@ const config: StorybookConfig = {

typescript: {
reactDocgen: 'react-docgen-typescript'
},
webpackFinal: async config => {
// Grab the existing rule that handles SVG imports
const fileLoaderRule = config.module?.rules?.find((rule) =>
(rule as { test?: RegExp })?.test?.test(".svg")
) as { [key: string]: any }

config.module?.rules?.push(
// Reapply the existing rule, but only for svg imports ending in ?url
{
...fileLoaderRule,
test: /\.svg$/i,
resourceQuery: /url/ // *.svg?url
},
// Convert all other *.svg imports to React components
{
test: /\.svg$/i,
issuer: fileLoaderRule.issuer,
resourceQuery: {
not: [...(fileLoaderRule?.resourceQuery?.not || []), /url/]
}, // exclude if *.svg?url
use: ["@svgr/webpack"]
}
)
// Modify the file loader rule to ignore *.svg, since we have it handled now.
fileLoaderRule.exclude = /\.svg$/i

return config
}
};
export default config;
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,6 @@ module.exports = {
// watchman: true,
moduleNameMapper: {
".(css|less|scss)$": "identity-obj-proxy",
"\\.svg": "<rootDir>/src/components/__mocks__/SvgMock.js",
},
};
Loading

0 comments on commit 8560ed9

Please sign in to comment.