File tree Expand file tree Collapse file tree 4 files changed +55
-7
lines changed
components/FeedbackWidget Expand file tree Collapse file tree 4 files changed +55
-7
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,9 @@ const config: StorybookConfig = {
47
47
} ,
48
48
} ,
49
49
webpackFinal : async ( config ) => {
50
+ config . module = config . module || { }
51
+ config . module . rules = config . module . rules || [ ]
52
+
50
53
if ( config . resolve ) {
51
54
config . resolve . plugins = [
52
55
...( config . resolve . plugins || [ ] ) ,
@@ -55,6 +58,22 @@ const config: StorybookConfig = {
55
58
} ) ,
56
59
]
57
60
}
61
+
62
+ // This modifies the existing image rule to exclude .svg files
63
+ // since you want to handle those files with @svgr /webpack
64
+ const imageRule = config . module . rules . find ( ( rule ) =>
65
+ rule ?. [ "test" ] ?. test ( ".svg" )
66
+ )
67
+ if ( imageRule ) {
68
+ imageRule [ "exclude" ] = / \. s v g $ /
69
+ }
70
+
71
+ // Configure .svg files to be loaded with @svgr /webpack
72
+ config . module . rules . push ( {
73
+ test : / \. s v g $ / ,
74
+ use : [ "@svgr/webpack" ] ,
75
+ } )
76
+
58
77
return config
59
78
} ,
60
79
typescript : {
Original file line number Diff line number Diff line change @@ -27,10 +27,31 @@ module.exports = (phase, { defaultConfig }) => {
27
27
test : / \. y a ? m l $ / ,
28
28
use : "yaml-loader" ,
29
29
} )
30
- config . module . rules . push ( {
31
- test : / \. s v g $ / ,
32
- use : "@svgr/webpack" ,
33
- } )
30
+
31
+ // SVG loader
32
+ // Grab the existing rule that handles SVG imports
33
+ const fileLoaderRule = config . module . rules . find ( ( rule ) =>
34
+ rule . test ?. test ?. ( ".svg" )
35
+ )
36
+
37
+ config . module . rules . push (
38
+ // Reapply the existing rule, but only for svg imports ending in ?url
39
+ {
40
+ ...fileLoaderRule ,
41
+ test : / \. s v g $ / i,
42
+ resourceQuery : / u r l / , // *.svg?url
43
+ } ,
44
+ // Convert all other *.svg imports to React components
45
+ {
46
+ test : / \. s v g $ / i,
47
+ issuer : fileLoaderRule . issuer ,
48
+ resourceQuery : { not : [ ...fileLoaderRule . resourceQuery . not , / u r l / ] } , // exclude if *.svg?url
49
+ use : [ "@svgr/webpack" ] ,
50
+ }
51
+ )
52
+
53
+ // Modify the file loader rule to ignore *.svg, since we have it handled now.
54
+ fileLoaderRule . exclude = / \. s v g $ / i
34
55
35
56
return config
36
57
} ,
Original file line number Diff line number Diff line change 1
1
declare module "*.svg" {
2
- import { ReactElement , SVGProps } from "react"
3
- const content : ( props : SVGProps < SVGElement > ) => ReactElement
2
+ import { FC , SVGProps } from "react"
3
+ const content : FC < SVGProps < SVGElement > >
4
+ export default content
5
+ }
6
+
7
+ declare module "*.svg?url" {
8
+ const content : unknown
4
9
export default content
5
10
}
Original file line number Diff line number Diff line change @@ -40,7 +40,10 @@ const FeedbackWidget = () => {
40
40
/>
41
41
</ PopoverTrigger >
42
42
43
- < PopoverContent className = "mx-2 w-80 max-w-[calc(100vw_-_1rem)] rounded bg-background p-4 sm:p-8" >
43
+ < PopoverContent
44
+ className = "mx-2 w-80 max-w-[calc(100vw_-_1rem)] rounded bg-background p-4 sm:p-8"
45
+ data-testid = "feedback-widget-modal"
46
+ >
44
47
< div className = "flex items-start gap-2" >
45
48
< header className = "me-0 flex-1 p-0 text-xl font-bold" >
46
49
{ feedbackSubmitted
You can’t perform that action at this time.
0 commit comments