Files
xrpl-dev-portal/@theme/components/MarkdownLink.tsx
2026-08-21 12:32:11 -07:00

29 lines
1.1 KiB
TypeScript

import React, { useCallback, useContext } from 'react';
import type { ComponentProps, ReactElement } from 'react';
import { MarkdownLinkContext } from '@redocly/theme/core/contexts';
import { Link as RouterLink } from '@redocly/theme/components/Link/Link';
import { linkClassName } from '../../shared/components/Link/Link';
// Overrides @redocly/theme's default MarkdownLink so plain markdown links get
// Link's class scheme, keeping client-side routing. intention="neutral" per
// design direction (docs/technical content stays black, not brand green).
type MarkdownLinkProps = Omit<ComponentProps<typeof RouterLink>, 'to' | 'onClick'> & {
href: string;
};
export function MarkdownLink({ href, className, ...props }: MarkdownLinkProps): ReactElement {
const markdownLinkContext = useContext(MarkdownLinkContext);
const onClick = useCallback(() => {
markdownLinkContext?.onMarkdownLinkClick?.(href);
}, [markdownLinkContext, href]);
const linkProps = {
...props,
languageInsensitive: true,
onClick,
className: linkClassName({ variation: 'inline', intention: 'neutral', className }),
};
return <RouterLink to={href} {...linkProps} />;
}