Skip to content

Commit 19358d0

Browse files
author
fergusbissetnhs
committed
fix: Removed the nextjs dependency
1 parent 6c41fb5 commit 19358d0

File tree

8 files changed

+244
-104
lines changed

8 files changed

+244
-104
lines changed

dist/src/nextjs.js

Lines changed: 48 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/src/nextjs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,6 @@
673673
"react-dom": "19.2.1",
674674
"sass": "^1.94.2"
675675
},
676-
"peerDependencies": {
677-
"next": ">=13.4.0 || ^14 || ^15"
678-
},
679-
"peerDependenciesMeta": {
680-
"next": {
681-
"optional": true
682-
}
683-
},
684676
"eslintConfig": {
685677
"extends": [
686678
"plugin:storybook/recommended"

src/hooks/useNavigationSplitNextUrlSync.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
// Deprecated wrapper kept for backward compatibility. Preferred import path:
2-
// import { useNavigationSplitNextUrlSync } from '@nhsdigital/fdp-design-system/nextjs'
3-
// This wrapper avoids static imports of next/navigation and delegates to the
4-
// real implementation only when available.
5-
// (React not required directly in wrapper)
1+
/**
2+
* @deprecated This hook is deprecated and will be removed in a future version.
3+
*
4+
* Use the framework-agnostic `useNavigationSplitUrlSync` instead:
5+
* ```ts
6+
* import { useNavigationSplitUrlSync } from '@nhsdigital/fdp-design-system';
7+
* ```
8+
*
9+
* For Next.js App Router integration, create your own wrapper - see the
10+
* JSDoc in src/nextjs/useNavigationSplitNextUrlSync.ts for an example.
11+
*/
612

713
function tryLoad<T = any>(mod: string): T | null {
814
try {
@@ -21,20 +27,30 @@ export interface UseNavigationSplitNextUrlSyncOptions {
2127
}
2228

2329
/**
24-
* useNavigationSplitNextUrlSync
30+
* @deprecated Use `useNavigationSplitUrlSync` from the main entry instead.
31+
* This Next.js-specific hook will be removed in a future version.
32+
*
2533
* Integrates NavigationSplitView state with the Next.js App Router.
2634
* Keeps selection + drill (three-column) state in the query string using
2735
* router.replace (default) or router.push. Scroll is suppressed by default.
2836
*/
2937
export function useNavigationSplitNextUrlSync<ID = string>(options: UseNavigationSplitNextUrlSyncOptions = {}) {
38+
// Emit deprecation warning
39+
if (typeof console !== 'undefined' && process.env.NODE_ENV !== 'production') {
40+
console.warn(
41+
'[useNavigationSplitNextUrlSync] DEPRECATED: This hook will be removed in a future version. ' +
42+
'Use useNavigationSplitUrlSync from the main entry, or create your own Next.js wrapper.'
43+
);
44+
}
45+
3046
const impl = tryLoad('@nhsdigital/fdp-design-system/dist/src/nextjs/useNavigationSplitNextUrlSync.js')
3147
|| tryLoad('@nhsdigital/fdp-design-system/src/nextjs/useNavigationSplitNextUrlSync');
3248
if (impl && typeof impl.useNavigationSplitNextUrlSync === 'function') {
33-
// Invoke underlying implementation (loss of generic inference acceptable for wrapper)
34-
return (impl.useNavigationSplitNextUrlSync as (o: UseNavigationSplitNextUrlSyncOptions)=>any)(options);
49+
// Invoke underlying implementation (loss of generic inference acceptable for wrapper)
50+
return (impl.useNavigationSplitNextUrlSync as (o: UseNavigationSplitNextUrlSyncOptions)=>any)(options);
3551
}
3652
if (process.env.NODE_ENV !== 'production') {
37-
console.warn('[useNavigationSplitNextUrlSync] Loaded legacy wrapper without Next.js context. Switch to importing from /nextjs entry for full functionality.');
53+
console.warn('[useNavigationSplitNextUrlSync] Loaded legacy wrapper without Next.js context. Switch to using useNavigationSplitUrlSync from the main entry.');
3854
}
3955
return {
4056
selectedId: undefined as ID | undefined,

src/nextjs.ts

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
1-
// NHS FDP Design System - Next.js Style Loader
2-
// Optimised CSS loading for Next.js applications
1+
/**
2+
* NHS FDP Design System - Next.js Entry Point
3+
*
4+
* @deprecated This entry point is deprecated and will be removed in a future version.
5+
*
6+
* Migration guide:
7+
*
8+
* 1. For URL sync hooks, use the framework-agnostic version:
9+
* ```ts
10+
* import { useNavigationSplitUrlSync } from '@nhsdigital/fdp-design-system';
11+
* ```
12+
* Or create your own Next.js-specific wrapper (see useNavigationSplitNextUrlSync.ts for example).
13+
*
14+
* 2. For behaviour initialization, create your own client component:
15+
* ```tsx
16+
* // app/components/BehavioursInit.tsx
17+
* "use client";
18+
* import { useEffect } from "react";
19+
*
20+
* export function BehavioursInit() {
21+
* useEffect(() => {
22+
* import("@nhsdigital/fdp-design-system/behaviours").then(({ initAll }) => {
23+
* if (typeof initAll === "function") initAll(document);
24+
* });
25+
* }, []);
26+
* return null;
27+
* }
28+
* ```
29+
*
30+
* 3. For core components and styles, import from the main entry:
31+
* ```ts
32+
* import { Button, Card } from '@nhsdigital/fdp-design-system';
33+
* import '@nhsdigital/fdp-design-system/css';
34+
* ```
35+
*/
336

437
// Core styles (load in layout.tsx)
538
// Align path with core.ts which imports from styles folder
@@ -8,10 +41,12 @@ import './styles/core.scss';
841
// Re-export core components for convenience
942
export * from './core';
1043

11-
// Next.js-specific hooks (sourced from dedicated nextjs folder)
44+
// Next.js-specific hooks (deprecated - use useNavigationSplitUrlSync from main entry)
45+
/** @deprecated Use useNavigationSplitUrlSync from main entry instead */
1246
export { useNavigationSplitNextUrlSync } from './nextjs/useNavigationSplitNextUrlSync';
1347

14-
// Next.js-specific behaviour initialization (no "use client" required)
48+
// Next.js-specific behaviour initialization (deprecated - create your own)
49+
/** @deprecated Create your own BehavioursInit component in your app */
1550
export { InitBehaviours, InitBehavioursInline } from './nextjs/InitBehaviours';
16-
// Client-side behaviours initializer (use in a small client island)
51+
/** @deprecated Create your own BehavioursInit component in your app */
1752
export { NHSBehavioursInit } from './nextjs/NHSBehavioursInit';

src/nextjs/InitBehaviours.tsx

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,24 @@
11
/**
2-
* DEPRECATED: Use <NHSBehavioursInit /> instead.
3-
* This wrapper forwards to the client-only component to ensure bundler-safe behaviour loading.
2+
* @deprecated These components are deprecated and will be removed in a future version.
3+
*
4+
* Create your own BehavioursInit component in your Next.js app instead.
5+
* See NHSBehavioursInit.tsx for migration guidance and example code.
46
*/
57
import { NHSBehavioursInit } from './NHSBehavioursInit';
68

7-
/** @deprecated Use <NHSBehavioursInit /> instead. */
9+
/**
10+
* @deprecated Use your own BehavioursInit component instead.
11+
* See NHSBehavioursInit.tsx for migration guidance.
12+
*/
813
export function InitBehaviours() {
914
// Forward to the client component. This avoids brittle inline script imports.
1015
return <NHSBehavioursInit />;
1116
}
1217

1318
/**
14-
* Alternative: Direct inline initialization (no dynamic import)
15-
* Use this if you want behaviours bundled with your app bundle
16-
*
17-
* @example
18-
* ```tsx
19-
* import { InitBehavioursInline } from '@nhsdigital/fdp-design-system/nextjs'
20-
*
21-
* export default function RootLayout({ children }) {
22-
* return (
23-
* <html>
24-
* <body>
25-
* {children}
26-
* <InitBehavioursInline />
27-
* </body>
28-
* </html>
29-
* )
30-
* }
31-
* ```
19+
* @deprecated Use your own BehavioursInit component instead.
20+
* See NHSBehavioursInit.tsx for migration guidance.
3221
*/
33-
/** @deprecated Use <NHSBehavioursInit /> instead. */
3422
export function InitBehavioursInline() {
3523
return <NHSBehavioursInit />;
3624
}

src/nextjs/NHSBehavioursInit.tsx

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,71 @@
11
"use client";
22

33
/**
4-
* Client-only behaviours initializer for Next.js apps.
5-
*
6-
* Purpose:
7-
* - Ensures the behaviours bundle is included in the consuming app's client build
8-
* - Exposes expected globals for the SSR header inline script
9-
* - Triggers initialisation after hydration
10-
*
11-
* Usage (App Router):
12-
* import { NHSBehavioursInit } from '@nhsdigital/fdp-design-system/nextjs';
13-
* // in app/layout.tsx (Server Component)
14-
* <body>
15-
* <NHSBehavioursInit />
16-
* <HeaderServer ... />
17-
* {children}
18-
* </body>
4+
* @deprecated This component is deprecated and will be removed in a future version.
5+
*
6+
* Instead, create your own client-side behaviours initializer in your Next.js app:
7+
*
8+
* ```tsx
9+
* // app/components/BehavioursInit.tsx
10+
* "use client";
11+
* import { useEffect } from "react";
12+
*
13+
* export function BehavioursInit() {
14+
* useEffect(() => {
15+
* let cancelled = false;
16+
* (async () => {
17+
* try {
18+
* const { initAll } = await import("@nhsdigital/fdp-design-system/behaviours");
19+
* if (!cancelled && typeof initAll === "function") {
20+
* initAll(document);
21+
* }
22+
* } catch (err) {
23+
* console.error("Failed to load behaviours", err);
24+
* }
25+
* })();
26+
* return () => { cancelled = true; };
27+
* }, []);
28+
* return null;
29+
* }
30+
* ```
31+
*
32+
* Then use it in your layout:
33+
* ```tsx
34+
* // app/layout.tsx
35+
* import { BehavioursInit } from "./components/BehavioursInit";
36+
*
37+
* export default function RootLayout({ children }) {
38+
* return (
39+
* <html>
40+
* <body>
41+
* {children}
42+
* <BehavioursInit />
43+
* </body>
44+
* </html>
45+
* );
46+
* }
47+
* ```
48+
*
49+
* This approach removes the Next.js dependency from the design system while
50+
* giving you full control over when and how behaviours are initialized.
1951
*/
2052
import { useEffect } from "react";
2153

54+
/**
55+
* @deprecated Create your own BehavioursInit component in your app instead.
56+
* See the JSDoc above for migration guidance.
57+
*/
2258
export function NHSBehavioursInit() {
2359
useEffect(() => {
60+
// Emit deprecation warning once
61+
if (process.env.NODE_ENV !== 'production') {
62+
console.warn(
63+
'[NHSBehavioursInit] DEPRECATED: This component will be removed in a future version. ' +
64+
'Create your own BehavioursInit component in your app instead. ' +
65+
'See the JSDoc comments for migration guidance.'
66+
);
67+
}
68+
2469
let cancelled = false;
2570

2671
(async () => {

0 commit comments

Comments
 (0)