MoraineProvider
Configure application-wide or subtree theme overrides, class merging, locale, text direction, and translated messages.
MoraineProvider supplies shared configuration to descendant Moraine components without rendering
an extra DOM element. It is optional: without a provider, components use their built-in recipes,
the default class merger, and the en-US locale.
Basic setup#
Wrap your application root—or any subtree that needs different settings—in MoraineProvider:
Props#
| Prop | Type | Default | Behavior when omitted (undefined) |
|---|---|---|---|
theme |
MoraineTheme | null |
null |
Inherits parent provider’s theme. |
cnConfig |
CnConfig |
Default cn | Inherits parent provider’s merger. |
locale |
string |
'en-US'* |
Inherits parent provider’s locale. |
detectLocale |
boolean |
true* |
Inherits parent provider’s locale. |
dir |
'ltr' | 'rtl' | null |
Document | Inherits parent direction. |
messages |
Partial message groups** | English | Inherits parent messages. |
children |
JSX.Element |
— | Descendants receiving this context. |
* On a root provider with no explicit locale, detectLocale defaults to true. SSR and the
first client render always use en-US, and after hydration the root provider follows
navigator.language and the languagechange event. Setting locale disables detectLocale.
** Type it as MoraineProviderProps['messages']; see Localization
for the groups and keys.
Nesting and reset rules#
Each prop follows an explicit inheritance rule when you nest a MoraineProvider inside another:
theme: Passing a new theme replaces the parent theme (themes are not merged). Passtheme={null}to clear inherited overrides and fall back to built-in recipes. Instanceclasses,styles,class, andstyleprops still override the theme.cnConfig: Passing an object creates a merger from Moraine’s defaults plus that config (it does not merge with the parent’scnConfig). PasscnConfig={{}}to restore the defaults.localeanddetectLocale: A nested provider inherits the parent locale unless it setslocaleor explicitly opts intodetectLocale.dir: Passing'ltr'or'rtl'overrides component behavior (keyboard navigation, popup placement, slider/tab arrows) without adding adirattribute to descendants; setdiron<html>for document layout. Passdir={null}to reset back to document detection.messages: Partial message packs deep-merge over the parent provider’s messages, so nested providers only need to declare the keys they override.
Related guides#
- Theming — authoring themes with
defineTheme(), dynamic switching, and portals. - Class Merging — configuring
cnConfig,createCn, anduseCn(). - Localization — built-in locales,
messageskeys, and RTL layout. - Server-Side Rendering — hydration-safe locale detection and server locale passing.