diff options
Diffstat (limited to 'frontend/src/components/Markdown.tsx')
| -rw-r--r-- | frontend/src/components/Markdown.tsx | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/frontend/src/components/Markdown.tsx b/frontend/src/components/Markdown.tsx index 7b187f14..278e49cd 100644 --- a/frontend/src/components/Markdown.tsx +++ b/frontend/src/components/Markdown.tsx @@ -1,9 +1,42 @@ -import { FunctionComponent } from 'react'; +import { Focusable } from 'decky-frontend-lib'; +import { FunctionComponent, useRef } from 'react'; import ReactMarkdown, { Options as ReactMarkdownOptions } from 'react-markdown'; import remarkGfm from 'remark-gfm'; -const Markdown: FunctionComponent<ReactMarkdownOptions> = (props) => { - return <ReactMarkdown remarkPlugins={[remarkGfm]} {...props} />; +interface MarkdownProps extends ReactMarkdownOptions { + onDismiss?: () => void; +} + +const Markdown: FunctionComponent<MarkdownProps> = (props) => { + return ( + <Focusable> + <ReactMarkdown + remarkPlugins={[remarkGfm]} + components={{ + div: (nodeProps) => <Focusable {...nodeProps.node.properties}>{nodeProps.children}</Focusable>, + a: (nodeProps) => { + const aRef = useRef<HTMLAnchorElement>(null); + return ( + // TODO fix focus ring + <Focusable + onActivate={() => {}} + onOKButton={() => { + aRef?.current?.click(); + props.onDismiss?.(); + }} + style={{ display: 'inline' }} + > + <a ref={aRef} {...nodeProps.node.properties}> + {nodeProps.children} + </a> + </Focusable> + ); + }, + }} + {...props} + /> + </Focusable> + ); }; export default Markdown; |
