Skip to content

Components and styles

Use a component map to change selected Markdown elements, and a stylesheet to adjust the site's appearance. Select both through docskit.config.ts:

TypeScript
components: "./components/mdx-components.tsx",
styles: ["./styles/theme.css"],

Create the files at those paths in your docs project.

Override a Markdown element

Export a default map from components/mdx-components.tsx:

components/mdx-components.tsxTSX
import type { MDXComponents } from "@pinanek/docskit";

export default {
  h2: (props) => <h2 {...props} className="guide-heading" />,
} satisfies MDXComponents;

The map is merged with the built-in components. This example replaces h2 and keeps the other defaults. A replacement takes responsibility for that element's markup and behavior; replacing a heading also replaces its built-in heading component.

Custom anchor components receive document URLs after Docskit resolves Markdown filename links. Preserve the supplied href when rendering an anchor.

Add a component to Markdown pages

You can also expose a named React component in the map:

components/mdx-components.tsxTSX
import type { MDXComponents } from "@pinanek/docskit";
import type { ReactNode } from "react";

function CommandNote({ children }: { children?: ReactNode }) {
  return <aside className="command-note">{children}</aside>;
}

export default {
  CommandNote,
} satisfies MDXComponents;

Then use it in an .md file:

content/guides/commands.md — page bodymdx
<CommandNote>Run commands from your project root.</CommandNote>

Keep the page's required title and description frontmatter above that body.

Add styles

Custom styles load after the package's styles. Override semantic tokens or style classes introduced by your components:

styles/theme.cssCSS
:root {
  --c-accent: var(--c-cpn-teal);
}

.command-note {
  margin-block: 1.5rem;
  padding: 1rem;
  border-inline-start: 3px solid var(--c-accent);
  background: var(--c-bg-subtle);
  color: var(--c-text);
}

Tokens include --c-text, --c-bg, --font-sans, and --font-mono. Check both light and dark themes when changing colors. Use logical properties such as padding-inline when the layout should follow the document's writing direction.

Share components with snapshots

Documentation snapshots freeze Markdown and navigation. Components and styles come from the current project. Keep your component props compatible with older Markdown pages while those versions are published.

Run pnpm check for TypeScript component checks and pnpm build to render the pages that use them. To inspect a working project, open the repository's custom homepage example. The package exports reference lists the public components available for advanced customization.