Skip to content

Getting started

Getting started

Requirements

  • React 19 (react and react-dom ^19.0.0)
  • Tailwind CSS ^4.1.0 only if you use the Tailwind path; the precompiled stylesheet needs no Tailwind
  • Browsers: Chrome/Edge 111+, Safari 16.4+, Firefox 128+ (the CSS uses @property, color-mix(), :where() and :has())
  • Node.js 22.12+ (engines); the package is ES modules only (see Installation)

Installation

npm install @mortenbrudvik/waveui

The npm package has always been @mortenbrudvik/waveui. Before 0.5 the repository's package.json used the name waveui, and the 0.4 guide imported from 'waveui'; import from @mortenbrudvik/waveui instead.

ES modules only. Since 1.0 the package ships ES modules alone: dist/*.mjs and one index.d.ts, reached through exports["."] (types and default; main points at dist/index.mjs). The style entries are files of the same exports map (below). Bundlers and import load it as before, and so does require() in CommonJS code on Node.js 22.12 and later, which returns the same module as import (22.12.x prints an ExperimentalWarning, 22.13 and later nothing); on an older Node.js require() stops with ERR_REQUIRE_ESM. A TypeScript file compiled as CommonJS (a .cts file, or a .ts file in a "type": "commonjs" package) resolves the types with module set to node20 or nodenext; under node16 it reports TS1479. Jest in its default CommonJS mode must transform the package (transformIgnorePatterns), or run in its ES modules mode; Vitest needs nothing.

Quick start

Pick one setup:

Your app Add Your own classes
Without Tailwind import '@mortenbrudvik/waveui/styles' once Classes of your own CSS on the --wave-* variables, or the token utilities of ./utilities (bg-wave-primary, text-wave-body-1)
Tailwind CSS 4, prefixed or not @import '@mortenbrudvik/waveui/tailwind'; in your Tailwind entry Tailwind utilities, with Wave's theme keys (bg-wave-primary, text-wave-body-1, shadow-wave-4) and the wave-rtl: variant
Tailwind CSS 4 with an entry you assemble ./tokens and ./variants.css in your entry, the components from ./styles in a layer of yours (Custom Tailwind setups) As with ./tailwind

In every setup the components' CSS comes precompiled, and every class the components draw carries Wave's utility prefix, wave: (wave:flex, wave:bg-primary), so no class of yours shares a name with one of Wave's, and your Tailwind build never scans the package. Those classes are internal: style the components through className, slotProps, the --wave-* tokens and the stable wave-* classes (Styling hooks).

Without Tailwind (precompiled CSS)

Import the precompiled stylesheet once and wrap your app in WaveProvider:

import '@mortenbrudvik/waveui/styles';
import { Button, WaveProvider } from '@mortenbrudvik/waveui';

export function App() {
  return (
    <WaveProvider theme="light">
      <Button appearance="primary" onClick={() => console.log('clicked')}>
        Get started
      </Button>
    </WaveProvider>
  );
}

WaveProvider is required on this path: the stylesheet scopes its base styles (font, colors, box sizing) and its reset of native elements (button, input, lists, headings, …) to the provider root and to portaled overlays. Components rendered outside a provider are not reset.

Your own classes. ./styles holds the components' CSS and nothing else. A Tailwind class you pass in className still merges with the component's classes, so p-2 on a Button removes the Button's own padding, but nothing defines it: the Button is left with no padding at all. Pass classes of your own CSS, or link the token utilities of ./utilities after the stylesheet and before your own CSS:

import '@mortenbrudvik/waveui/styles';
import '@mortenbrudvik/waveui/utilities.css';
import './app.css'; // your own CSS comes last

./utilities has Wave's colors (background, text, border, ring, fill and stroke), type ramp, shadows, font families and animations, without variants and without spacing or layout utilities (Styles).

Tailwind CSS 4

Add Wave to your Tailwind entry instead:

/* app.css */
@import 'tailwindcss';
@import '@mortenbrudvik/waveui/tailwind';

This adds Wave's tokens and its namespaced theme keys to layer(theme) (your own classes use them as bg-wave-primary, text-wave-body-1, shadow-wave-4), its scoped base styles to layer(base), and the components' precompiled utilities to layer(components), whichever of the two imports comes first. Tailwind scans nothing of the package (the entry has no @source). An app whose own build uses a prefix (@import 'tailwindcss' prefix(tw);) imports it the same way: its classes are tw:bg-wave-primary, and Wave's keep wave:. Never import @mortenbrudvik/waveui/styles as well in a Tailwind app: it would define the components' utilities a second time, unlayered.

The cascade. The entry declares @layer theme, base, components, utilities;, so across layers the layer decides, not the specificity:

  • Any utility of yours, and any unlayered rule of yours, wins over Wave's classes. A bare background class of yours on a Wave component (className="bg-wave-error") therefore also covers its hover, pressed, selected and disabled backgrounds; give those states their colors too, with Wave's gate (Buttons).
  • A class of yours in @layer components shares the layer with Wave's utilities, so specificity decides, then source order: a one-class rule of yours that comes later wins over Wave's resting classes, while Wave's gated hover and pressed classes (specificity 0,4,0) and its state classes (data-[selected]:…, 0,2,0) still win over it.
  • Your own @layer base rules share the layer with Wave's scoped base styles, which have no specificity: an element rule of yours (h2 { … }) wins, and a * rule wins when it comes later. A token override of yours in @layer base wins over Wave's tokens in theme when it targets the theme selectors, as in Customizing tokens (:root, .wave-light { --wave-primary: … }): a provider root carries its theme class, which declares the theme's tokens again, so an override on :root alone reaches only the theme-independent tokens there (the ramps: :root { --wave-brand-80: … }).
  • An unlayered reset of yours (*{margin:0}, normalize, Bootstrap's reboot) wins over the components' utilities too, and strips them: put it in @layer base, as Tailwind puts its Preflight.

Wave's 0.x names. Your Tailwind theme gets Wave's colors, type ramp and shadows under the wave namespace only: without a theme of your own, bg-primary, text-foreground, border-border, text-body-1 and shadow-4 no longer resolve. Write bg-wave-primary, text-wave-foreground, border-wave-border, text-wave-body-1 and shadow-wave-4; the migration codemod rewrites them (Upgrading to 1.0).

Your theme styles your classes, not Wave's. The components' utilities come precompiled with every theme value inlined, so an @theme of yours (--spacing, --radius-*, --shadow-*, colors) does not restyle them (through 0.x it did: this entry scanned Wave's dist, and your build generated the components' classes); restyle Wave through its --wave-* tokens (Customizing tokens). For the same reason your build no longer generates a class only because a component uses it: a class of yours must be in your build's sources.

Wrap the app in WaveProvider here too. It selects the theme and direction, paints the themed background, text color and font, and passes the theme to portaled overlays (dialogs, menus, popovers, toasts).