diff --git a/code/addons/docs/src/DocsRenderer.tsx b/code/addons/docs/src/DocsRenderer.tsx index cd9ae48c262b..1940a2a0e25b 100644 --- a/code/addons/docs/src/DocsRenderer.tsx +++ b/code/addons/docs/src/DocsRenderer.tsx @@ -48,6 +48,8 @@ export class DocsRenderer { ...docsParameter?.components, }; + const TDocs = Docs as typeof Docs; + return new Promise((resolve, reject) => { import('@mdx-js/react') .then(({ MDXProvider }) => @@ -55,7 +57,7 @@ export class DocsRenderer { renderElement( - + , element diff --git a/code/ui/blocks/src/blocks/Docs.tsx b/code/ui/blocks/src/blocks/Docs.tsx index fdda86fcc5dd..25f20f31dcc5 100644 --- a/code/ui/blocks/src/blocks/Docs.tsx +++ b/code/ui/blocks/src/blocks/Docs.tsx @@ -7,13 +7,16 @@ import type { DocsContextProps } from './DocsContext'; import { DocsContainer } from './DocsContainer'; import { DocsPage } from './DocsPage'; -export type DocsProps = { +export type DocsProps = { docsParameter: Parameters; - context: DocsContextProps; + context: DocsContextProps; }; -export const Docs = ({ docsParameter, context }: DocsProps) => { - const Container: ComponentType<{ context: DocsContextProps; theme: Theme }> = +export function Docs({ + context, + docsParameter, +}: DocsProps) { + const Container: ComponentType<{ context: DocsContextProps; theme: Theme }> = docsParameter.container || DocsContainer; const Page = docsParameter.page || DocsPage; @@ -23,4 +26,4 @@ export const Docs = ({ docsParameter, context }: DocsProps ); -}; +} diff --git a/code/ui/blocks/src/blocks/external/ExternalDocs.tsx b/code/ui/blocks/src/blocks/external/ExternalDocs.tsx index 1a05a0d8fd18..869dcf66a5ab 100644 --- a/code/ui/blocks/src/blocks/external/ExternalDocs.tsx +++ b/code/ui/blocks/src/blocks/external/ExternalDocs.tsx @@ -1,4 +1,4 @@ -import type { FunctionComponent } from 'react'; +import type { PropsWithChildren } from 'react'; import React, { useRef } from 'react'; import type { Renderer, ProjectAnnotations } from '@storybook/types'; import { composeConfigs } from '@storybook/preview-api'; @@ -6,28 +6,30 @@ import { composeConfigs } from '@storybook/preview-api'; import { Docs } from '../Docs'; import { ExternalPreview } from './ExternalPreview'; -export type ExternalDocsProps = { - projectAnnotationsList: ProjectAnnotations[]; +export type ExternalDocsProps = { + projectAnnotationsList: ProjectAnnotations[]; }; -function usePreview( - projectAnnotations: ProjectAnnotations +function usePreview( + projectAnnotations: ProjectAnnotations ) { - const previewRef = useRef(); - if (!previewRef.current) previewRef.current = new ExternalPreview(projectAnnotations); + const previewRef = useRef>(); + if (!previewRef.current) previewRef.current = new ExternalPreview(projectAnnotations); return previewRef.current; } -export const ExternalDocs: FunctionComponent = ({ +export function ExternalDocs({ projectAnnotationsList, children, -}) => { - const projectAnnotations = composeConfigs(projectAnnotationsList); - const preview = usePreview(projectAnnotations); +}: PropsWithChildren>) { + const projectAnnotations = composeConfigs(projectAnnotationsList); + const preview = usePreview(projectAnnotations); const docsParameter = { ...projectAnnotations.parameters?.docs, page: () => children, }; - return ; -}; + const TDocs = Docs as typeof Docs; + + return ; +}