Skip to content

ConfigProvider

ConfigProvider configures every raft-ui component below it: theme, 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

A provider that sets theme or themeMode opens a theme scope on its own element. Scopes nest: the inner provider inherits elegant from its parent and only switches the mode.

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 theme, themeMode or themeOverrides is set.Unreleased
borderedbooleanundefinedDefault for components that support bordered.Unreleased
clsPrefixstring"r"Class name prefix. The shipped CSS uses r, 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. raft-ui does not bundle Shiki; see Code. undefined inherits the parent’s.Unreleased
localeRLocale | 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
theme"brutal" | "elegant"undefinedTheme family. undefined inherits the parent’s.Unreleased
themeMode"light" | "dark"undefinedLight or dark. undefined inherits the parent’s.Unreleased
themeOverridesRecord<"--r-…", string> | nullundefinedCSS variables written on the provider’s element, merged over the parent’s. null stops inheriting.Unreleased

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 "raft-ui"; const enGB = createLocale({ name: "en-GB", global: { cancel: "Dismiss" } }, enUS); <ConfigProvider locale={zhCN}>…</ConfigProvider>;