Cratis Components: build your first command dialog
Cratis Components supplies React command dialogs with form binding, validation state, and dialog lifecycle management for Cratis Arc backends. Build your first dialog: enter an author’s name and submit it with the generated RegisterAuthor command. You will configure the providers, add the name field, and check what happens when the command succeeds or is rejected. The library tutorial then adds the author list and selected author’s books.
This flow uses a generated proxy, the TypeScript class Arc creates so your browser can execute a backend command. Components does not generate that class or start the backend. If you only need to display an array or edit local state, choose a local-data surface instead; the package peer requirements still apply. Chronicle is not required.
Prerequisites
Section titled “Prerequisites”- A React 19 application built with TypeScript. Components declares
reactandreact-dom^19.0.0as peers. - An Arc frontend with generated proxies and
experimentalDecorators/emitDecoratorMetadataenabled. The Arc tutorial’s first slice sets up the project,tsconfig.json, and Vite proxy that this page assumes. @cratis/arcand@cratis/arc.reactin the range>=20.3.1 <26. This checkout pins its Arc development dependencies to 25.3.1. The wider peer range is not a claim that every accepted version is exercised.- If you use strict Yarn PnP with
@cratis/arc.react@22.6.2, apply the version-specific workaround before installing.
Keep the Arc backend running and retain the Arc tutorial’s development-server routing. The examples below use its .NET/JVM proxy paths. Check that src/Authors/RegisterAuthor.ts exports the generated RegisterAuthor command with required id and name. The later table chapter also needs AllAuthors from src/Authors/Author.ts. If an export is missing, finish the backend slice and regenerate proxies rather than writing a substitute command class. For Arc’s TypeScript backend, use the different *.proxy.ts paths described in the first slice instead of copying these imports.
Install and wire it up
Section titled “Install and wire it up”-
Install Components.
Install Components 4 npm install @cratis/components@^4React Aria, the internationalized date implementation, and React Icons are internal dependencies. The package does not depend on PrimeReact or any other UI kit or theme runtime, and you don’t configure an icon package. The optional MUI and PrimeReact integrations are separate renderer adapter packages.
The package requires React, Arc, Fundamentals, and
reflect-metadataas peers.tsyringeis an optional peer: Components never imports it, and Arc React installs it as its own dependency. Keep@cratis/arcand@cratis/arc.reacton the same version your generated proxies were produced with. A strict installer can install the required peers explicitly (replace the Arc version with the one your backend uses):Install explicit peers ARC_VERSION=23.0.0npm install @cratis/components@^4 \"@cratis/arc@$ARC_VERSION" "@cratis/arc.react@$ARC_VERSION" \@cratis/fundamentals@^7.19.2 react@^19 react-dom@^19 \reflect-metadata@0.2.2Use Arc 22.16.0 or newer if you plan to use
AutoCommandForm’s explicit field binding.pixi.js@^8.20.0is another optional peer, needed only if you useCanvasorPivotViewer. Every other component needs nothing beyond the required peers above; install Pixi later, when you reach a spatial workspace or card-grid screen. See Choosing a component. -
Create the CSS entry file, keeping the package imports in this order:
src/index.css @import '@cratis/components/tokens';@import '@cratis/components/styles';@import '@cratis/components/theme'; /* optional baseline appearance */Import that local file once from your application entry, alongside
reflect-metadata:src/main.tsx import 'reflect-metadata';import './index.css';import { createRoot } from 'react-dom/client';import { App } from './App';createRoot(document.getElementById('root')!).render(<App />);tokensdefines stable--cratis-*variables with conservative light defaults.stylessupplies component structure in low-priority Cratis CSS layers without applying a global Preflight reset.themeadds automatic and explicit dark mode, forced colors, and themed subtrees.A product with its own design system can omit
theme, map its own variables onto--cratis-*, and customize stabledata-cratis-partelements orptattributes.stylesis every component’s CSS in one file. To download only the surfaces you mount, import@cratis/components/styles/baseplus one<subpath>/stylesentry point per surface instead — see Per-area stylesheets.This CSS-first path avoids TypeScript 6’s
TS2882for direct side-effect imports of the package’s stylesheet subpaths, which ship no type declarations. Keep your bundler’s CSS module types enabled; Vite projects normally referencevite/client. If a non-Vite setup needs a declaration for the local CSS import, adddeclare module '*.css';in a project-included.d.tsfile.Existing applications can retain direct TypeScript imports of the three package stylesheets if they declare those subpaths once, for example in
src/cratis-components-styles.d.ts. These declarations are an alternative to the CSS-first path, not an extra step required by it:src/cratis-components-styles.d.ts declare module '@cratis/components/tokens';declare module '@cratis/components/styles';declare module '@cratis/components/theme'; -
Mount both providers around your application.
<Arc>supplies the command and query runtime the generated proxies use;CratisComponentsProvidersupplies Components’ locale, labels, and optional toast region. The Components provider does not replace<Arc>or configure the backend URL. Keep the Arc connection settings from your application.Librarybelow is the handwritten component you will create later on this page:src/App.tsx import { Arc } from '@cratis/arc.react';import { CratisComponentsProvider } from '@cratis/components';import { Library } from './Library';export const App = () => (<Arc><CratisComponentsProvider value={{ locale: 'en-US' }} toaster><Library /></CratisComponentsProvider></Arc>);
See the payoff
Section titled “See the payoff”CommandDialog takes the generated command, renders its fields and the OK/Cancel footer, keeps Add disabled until the form is valid, disables every button while the command executes, and closes only when the command succeeds:
import { useState } from 'react';import { Guid } from '@cratis/fundamentals';import { CommandDialog } from '@cratis/components/CommandDialog';import { InputTextField } from '@cratis/components/CommandForm';import { RegisterAuthor } from './Authors/RegisterAuthor';
export const AddAuthor = () => { const [id] = useState(() => Guid.create()); return ( <CommandDialog<RegisterAuthor> command={RegisterAuthor} title='Add author' okLabel='Add' initialValues={{ id }} > <InputTextField<RegisterAuthor> value={(command) => command.name} title='Name' /> </CommandDialog> );};The backend requires an id, but the user only enters a name. Put the generated id in initialValues so validation can see it as soon as the dialog opens. Do not wait for onBeforeExecute: that callback runs after validation, so an unset required id would keep Add disabled.
Open the dialog with Arc’s useDialog hook. It mounts the dialog only while it is open, so every Add author click gets a fresh id:
import { useDialog } from '@cratis/arc.react/dialogs';import { AddAuthor } from './AddAuthor';
export const Library = () => { const [AddAuthorDialog, showAddAuthor] = useDialog(AddAuthor); return ( <> <button type='button' onClick={() => void showAddAuthor()}> Add author </button> <AddAuthorDialog /> </> );};Run the app, click Add author, and type a name. Add enables, the dialog executes RegisterAuthor when you confirm, and it closes once the backend reports success. If the backend rejects the command, the dialog stays open. Server validation results appear against the fields; other failures still need application handling. Cancel, the close button, and Escape close it without executing.
Before continuing, leave the required name empty and check that Add stays disabled. Enter a name, cancel, and confirm that nothing was submitted. Then submit a valid command and check that the dialog closes only on success. Try the flow with a keyboard too, checking the title, field label, and return focus in your application. For a server validation failure, the dialog should stay open with the field messages visible.
No application isExecuting state or duplicate client validation logic is required for this flow. Generated types help detect contract changes; regenerate proxies when C# changes and update affected accessors. The next tutorial adds an observable table: seeing its new row is a separate query-result checkpoint, not something closing this dialog guarantees.
For a complete list-and-detail screen, continue with the library tutorial.
Optional setup details
Section titled “Optional setup details”Provider configuration and localized labels are optional for this first dialog.
Yarn PnP with Arc React 22.6.2
Section titled “Yarn PnP with Arc React 22.6.2”If you retain @cratis/arc.react@22.6.2, that version imports rxjs without declaring it. A strict Yarn PnP consumer needs rxjs@7.8.2 and this version-specific package extension:
packageExtensions: '@cratis/arc.react@22.6.2': dependencies: rxjs: '7.8.2'This workaround is not needed with Arc React 22.16.0. Remove the old extension when upgrading; do not apply it to every Arc version.
What the provider sets up
Section titled “What the provider sets up”CratisComponentsProvider supplies the locale, Components-specific labels, and an optional app-wide toast region (toaster). React Aria uses the locale for date, number, keyboard, and screen-reader behavior. Styling remains CSS-owned rather than provider-owned. Every value is optional, so <CratisComponentsProvider> with no props also works. The full configuration surface is in the CratisComponentsProvider reference.
React Aria is an implementation dependency. Public props, parts, CSS variables, and event types are owned by Cratis.
Localize Components labels
Section titled “Localize Components labels”React Aria supplies its own locale data. Configure only labels owned by Components:
<CratisComponentsProvider value={{ locale: 'nb-NO', messages: { paginator: { navigation: 'Sidenavigasjon', first: 'Første side', previous: 'Forrige side', next: 'Neste side', last: 'Siste side', }, datePicker: { today: 'I dag', clear: 'Tøm', openCalendar: 'Åpne kalender', previousMonth: 'Forrige måned', nextMonth: 'Neste måned', }, }, }}> <YourApp /></CratisComponentsProvider>Choose how it looks
Section titled “Choose how it looks”Start with the baseline theme or your own token values, then customize individual parts where the screen needs it:
- Import
themefor the Cratis baseline. - Define your own
--cratis-*token values for a product design system. - Add classes or ordinary HTML attributes through each component’s Cratis-owned
ptparts. - Target stable
data-cratis-partand state attributes when product CSS needs structural control.
Do not target React Aria class names or internal DOM structure. See Styling and Stable component parts.
If something doesn’t work
Section titled “If something doesn’t work”- Add never enables — check client validation and every required value, including hidden ids in
initialValues. See Troubleshooting. - Components render unstyled — the
tokensandstylesimports are missing or run after your product CSS in the wrong order. See Troubleshooting. - Commands or queries never reach the backend — check that
<Arc>wraps the app and that its settings and your dev-server proxy match the backend routes. See Troubleshooting.
Your handwritten AddAuthor dialog now uses the generated RegisterAuthor command. <Arc> supplies command and query behavior; CratisComponentsProvider supplies UI configuration. Components owns the public React contract, with React Aria supplying selected interaction primitives internally.
Next, build a live library screen. Keep these providers and styles: the tutorial adds a query-backed author table, then connects selection to the author’s books. Check the query result separately from command success.
Where to go next
Section titled “Where to go next”- Build the library screen tutorial — follow one screen from a live table through command actions and list-and-detail composition
- Building a form
- Displaying data
- Choosing a component
- Troubleshooting — installation, styling, rendering, and form symptoms
- Migrate from Components 3
- Understand the UI foundation — including the capability profiles and capability matrix behind Foundation, Advanced React, and Spatial components