fix: <Media/> show fallback

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei
2024-08-12 23:07:53 +08:00
parent 4f429a9f2b
commit ca0fd1802c
2 changed files with 12 additions and 4 deletions
+11 -4
View File
@@ -14,6 +14,7 @@ const failedList = new Set<string | undefined>()
type BaseProps = {
mediaContainerClassName?: string
showFallback?: boolean
}
export type MediaProps = BaseProps &
(
@@ -47,7 +48,7 @@ const MediaImpl: FC<MediaProps> = ({
mediaContainerClassName,
...props
}) => {
const { src, style, type, previewImageUrl, ...rest } = props
const { src, style, type, previewImageUrl, showFallback, ...rest } = props
const [hidden, setHidden] = useState(!src)
const [imgSrc, setImgSrc] = useState(() =>
proxy && src && !failedList.has(src) ?
@@ -198,7 +199,9 @@ const MediaImpl: FC<MediaProps> = ({
type,
])
if (hidden) return <FallbackMedia {...props} />
if (hidden) {
if (showFallback) { return <FallbackMedia {...props} /> } else { return null }
}
return (
<div className={cn("overflow-hidden rounded", className)} style={style}>
{InnerContent}
@@ -232,9 +235,13 @@ const FallbackMedia: FC<MediaProps> = ({
<p className="flex items-center gap-1">
Go to
{" "}
<a href={props.src} target="_blank" rel="noreferrer" className="follow-link--underline">
<a
href={props.src}
target="_blank"
rel="noreferrer"
className="follow-link--underline"
>
{props.src}
</a>
<i className="i-mgc-external-link-cute-re" />
</p>
+1
View File
@@ -156,6 +156,7 @@ const Img: Components["img"] = ({ node, ...props }) => {
mediaContainerClassName: tw`max-w-full inline size-auto`,
popper: true,
className: tw`inline`,
showFallback: true,
})
}