File tree Expand file tree Collapse file tree 3 files changed +48
-3
lines changed
packages/react-notion-x/src Expand file tree Collapse file tree 3 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import { ExtendedRecordMap } from 'notion-types'
5
5
import { AssetWrapper } from './components/asset-wrapper'
6
6
import { Checkbox as DefaultCheckbox } from './components/checkbox'
7
7
import { Header } from './components/header'
8
- import { wrapNextImage , wrapNextLink } from './next'
8
+ import { wrapNextImage , wrapNextLegacyImage , wrapNextLink } from './next'
9
9
import {
10
10
MapImageUrlFn ,
11
11
MapPageUrlFn ,
@@ -199,8 +199,20 @@ export const NotionContextProvider: React.FC<PartialNotionContext> = ({
199
199
[ themeComponents ]
200
200
)
201
201
202
- if ( wrappedThemeComponents . nextImage ) {
202
+ if (
203
+ wrappedThemeComponents . nextImage &&
204
+ wrappedThemeComponents . nextLegacyImage
205
+ ) {
206
+ console . warn (
207
+ 'You should not pass both nextImage and nextLegacyImage. Only nextImage component will be used.'
208
+ )
203
209
wrappedThemeComponents . Image = wrapNextImage ( themeComponents . nextImage )
210
+ } else if ( wrappedThemeComponents . nextImage ) {
211
+ wrappedThemeComponents . Image = wrapNextImage ( themeComponents . nextImage )
212
+ } else if ( wrappedThemeComponents . nextLegacyImage ) {
213
+ wrappedThemeComponents . Image = wrapNextLegacyImage (
214
+ themeComponents . nextLegacyImage
215
+ )
204
216
}
205
217
206
218
if ( wrappedThemeComponents . nextLink ) {
Original file line number Diff line number Diff line change @@ -10,6 +10,38 @@ export const wrapNextImage = (NextImage: any): React.FC<any> => {
10
10
width,
11
11
height,
12
12
13
+ className,
14
+
15
+ fill,
16
+
17
+ ...rest
18
+ } ) {
19
+ if ( fill === 'undefined' ) {
20
+ fill = ! ( width && height )
21
+ }
22
+
23
+ return (
24
+ < NextImage
25
+ className = { className }
26
+ src = { src }
27
+ alt = { alt }
28
+ width = { ! fill && width && height ? width : undefined }
29
+ height = { ! fill && width && height ? height : undefined }
30
+ fill = { fill }
31
+ { ...rest }
32
+ />
33
+ )
34
+ } , isEqual )
35
+ }
36
+
37
+ export const wrapNextLegacyImage = ( NextLegacyImage : any ) : React . FC < any > => {
38
+ return React . memo ( function ReactNotionXNextLegacyImage ( {
39
+ src,
40
+ alt,
41
+
42
+ width,
43
+ height,
44
+
13
45
className,
14
46
style,
15
47
@@ -22,7 +54,7 @@ export const wrapNextImage = (NextImage: any): React.FC<any> => {
22
54
}
23
55
24
56
return (
25
- < NextImage
57
+ < NextLegacyImage
26
58
className = { className }
27
59
src = { src }
28
60
alt = { alt }
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ export interface NotionComponents {
59
59
60
60
// optional next.js-specific overrides
61
61
nextImage ?: any
62
+ nextLegacyImage ?: any
62
63
nextLink ?: any
63
64
}
64
65
You can’t perform that action at this time.
0 commit comments