import React, { PropsWithChildren, Fragment } from 'react';
import { HTMLSourceInline } from 'react-native-render-html';
import { ToolkitProvider, UIToolkitConfig } from '@doc/pages';
import { WEBSITE_BASE } from '@doc/constants';
const Chapter = ({ children, title }: PropsWithChildren<{ title: string }>) => (
{title}
{children}
);
const Header = ({ children }: PropsWithChildren<{}>) => (
{children}
);
function normalizeUrl(url: string, fragment?: string) {
const normalizedFragment = fragment ? `#${fragment}` : '';
if (url.startsWith('/')) {
return WEBSITE_BASE + url.substr(1) + normalizedFragment;
}
return WEBSITE_BASE + url + normalizedFragment;
}
export default function MdxToolkitProvider({
children: toolkitChildren
}: PropsWithChildren<{}>) {
const config: UIToolkitConfig = {
Chapter,
Section: ({ children, title }) => (
{title}
{children}
),
Header,
List: ({ children, type = 'decimal' }) => (
{children}
),
ListItem: ({ children }) => {children},
Paragraph: ({ children }) => {children}
,
Bold: ({ children }) => {children},
RenderHtmlCard: ({
caption,
snippet,
expoSource,
title,
props,
preferHtmlSrc,
extraneousDeps,
snapshot
}) => {
const html = (props.source as HTMLSourceInline).html;
return (
);
},
SourceDisplay: (props) => ,
TNodeTransformDisplay: ({ snaphost, ...props }) => {
return ;
},
Admonition: ({ children, type, title }) => (
{children}
),
RefBuilder: ({ name, url, type }) => {
return ;
},
RefDoc: ({ target, children, fragment }) => {
const linkFragments =
target.group === 'root'
? ['/docs', target.id]
: ['/docs', target.group, target.id];
return (
);
},
Acronym: ({ fullName, name, definition }) => (
),
SvgFigure: ({ asset, description, title }) => (
),
InlineCode: ({ children }) => {children},
Hyperlink: ({ children, url }) => {children},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
RefAPI: ({ library, name, url, member, full, plural }) => {
const isRNProp = url.match(/^\/api\/renderhtmlprops/);
return (
);
},
DList: ({ children }) => {children}
,
DListTitle: ({ children }) => {children},
DListItem: ({ children }) => {children},
Conditional: ({ platform, children }) =>
platform === 'web' ? {children} : null
};
return {toolkitChildren};
}