Skip to content

CratisComponentsProvider

Single setup point for Cratis Components. Wraps PrimeReact’s PrimeReactProvider so the package can layer Cratis-wide defaults on top of PrimeReact’s pass-through and unstyled mechanisms while still letting the consumer take complete control.

  • Hosts the PrimeReact pt / unstyled / ptOptions / inputStyle / ripple / appendTo / zIndex / locale configuration for every Cratis wrapper below it in the tree.

  • Deep-merges Cratis-wide defaults with the consumer’s value, so future Cratis defaults can land without breaking consumer overrides.

  • Re-exported from the package root so the recommended setup is one import:

    import { CratisComponentsProvider } from '@cratis/components';

Mount once at the root of your tree:

import '@cratis/components/styles';
import { CratisComponentsProvider } from '@cratis/components';
export const App = () => (
<CratisComponentsProvider>
<YourApp />
</CratisComponentsProvider>
);

The value prop accepts the full PrimeReact APIOptions shape. The most commonly used members are unstyled, pt, ptOptions, inputStyle, ripple, and appendTo:

import { CratisComponentsProvider } from '@cratis/components';
import { globalPt } from './pt-preset';
export const App = () => (
<CratisComponentsProvider value={{ unstyled: true, pt: globalPt }}>
<YourApp />
</CratisComponentsProvider>
);

The value is deep-merged with the Cratis defaults (currently empty) so consumer settings always win. Pass a stable reference (a module-level constant or a useMemo result) to avoid unnecessary re-renders.

Partial<APIOptions> — Cratis-wide and PrimeReact pass-through configuration. Merged on top of the library’s defaults and made available to every Cratis component below in the tree.

The most useful members:

MemberPurpose
unstyledWhen true, disables every PrimeReact base style. Combine with pt (or per-component CSS / Tailwind) to fully restyle.
ptPer-component pass-through configuration. Keys are PrimeReact component names (button, dialog, inputtext, …); values are slot configuration objects.
ptOptionsControls merge vs. replace behavior for pt. Default is { mergeSections: true } which merges per-instance pt with the global preset.
inputStyle'outlined' or 'filled' — switches the default input rendering across the whole app.
rippleEnables PrimeReact’s ripple animation on supported components.
appendToWhere overlays mount (document.body, 'self', or a DOM ref). The Cratis Dropdown defaults to document.body independently of this setting.
zIndexPer-overlay-type z-index baseline ({ modal: 1100, overlay: 1000, … }).
localePrimeReact locale string.

The full type is re-exported as CratisComponentsConfig.

React.ReactNode — your application tree.

CratisComponentsProvider is optional. If you’d rather mount PrimeReact’s own provider directly, that works too — every Cratis wrapper reads the same context:

import { PrimeReactProvider } from 'primereact/api';
export const App = () => (
<PrimeReactProvider value={{ unstyled: true, pt: globalPt }}>
<YourApp />
</PrimeReactProvider>
);

The Cratis provider exists to give Cratis one place to layer in defaults later without breaking consumers, and to keep the setup discoverable from a single import path.

Pure helpers (testing / library extension)

Section titled “Pure helpers (testing / library extension)”

The merge logic is exported so the contract can be verified without rendering React:

import { mergeCratisComponentsConfig, cratisDefaults } from '@cratis/components';
const merged = mergeCratisComponentsConfig({ unstyled: true, pt: myPt });
// → { ...cratisDefaults, unstyled: true, pt: myPt }
ExportDescription
CratisComponentsProviderThe React component.
CratisComponentsProviderPropsProps type.
CratisComponentsConfigAlias for Partial<APIOptions>.
cratisDefaultsThe Cratis-wide defaults that ship today (currently {}).
mergeCratisComponentsConfigPure deep-merge helper used inside the provider.