Skip to content

ConfigProvider

Use ConfigProvider once near the root of your app to set what every Pika component below it shares: light or dark mode, theme overrides, the language of built-in strings, default props and where overlays mount. Nest another one to change any of these for one part of the page, such as a dark sidebar. Components also work without one, with the defaults.

ConfigProvider configures every Pika component below it: theme mode, theme overrides, locale, component defaults, class prefix and where overlays mount. Each field is merged over the nearest parent provider, so providers can be nested.

Demos

Nested theme scopes

Pika has two modes, light and dark. Light is the default, also when no provider sets a mode. A provider that sets themeMode or themeOverrides opens a theme scope: it writes data-p-theme-mode="light" or "dark" on its own element, and the tokens below it follow that mode. Scopes nest: here a light scope holds a nested dark scope.

Theme overrides

themeOverrides writes CSS variables onto the provider’s element. Tokens derived from an overridden base token follow it.

Locale

locale sets the UI strings for everything below the provider. Switch between zhCN and enUS: the loading button and the spinner announce their state to screen readers in the chosen language. Strings a locale leaves out fall back to enUS.

Props

NameTypeDefaultDescriptionVersion
abstractbooleanfalseRenders no element and only provides context. Ignored, with a warning, when themeMode or themeOverrides is set.Unreleased
borderedbooleanundefinedDefault for components that support bordered.Unreleased
clsPrefixstring"p"Class name prefix. The shipped CSS uses p, so a different prefix also needs CSS built with it.Unreleased
componentOptionsRecord<string, Record<string, unknown>> | nullundefinedDefault props per component, merged over the parent’s per component. null stops inheriting.Unreleased
highlighterCodeHighlighterundefinedShiki highlighter for Code, loaded with codeTheme. Pika does not bundle Shiki; see Code. undefined inherits the parent’s.Unreleased
katexEquationRendererundefinedKaTeX for Equation (import katex from "katex"). Pika does not bundle KaTeX; see Equation. undefined inherits the parent’s.Unreleased
localePLocale | nullundefinedUI strings. undefined inherits the parent’s; null resets to enUS.Unreleased
namespacestringundefinedClass added to containers that overlays portal into.Unreleased
portalContainerHTMLElement | nulldocument.bodyWhere overlays portal to.Unreleased
themeMode"light" | "dark"undefinedLight or dark. undefined inherits the parent’s; with no mode set anywhere it is "light".Unreleased
themeOverridesRecord<"--p-…", string> | nullundefinedCSS variables written on the provider’s element, merged over the parent’s. null stops inheriting.Unreleased

Removed: theme

The theme prop, the ThemeName type and the Brutal theme have been removed. This is a breaking change: delete theme="…" from your providers and use themeMode only. The data-p-theme attribute is gone too; style scopes with [data-p-theme-mode] instead.

Locales

enUS and zhCN ship with the package. createLocale(partial, fallback) completes a partial locale from a full one, namespace by namespace.

tsx
import { ConfigProvider, createLocale, enUS, zhCN } from "@pika-lab/react"; const enGB = createLocale({ name: "en-GB", global: { cancel: "Dismiss" } }, enUS); <ConfigProvider locale={zhCN}>…</ConfigProvider>;