v0.1.8 — corrige l'import côté Server Component (Next App Router)
- ToastProvider/useToast déplacés dans @napps/design-system/toast ("use client")
- index principal de nouveau importable depuis un Server Component
- test de non-régression test/run-next-smoke.sh (next build)
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
.next/
|
||||
next-env.d.ts
|
||||
@@ -0,0 +1,23 @@
|
||||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { Checkbox, ColorPicker, Dialog, Radio, SegmentedControl, TabBar, Toggle } from '@napps/design-system';
|
||||
import { useToast } from '@napps/design-system/toast';
|
||||
|
||||
export function ClientDemo() {
|
||||
const toast = useToast();
|
||||
const [on, setOn] = useState(false);
|
||||
const [tab, setTab] = useState('a');
|
||||
const [color, setColor] = useState('#0B6CFF');
|
||||
return (
|
||||
<div>
|
||||
<Toggle checked={on} onChange={setOn} aria-label="toggle" />
|
||||
<Checkbox checked={on} onChange={setOn} aria-label="checkbox" />
|
||||
<Radio checked={on} onChange={() => setOn(true)} aria-label="radio" />
|
||||
<SegmentedControl options={[{ label: 'A', value: 'a' }, { label: 'B', value: 'b' }]} value={tab} onChange={setTab} aria-label="seg" />
|
||||
<TabBar items={[{ value: 'a', label: 'A' }]} value={tab} onChange={setTab} aria-label="tabs" />
|
||||
<ColorPicker value={color} onChange={setColor} aria-label="color" />
|
||||
<Dialog open={false} title="t" actions={[{ label: 'OK', onClick: () => toast.show('ok') }]} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// Server Component. ToastProvider est un composant client : il passe par un wrapper
|
||||
// "use client" (voir providers.tsx), c'est le motif documenté dans le README.
|
||||
import '@napps/design-system/tokens.css';
|
||||
import type { ReactNode } from 'react';
|
||||
import { Providers } from './providers';
|
||||
|
||||
export default function RootLayout({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<html lang="fr">
|
||||
<body>
|
||||
<Providers>{children}</Providers>
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
// Server Component (pas de "use client"). Importe CHAQUE export d'exécution du point d'entrée
|
||||
// principal : si l'un d'eux appelle une API réservée aux composants client au chargement du
|
||||
// module (createContext…), `next build` échoue ici — c'est la régression de la v0.1.7.
|
||||
import {
|
||||
Badge, Button, Card, Checkbox, ColorPicker, Dialog, EmptyState, IconBadge, ListRow, Radio,
|
||||
SegmentedControl, Select, Spinner, Surface, TabBar, Text, TextField, Toast, Toggle, Toolbar,
|
||||
} from '@napps/design-system';
|
||||
import * as DS from '@napps/design-system';
|
||||
import { ClientDemo } from './client-demo';
|
||||
|
||||
// Exports qui ne peuvent qu'être importés côté serveur (props fonctions) : ils doivent au moins exister.
|
||||
const importOnly = { Checkbox, ColorPicker, Dialog, Radio, SegmentedControl, TabBar, Toggle };
|
||||
|
||||
export default function Page() {
|
||||
const missing = Object.entries(importOnly).filter(([, v]) => typeof v !== 'function').map(([k]) => k);
|
||||
if (missing.length) throw new Error(`exports manquants : ${missing.join(', ')}`);
|
||||
// ToastProvider/useToast ne doivent PAS être dans l'index principal (composants client).
|
||||
for (const k of ['ToastProvider', 'useToast']) {
|
||||
if (k in DS) throw new Error(`${k} ne doit pas être exporté par l'index principal`);
|
||||
}
|
||||
return (
|
||||
<Surface level="grouped">
|
||||
<Toolbar title="Smoke" />
|
||||
<Text variant="headline">Titre</Text>
|
||||
<Card>
|
||||
<ListRow title="Ligne" subtitle="sous-titre" trailing={<Badge tone="neutral">1</Badge>} />
|
||||
<IconBadge tone="neutral">i</IconBadge>
|
||||
</Card>
|
||||
<TextField placeholder="champ" />
|
||||
<Select defaultValue="a"><option value="a">A</option></Select>
|
||||
<Button>OK</Button>
|
||||
<Spinner />
|
||||
<EmptyState title="Vide" />
|
||||
<Toast tone="success">Fait</Toast>
|
||||
<ClientDemo />
|
||||
</Surface>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
'use client';
|
||||
|
||||
import type { ReactNode } from 'react';
|
||||
import { ToastProvider } from '@napps/design-system/toast';
|
||||
|
||||
export function Providers({ children }: { children: ReactNode }) {
|
||||
return <ToastProvider>{children}</ToastProvider>;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export default {};
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "napps-design-system-next-smoke",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": { "build": "next build" },
|
||||
"dependencies": {
|
||||
"@napps/design-system": "*",
|
||||
"next": "16.3.5",
|
||||
"react": "19.2.8",
|
||||
"react-dom": "19.2.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22",
|
||||
"@types/react": "^19",
|
||||
"@types/react-dom": "^19",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2017",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "react-jsx",
|
||||
"skipLibCheck": true,
|
||||
"incremental": true,
|
||||
"plugins": [{ "name": "next" }]
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user