Skip to content

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.

  • A React 19 application built with TypeScript. Components declares react and react-dom ^19.0.0 as peers.
  • An Arc frontend with generated proxies and experimentalDecorators/emitDecoratorMetadata enabled. The Arc tutorial’s first slice sets up the project, tsconfig.json, and Vite proxy that this page assumes.
  • @cratis/arc and @cratis/arc.react in 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.

  1. Install Components.

    Install Components 4
    npm install @cratis/components@^4

    React 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-metadata as peers. tsyringe is an optional peer: Components never imports it, and Arc React installs it as its own dependency. Keep @cratis/arc and @cratis/arc.react on 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.0
    npm 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.2

    Use Arc 22.16.0 or newer if you plan to use AutoCommandForm’s explicit field binding.

    pixi.js@^8.20.0 is another optional peer, needed only if you use Canvas or PivotViewer. 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.

  2. 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 />);

    tokens defines stable --cratis-* variables with conservative light defaults. styles supplies component structure in low-priority Cratis CSS layers without applying a global Preflight reset. theme adds 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 stable data-cratis-part elements or pt attributes.

    styles is every component’s CSS in one file. To download only the surfaces you mount, import @cratis/components/styles/base plus one <subpath>/styles entry point per surface instead — see Per-area stylesheets.

    This CSS-first path avoids TypeScript 6’s TS2882 for 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 reference vite/client. If a non-Vite setup needs a declaration for the local CSS import, add declare module '*.css'; in a project-included .d.ts file.

    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';
  3. Mount both providers around your application. <Arc> supplies the command and query runtime the generated proxies use; CratisComponentsProvider supplies 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. Library below 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>
    );

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:

src/AddAuthor.tsx
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:

src/Library.tsx
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.

Provider configuration and localized labels are optional for this first dialog.

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:

.yarnrc.yml
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.

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.

RegisterAuthor proxy

CommandDialog

AllAuthors proxy

DataTable

Arc runtime

Cratis-owned semantic markup

React Aria behavior

--cratis-* tokens

React Aria is an implementation dependency. Public props, parts, CSS variables, and event types are owned by Cratis.

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>

Start with the baseline theme or your own token values, then customize individual parts where the screen needs it:

  • Import theme for 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 pt parts.
  • Target stable data-cratis-part and 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.

  • Add never enables — check client validation and every required value, including hidden ids in initialValues. See Troubleshooting.
  • Components render unstyled — the tokens and styles imports 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.