import React from 'react'; import { type CSSObject } from 'restyle'; import type { Languages } from '../../utils/get-language.ts'; import { type CopyButtonProps } from '../CopyButton/index.ts'; import { type LineNumbersProps } from './LineNumbers.tsx'; import { type TokensProps } from './Tokens.tsx'; import type { AnnotationRenderers } from './Tokens.tsx'; import { type ToolbarProps } from './Toolbar.tsx'; import { type PathLike } from '../../utils/path.ts'; import { type SlotComponentOrProps } from '../../utils/slot-components.ts'; export interface CodeBlockBaseProps { /** Name or path of the code block. Ordered file names will be stripped from the name e.g. `01.index.tsx` becomes `index.tsx`. */ path?: PathLike; /** The base directory to use when analyzing the source code. This will read the local file system contents from the `baseDirectory` joined with the `path` prop instead of creating a virtual file. */ baseDirectory?: PathLike; /** Language of the source code provided to the `Tokens` component. When `path` is defined, the file extension will be used to determine the language by default. */ language?: Languages; /** A string of comma separated lines and ranges to highlight e.g. `'1, 3-5, 7'`. */ highlightedLines?: string; /** A string of comma separated lines and ranges to focus e.g. `'6-8, 12'`. */ focusedLines?: string; /** Opacity of unfocused lines when using `focusedLines`. */ unfocusedLinesOpacity?: number; /** Show or hide a button that copies the source code to the clipboard. Accepts a boolean or a string that will be copied. */ allowCopy?: boolean | string; /** Whether or not to allow errors. Accepts a boolean or comma-separated list of allowed error codes. */ allowErrors?: boolean | string; /** Show or hide error diagnostics. */ showErrors?: boolean; /** Show or hide line numbers. */ showLineNumbers?: boolean; /** Show or hide the toolbar. */ showToolbar?: boolean; /** Whether or not to analyze the source code for type errors and provide quick information on hover. */ shouldAnalyze?: boolean; /** Whether or not to format the source code using `prettier` if installed. */ shouldFormat?: boolean; /** Annotation renderers used to transform inline or block annotations. */ annotations?: AnnotationRenderers; /** Override the default component renderers. */ components?: Partial; } export interface CodeBlockComponentOverrides { Container: SlotComponentOrProps & { css?: CSSObject; }>; Toolbar: SlotComponentOrProps; Pre: SlotComponentOrProps & { css?: CSSObject; }>; LineNumbers: SlotComponentOrProps; Code: SlotComponentOrProps & { css?: CSSObject; }>; Tokens: SlotComponentOrProps; CopyButton: SlotComponentOrProps; } export interface CodeBlockComponents { Container: React.ComponentType & { css?: CSSObject; }>; Toolbar: React.ComponentType; Pre: React.ComponentType & { css?: CSSObject; }>; LineNumbers: React.ComponentType; Code: React.ComponentType & { css?: CSSObject; }>; Tokens: React.ComponentType; CopyButton: React.ComponentType; } export type CodeBlockProps = (CodeBlockBaseProps & { /** Pass a code string to highlight or override default rendering using `Tokens`, `LineNumbers`, and `Toolbar` components. */ children: React.ReactNode; }) | (CodeBlockBaseProps & { /** Pass a code string to highlight or override default rendering using `Tokens`, `LineNumbers`, and `Toolbar` components. When omitted, the source text will be loaded from the file system using the `path` and `baseDirectory` props. */ children?: React.ReactNode; /** Name or path of the code block. Ordered file names will be stripped from the name e.g. `01.index.tsx` becomes `index.tsx`. */ path: PathLike; }); /** * Displays syntax-highlighted source code with optional line numbers, toolbar, * copy-to-clipboard button, and error diagnostics. */ export declare function CodeBlock(props: CodeBlockProps | React.ComponentProps<'pre'>): React.JSX.Element;