Skip to content

NHS FDP React component library, to support NHS branded UI and workflow on FDP and NHS staff-facing interfaces.

License

Notifications You must be signed in to change notification settings

NHSDigital/fdp-react-design-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NHS FDP Design System

A comprehensive design system for NHS digital services built with React, TypeScript, and design tokens.

Overview

The NHS FDP Design System provides a complete set of reusable components, design tokens, and guidelines to help teams build consistent, accessible NHS digital services.

Installation

From npm (public registry)

npm install @nhsdigital/fdp-design-system

From GitHub Packages

If the npm package is not yet available, you can install from GitHub Packages:

  1. Create or edit .npmrc in your project root:

    @nhsdigital:registry=https://npm.pkg.github.com
    
  2. Authenticate with GitHub Packages (requires a GitHub PAT with read:packages scope):

    npm login --registry=https://npm.pkg.github.com
  3. Install the package:

    npm install @nhsdigital/fdp-design-system

Basic Usage

import { Button, Panel, Heading } from '@nhsdigital/fdp-design-system';
import '@nhsdigital/fdp-design-system/dist/nhs-fdp-design-system.css';

function App() {
  return (
    <Panel>
      <Heading level={1}>Welcome to NHS FDP Design System</Heading>
      <Button variant="primary">Get Started</Button>
    </Panel>
  );
}

Component-level imports

You can import individual components via stable subpaths to keep bundles lean and make intent explicit:

// Import a single component (JS + types)
import Button from '@nhsdigital/fdp-design-system/components/Button';

// Many components are available this way, e.g.
import Card from '@nhsdigital/fdp-design-system/components/Card';
import Grid from '@nhsdigital/fdp-design-system/components/Grid';

// Server-only variants (where available)
import { HeaderServer } from '@nhsdigital/fdp-design-system/components/Header/server';

// Styles can still be brought in globally or per-component via CSS subpaths
import '@nhsdigital/fdp-design-system/components/Button/css';

Notes:

  • Subpath exports are generated from the built dist/src/components/*/index.{js,d.ts} entries.
  • Server subpaths (e.g. components/Header/server) are available where a server-safe variant exists.
  • Tree-shaking works with both the root entry and component subpaths; choose whichever suits your project structure.

Next.js Setup

Interactive components (Header overflow, CharacterCount, etc.) require the behaviour bundle to run on the client. Keep your root layout as a Server Component and add a tiny client-only initializer.

Quick Setup (recommended)

// app/layout.tsx (Server Component)
import '@nhsdigital/fdp-design-system/dist/nhs-fdp-design-system.css';
import { HeaderServer } from '@nhsdigital/fdp-design-system/ssr';
import { NHSBehavioursInit } from '@nhsdigital/fdp-design-system/nextjs';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        <NHSBehavioursInit /> {/* client island ensures behaviours are bundled and initialised */}
        <HeaderServer serviceName="Service" navigation={{ items: [ { href: '/', text: 'Home' } ] }} />
        {children}
      </body>
    </html>
  );
}

Why this works:

  • Your layout stays server-rendered (no "use client").
  • NHSBehavioursInit runs only on the client and imports the behaviours bundle so the Header can enhance.

Complete Next.js Setup Guide – Detailed setup, verification, and troubleshooting

Project Structure

nhs-fdp-design-system/
├── docs/                    # Documentation
│   ├── components/          # Component guides
│   ├── migration/           # Migration documentation
│   ├── tokens/              # Design token documentation
│   ├── testing/             # Testing guides
│   └── guides/              # Development guides
├── src/                     # Source code
│   ├── components/          # React components
│   ├── styles/              # Global styles
│   └── tokens/              # Design token definitions
├── examples/                # Usage examples
├── config/                  # Configuration files
├── tests/                   # Test suites
└── storybook/               # Storybook configuration

Documentation

Server / Client Variant Pattern

Some interactive components adopt an explicit split to guarantee deterministic, hook‑free server markup and eliminate hydration warnings while still providing a progressive enhancement path:

  • Component.render.tsx – Pure render function producing static JSX (no hooks / side effects). Shared source of truth.
  • Component.tsx – Client interactive variant that wraps the pure renderer and adds state, effects and data attributes for behaviours.
  • Component.server.tsx – Server (static) variant invoking the pure renderer only. Contains no React hooks (enforced via npm run verify:server-variants).

Current migrated components: Radios, Header (exporting RadiosServer, HeaderServer). You can import server variants via @nhsdigital/fdp-design-system/components/ComponentName/server.

Quick SSR usage (Next.js server components):

// Import SSR-safe components only
import { Header, ButtonServer, SummaryList, Input, Textarea, Select } from '@nhsdigital/fdp-design-system/ssr';

Development

Prerequisites

  • Node.js 18+
  • npm 9+

Setup

# Clone the repository
git clone https://github.com/NHSDigital/fdp-react-design-system.git
cd fdp-react-design-system

# Install dependencies
npm install

# Build design tokens
npm run build:tokens

# Start development server
npm run storybook

Available Scripts

# Build
npm run build                  # Full production build (alias for build:parity)
npm run build:parity           # Complete build with all verification steps
npm run build:quiet            # Clean build output (filters npm warnings)
npm run build:fast             # Quick dev build (skips some verification)

# Design tokens
npm run build:tokens           # Build design tokens (smart rebuild)

# Storybook
npm run storybook              # Start Storybook (dev)
npm run build-storybook        # Build Storybook (static)

# Tests
npm run test:components        # Run full component test suite (quiet summary)
npm run test:metrics           # Run full suite with metrics summary (and text coverage)
npm run test:ssr-components    # Run server-side rendering compatibility tests

# Code quality
npm run lint                   # ESLint
npm run typecheck              # TypeScript type checking

Architecture

Design Token System

Built with Style Dictionary, our design tokens provide:

  • Semantic tokens for consistent theming
  • Component tokens for specific component styling
  • Multi-platform output (CSS, SCSS, JavaScript, iOS, Android)

Component Architecture

  • React functional components with TypeScript
  • Compound component patterns for flexible APIs
  • Polymorphic components for semantic flexibility
  • CSS Modules with design token integration

Data Visualisation

Primary overview: Data Visualisation Overview

Contributing

We welcome contributions! Please see our contributing guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Workflow

  1. Components: Add new components in src/components/
  2. Stories: Create Storybook stories for documentation
  3. Tests: Write unit and visual regression tests
  4. Tokens: Update design tokens in packages/nhs-fdp/tokens/

Related Projects

Support

Licence

Unless stated otherwise, the codebase is released under the MIT License. This covers both the codebase and any sample code in the documentation.

Any HTML or Markdown documentation is © Crown Copyright and available under the terms of the Open Government Licence v3.0.

About

NHS FDP React component library, to support NHS branded UI and workflow on FDP and NHS staff-facing interfaces.

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 7