React playground

Nova v3.37.0

Preview

React

Next.js Integration

Next.js Integration Guide

Introduction

This guide walks you through integrating Nova Design System with Next.js, covering project setup, server and client component usage, dark mode, and Storybook configuration.

What You'll Learn

  • Setting up a new Next.js project with Nova
  • Configuring Tailwind CSS and design tokens
  • Understanding server vs client component imports
  • Implementing dark mode
  • Configuring Storybook for Next.js projects

Getting Started

Step 1: Create a New Next.js Application

Start by creating a new Next.js application using the official create-next-app tool:

bashnpx create-next-app@latest

During the interactive setup, select the following options:

  • TypeScript: yes
  • ESLint: recommended
  • Tailwind CSS: required
  • src/ directory: as you wish
  • App Router: as you wish
  • Import alias: as you wish

Step 2: Install Nova Design System Packages

Navigate to your project directory and install the required Nova packages:

bashnpm install @nova-design-system/nova-webcomponents @nova-design-system/nova-base @nova-design-system/nova-react

These packages include:

  • nova-webcomponents: Core web components library
  • nova-base: Base styles, themes, and utilities
  • nova-react: React wrapper for the web components

Step 3: Configure Tailwind CSS

Replace the entire contents of src/app/globals.css with the following:

css@import 'tailwindcss';
@import '@nova-design-system/nova-base/theme/plugin.css';
@import '@nova-design-system/nova-base/dist/css/spark.css';
/* Or import ocean.css instead of spark.css. */

This configuration:

  • Imports Tailwind CSS base styles
  • Imports Nova's CSS-only Tailwind theme, components, utilities, and dark variant
  • Imports Nova's Spark design tokens
  • Requires no tailwind.config file, @config, @plugin, or JavaScript theme import

Do not combine theme/plugin.css with the JavaScript plugin or with nova-utils.css.

Deprecated JavaScript configuration

The previous JavaScript setup remains available for backward compatibility. Do not combine it with theme/plugin.css.

tailwind.config.ts:

typescriptimport type { Config } from 'tailwindcss'
import { novaTailwindTheme } from '@nova-design-system/nova-base/theme'

export default {
  theme: novaTailwindTheme,
} satisfies Config

src/app/globals.css:

css@import 'tailwindcss';
@import '@nova-design-system/nova-base/dist/css/spark.css';

@config '../../tailwind.config.ts';
@plugin '@nova-design-system/nova-base/theme/plugin';
@custom-variant dark (&:where(.dark, .dark *));

Step 4: Configure TT Norms Font

Add the stylesheet hosted on our CDN in the <head> tag of your layout.tsx file. Since this font is licensed for Elia Group only, you will find the exact URL in our wiki.

Step 5: Verify Your Setup

Now you can verify everything is working. Update src/app/page.tsx:

tsximport { NvButton } from "@nova-design-system/nova-react/server";

export default function Home() {
  return (
    <main className="flex min-h-screen flex-col items-center justify-center p-24">
      <NvButton>Hello Nova</NvButton>
    </main>
  );
}

Server and Client Components

Nova provides two import paths for components. Choosing the correct one depends on whether your component is a Server Component or a Client Component.

Import pathUse case'use client' required?
@nova-design-system/nova-react/serverServer Components (no interactivity)No
@nova-design-system/nova-reactClient Components (with interactivity)Yes

Important: Do not mix these up. Using the /server import inside a 'use client' component will cause React hydration errors because the server and client render different HTML.

Server Components

Use the /server import for components that don't need interactivity (no event handlers, no hooks, no state). Next.js renders these entirely on the server for a fast initial paint.

typescript// app/page.tsx (Server Component - no 'use client' needed)
import { NvButton, NvAvatar } from '@nova-design-system/nova-react/server';

export default function Page() {
  return (
    <div>
      <NvAvatar initials="JD" size="large" />
      <NvButton emphasis="high">Click Me</NvButton>
    </div>
  );
}

Client Components

When you need interactivity — event handlers, React hooks, or state — add 'use client' to the top of the file and use next/dynamic with ssr: false to import Nova components.

Why dynamic imports are needed

Nova's /server import is designed to handle SSR — it pre-renders the full component DOM on the server and wraps the client component with next/dynamic({ ssr: false }) internally. However, the /server createComponent returns an async function component, which is only supported in React Server Components. Using it inside a 'use client' component will cause errors.

The root import (@nova-design-system/nova-react) provides synchronous client components, but Nova's web components use light DOM rendering (shadow: false). When Next.js server-renders a 'use client' component, it outputs a bare custom element tag (e.g. <nv-fieldtext>). On the client, the web component upgrades and injects its internal DOM into the light DOM before React hydrates, causing a hydration mismatch.

Using next/dynamic with ssr: false skips server-rendering for Nova components entirely, avoiding the mismatch.

Example

tsx'use client';

import { useState } from 'react';
import dynamic from 'next/dynamic';

const NvFieldtext = dynamic(
  () => import('@nova-design-system/nova-react').then((m) => ({ default: m.NvFieldtext })),
  { ssr: false }
);
const NvButton = dynamic(
  () => import('@nova-design-system/nova-react').then((m) => ({ default: m.NvButton })),
  { ssr: false }
);

export function SearchForm() {
  const [query, setQuery] = useState('');

  return (
    <div>
      <NvFieldtext
        label="Search"
        value={query}
        onValueChanged={(e) => setQuery(e.detail)}
      />
      <NvButton onClick={() => console.log(query)}>Search</NvButton>
    </div>
  );
}

Some Nova components like NvDatatable are pure React components (not web components) and are only available from the root import. These don't need next/dynamic but require suppressHydrationWarning:

tsx'use client';

import { NvDatatable } from '@nova-design-system/nova-react';

export function DataTable() {
  return <NvDatatable suppressHydrationWarning data={data} columns={columns} />;
}

Dark Mode Support

Nova includes built-in dark mode support through the Tailwind dark mode variant configured by the CSS plugin in Step 3.

To implement a dark mode toggle, install next-themes:

bashnpm install next-themes

Then wrap your application with the ThemeProvider:

tsx// app/layout.tsx
import { ThemeProvider } from 'next-themes'

export default function Layout({ children }) {
  return (
    <html suppressHydrationWarning>
      <head />
      <body>
        <ThemeProvider attribute="class">{children}</ThemeProvider>
      </body>
    </html>
  )
}

By default, this will toggle dark mode when the browser requests it. You can also toggle it manually with the additional hooks provided by the library.

Storybook Integration

If you're using Storybook to document custom components built on top of Nova, you'll need special configuration when those components import from the /server path.

The Problem

Storybook cannot render Next.js server components directly. If your custom components import Nova components from @nova-design-system/nova-react/server, Storybook will fail to render them.

The Solution

Configure Storybook to redirect server imports to the client versions using webpack aliases.

1. Install Required Packages

bashnpm install --save-dev @storybook/addon-styling-webpack

2. Configure Webpack Alias

In your .storybook/main.js (or .storybook/main.ts), add the following webpack configuration:

javascriptmodule.exports = {
  // ... other config
  webpackFinal: async (config) => {
    if (config.resolve) {
      config.resolve.alias = {
        ...config.resolve.alias,
        "@nova-design-system/nova-react/server": require.resolve(
          "@nova-design-system/nova-react"
        ),
      };
    }
    return config;
  },
};

This redirects imports from @nova-design-system/nova-react/server to the client versions, allowing Storybook to render your components.

3. Configure Tailwind CSS Support

Add the styling addon to your .storybook/main.js:

javascriptmodule.exports = {
  addons: [
    // ... other addons
    '@storybook/addon-styling-webpack',
  ],
  // ... rest of config
};

4. Import Global Styles

In your .storybook/preview.tsx file, import your Tailwind entry file:

typescriptimport "../src/app/globals.css";

// ... rest of preview config

This makes sure that all Nova styles and Tailwind utilities are available in your Storybook stories.