# Opus React

**Build modern business applications without rebuilding the foundations.**

Opus is a production-ready, themeable React design system for dashboards, CRM products, internal tools, data-rich workflows, and browser-based desktop experiences. It combines polished visual design with accessible interaction patterns, strong TypeScript support and a broad component catalogue—from form primitives to complete application layouts and draggable multi-window workspaces.

[Component catalogue](https://project-opus.netlify.app/documentation/components) · [GitHub](https://github.com/Carl-Fearby/Opus)

[![Opus website and design system](https://raw.githubusercontent.com/Carl-Fearby/Opus/main/Library/packages/opus-react/assets/npm/marketing.png)](https://project-opus.netlify.app/documentation/components)

<table>
  <tr>
    <td width="50%"><a href="https://project-opus.netlify.app/documentation/components"><img src="https://raw.githubusercontent.com/Carl-Fearby/Opus/main/Library/packages/opus-react/assets/npm/components.png" alt="Browse the Opus component library" /></a></td>
    <td width="50%"><a href="https://project-opus.netlify.app/documentation/components"><img src="https://raw.githubusercontent.com/Carl-Fearby/Opus/main/Library/packages/opus-react/assets/npm/playground.png" alt="Explore the Opus component catalogue" /></a></td>
  </tr>
  <tr>
    <td align="center"><strong>Component library</strong></td>
    <td align="center"><strong>Component catalogue</strong></td>
  </tr>
</table>

## Why Opus

- **Hundreds of composable components** covering forms, content, navigation, overlays, charts, dashboards, media and desktop-style experiences.
- **Build complete web desktops** with draggable and resizable windows, desktop shortcuts, a responsive dock, minimise/maximise behaviour, focus management, and application-defined window content.
- **Designed for real application interfaces**, with responsive layouts, resizable panes, rich data views and reusable workflow components.
- **Themeable by default**, including light and dark modes, CSS design tokens and runtime accent colours.
- **Accessible and typed**, with keyboard-aware interactions and complete TypeScript definitions.
- **Preview before you build** in the live component library and editable playground.

## Requirements

- React `^18.2.0` or `^19.0.0`
- React DOM `^18.2.0` or `^19.0.0`
- `three` `^0.185.0` — optional, only needed for 3D model components

## API stability and upgrades

Published APIs are labelled **Stable**, **Beta**, or **Experimental**. Most current primitives are Beta while their final cross-browser and accessibility reviews complete; Labs, games, and provider-specific integrations are Experimental. See [the API stability policy](./API_STABILITY.md) for compatibility guarantees, deprecation handling, and the supported-browser matrix. All user-facing changes and migrations are recorded in [the changelog](./CHANGELOG.md).

## Install

```bash
npm install opus-react
```

Peer dependencies:

```bash
npm install react react-dom
```

Optional peer for 3D model viewers:

```bash
npm install three
```

## Quick start

Import Opus styles, then wrap your app with `OpusThemeProvider`.

```tsx
import "opus-react/styles.css";
import "opus-react/index.css";

import { OpusThemeProvider, Button, TextField } from "opus-react";

export function App() {
  return (
    <OpusThemeProvider theme="dark">
      <Button variant="primary">Save</Button>
      <TextField label="Full name" placeholder="Jane Cooper" />
    </OpusThemeProvider>
  );
}
```

### Styles

| Import | Purpose |
| --- | --- |
| `opus-react/styles.css` | Theme tokens (`--opus-*` CSS variables) for light and dark mode |
| `opus-react/index.css` | Component CSS modules plus bundled country-flag assets for `PhoneNumberField` |
| `opus-react/flags.css` | Standalone flag stylesheet (optional — already included in `index.css`) |

`OpusThemeProvider` sets `data-theme` on `document.documentElement` by default, so themed CSS variables apply everywhere — including portalled content such as modals, drawers, and toasts.

## Next.js

Add `opus-react` to `transpilePackages`:

```ts
// next.config.ts
const nextConfig = {
  transpilePackages: ["opus-react"],
};

export default nextConfig;
```

Import styles in your root layout:

```tsx
import "opus-react/styles.css";
import "opus-react/index.css";
```

## Theme provider

```tsx
import { OpusThemeProvider } from "opus-react";

export function App() {
  return (
    <OpusThemeProvider theme="light">
      <YourApp />
    </OpusThemeProvider>
  );
}
```

Available themes: `"light"` | `"dark"`

Neumorphism is an optional surface style in either colour mode:

```tsx
<OpusThemeProvider theme="dark" defaults={{ appearance: "neumorphism" }}>
  <App />
</OpusThemeProvider>
```

Controls share one material colour, with raised surfaces and inset inputs/selected states.
Dark mode uses subtler lighting. This applies to the component library, including navigation,
forms, tables, dashboard widgets, and portalled menus/dialogs. Scoped providers also carry their
appearance into portals without changing the surrounding application.

Keyboard focus, validation, status indicators, chart series, colour-picker swatches, media,
and branded artwork retain their meaningful visual cues. Neumorphism takes precedence over
decorative gradients and glass surfaces; explicit corner-radius settings still apply.
Switch `appearance` to `"standard"` to restore normal component styling.


Pass `applyToDocument={false}` if you manage `data-theme` yourself (for example on a scoped container in embedded widgets).

## Internationalisation

Components ask for text by key and carry an English fallback, so you can translate them with whatever engine your app already uses. Nothing in the library requires a particular translation library.

### Use the shipped translations

The package ships built-in translations for 48 languages (English plus 47 others, including right-to-left Arabic, Persian, Hebrew and Urdu).

```tsx
import { OpusI18nProvider, getOpusTranslations, opusTranslationLocales } from "opus-react";

// opusTranslationLocales lists every shipped locale, e.g. "en", "fr", "ja", "ar".
const locale = "fr";

export function App() {
  return (
    <OpusI18nProvider locale={locale} messages={getOpusTranslations(locale)}>
      <YourApp />
    </OpusI18nProvider>
  );
}
```

Built-in translations cover shared controls such as Kanban, Pagination, DataGrid, FilterBuilder, SearchBox, Calendar, Modal, Drawer and ConfirmDialog; pass extra keys through `messages` to override or extend any string, and components fall back to English when a key is not supplied.

### Or resolve keys with your own engine

Pass `translate` and Opus asks your app first, then any `messages` dictionary, then the English copy shipped with the component. Return `undefined`, `null` or an empty string to decline a key.

```tsx
import { useTranslation } from "react-i18next";
import { LanguagePicker, OpusI18nProvider } from "opus-react";

export function AppRoot() {
  const { i18n } = useTranslation();

  return (
    <OpusI18nProvider
      availableLocales={["en", "fr", "de"]}
      locale={i18n.resolvedLanguage ?? "en"}
      onLocaleChange={(locale) => void i18n.changeLanguage(locale)}
      translate={(key, params) => i18n.t(key, { ns: "opus", ...params })}
    >
      <LanguagePicker />
      <YourApp />
    </OpusI18nProvider>
  );
}
```

Your app stays in charge of state, persistence and the document language: `onLocaleChange` reports a selection, and `locale` comes back in. `availableLocales` accepts bare codes or `{ id, label, flag, country, htmlLang }`. `LanguagePicker` reads locale, options and handler from the provider, names each choice in the active language, and can be overridden per instance with the same props.

`LanguagePicker` opens a list of languages with a flag, the active name and a tick on the current one. Pass `country` (an ISO 3166-1 alpha-2 code such as `"fr"`) to render the bundled flag-icons SVG, or `flag` for an emoji fallback. Longer lists gain a search field that matches the name shown in the active language, the language's own name and its English name, so someone browsing in Urdu can still find a language by typing "English". Set `searchable` to force the field on or off.

### Find keys your dictionary is missing

The package exports its key contract, so an upgrade can be checked without guesswork:

```tsx
import { auditOpusTranslations } from "opus-react";

const report = auditOpusTranslations(myFrenchDictionary);
// report.missing  — built-in keys this dictionary does not translate
// report.unknown  — keys this version of the library no longer resolves
// report.drifted  — English copy that changed (audit with { english: true })
// report.optional — resolved keys that ship no built-in translation
```

`opusTranslationManifest` maps every key to its English fallback and whether the package translates it in every locale, and `opusDynamicTranslationPrefixes` lists the namespaces Opus assembles at runtime (such as `errorState.`) whose keys cannot be enumerated.

The translations are machine-assisted and are being proof-read by native speakers. Corrections are welcome — see the contributors section of the Opus site or open an issue on GitHub.

## Accent colour

Opus supports runtime accent colours via CSS variables.

```tsx
import { OpusThemeProvider, createAccentStyle } from "opus-react";

export function App() {
  return (
    <OpusThemeProvider theme="dark">
      <div style={createAccentStyle("#8f6cff")}>
        <YourApp />
      </div>
    </OpusThemeProvider>
  );
}
```

Or use the included picker:

```tsx
import { AccentColorPicker } from "opus-react";

<AccentColorPicker value={accent} onChange={setAccent} />;
```

## What's included

### Forms

- `Button`, `TextField`, `TextAreaField`, `RichTextField`
- `SelectField`, `FilterSelectField`, `MultiSelectField`, `TreeSelectField`, `CascaderField`
- `ComboboxField`, `AsyncSelectField`, `AsyncMultiSelectField`
- `CheckboxField`, `RadioGroup`, `SwitchField`
- `NumberField`, `RangeField`, `SliderRangeField`, `RatingField`
- `DateField`, `ColorField`, `FileField`, `HiddenField`
- `ChipInput`, `PhoneNumberField`, `CountryPickerField`
- `PasswordStrengthField`, `TransferListField`, `SegmentedControlField`
- `ThemeToggleField`, `FieldShell`

### Overlays and feedback

- `Modal`, `Dialog`, `ConfirmDialog`, `Drawer`, `BottomSheet`, `Popover`
- `DropdownMenu`, `ContextMenuProvider`, `CommandPalette`
- `Tooltip`, `Toast`, `ToastProvider`, `Alert`

### Content and data

- `OpusBrand` — canonical `icon`, `wordmark`, and `full` logo variants
- `Card`, `Panel`, `Section`, `Table`, `DataGrid`
- `DataGrid` supports sort, filter, resize, grouped/tree/pivot layouts, a column manager, and saved column views
- `TreeTable` for expandable hierarchical records
- `Markdown` and `CodeEditor` for documentation and developer surfaces
- `Tabs`, `Accordion`, `AccordionGroup`, `ShowMore`
- `Badge`, `Avatar`, `AvatarGroup`, `List`, `DescriptionList`
- `PropertyGrid`, `Statistic`, `EmptyState`, `ErrorState`, `ErrorBoundary`, `Skeleton`
- `ContentTimeline`, `TreeView`, `MasonryGrid`, `JsonViewer`

### Layout

- `Stack`, `Columns`, `Grid`, `Splitter`, `ResizablePanel`
- `DockLayout`, `ScrollArea`, `AspectRatio`, `Container`, `Spacer`
- `Breadcrumb`, `Pagination`, `PageHeader`, `Toolbar`, `OverflowToolbar`
- `BottomNavigation`, `NavigationRail`, `SplitButton`, `FloatingActionButton`

### Navigation

- `Sidebar`, `TopNavigation`, `MegaMenu`

### Charts and metrics

- `Chart` — bar, line, area, pie, donut, scatter, funnel, radar, sankey, treemap, and more
- `Gauge`, `Sparkline`, `ProgressRing`, `ProgressBar`, `Speedometer`
- `StatCard`, `MetricTile`, `StatusIndicator`, `TrendBadge`
- `Tiles`, `Tile`, `StatTile`, `StatTiles`

### Dashboard widgets

- `DashboardContentContainer`
- `PipelineOverview`, `DealsOverTime`
- `UpcomingTasks`, `RecentActivity`, `TopPerformingUsers`

Compose dashboard rows with `Columns`:

```tsx
import {
  Columns,
  DashboardContentContainer,
  UpcomingTasks,
  RecentActivity,
  TopPerformingUsers,
} from "opus-react";

<Columns direction="row" columns={3} gap={16}>
  <DashboardContentContainer data-component="upcoming-tasks" width="full">
    <UpcomingTasks title="Upcoming Tasks" tasks={tasks} />
  </DashboardContentContainer>
  <DashboardContentContainer data-component="recent-activity" width="full">
    <RecentActivity title="Recent Activity" items={activity} />
  </DashboardContentContainer>
  <DashboardContentContainer data-component="top-performing-users" width="full">
    <TopPerformingUsers title="Top Performing People" users={people} />
  </DashboardContentContainer>
</Columns>;
```

### Desktop applications

Create browser-based desktop and workspace experiences from reusable primitives. Opus supplies the shell and interaction model while your application owns every shortcut, dock item, window, and piece of content.

[![Opus browser desktop with draggable application windows, shortcuts, and dock](https://raw.githubusercontent.com/Carl-Fearby/Opus/main/Library/packages/opus-react/assets/npm/desktop.png)](https://project-opus.netlify.app/documentation/components)

- `Desktop` — stateful workspace shell with wallpaper, shortcuts, windows, dock placement, and edge-to-edge mode
- `DesktopWindow` — draggable, resizable, focus-aware windows with close, minimise, maximise, and restore transitions
- `DesktopDock` — resizable dock with bottom, left, and right placement plus optional auto-hide
- `DesktopIcon` — keyboard-accessible, selectable shortcuts with single- or double-click opening
- `VideoPlayer` — window-ready media playback with responsive controls and ambient blurred video fill

```tsx
import {
  Desktop,
  type DesktopDockItem,
  type DesktopShortcut,
  type DesktopWindowItem,
} from "opus-react";

const shortcuts: DesktopShortcut[] = [
  { id: "documents", icon: "folder-open", label: "Documents", x: 20, y: 20 },
  { id: "contacts", icon: "users", label: "Contacts", x: 20, y: 124 },
];

const dockItems: DesktopDockItem[] = shortcuts.map(({ id, icon, label }) => ({
  id,
  icon,
  label,
}));

const windows: DesktopWindowItem[] = [
  {
    id: "documents",
    title: "Documents",
    icon: "folder-open",
    open: true,
    rect: { x: 180, y: 64, width: 640, height: 420 },
    content: <div style={{ padding: 24 }}>Your documents application</div>,
  },
  {
    id: "contacts",
    title: "Contacts",
    icon: "users",
    open: false,
    rect: { x: 320, y: 120, width: 560, height: 400 },
    content: <div style={{ padding: 24 }}>Your contacts application</div>,
  },
];

export function Workspace() {
  return (
    <Desktop
      dockAutoHide
      dockItems={dockItems}
      edgeToEdge
      onAction={(action, id) => console.log(action, id)}
      shortcuts={shortcuts}
      wallpaper="aurora"
      windows={windows}
    />
  );
}
```

The same React composition works in a normal web application or inside a desktop wrapper such as Electron—without moving application behaviour into the shell component.

### Media and 3D

- `Carousel`, `Lightbox`, `ImageThumbnail`, `ImageGallery`
- `ModelViewer`, `ModelLightbox`, `ModelThumbnail`, `ModelGallery` (requires `three`)

### Builders and planning

- `FilterBuilder`, `QueryBuilder`, `RuleBuilder`
- `PermissionsMatrix`, `DualListBuilder`
- `Scheduler`, `KanbanBoard`, `Calendar`, `ResourcePlanner`
- `PropertyInspector`

### Utilities

- `OpusThemeProvider`, `useOpusTheme`
- `AccentColorPicker`, `createAccentStyle`, `useAccentPreference`
- `IconPicker`, `CatalogIcon`, `Icon`
- `Portal`, `FocusTrap`, `VisuallyHidden`
- `HotkeyManager`, `useHotkey`, `KeyboardShortcut`
- `Clipboard`, `CopyButton`
- `ThemeProvider`, `ThemeSwitcher`
- `ResizeObserver`, `IntersectionObserver`, `Spinner`

## Examples

### Button

```tsx
import { Button } from "opus-react";

<Button variant="primary">Create project</Button>
<Button variant="secondary">Cancel</Button>
```

### Text field with validation

```tsx
import { TextField } from "opus-react";

<TextField
  label="Email address"
  placeholder="you@example.com"
  error="Enter a valid email address"
/>
```

### Toast notifications

```tsx
import { OpusThemeProvider, ToastProvider, useToast, Button } from "opus-react";

function NotifyButton() {
  const { showToast } = useToast();

  return (
    <Button
      variant="primary"
      onClick={() => showToast({ title: "Saved", description: "Your changes were saved." })}
    >
      Save
    </Button>
  );
}

export function App() {
  return (
    <OpusThemeProvider theme="dark">
      <ToastProvider>
        <NotifyButton />
      </ToastProvider>
    </OpusThemeProvider>
  );
}
```

### Chart

```tsx
import { Chart } from "opus-react";

<Chart
  variant="bar-chart-vertical"
  title="Revenue by region"
  data={[
    { label: "EMEA", value: 42 },
    { label: "APAC", value: 28 },
    { label: "AMER", value: 35 },
  ]}
/>
```

## TypeScript

Type definitions ship with the package (`dist/index.d.ts`). Component prop types and shared tokens (for example `ChartVariant`, `ButtonVariant`, `Theme`) are exported from `opus-react`.

## Package exports

```json
{
  ".": "./dist/index.js",
  "./styles.css": "./dist/styles.css",
  "./index.css": "./dist/index.css",
  "./flags.css": "./dist/flags.css"
}
```

ESM and CommonJS builds are both published.

## Not included in the package

The published npm package does **not** include:

- Documentation site shells and routing
- Component preview / settings tooling
- Generated usage-code helpers
- Internal monorepo build scripts

Those live in the Opus Library workspace and are for development and docs only.

## Publishing (maintainers)

From the Library workspace root:

```bash
cd Library
npm run build:lib
npm publish -w opus-react --access public
```

`prepublishOnly` runs the package build automatically. Bump the version in `packages/opus-react/package.json` before publishing.

## Contribute to Opus

We are looking for contributors who want to help improve Opus. Useful contributions range from
small component refinements, accessibility fixes, tests, examples, and documentation through to
new primitives, application compositions, dashboard patterns, and desktop features.

You do not need to commit to a large feature. If you would like to get involved, tell us what you
are interested in and which part of Opus you would like to work on:

- Email [carlfearby@me.com](mailto:carlfearby@me.com)
- WhatsApp [+44 7940 147138](https://wa.me/447940147138)
- Browse the source, fork the project, or open a pull request at [Carl-Fearby/Opus](https://github.com/Carl-Fearby/Opus)

## License

MIT — see [`LICENSE`](./LICENSE).
