Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e744802887 |
@@ -49,12 +49,12 @@ consommer directement depuis ce dépôt git :
|
||||
```json
|
||||
{
|
||||
"dependencies": {
|
||||
"@napps/design-system": "git+https://git.studio-n.fr/napps/design-system.git#v0.1.7"
|
||||
"@napps/design-system": "git+https://git.studio-n.fr/napps/design-system.git#v0.1.8"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Toujours pointer sur un tag (`#v0.1.7`, jamais `#main`) pour qu'un `npm install` ne récupère
|
||||
Toujours pointer sur un tag (`#v0.1.8`, jamais `#main`) pour qu'un `npm install` ne récupère
|
||||
pas silencieusement des changements non prévus. À chaque évolution notable du design
|
||||
system, tagger une nouvelle version (`git tag -a vX.Y.Z`) et mettre à jour cette référence
|
||||
dans les apps qui doivent en profiter.
|
||||
@@ -273,12 +273,22 @@ champs sont à 15px depuis la v0.1.6. Non modifié ici.
|
||||
### 3. `Toast` et `useToast`
|
||||
|
||||
```tsx
|
||||
import { ToastProvider, useToast } from '@napps/design-system';
|
||||
// app/providers.tsx — composant client, posé une fois dans le layout racine
|
||||
'use client';
|
||||
import { ToastProvider } from '@napps/design-system/toast';
|
||||
|
||||
// une fois, près de la racine
|
||||
<ToastProvider>{children}</ToastProvider>
|
||||
export function Providers({ children }: { children: React.ReactNode }) {
|
||||
return <ToastProvider>{children}</ToastProvider>;
|
||||
}
|
||||
|
||||
// app/layout.tsx (Server Component) : <body><Providers>{children}</Providers></body>
|
||||
```
|
||||
|
||||
```tsx
|
||||
// N'importe quel composant "use client" situé sous le provider
|
||||
'use client';
|
||||
import { useToast } from '@napps/design-system/toast';
|
||||
|
||||
// n'importe où en dessous
|
||||
const toast = useToast();
|
||||
toast.show('Véhicule enregistré'); // success (défaut)
|
||||
toast.show('Échec de l’enregistrement', { tone: 'error' });
|
||||
@@ -286,6 +296,11 @@ toast.show('Copié', { duration: 1500 });
|
||||
toast.dismiss();
|
||||
```
|
||||
|
||||
`ToastProvider` et `useToast` s'importent **uniquement** depuis `@napps/design-system/toast`
|
||||
(point d'entrée marqué `"use client"`), pas depuis l'index principal. `useToast` ne s'appelle que
|
||||
dans un composant client ; le provider se pose dans un wrapper `"use client"` (Next App Router)
|
||||
ou directement à la racine (Vite, CRA…).
|
||||
|
||||
- Pastille `--bg-grouped` (opaque), rayon pill, hauteur `--control-height-regular`, texte
|
||||
subheadline, centrée en bas (`--space-6` + safe-area), `z-index: var(--z-toast)` (1100).
|
||||
Ombre `0 8px 48px` (0,25 en light, 0,5 en dark, comme `.dialog`) + filet `--separator`.
|
||||
@@ -300,6 +315,26 @@ toast.dismiss();
|
||||
disparaît seul est discutable au regard de WCAG 2.2.1 (temps suffisant) — pour une erreur
|
||||
importante, préférer un message persistant. `useToast` hors `<ToastProvider>` lève une erreur.
|
||||
|
||||
## v0.1.8 — correctif Next.js (App Router) : ToastProvider dans un point d'entrée « use client »
|
||||
|
||||
La v0.1.7 plantait dans tout Server Component Next qui importait un composant du package
|
||||
(`TypeError: createContext only works in Client Components`) : `ToastProvider` appelait
|
||||
`createContext` au chargement du module, dans le bundle principal sans directive `"use client"`.
|
||||
|
||||
- `ToastProvider` et `useToast` (et leurs types) **quittent l'index principal** et vivent dans
|
||||
`@napps/design-system/toast`, construit avec la bannière `"use client"` (tsup, entrée `toast`
|
||||
uniquement), déclaré dans `exports` des deux `package.json`. L'index principal reste importable
|
||||
depuis un Server Component (`Toast`, présentationnel, y reste).
|
||||
- **Migration depuis la v0.1.7** : `import { ToastProvider, useToast } from '@napps/design-system'`
|
||||
→ `from '@napps/design-system/toast'` (voir la section Toast ci-dessus).
|
||||
- Limites connues, inchangées : `Dialog` et `SegmentedControl` utilisent des hooks/handlers et ne
|
||||
sont utilisables que depuis un composant client (comme tout composant recevant des fonctions en
|
||||
props : `Toggle`, `Checkbox`, `Radio`, `TabBar`, `ColorPicker`).
|
||||
- Non-régression : `bash test/run-next-smoke.sh` empaquette le package racine (tel qu'installé par un
|
||||
consommateur), l'installe dans un mini projet Next 16 (`test/next-smoke`) dont un Server Component
|
||||
importe chaque export d'exécution de l'index principal, et lance `next build`. Vérifié : le test
|
||||
échoue (`createContext is not a function`) quand `ToastProvider` est remis dans l'index principal.
|
||||
|
||||
## Développer le package
|
||||
|
||||
```bash
|
||||
@@ -307,6 +342,9 @@ cd packages/design-system
|
||||
npm install
|
||||
npm run build # génère dist/ (ESM + CJS + types + CSS)
|
||||
npm run dev # rebuild en continu
|
||||
|
||||
# depuis la racine du dépôt : test d'import côté serveur (Next App Router)
|
||||
bash test/run-next-smoke.sh
|
||||
```
|
||||
|
||||
## Prochaines étapes
|
||||
|
||||
+7
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@napps/design-system",
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.8",
|
||||
"private": false,
|
||||
"description": "Identité visuelle et bibliothèque de composants nApps — direction A4 (Précision / Vibrance)",
|
||||
"type": "module",
|
||||
@@ -14,7 +14,12 @@
|
||||
"import": "./packages/design-system/dist/index.js",
|
||||
"require": "./packages/design-system/dist/index.cjs"
|
||||
},
|
||||
"./tokens.css": "./packages/design-system/dist/index.css"
|
||||
"./tokens.css": "./packages/design-system/dist/index.css",
|
||||
"./toast": {
|
||||
"types": "./packages/design-system/dist/toast.d.ts",
|
||||
"import": "./packages/design-system/dist/toast.js",
|
||||
"require": "./packages/design-system/dist/toast.cjs"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"packages/design-system/dist"
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@napps/design-system",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.8",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@napps/design-system",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.8",
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.3.0",
|
||||
"@types/react-dom": "^18.3.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@napps/design-system",
|
||||
"version": "0.1.7",
|
||||
"version": "0.1.8",
|
||||
"private": false,
|
||||
"description": "Identité visuelle et bibliothèque de composants nApps — direction A4 (Précision / Vibrance)",
|
||||
"type": "module",
|
||||
@@ -14,7 +14,12 @@
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs"
|
||||
},
|
||||
"./tokens.css": "./dist/index.css"
|
||||
"./tokens.css": "./dist/index.css",
|
||||
"./toast": {
|
||||
"types": "./dist/toast.d.ts",
|
||||
"import": "./dist/toast.js",
|
||||
"require": "./dist/toast.cjs"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
@@ -23,8 +28,8 @@
|
||||
"**/*.css"
|
||||
],
|
||||
"scripts": {
|
||||
"prepare": "tsup",
|
||||
"build": "tsup",
|
||||
"prepare": "npm run build",
|
||||
"build": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\" && tsup",
|
||||
"dev": "tsup --watch",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
|
||||
@@ -59,6 +59,3 @@ export type { ColorPickerProps } from './components/ColorPicker';
|
||||
|
||||
export { Toast } from './components/Toast';
|
||||
export type { ToastProps, ToastTone } from './components/Toast';
|
||||
|
||||
export { ToastProvider, useToast } from './components/ToastProvider';
|
||||
export type { ToastProviderProps, ToastOptions, ToastApi } from './components/ToastProvider';
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// Point d'entrée séparé « @napps/design-system/toast » : construit avec la directive "use client"
|
||||
// (voir tsup.config.ts), car ToastProvider appelle createContext au niveau du module.
|
||||
export { ToastProvider, useToast } from './components/ToastProvider';
|
||||
export type { ToastProviderProps, ToastOptions, ToastApi } from './components/ToastProvider';
|
||||
@@ -1,12 +1,19 @@
|
||||
import { defineConfig } from 'tsup';
|
||||
|
||||
export default defineConfig({
|
||||
entry: ['src/index.ts'],
|
||||
format: ['esm', 'cjs'],
|
||||
const common = {
|
||||
format: ['esm', 'cjs'] as ('esm' | 'cjs')[],
|
||||
dts: true,
|
||||
splitting: false,
|
||||
sourcemap: true,
|
||||
clean: true,
|
||||
// dist/ est vidé par le script `build` (deux configs en parallèle se marcheraient dessus).
|
||||
clean: false,
|
||||
external: ['react', 'react-dom'],
|
||||
injectStyle: false,
|
||||
});
|
||||
};
|
||||
|
||||
export default defineConfig([
|
||||
// Index principal : composants importables depuis un Server Component (aucune directive client).
|
||||
{ ...common, entry: { index: 'src/index.ts' } },
|
||||
// Point d'entrée « /toast » : ToastProvider/useToast créent un contexte React → "use client".
|
||||
{ ...common, entry: { toast: 'src/toast.ts' }, banner: { js: '"use client";' } },
|
||||
]);
|
||||
|
||||
@@ -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"]
|
||||
}
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
# Non-régression : le package tel que l'installe un consommateur (tarball du package RACINE,
|
||||
# donc son manifeste proxy) doit s'importer depuis un Server Component Next (App Router).
|
||||
# Usage : bash test/run-next-smoke.sh
|
||||
set -euo pipefail
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
WORK="$(mktemp -d)"
|
||||
trap 'rm -rf "$WORK"' EXIT
|
||||
|
||||
cd "$ROOT"
|
||||
npm pack --pack-destination "$WORK" >/dev/null # déclenche `prepare` (build) puis empaquette
|
||||
TARBALL="$(ls "$WORK"/napps-design-system-*.tgz)"
|
||||
|
||||
cp -r "$ROOT/test/next-smoke" "$WORK/app"
|
||||
cd "$WORK/app"
|
||||
npm pkg set "dependencies.@napps/design-system=file:$TARBALL" >/dev/null
|
||||
npm install --no-audit --no-fund
|
||||
npx next build
|
||||
echo "OK — next build a réussi avec $(basename "$TARBALL")"
|
||||
Reference in New Issue
Block a user