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.
- Button loading label
- Spinner label
#Props
| Name | Type | Default | Description | Version |
|---|---|---|---|---|
abstract | boolean | false | Renders no element and only provides context. Ignored, with a warning, when themeMode or themeOverrides is set. | Unreleased |
bordered | boolean | undefined | Default for components that support bordered. | Unreleased |
clsPrefix | string | "p" | Class name prefix. The shipped CSS uses p, so a different prefix also needs CSS built with it. | Unreleased |
componentOptions | Record<string, Record<string, unknown>> | null | undefined | Default props per component, merged over the parent’s per component. null stops inheriting. | Unreleased |
highlighter | CodeHighlighter | undefined | Shiki highlighter for Code, loaded with codeTheme. Pika does not bundle Shiki; see Code. undefined inherits the parent’s. | Unreleased |
katex | EquationRenderer | undefined | KaTeX for Equation (import katex from "katex"). Pika does not bundle KaTeX; see Equation. undefined inherits the parent’s. | Unreleased |
locale | PLocale | null | undefined | UI strings. undefined inherits the parent’s; null resets to enUS. | Unreleased |
namespace | string | undefined | Class added to containers that overlays portal into. | Unreleased |
portalContainer | HTMLElement | null | document.body | Where overlays portal to. | Unreleased |
themeMode | "light" | "dark" | undefined | Light or dark. undefined inherits the parent’s; with no mode set anywhere it is "light". | Unreleased |
themeOverrides | Record<"--p-…", string> | null | undefined | CSS 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.
import { ConfigProvider, createLocale, enUS, zhCN } from "@pika-lab/react";
const enGB = createLocale({ name: "en-GB", global: { cancel: "Dismiss" } }, enUS);
<ConfigProvider locale={zhCN}>…</ConfigProvider>;