Skip to content

Commit 511f952

Browse files
committed
[render] Add img component
1 parent dd67c06 commit 511f952

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

packages/render/src/block.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { A } from "./components/html/a"
1010
import { Toggle } from "./components/toggle"
1111
import { PageTitle } from "./components/page-title"
1212
import { Code } from "./components/html/code"
13+
import { Img } from "./components/html/img"
1314

1415
const defaultFormatDateFn = (date: Date) => date.toString()
1516
const defaultResolveLinkFn = (nId: string) => null
@@ -26,6 +27,7 @@ export const Render = ({
2627
a?: (props: React.ComponentPropsWithoutRef<"a">) => JSX.Element
2728
code?: (props: React.ComponentPropsWithoutRef<"code">) => JSX.Element
2829
iframe?: (props: React.ComponentPropsWithoutRef<"iframe">) => JSX.Element
30+
img?: (props: React.ComponentPropsWithoutRef<"img">) => JSX.Element
2931
}
3032
}
3133
}) => {
@@ -36,6 +38,7 @@ export const Render = ({
3638
a: options?.htmlComponents?.a ?? A,
3739
code: options?.htmlComponents?.code ?? Code,
3840
iframe: options?.htmlComponents?.iframe,
41+
img: options?.htmlComponents?.img ?? Img,
3942
},
4043
}
4144
return (
@@ -293,7 +296,11 @@ const Block = ({ block, options }: { block: BlockObjectResponseWithChildren; opt
293296
// ref: .notion-asset-wrapper
294297
// note: original breakpoint for max-w: `only screen and (max-width: 730px)`
295298
<figure className="my-2 w-full">
296-
<img src={imageUrl} alt={imageHasCaption ? block.image.caption[0].plain_text : "image"} className="rounded" />
299+
<options.htmlComponents.img
300+
src={imageUrl}
301+
alt={imageHasCaption ? block.image.caption[0].plain_text : "image"}
302+
className="rounded"
303+
/>
297304
{imageHasCaption ? (
298305
// ref: .notion-asset-caption
299306
<figcaption className="whitespace-pre-wrap break-words py-1.5 ps-0.5 text-sm leading-[1.4] text-[color:var(--fg-color-3)] caret-[color:var(--fg-color)]">
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const Img = ({ ...props }: React.ComponentPropsWithoutRef<"img">) => {
2+
return <img {...props} />
3+
}

packages/render/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ export type RenderOptions = {
1616
a: (props: React.ComponentPropsWithoutRef<"a">) => JSX.Element
1717
code: (props: React.ComponentPropsWithoutRef<"code">) => JSX.Element
1818
iframe?: (props: React.ComponentPropsWithoutRef<"iframe">) => JSX.Element
19+
img: (props: React.ComponentPropsWithoutRef<"img">) => JSX.Element
1920
}
2021
}

0 commit comments

Comments
 (0)