@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
117 lines • 4.74 kB
text/typescript
import * as React from 'react';
import type { Code, CodeHighlighterProps, ContentLoadingProps, ContentProps, LoadCodeMeta, LoadSource, LoadVariantMeta, ParseSource, SourceEnhancers } from "../CodeHighlighter/types.mjs";
import { type DemoGlobalData } from "../createDemoData/types.mjs";
type CreateDemoMeta = {
name?: string;
slug?: string;
displayName?: string;
variantType?: string;
skipPrecompute?: boolean;
highlightAfter?: CodeHighlighterProps<{}>['highlightAfter'];
enhanceAfter?: CodeHighlighterProps<{}>['enhanceAfter'];
editActivation?: CodeHighlighterProps<{}>['editActivation'];
precompute?: Code;
ClientProvider?: React.ComponentType<{
children: React.ReactNode;
}>;
/**
* Render this demo "collapse to empty": the code block collapses to an empty
* window (whole block hidden until expanded). Mirrors the demo component's
* `collapseToEmpty` prop, and sets the default for `<Demo>` renders.
*/
collapseToEmpty?: boolean;
/**
* Opt this demo out of a factory `collapseToEmpty` default, collapsing to the
* focus window instead. Mirrors the demo component's `showCollapsedFocus` prop.
*/
showCollapsedFocus?: boolean;
/**
* Whether this demo's (collapsible) code block starts expanded. Mirrors the
* demo component's `initialExpanded` prop, and sets the default for `<Demo>`
* renders.
*/
initialExpanded?: boolean;
/**
* Opt this demo out of a factory `initialExpanded` default, starting
* collapsed instead. Mirrors the demo component's `initialCollapsed` prop.
*/
initialCollapsed?: boolean;
};
type AbstractCreateDemoOptions<T extends {}> = {
DemoContent: React.ComponentType<ContentProps<T>>;
DemoContentLoading?: React.ComponentType<ContentLoadingProps<T>>;
DemoTitle?: React.ComponentType<{
slug?: string;
children?: string;
}>;
controlled?: boolean;
demoGlobalData?: DemoGlobalData[];
variantTypes?: Record<string, string>;
highlightAfter?: CodeHighlighterProps<{}>['highlightAfter'];
enhanceAfter?: CodeHighlighterProps<{}>['enhanceAfter'];
editActivation?: CodeHighlighterProps<{}>['editActivation'];
fallbackUsesExtraFiles?: boolean;
fallbackUsesAllVariants?: boolean;
loadCodeMeta?: LoadCodeMeta;
loadVariantMeta?: LoadVariantMeta;
loadSource?: LoadSource;
sourceParser?: Promise<ParseSource>;
sourceEnhancers?: SourceEnhancers;
/**
* Default every demo from this factory to "collapse to empty": the code block
* collapses to an empty window (hidden until expanded). Individual demos opt
* out with `meta.showCollapsedFocus` / `meta.collapseToEmpty: false`, or per
* render with `<Demo showCollapsedFocus />`.
*/
collapseToEmpty?: boolean;
/**
* Default every demo from this factory to start expanded. Individual demos
* override with `meta.initialExpanded: false` or `<Demo initialExpanded={false} />`.
*/
initialExpanded?: boolean;
/**
* `file://` URL of the project root used to resolve `url`s gathered from
* `import.meta.url`. Combined with `projectUrl` to rewrite local `file://`
* URLs into hosted Git URLs (e.g.
* `https://github.com/owner/repo/tree/<branch>/`) before they reach the
* `CodeHighlighter`.
*
* Typically read from an environment variable populated by the build
* pipeline (e.g. `process.env.SOURCE_CODE_ROOT_DIR` from
* `withDeploymentConfig`). When either `projectDir` or `projectUrl` is
* missing, URLs are left untouched.
*/
projectDir?: string;
/**
* Public URL prefix that maps to `projectDir`. See `projectDir` for
* details.
*/
projectUrl?: string;
};
export declare function abstractCreateDemo<T extends {}>(options: AbstractCreateDemoOptions<T>, url: string, variants: {
[key: string]: React.ComponentType;
}, meta: CreateDemoMeta | undefined): React.ComponentType<T & {
collapseToEmpty?: boolean;
showCollapsedFocus?: boolean;
initialExpanded?: boolean;
initialCollapsed?: boolean;
}> & {
Title: React.ComponentType;
};
export declare function createDemoFactory<T extends {}>(options: AbstractCreateDemoOptions<T>): (url: string, component: React.ComponentType, meta?: CreateDemoMeta) => React.ComponentType<T & {
collapseToEmpty?: boolean;
showCollapsedFocus?: boolean;
initialExpanded?: boolean;
initialCollapsed?: boolean;
}> & {
Title: React.ComponentType;
};
export declare function createDemoWithVariantsFactory<T extends {}>(options: AbstractCreateDemoOptions<T>): (url: string, variants: Record<string, React.ComponentType>, meta?: CreateDemoMeta) => React.ComponentType<T & {
collapseToEmpty?: boolean;
showCollapsedFocus?: boolean;
initialExpanded?: boolean;
initialCollapsed?: boolean;
}> & {
Title: React.ComponentType;
};
export {};