feat: collapsible event references in chat

This commit is contained in:
2023-08-02 18:59:01 +02:00
parent a11eeef698
commit 08d554aa8f
11 changed files with 246 additions and 53 deletions

View File

@ -4,12 +4,17 @@ import { useMemo } from "react";
import ReactMarkdown from "react-markdown";
import { HyperText } from "element/hypertext";
import { transformText, type Fragment } from "element/text";
import {
transformText,
type Fragment,
type NostrComponents,
} from "element/text";
import type { Tags } from "types";
interface MarkdownProps {
content: string;
tags?: Tags;
customComponents?: NostrComponents;
}
interface LinkProps {
@ -21,20 +26,36 @@ interface ComponentProps {
children?: Array<Fragment>;
}
export function Markdown({ content, tags = [] }: MarkdownProps) {
export function Markdown({
content,
tags = [],
customComponents,
}: MarkdownProps) {
const components = useMemo(() => {
return {
li: ({ children, ...props }: ComponentProps) => {
return children && <li {...props}>{transformText(children, tags)}</li>;
return (
children && (
<li {...props}>
{transformText(children, tags, customComponents)}
</li>
)
);
},
td: ({ children }: ComponentProps) => {
return children && <td>{transformText(children, tags)}</td>;
return (
children && <td>{transformText(children, tags, customComponents)}</td>
);
},
th: ({ children }: ComponentProps) => {
return children && <th>{transformText(children, tags)}</th>;
return (
children && <th>{transformText(children, tags, customComponents)}</th>
);
},
p: ({ children }: ComponentProps) => {
return children && <p>{transformText(children, tags)}</p>;
return (
children && <p>{transformText(children, tags, customComponents)}</p>
);
},
a: ({ href, children }: LinkProps) => {
return href && <HyperText link={href}>{children}</HyperText>;