@cgi-learning-hub/ui 1.6.0-dev.1749207390 → 1.6.0-dev.1749572967
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Autocomplete-XmIFWgiQ.js → Autocomplete-BVy1WjPe.js} +45 -45
- package/dist/Autocomplete-v4ZcHulv.cjs +6 -0
- package/dist/components/ButtonGroup/ButtonGroup.cjs.js +1 -0
- package/dist/components/ButtonGroup/ButtonGroup.d.ts +3 -0
- package/dist/components/{SwitchView/SwitchView.es.js → ButtonGroup/ButtonGroup.es.js} +12 -9
- package/dist/components/ButtonGroup/index.cjs.js +1 -0
- package/dist/components/ButtonGroup/index.d.ts +2 -0
- package/dist/components/ButtonGroup/index.es.js +4 -0
- package/dist/components/{SwitchView → ButtonGroup}/types.d.ts +4 -3
- package/dist/components/index.cjs.js +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.es.js +23 -23
- package/dist/components/stories/Autocomplete.stories.cjs.js +1 -1
- package/dist/components/stories/Autocomplete.stories.es.js +1 -1
- package/dist/components/stories/ButtonGroup.stories.cjs.js +153 -0
- package/dist/components/stories/{SwitchView.stories.d.ts → ButtonGroup.stories.d.ts} +4 -3
- package/dist/components/stories/{SwitchView.stories.es.js → ButtonGroup.stories.es.js} +433 -272
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +23 -23
- package/package.json +1 -1
- package/dist/Autocomplete-CpRv6_iv.cjs +0 -6
- package/dist/components/SwitchView/SwitchView.cjs.js +0 -1
- package/dist/components/SwitchView/SwitchView.d.ts +0 -3
- package/dist/components/SwitchView/index.cjs.js +0 -1
- package/dist/components/SwitchView/index.d.ts +0 -2
- package/dist/components/SwitchView/index.es.js +0 -4
- package/dist/components/stories/SwitchView.stories.cjs.js +0 -143
- /package/dist/components/{SwitchView → ButtonGroup}/style.cjs.js +0 -0
- /package/dist/components/{SwitchView → ButtonGroup}/style.es.js +0 -0
- /package/dist/components/{SwitchView → ButtonGroup}/types.cjs.js +0 -0
- /package/dist/components/{SwitchView → ButtonGroup}/types.es.js +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as e, a as t, b as l, c as o, d as r, e as i, B as C, C as g, f as p, g as n, h as m, i as d, aD as c, D as y, aG as u, L as b, j as f, M as x, P as U, S as T, k as S, ay as h, T as L, l as I, m as A, n as B, o as k, p as P, q as F, r as D, s as M, ax as v, t as
|
|
1
|
+
import { A as e, a as t, b as l, c as o, d as r, e as i, B as C, C as g, f as p, g as n, h as m, i as d, aD as c, D as y, aG as u, L as b, j as f, M as x, P as U, S as T, k as S, ay as h, T as L, l as I, m as A, n as B, o as k, p as P, q as F, r as D, s as M, ax as v, t as G, u as w, v as R, y as H, w as _, E, G as V, ar as z, a5 as O, I as j, K as Q, a8 as q, O as N, a7 as W, R as Y, V as J, X as K, a9 as X, at as Z, a0 as $, a6 as ss, _ as as, ab as es, aC as ts, aq as ls, z as os, F as rs, H as is, x as Cs, J as gs, N as ps, Q as ns, U as ms, W as ds, Y as cs, aa as ys, ac as us, ae as bs, aF as fs, ag as xs, ai as Us, ak as Ts, am as Ss, ao as hs, aK as Ls, aM as Is, aO as As, aQ as Bs, aS as ks, aU as Ps, aW as Fs, aY as Ds, aI as Ms, b0 as vs, a_ as Gs, b2 as ws, ad as Rs, $ as Hs, a2 as _s, a3 as Es, af as Vs, az as zs, ah as Os, aj as js, Z as Qs, aw as qs, al as Ns, an as Ws, ap as Ys, aJ as Js, aL as Ks, aH as Xs, aN as Zs, aP as $s, aR as sa, aT as aa, aV as ea, aX as ta, a1 as la, aZ as oa, a$ as ra, b1 as ia, as as Ca, au as ga, av as pa, aE as na, aA as ma, aB as da, a4 as ca } from "../ToggleButtonGroup-C2VnPpq_.js";
|
|
2
2
|
import { D as ua, u as ba } from "../DatePicker-CTAJnIvu.js";
|
|
3
3
|
import { b as xa, A as Ua, a as Ta, g as Sa } from "../Alert-DdmE0EMo.js";
|
|
4
4
|
import { default as La } from "./Button/Button.es.js";
|
|
@@ -6,7 +6,7 @@ import { default as Aa } from "./ColorPicker/ColorPicker.es.js";
|
|
|
6
6
|
import { default as ka } from "./Dialog/Dialog.es.js";
|
|
7
7
|
import { default as Fa } from "./Dropzone/Dropzone.es.js";
|
|
8
8
|
import { default as Ma } from "./EllipsisWithTooltip/EllipsisWithTooltip.es.js";
|
|
9
|
-
import { default as
|
|
9
|
+
import { default as Ga } from "./EmptyState/EmptyState.es.js";
|
|
10
10
|
import { default as Ra } from "./FileList/FileList.es.js";
|
|
11
11
|
import { default as _a } from "./FileList/FileListItem.es.js";
|
|
12
12
|
import { default as Va } from "./FolderCard/FolderCard.es.js";
|
|
@@ -20,10 +20,10 @@ import { default as se } from "./ResourceCard/ResourceCard.es.js";
|
|
|
20
20
|
import { default as ee } from "./SearchInput/SearchInput.es.js";
|
|
21
21
|
import { default as le } from "./TreeView/TreeView.es.js";
|
|
22
22
|
import { ICON_TYPE as re } from "./TreeView/types.es.js";
|
|
23
|
-
import { default as Ce } from "./
|
|
23
|
+
import { default as Ce } from "./ButtonGroup/ButtonGroup.es.js";
|
|
24
24
|
import { c as pe, T as ne, a as me, b as de, d as ce, g as ye, e as ue, f as be, i as fe, k as xe, h as Ue, t as Te, j as Se, u as he } from "../Tab-fionqt7a.js";
|
|
25
|
-
import { A as Ie, L as Ae, a as Be, c as ke, g as Pe, b as Fe, l as De } from "../Autocomplete-
|
|
26
|
-
import { B as ve, b as
|
|
25
|
+
import { A as Ie, L as Ae, a as Be, c as ke, g as Pe, b as Fe, l as De } from "../Autocomplete-BVy1WjPe.js";
|
|
26
|
+
import { B as ve, b as Ge, g as we } from "../Backdrop-BSLhsv85.js";
|
|
27
27
|
import { B as He, b as _e, g as Ee } from "../Badge-D9BY47ln.js";
|
|
28
28
|
import { B as ze, b as Oe } from "../Box-DjbKEblU.js";
|
|
29
29
|
import { C as Qe, a as qe, b as Ne, d as We, c as Ye, f as Je, e as Ke, h as Xe, g as Ze } from "../CardContent-rIQGzMEo.js";
|
|
@@ -34,7 +34,7 @@ import { C as mt, c as dt, g as ct } from "../CustomTreeItem-D-Fd2rf4.js";
|
|
|
34
34
|
import { D as ut, a as bt, d as ft, b as xt, e as Ut, g as Tt, c as St, f as ht } from "../DialogContent-Bnuj13Sv.js";
|
|
35
35
|
import { D as It, a as At, d as Bt, g as kt } from "../DialogTitle-BT0ckfTq.js";
|
|
36
36
|
import { D as Ft } from "../Divider-Bsr4YOx4.js";
|
|
37
|
-
import { F as Mt, a as vt, c as
|
|
37
|
+
import { F as Mt, a as vt, c as Gt, f as wt, b as Rt, g as Ht, d as _t } from "../FormLabel-C_NeUysJ.js";
|
|
38
38
|
import { F as Vt, R as zt, f as Ot, g as jt, a as Qt, r as qt, u as Nt } from "../Radio-DQq7Mj29.js";
|
|
39
39
|
import { F as Yt, R as Jt, f as Kt, g as Xt, a as Zt, r as $t } from "../RadioGroup-D-KO9Ylf.js";
|
|
40
40
|
import { F as al, T as el, f as tl, g as ll, a as ol, t as rl } from "../TextField-CbcJBZMa.js";
|
|
@@ -44,7 +44,7 @@ import { I as ml, g as dl, i as cl } from "../IconButton-ZOYYBKrY.js";
|
|
|
44
44
|
import { I as ul, a as bl, S as fl, c as xl, g as Ul, d as Tl, i as Sl, b as hl, s as Ll } from "../Select-CHo4cwj1.js";
|
|
45
45
|
import { L as Al, g as Bl, l as kl } from "../Link-CPIGW37d.js";
|
|
46
46
|
import { L as Fl, g as Dl, l as Ml } from "../List-4Tnjo8WV.js";
|
|
47
|
-
import { L as
|
|
47
|
+
import { L as Gl, b as wl, g as Rl, a as Hl, l as _l } from "../ListItem-CeosJHtu.js";
|
|
48
48
|
import { L as Vl, a as zl } from "../ListItemText-BlTklQGT.js";
|
|
49
49
|
import { M as jl, g as Ql, m as ql } from "../Menu-CtyhzSeU.js";
|
|
50
50
|
import { M as Wl, g as Yl, a as Jl, l as Kl, m as Xl } from "../MenuItem-Cpp55CvO.js";
|
|
@@ -53,7 +53,7 @@ import { P as lo, g as oo, p as ro } from "../Paper-yeP8q4RO.js";
|
|
|
53
53
|
import { S as Co } from "../Stack-B_iq0mhq.js";
|
|
54
54
|
import { S as po, a as no, d as mo, b as co, c as yo, k as uo, f as bo, i as fo, g as xo, l as Uo, e as To, s as So, h as ho, j as Lo, u as Io, m as Ao } from "../Stepper-Co2LRzY9.js";
|
|
55
55
|
import { S as ko, g as Po, s as Fo } from "../createSvgIcon-BWru5SCV.js";
|
|
56
|
-
import { S as Mo, g as vo, s as
|
|
56
|
+
import { S as Mo, g as vo, s as Go } from "../Switch-B0HwIwIM.js";
|
|
57
57
|
import { T as Ro, g as Ho, t as _o } from "../Tooltip-KsV9NFU9.js";
|
|
58
58
|
import { T as Vo, g as zo, t as Oo } from "../Typography-CYUXO-Vm.js";
|
|
59
59
|
import { T as Qo, n as qo, b as No, c as Wo, y as Yo, u as Jo, v as Ko, q as Xo, f as Zo, w as $o, x as sr, m as ar, z as er, j as tr, k as lr, A as or, g as rr, a as ir, h as Cr, e as gr, l as pr, s as nr, o as mr, D as dr, C as cr, E as yr, p as ur, i as br, r as fr, d as xr, B as Ur, t as Tr } from "../generateUtilityClasses-BbL5PyhJ.js";
|
|
@@ -62,7 +62,7 @@ import { u as Ar } from "../useFormControl-CatNKXAi.js";
|
|
|
62
62
|
import { g as kr, l as Pr } from "../listItemTextClasses-x9hDn3Oc.js";
|
|
63
63
|
import { u as Dr } from "../useTheme-B0omzE6M.js";
|
|
64
64
|
import { u as vr } from "../useThemeProps-Bel8apgw.js";
|
|
65
|
-
import { s as
|
|
65
|
+
import { s as wr } from "../DefaultPropsProvider-CRQ3Gr22.js";
|
|
66
66
|
import { css as Hr, keyframes as _r } from "@emotion/react";
|
|
67
67
|
export {
|
|
68
68
|
e as Accordion,
|
|
@@ -79,6 +79,7 @@ export {
|
|
|
79
79
|
ze as Box,
|
|
80
80
|
C as Breadcrumbs,
|
|
81
81
|
La as Button,
|
|
82
|
+
Ce as ButtonGroup,
|
|
82
83
|
Qe as Card,
|
|
83
84
|
g as CardActionArea,
|
|
84
85
|
qe as CardActions,
|
|
@@ -103,7 +104,7 @@ export {
|
|
|
103
104
|
y as Drawer,
|
|
104
105
|
Fa as Dropzone,
|
|
105
106
|
Ma as EllipsisWithTooltip,
|
|
106
|
-
|
|
107
|
+
Ga as EmptyState,
|
|
107
108
|
u as Experimental_CssVarsProvider,
|
|
108
109
|
Ra as FileList,
|
|
109
110
|
_a as FileListItem,
|
|
@@ -113,7 +114,7 @@ export {
|
|
|
113
114
|
Yt as FormGroup,
|
|
114
115
|
al as FormHelperText,
|
|
115
116
|
vt as FormLabel,
|
|
116
|
-
|
|
117
|
+
Gt as FormLabelRoot,
|
|
117
118
|
Cl as GlobalStyles,
|
|
118
119
|
pl as Grid,
|
|
119
120
|
Oa as Heading,
|
|
@@ -125,7 +126,7 @@ export {
|
|
|
125
126
|
b as LinearProgress,
|
|
126
127
|
Al as Link,
|
|
127
128
|
Fl as List,
|
|
128
|
-
|
|
129
|
+
Gl as ListItem,
|
|
129
130
|
Vl as ListItemButton,
|
|
130
131
|
f as ListItemIcon,
|
|
131
132
|
zl as ListItemText,
|
|
@@ -158,7 +159,6 @@ export {
|
|
|
158
159
|
h as StyledEngineProvider,
|
|
159
160
|
ko as SvgIcon,
|
|
160
161
|
Mo as Switch,
|
|
161
|
-
Ce as SwitchView,
|
|
162
162
|
Qo as THEME_ID,
|
|
163
163
|
pe as Tab,
|
|
164
164
|
ne as TabContext,
|
|
@@ -176,8 +176,8 @@ export {
|
|
|
176
176
|
ce as Tabs,
|
|
177
177
|
el as TextField,
|
|
178
178
|
v as ThemeProvider,
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
G as ToggleButton,
|
|
180
|
+
w as ToggleButtonGroup,
|
|
181
181
|
R as Toolbar,
|
|
182
182
|
Ro as Tooltip,
|
|
183
183
|
le as TreeView,
|
|
@@ -193,7 +193,7 @@ export {
|
|
|
193
193
|
j as appBarClasses,
|
|
194
194
|
Be as autocompleteClasses,
|
|
195
195
|
Q as avatarClasses,
|
|
196
|
-
|
|
196
|
+
Ge as backdropClasses,
|
|
197
197
|
_e as badgeClasses,
|
|
198
198
|
No as blue,
|
|
199
199
|
q as blueGrey,
|
|
@@ -235,7 +235,7 @@ export {
|
|
|
235
235
|
ts as experimental_extendTheme,
|
|
236
236
|
ls as experimental_sx,
|
|
237
237
|
er as extendTheme,
|
|
238
|
-
|
|
238
|
+
wt as formControlClasses,
|
|
239
239
|
Ot as formControlLabelClasses,
|
|
240
240
|
Kt as formGroupClasses,
|
|
241
241
|
tl as formHelperTextClasses,
|
|
@@ -248,7 +248,7 @@ export {
|
|
|
248
248
|
gs as getAppBarUtilityClass,
|
|
249
249
|
Pe as getAutocompleteUtilityClass,
|
|
250
250
|
ps as getAvatarUtilityClass,
|
|
251
|
-
|
|
251
|
+
we as getBackdropUtilityClass,
|
|
252
252
|
Ee as getBadgeUtilityClass,
|
|
253
253
|
ns as getBreadcrumbsUtilityClass,
|
|
254
254
|
ms as getCardActionAreaUtilityClass,
|
|
@@ -281,7 +281,7 @@ export {
|
|
|
281
281
|
Ul as getInputUtilityClass,
|
|
282
282
|
xs as getLinearProgressUtilityClass,
|
|
283
283
|
Bl as getLinkUtilityClass,
|
|
284
|
-
|
|
284
|
+
wl as getListItemButtonUtilityClass,
|
|
285
285
|
Yl as getListItemIconUtilityClass,
|
|
286
286
|
kr as getListItemTextUtilityClass,
|
|
287
287
|
Rl as getListItemUtilityClass,
|
|
@@ -322,8 +322,8 @@ export {
|
|
|
322
322
|
xe as getTabsUtilityClass,
|
|
323
323
|
ol as getTextFieldUtilityClass,
|
|
324
324
|
vs as getToggleButtonGroupUtilityClass,
|
|
325
|
-
|
|
326
|
-
|
|
325
|
+
Gs as getToggleButtonUtilityClass,
|
|
326
|
+
ws as getToolbarUtilityClass,
|
|
327
327
|
Ho as getTooltipUtilityClass,
|
|
328
328
|
zo as getTypographyUtilityClass,
|
|
329
329
|
rr as green,
|
|
@@ -376,9 +376,9 @@ export {
|
|
|
376
376
|
So as stepClasses,
|
|
377
377
|
ho as stepLabelClasses,
|
|
378
378
|
Lo as stepperClasses,
|
|
379
|
-
|
|
379
|
+
wr as styled,
|
|
380
380
|
Fo as svgIconClasses,
|
|
381
|
-
|
|
381
|
+
Go as switchClasses,
|
|
382
382
|
Ue as tabClasses,
|
|
383
383
|
Te as tabPanelClasses,
|
|
384
384
|
Js as tableBodyClasses,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),a=require("../../Autocomplete-
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),a=require("../../Autocomplete-v4ZcHulv.cjs"),s=require("../../TextField-BD5v4wWW.cjs"),i=t=>{const o=["Paris","Londres","Berlin","Madrid","Rome","Amsterdam","Bruxelles","Lisbonne","Vienne","Athènes"];return e.jsx(a.Autocomplete,{options:o,sx:{width:300},renderInput:l=>e.jsx(s.TextField,{...l,label:"Choisissez une ville"}),...t})},n={title:"Components/Autocomplete",component:i,parameters:{docs:{description:{component:`L'autocomplete est une saisie de texte normale enrichie d'un panel d'options suggérées.
|
|
2
2
|
|
|
3
3
|
Pour explorer les cas d'usage possibles : [Autocomplete component - Material UI](https://mui.com/material-ui/react-autocomplete)`}}},argTypes:{autoHighlight:{control:"boolean",description:"Met automatiquement en surbrillance la première option",table:{defaultValue:{summary:"false"}}},disableClearable:{control:"boolean",description:"Désactive la possibilité de vider le champ",table:{defaultValue:{summary:"false"}}},disabled:{control:"boolean",description:"Désactive le composant",table:{defaultValue:{summary:"false"}}}}},r={args:{autoHighlight:!1,disableClearable:!1,disabled:!1}};exports.Default=r;exports.default=n;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),B=require("../../createSvgIcon-r-LuM8rr.cjs"),l=require("react"),p=require("../ButtonGroup/ButtonGroup.cjs.js"),u=require("../../Box-xgRKDOV1.cjs"),t=require("../../Typography-CTc5xI5k.cjs"),a=require("../../Grid-D0L0VF_j.cjs"),v=require("../../Button-qSgmSSw2.cjs"),o=require("../../Paper-Dy4nClba.cjs"),C=B.createSvgIcon(e.jsx("path",{d:"M20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2M8 11H4V6h4zm6 0h-4V6h4zm6 0h-4V6h4zM8 18H4v-5h4zm6 0h-4v-5h4zm6 0h-4v-5h4z"}),"CalendarViewMonth"),V=B.createSvgIcon(e.jsx("path",{fillRule:"evenodd",d:"M3 3v8h8V3zm6 6H5V5h4zm-6 4v8h8v-8zm6 6H5v-4h4zm4-16v8h8V3zm6 6h-4V5h4zm-6 4v8h8v-8zm6 6h-4v-4h4z"}),"GridView"),g=B.createSvgIcon(e.jsx("path",{d:"M3 13h2v-2H3zm0 4h2v-2H3zm0-8h2V7H3zm4 4h14v-2H7zm0 4h14v-2H7zM7 7v2h14V7z"}),"List"),j=B.createSvgIcon(e.jsx("path",{d:"M21 8H3V4h18zm0 2H3v4h18zm0 6H3v4h18z"}),"TableRows"),w=B.createSvgIcon(e.jsx("path",{d:"M2 4v7h20V4zm8 16h12v-7H10zm-8 0h6v-7H2z"}),"ViewComfy"),f=B.createSvgIcon(e.jsx("path",{d:"M14.67 5v6.5H9.33V5zm1 6.5H21V5h-5.33zm-1 7.5v-6.5H9.33V19zm1-6.5V19H21v-6.5zm-7.34 0H3V19h5.33zm0-1V5H3v6.5z"}),"ViewModule"),I={title:"Components/ButtonGroup",component:p,argTypes:{buttonList:{description:"**[Requis]** Liste des boutons à afficher dans le ButtonGroup.",control:"object",table:{required:!0,type:{summary:"readonly ButtonItem[]"}}},viewMode:{description:"**[Requis]** Valeur actuellement sélectionnée.",control:"text",table:{required:!0,type:{summary:"T[number]['value']"}}},onChange:{description:"**[Requis]** Fonction appelée lorsqu'un bouton est sélectionné.",table:{required:!0,type:{summary:"(value: T[number]['value']) => void"}}},colorVariant:{description:"**[Optionnel]** Variante de couleur des boutons.",control:"select",options:["primary","secondary"],defaultValue:"primary",table:{required:!1,type:{summary:"ColorVariant"},defaultValue:{summary:"primary"}}},size:{description:"**[Optionnel]** Taille des boutons.",control:"select",options:["small","medium","large"],defaultValue:"small",table:{required:!1,type:{summary:"string"},defaultValue:{summary:"small"}}},orientation:{description:"**[Optionnel]** Orientation du groupe de boutons.",control:"select",options:["horizontal","vertical"],defaultValue:"horizontal",table:{required:!1,type:{summary:"string"},defaultValue:{summary:"horizontal"}}}},parameters:{docs:{description:{component:`
|
|
2
|
+
## ButtonGroup
|
|
3
|
+
|
|
4
|
+
Un composant générique TypeScript pour permettre à l'utilisateur de basculer entre différents modes d'affichage ou options avec une sécurité de type complète.
|
|
5
|
+
|
|
6
|
+
### 🔥 Typage générique et sécurité des types
|
|
7
|
+
|
|
8
|
+
Le ButtonGroup utilise TypeScript générique avancé pour inférer automatiquement les types des valeurs possibles à partir de la liste des boutons fournie. **Il n'est plus nécessaire de définir un enum**, les types sont déduits automatiquement grâce à la magie de TypeScript !
|
|
9
|
+
|
|
10
|
+
**Point clé** : Utilisez toujours \`as const\` après votre tableau de boutons pour permettre l'inférence de type littéral.
|
|
11
|
+
|
|
12
|
+
### 🎯 Utilisation recommandée pour éviter les types 'any'
|
|
13
|
+
|
|
14
|
+
\`\`\`typescript
|
|
15
|
+
// ✅ CORRECT : Définition avec 'as const' pour l'inférence de type
|
|
16
|
+
const viewButtons = [
|
|
17
|
+
{ value: "cards", icon: <ViewModuleIcon /> },
|
|
18
|
+
{ value: "table", icon: <TableRowsIcon /> },
|
|
19
|
+
{ value: "list", icon: <ListIcon /> }
|
|
20
|
+
] as const; // ← IMPORTANT : ne pas oublier 'as const'
|
|
21
|
+
|
|
22
|
+
// ✅ CORRECT : Typage explicite pour le state et le handler
|
|
23
|
+
type ViewType = (typeof viewButtons)[number]["value"]; // "cards" | "table" | "list"
|
|
24
|
+
|
|
25
|
+
const [currentView, setCurrentView] = useState<ViewType>("cards");
|
|
26
|
+
|
|
27
|
+
const handleViewChange = useCallback((value: ViewType) => {
|
|
28
|
+
console.log(\`Vue sélectionnée: \${value}\`); // ← value est typé correctement
|
|
29
|
+
setCurrentView(value);
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
32
|
+
<ButtonGroup
|
|
33
|
+
buttonList={viewButtons}
|
|
34
|
+
viewMode={currentView}
|
|
35
|
+
onChange={handleViewChange} // ← Pas d'erreur 'any' !
|
|
36
|
+
/>
|
|
37
|
+
\`\`\`
|
|
38
|
+
|
|
39
|
+
### ❌ À éviter : patterns qui causent des types 'any'
|
|
40
|
+
|
|
41
|
+
\`\`\`typescript
|
|
42
|
+
// ❌ INCORRECT : Sans 'as const'
|
|
43
|
+
const viewButtons = [
|
|
44
|
+
{ value: "cards", icon: <ViewModuleIcon /> },
|
|
45
|
+
{ value: "table", icon: <TableRowsIcon /> }
|
|
46
|
+
]; // ← types inférés comme 'string' au lieu de littéraux
|
|
47
|
+
|
|
48
|
+
// ❌ INCORRECT : Handler sans typage explicite
|
|
49
|
+
const handleViewChange = (value) => { // ← 'value' aura le type 'any'
|
|
50
|
+
setCurrentView(value);
|
|
51
|
+
};
|
|
52
|
+
\`\`\`
|
|
53
|
+
|
|
54
|
+
### 🛠️ Personnalisation
|
|
55
|
+
|
|
56
|
+
- \`colorVariant\`: Choix entre les palettes "primary" et "secondary"
|
|
57
|
+
- \`size\`: Contrôle la taille des boutons ("small", "medium", "large")
|
|
58
|
+
- \`orientation\`: Affichage horizontal ou vertical du groupe de boutons
|
|
59
|
+
- \`disabled\`: Possibilité de désactiver individuellement certains boutons
|
|
60
|
+
|
|
61
|
+
### 📋 Structure des données
|
|
62
|
+
|
|
63
|
+
Le composant attend un tableau d'objets \`ButtonItem\` typé de manière générique :
|
|
64
|
+
|
|
65
|
+
\`\`\`typescript
|
|
66
|
+
interface ButtonItem<T extends string = string> {
|
|
67
|
+
value: T; // Valeur unique pour ce bouton (obligatoire)
|
|
68
|
+
icon: ReactNode; // Icône à afficher (obligatoire)
|
|
69
|
+
disabled?: boolean; // Désactiver ce bouton spécifique (facultatif)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Le composant infère automatiquement T à partir de votre tableau
|
|
73
|
+
type SwitchViewProps<T extends readonly ButtonItem<string>[]> = {
|
|
74
|
+
buttonList: T;
|
|
75
|
+
viewMode: T[number]["value"]; // Type inféré automatiquement
|
|
76
|
+
onChange: (value: T[number]["value"]) => void; // Type inféré automatiquement
|
|
77
|
+
// ... autres props
|
|
78
|
+
}
|
|
79
|
+
\`\`\`
|
|
80
|
+
|
|
81
|
+
### 🎉 Avantages du typage générique
|
|
82
|
+
|
|
83
|
+
1. **Auto-complétion** : IDE suggère automatiquement les valeurs possibles
|
|
84
|
+
2. **Vérification à la compilation** : Erreurs détectées avant l'exécution
|
|
85
|
+
3. **Refactoring sûr** : Renommer une valeur met à jour toutes les références
|
|
86
|
+
4. **Documentation vivante** : Les types servent de documentation
|
|
87
|
+
|
|
88
|
+
### 💡 Conseils pour une utilisation optimale
|
|
89
|
+
|
|
90
|
+
1. **Utilisez des types helper** pour éviter la répétition :
|
|
91
|
+
\`\`\`typescript
|
|
92
|
+
type ViewConfig = typeof viewButtons;
|
|
93
|
+
type ViewType = ViewConfig[number]["value"];
|
|
94
|
+
\`\`\`
|
|
95
|
+
|
|
96
|
+
2. **Créez des constantes réutilisables** :
|
|
97
|
+
\`\`\`typescript
|
|
98
|
+
export const VIEW_MODES = {
|
|
99
|
+
CARDS: "cards",
|
|
100
|
+
TABLE: "table",
|
|
101
|
+
LIST: "list"
|
|
102
|
+
} as const;
|
|
103
|
+
|
|
104
|
+
const viewButtons = [
|
|
105
|
+
{ value: VIEW_MODES.CARDS, icon: <ViewModuleIcon /> },
|
|
106
|
+
// ...
|
|
107
|
+
] as const;
|
|
108
|
+
\`\`\`
|
|
109
|
+
|
|
110
|
+
3. **Utilisez des factory functions** pour des configurations complexes :
|
|
111
|
+
\`\`\`typescript
|
|
112
|
+
const createViewButton = <T extends string>(value: T, icon: ReactNode) =>
|
|
113
|
+
({ value, icon } as const);
|
|
114
|
+
\`\`\`
|
|
115
|
+
`}}}},b=[{value:"cards",icon:e.jsx(f,{})},{value:"table",icon:e.jsx(j,{})},{value:"list",icon:e.jsx(g,{})}],z=[{value:"grid",icon:e.jsx(V,{})},{value:"cards",icon:e.jsx(w,{})},{value:"table",icon:e.jsx(j,{})},{value:"list",icon:e.jsx(g,{})},{value:"calendar",icon:e.jsx(C,{})}],q=[{value:"cards",icon:e.jsx(f,{})},{value:"table",icon:e.jsx(j,{}),disabled:!0},{value:"list",icon:e.jsx(g,{})}],G={render:()=>{const[n,r]=l.useState("cards"),c=l.useCallback(s=>{console.log(`Vue sélectionnée: ${s}`),r(s)},[]);return e.jsxs(u.Box,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"h6",gutterBottom:!0,children:"Sélecteur de vue standard"}),e.jsx(p,{buttonList:b,viewMode:n,onChange:c}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:2},children:["Vue actuelle: ",e.jsx("strong",{children:n})]})]})},parameters:{controls:{disable:!0},actions:{disable:!0},docs:{description:{story:"Sélecteur de vue basique permettant de basculer entre trois modes d'affichage : cartes, tableau et liste."}}}},P={render:()=>{const[n,r]=l.useState("table"),[c,s]=l.useState("primary"),[x,i]=l.useState("small"),[h,m]=l.useState("horizontal");return e.jsxs(u.Box,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"h6",gutterBottom:!0,children:"Personnalisation en temps réel"}),e.jsxs(a.Grid,{container:!0,spacing:2,sx:{mb:3},children:[e.jsxs(a.Grid,{size:{xs:12,sm:6,md:3},children:[e.jsx(t.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Couleur"}),e.jsxs(u.Box,{sx:{display:"flex",gap:1},children:[e.jsx(v.Button,{size:"small",variant:c==="primary"?"contained":"outlined",onClick:()=>s("primary"),children:"Primary"}),e.jsx(v.Button,{size:"small",variant:c==="secondary"?"contained":"outlined",onClick:()=>s("secondary"),children:"Secondary"})]})]}),e.jsxs(a.Grid,{size:{xs:12,sm:6,md:3},children:[e.jsx(t.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Taille"}),e.jsx(u.Box,{sx:{display:"flex",gap:1},children:["small","medium","large"].map(y=>e.jsx(v.Button,{size:"small",variant:x===y?"contained":"outlined",onClick:()=>i(y),children:y},y))})]}),e.jsxs(a.Grid,{size:{xs:12,sm:6,md:3},children:[e.jsx(t.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Orientation"}),e.jsxs(u.Box,{sx:{display:"flex",gap:1},children:[e.jsx(v.Button,{size:"small",variant:h==="horizontal"?"contained":"outlined",onClick:()=>m("horizontal"),children:"Horizontal"}),e.jsx(v.Button,{size:"small",variant:h==="vertical"?"contained":"outlined",onClick:()=>m("vertical"),children:"Vertical"})]})]}),e.jsxs(a.Grid,{size:{xs:12,sm:6,md:3},children:[e.jsx(t.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Vue actuelle"}),e.jsx(t.Typography,{variant:"body2",color:"primary",children:e.jsx("strong",{children:n})})]})]}),e.jsx(o.Paper,{sx:{p:3,display:"inline-block"},children:e.jsx(p,{buttonList:b,viewMode:n,onChange:y=>{console.log(`Vue sélectionnée: ${y}`),r(y)},colorVariant:c,size:x,orientation:h})})]})},parameters:{controls:{disable:!0},actions:{disable:!0},docs:{description:{story:"Interface de démonstration permettant de tester toutes les options de personnalisation disponibles : couleur, taille et orientation des boutons."}}}},L={render:()=>{const n=[{value:"on",icon:e.jsx(f,{})},{value:"off",icon:e.jsx(j,{})}],r=[{value:"active",icon:e.jsx(w,{})},{value:"inactive",icon:e.jsx(g,{})},{value:"pending",icon:e.jsx(V,{})}],c=[{value:"edit",icon:e.jsx(f,{})},{value:"view",icon:e.jsx(j,{})},{value:"preview",icon:e.jsx(g,{})}],[s,x]=l.useState("on"),[i,h]=l.useState("active"),[m,y]=l.useState("edit");return e.jsxs(u.Box,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"h6",gutterBottom:!0,children:"Différents contextes d'utilisation"}),e.jsx(t.Typography,{variant:"body2",color:"text.secondary",paragraph:!0,children:"Le même composant s'adapte automatiquement à différents types de données."}),e.jsxs(a.Grid,{container:!0,spacing:3,children:[e.jsx(a.Grid,{size:{xs:12,md:4},children:e.jsxs(o.Paper,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:"Mode binaire"}),e.jsx(t.Typography,{variant:"caption",color:"text.secondary",display:"block",sx:{mb:2},children:"Activation/Désactivation simple"}),e.jsx(p,{buttonList:n,viewMode:s,onChange:d=>{console.log("Simple:",d),x(d)}}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:1},children:["État: ",s]})]})}),e.jsx(a.Grid,{size:{xs:12,md:4},children:e.jsxs(o.Paper,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:"Statut système"}),e.jsx(t.Typography,{variant:"caption",color:"text.secondary",display:"block",sx:{mb:2},children:"Gestion d'états métier"}),e.jsx(p,{buttonList:r,viewMode:i,onChange:d=>{console.log("Status:",d),h(d)},colorVariant:"secondary"}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:1},children:["Statut: ",i]})]})}),e.jsx(a.Grid,{size:{xs:12,md:4},children:e.jsxs(o.Paper,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:"Mode d'édition"}),e.jsx(t.Typography,{variant:"caption",color:"text.secondary",display:"block",sx:{mb:2},children:"Interface utilisateur adaptative"}),e.jsx(p,{buttonList:c,viewMode:m,onChange:d=>{console.log("Mode:",d),y(d)},size:"medium"}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:1},children:["Mode: ",m]})]})})]}),e.jsxs(o.Paper,{sx:{p:2,mt:3,backgroundColor:"info.light",color:"info.contrastText"},children:[e.jsx(t.Typography,{variant:"subtitle2",gutterBottom:!0,children:"🎯 Flexibilité du composant"}),e.jsx(t.Typography,{variant:"body2",children:"Un seul composant peut gérer n'importe quel ensemble d'options, s'adaptant automatiquement au contexte d'utilisation."})]})]})},parameters:{controls:{disable:!0},actions:{disable:!0},docs:{description:{story:"Démonstration de la polyvalence du composant avec différents ensembles d'options : mode binaire, statuts système et modes d'édition."}}}},k={render:()=>{const n=["primary","secondary"],[r,c]=l.useState({primary:"cards",secondary:"table"});return e.jsxs(u.Box,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"h6",gutterBottom:!0,children:"Comparaison des variantes de couleurs"}),e.jsx(a.Grid,{container:!0,spacing:3,children:n.map(s=>e.jsx(a.Grid,{size:{xs:12,md:6},children:e.jsxs(o.Paper,{sx:{p:2},children:[e.jsxs(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:["Variante ",s]}),e.jsx(p,{buttonList:b,viewMode:r[s],onChange:x=>{c(i=>({...i,[s]:x}))},colorVariant:s}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:1},children:["Sélectionné: ",r[s]]})]})},s))})]})},parameters:{controls:{disable:!0},actions:{disable:!0},docs:{description:{story:"Démonstration des deux variantes de couleurs disponibles : primary et secondary."}}}},D={render:()=>{const n=["small","medium","large"],[r,c]=l.useState({small:"cards",medium:"table",large:"list"});return e.jsxs(u.Box,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"h6",gutterBottom:!0,children:"Comparaison des tailles"}),e.jsx(a.Grid,{container:!0,spacing:3,children:n.map(s=>e.jsx(a.Grid,{size:{xs:12,md:4},children:e.jsxs(o.Paper,{sx:{p:2},children:[e.jsxs(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:["Taille ",s]}),e.jsx(p,{buttonList:b,viewMode:r[s],onChange:x=>{c(i=>({...i,[s]:x}))},size:s}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:1},children:["Sélectionné: ",r[s]]})]})},s))})]})},parameters:{controls:{disable:!0},actions:{disable:!0},docs:{description:{story:"Démonstration des trois tailles disponibles : small, medium et large."}}}},R={render:()=>{const[n,r]=l.useState("grid"),c=l.useCallback(s=>{r(s)},[]);return e.jsxs(u.Box,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"h6",gutterBottom:!0,children:"Orientation verticale"}),e.jsxs(a.Grid,{container:!0,spacing:3,children:[e.jsx(a.Grid,{size:{xs:12,md:6},children:e.jsxs(o.Paper,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:"Orientation verticale - Taille medium"}),e.jsx(p,{buttonList:z,viewMode:n,onChange:c,orientation:"vertical",size:"medium"})]})}),e.jsx(a.Grid,{size:{xs:12,md:4},children:e.jsxs(o.Paper,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:"Orientation horizontale (comparaison)"}),e.jsx(p,{buttonList:z,viewMode:n,onChange:c,orientation:"horizontal",size:"medium"})]})})]}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:2},children:["Vue actuelle: ",e.jsx("strong",{children:n})]})]})},parameters:{controls:{disable:!0},actions:{disable:!0},docs:{description:{story:"Démonstration de l'orientation verticale comparée à l'orientation horizontale avec plus d'options."}}}},O={render:()=>{const n=[{value:"grid",icon:e.jsx(V,{}),text:"Grille"},{value:"table",icon:e.jsx(j,{}),text:"Tableau"},{value:"list",icon:e.jsx(g,{}),text:"Liste"}],r=[{value:"cards",icon:e.jsx(f,{})},{value:"comfort",icon:e.jsx(w,{})},{value:"calendar",icon:e.jsx(C,{})}],c=[{value:"overview",icon:e.jsx(V,{}),text:"Vue d'ensemble"},{value:"details",icon:e.jsx(w,{})},{value:"settings",icon:e.jsx(C,{}),text:"Paramètres"}],[s,x]=l.useState("grid"),[i,h]=l.useState("cards"),[m,y]=l.useState("overview");return e.jsxs(u.Box,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"h6",gutterBottom:!0,children:"Texte optionnel dans les boutons"}),e.jsxs(a.Grid,{container:!0,spacing:3,children:[e.jsx(a.Grid,{size:{xs:12,md:4},children:e.jsxs(o.Paper,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:"Avec texte"}),e.jsx(t.Typography,{variant:"caption",color:"text.secondary",display:"block",sx:{mb:2},children:"Tous les boutons ont un texte explicatif"}),e.jsx(p,{buttonList:n,viewMode:s,onChange:d=>x(d),size:"medium"}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:1},children:["Sélection: ",s]})]})}),e.jsx(a.Grid,{size:{xs:12,md:4},children:e.jsxs(o.Paper,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:"Icônes seulement"}),e.jsx(t.Typography,{variant:"caption",color:"text.secondary",display:"block",sx:{mb:2},children:"Format classique avec icônes uniquement"}),e.jsx(p,{buttonList:r,viewMode:i,onChange:d=>h(d),colorVariant:"secondary",size:"medium"}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:1},children:["Sélection: ",i]})]})}),e.jsx(a.Grid,{size:{xs:12,md:4},children:e.jsxs(o.Paper,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:"Format mixte"}),e.jsx(t.Typography,{variant:"caption",color:"text.secondary",display:"block",sx:{mb:2},children:"Certains boutons avec texte, d'autres sans"}),e.jsx(p,{buttonList:c,viewMode:m,onChange:d=>y(d),size:"medium",orientation:"vertical"}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:1},children:["Sélection: ",m]})]})})]}),e.jsxs(o.Paper,{sx:{p:3,mt:3,backgroundColor:"info.light"},children:[e.jsx(t.Typography,{variant:"subtitle2",gutterBottom:!0,children:"💡 Utilisation du texte optionnel"}),e.jsxs(t.Typography,{variant:"body2",component:"div",children:["• Le texte s'affiche automatiquement si la propriété"," ",e.jsx("code",{children:"text"})," est définie",e.jsx("br",{}),"• Compatible avec l'ancien format (icônes seules)",e.jsx("br",{}),"• Possibilité de mélanger boutons avec et sans texte",e.jsx("br",{}),"• L'espacement est automatiquement ajusté entre l'icône et le texte"]})]}),e.jsxs(o.Paper,{sx:{p:2,mt:2,backgroundColor:"grey.100"},children:[e.jsx(t.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Exemple de code"}),e.jsx("pre",{style:{margin:0,fontSize:"0.875rem",overflow:"auto"},children:`const buttons = [
|
|
116
|
+
{
|
|
117
|
+
value: "grid",
|
|
118
|
+
icon: <GridIcon />,
|
|
119
|
+
text: "Grille" // ← Texte optionnel
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
value: "list",
|
|
123
|
+
icon: <ListIcon /> // ← Pas de texte, seule l'icône
|
|
124
|
+
}
|
|
125
|
+
] as const;`})]})]})},parameters:{controls:{disable:!0},actions:{disable:!0},docs:{description:{story:"Démonstration de l'utilisation du texte optionnel dans les boutons. Le texte s'affiche automatiquement si la propriété `text` est présente, permettant une grande flexibilité dans la présentation."}}}},A={render:()=>{const[n,r]=l.useState("cards"),c=l.useCallback(s=>{r(s)},[]);return e.jsxs(u.Box,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"h6",gutterBottom:!0,children:"Gestion des boutons désactivés"}),e.jsxs(o.Paper,{sx:{p:3},children:[e.jsx(p,{buttonList:q,viewMode:n,onChange:c,size:"medium"}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:2},children:["Vue actuelle: ",e.jsx("strong",{children:n})]}),e.jsx(t.Typography,{variant:"body2",color:"text.secondary",sx:{mt:1},children:'Le bouton "Table" est désactivé dans cet exemple'}),e.jsxs(u.Box,{sx:{mt:2},children:[e.jsx(v.Button,{variant:"outlined",size:"small",onClick:()=>r("list"),sx:{mr:1},children:"Sélectionner Liste"}),e.jsx(v.Button,{variant:"outlined",size:"small",onClick:()=>r("cards"),children:"Sélectionner Cartes"})]})]})]})},parameters:{controls:{disable:!0},actions:{disable:!0},docs:{description:{story:"Exemple montrant comment désactiver individuellement certains boutons en utilisant la propriété `disabled` dans les éléments du tableau."}}}},E={render:()=>{const[n,r]=l.useState("grid"),c=l.useCallback(s=>{r(s)},[]);return e.jsxs(u.Box,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"h6",gutterBottom:!0,children:"Plus d'options d'affichage"}),e.jsxs(o.Paper,{sx:{p:3},children:[e.jsx(p,{buttonList:z,viewMode:n,onChange:c,colorVariant:"secondary",size:"large"}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:2},children:["Vue actuelle: ",e.jsx("strong",{children:n})]}),e.jsx(t.Typography,{variant:"body2",color:"text.secondary",sx:{mt:1},children:"Cet exemple montre un ButtonGroup avec 5 options différentes en variante secondary et taille large"})]})]})},parameters:{controls:{disable:!0},actions:{disable:!0},docs:{description:{story:"Exemple avec davantage d'options pour montrer la flexibilité du composant avec plusieurs modes d'affichage."}}}},H={render:()=>{const[n,r]=l.useState("cards"),c=l.useCallback(i=>{console.log("Changement de vue:",i),r(i)},[]),s=l.useCallback(i=>{console.log("Changement externe:",i),r(i)},[]),x=()=>{switch(n){case"cards":return"Affichage en cartes - Idéal pour une vue d'ensemble visuelle";case"table":return"Affichage en tableau - Parfait pour comparer des données";case"list":return"Affichage en liste - Optimal pour parcourir rapidement";default:return"Mode d'affichage inconnu"}};return e.jsxs(u.Box,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"h6",gutterBottom:!0,children:"Synchronisation avec d'autres composants"}),e.jsxs(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:["Vue actuelle: ",e.jsx("strong",{children:n})]}),e.jsx(t.Typography,{variant:"body2",color:"text.secondary",paragraph:!0,children:x()}),e.jsxs(a.Grid,{container:!0,spacing:3,children:[e.jsx(a.Grid,{size:{xs:12,md:6},children:e.jsxs(o.Paper,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:"ButtonGroup Principal"}),e.jsx(p,{buttonList:b,viewMode:n,onChange:c,size:"medium"})]})}),e.jsx(a.Grid,{size:{xs:12,md:6},children:e.jsxs(o.Paper,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:"Contrôles externes"}),e.jsx(u.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:b.map(i=>e.jsxs(v.Button,{variant:n===i.value?"contained":"outlined",onClick:()=>s(i.value),size:"small",startIcon:i.icon,children:["Mode ",i.value]},i.value))})]})})]}),e.jsxs(o.Paper,{sx:{p:2,mt:2,backgroundColor:"grey.50"},children:[e.jsx(t.Typography,{variant:"subtitle2",gutterBottom:!0,children:"Actions rapides"}),e.jsx(v.Button,{variant:"text",size:"small",onClick:()=>{const i=["cards","table","list"],h=i[Math.floor(Math.random()*i.length)];s(h)},sx:{mr:1},children:"Vue aléatoire"}),e.jsx(v.Button,{variant:"text",size:"small",onClick:()=>{const h=(b.findIndex(m=>m.value===n)+1)%b.length;s(b[h].value)},children:"Vue suivante"})]})]})},parameters:{controls:{disable:!0},actions:{disable:!0},docs:{description:{story:"Démonstration de la synchronisation entre le ButtonGroup et d'autres composants. Cette story montre comment le ButtonGroup peut être intégré dans une interface complexe où la sélection peut provenir de différentes sources mais reste synchronisée."}}}},U={render:()=>{const n=[{value:"overview",icon:e.jsx(w,{})},{value:"detailed",icon:e.jsx(j,{})},{value:"analytics",icon:e.jsx(V,{})}],r=[{value:"grid",icon:e.jsx(V,{})},{value:"list",icon:e.jsx(g,{})},{value:"tree",icon:e.jsx(f,{})}],c=[{value:"chart",icon:e.jsx(C,{})},{value:"table",icon:e.jsx(j,{})},{value:"raw",icon:e.jsx(g,{}),disabled:!0}],[s,x]=l.useState("overview"),[i,h]=l.useState("grid"),[m,y]=l.useState("chart");return e.jsxs(u.Box,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"h6",gutterBottom:!0,children:"Cas d'utilisation dans une interface complexe"}),e.jsxs(a.Grid,{container:!0,spacing:3,children:[e.jsx(a.Grid,{size:{xs:12,md:4},children:e.jsxs(o.Paper,{sx:{p:2,height:"100%"},children:[e.jsx(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:"Dashboard"}),e.jsx(p,{buttonList:n,viewMode:s,onChange:d=>x(d),colorVariant:"primary",size:"small",orientation:"vertical"}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:2},children:["Mode: ",s]})]})}),e.jsx(a.Grid,{size:{xs:12,md:4},children:e.jsxs(o.Paper,{sx:{p:2,height:"100%"},children:[e.jsx(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:"Explorateur de fichiers"}),e.jsx(p,{buttonList:r,viewMode:i,onChange:d=>h(d),colorVariant:"secondary",size:"medium"}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:2},children:["Affichage: ",i]})]})}),e.jsx(a.Grid,{size:{xs:12,md:4},children:e.jsxs(o.Paper,{sx:{p:2,height:"100%"},children:[e.jsx(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:"Visualisation de données"}),e.jsx(p,{buttonList:c,viewMode:m,onChange:d=>y(d),colorVariant:"primary",size:"large"}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:2},children:["Format: ",m]}),e.jsx(t.Typography,{variant:"caption",color:"text.secondary",children:'(Le mode "raw" est temporairement désactivé)'})]})})]}),e.jsxs(o.Paper,{sx:{p:2,mt:3,backgroundColor:"info.light",color:"info.contrastText"},children:[e.jsx(t.Typography,{variant:"subtitle2",gutterBottom:!0,children:"📊 Résumé des sélections (tous typés !)"}),e.jsxs(t.Typography,{variant:"body2",children:["Dashboard: ",e.jsx("strong",{children:s})," | Fichiers:"," ",e.jsx("strong",{children:i})," | Données: ",e.jsx("strong",{children:m})]})]}),e.jsxs(o.Paper,{sx:{p:2,mt:2,backgroundColor:"warning.light",color:"warning.contrastText"},children:[e.jsx(t.Typography,{variant:"subtitle2",gutterBottom:!0,children:"🔍 Inspection des types"}),e.jsxs(t.Typography,{variant:"body2",component:"div",children:[e.jsx("code",{children:"DashboardType:"})," ",'"overview" | "detailed" | "analytics"',e.jsx("br",{}),e.jsx("code",{children:"FileType:"})," ",'"grid" | "list" | "tree"',e.jsx("br",{}),e.jsx("code",{children:"DataType:"})," ",'"chart" | "table" | "raw"']}),e.jsx(t.Typography,{variant:"caption",sx:{mt:1,display:"block"},children:"Chaque callback reçoit exactement le bon type, aucune configuration supplémentaire requise !"})]})]})},parameters:{controls:{disable:!0},actions:{disable:!0},docs:{description:{story:"Exemple d'utilisation complexe montrant comment le ButtonGroup peut être utilisé dans différents contextes au sein d'une même interface, avec différentes configurations (tailles, couleurs, orientations) selon le besoin. Chaque instance a son propre type inféré automatiquement."}}}},F={render:()=>{const n={CARDS:"cards",TABLE:"table",LIST:"list"},r=(T,S,M=!1)=>({value:T,icon:S,disabled:M}),c=[r(n.CARDS,e.jsx(f,{})),r(n.TABLE,e.jsx(j,{})),r(n.LIST,e.jsx(g,{}))],s=[r("dashboard",e.jsx(V,{})),r("users",e.jsx(w,{})),r("settings",e.jsx(C,{})),r("logs",e.jsx(g,{}),!0)],[x,i]=l.useState(n.CARDS),[h,m]=l.useState("dashboard"),y=l.useCallback(T=>{console.log("Vue commune changée:",T),i(T)},[]),d=l.useCallback(T=>{console.log("Vue admin changée:",T),m(T)},[]);return e.jsxs(u.Box,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"h6",gutterBottom:!0,children:"🚀 Bonnes pratiques pour le typage"}),e.jsxs(a.Grid,{container:!0,spacing:3,children:[e.jsx(a.Grid,{size:{xs:12,md:6},children:e.jsxs(o.Paper,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:"Configuration standard"}),e.jsx(t.Typography,{variant:"caption",color:"text.secondary",display:"block",sx:{mb:2},children:"Utilisation de constantes et factory functions"}),e.jsx(p,{buttonList:c,viewMode:x,onChange:y,size:"medium"}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:1},children:["Sélection: ",x]})]})}),e.jsx(a.Grid,{size:{xs:12,md:6},children:e.jsxs(o.Paper,{sx:{p:2},children:[e.jsx(t.Typography,{variant:"subtitle1",gutterBottom:!0,children:"Configuration avancée"}),e.jsx(t.Typography,{variant:"caption",color:"text.secondary",display:"block",sx:{mb:2},children:"Types spécialisés avec bouton désactivé"}),e.jsx(p,{buttonList:s,viewMode:h,onChange:d,colorVariant:"secondary",size:"medium"}),e.jsxs(t.Typography,{variant:"body2",sx:{mt:1},children:["Admin: ",h]})]})})]}),e.jsxs(o.Paper,{sx:{p:3,mt:3,backgroundColor:"success.light"},children:[e.jsx(t.Typography,{variant:"h6",gutterBottom:!0,children:"📚 Code examples - Bonnes pratiques"}),e.jsxs(u.Box,{sx:{mb:2},children:[e.jsx(t.Typography,{variant:"subtitle2",gutterBottom:!0,children:"1. ✅ Utilisation de constantes réutilisables"}),e.jsx(o.Paper,{sx:{p:2,backgroundColor:"grey.100"},children:e.jsx("pre",{style:{margin:0,fontSize:"0.875rem",overflow:"auto"},children:`const VIEW_MODES = {
|
|
126
|
+
CARDS: "cards",
|
|
127
|
+
TABLE: "table",
|
|
128
|
+
LIST: "list"
|
|
129
|
+
} as const;
|
|
130
|
+
|
|
131
|
+
const buttons = [
|
|
132
|
+
{ value: VIEW_MODES.CARDS, icon: <Icon /> }
|
|
133
|
+
] as const;`})})]}),e.jsxs(u.Box,{sx:{mb:2},children:[e.jsx(t.Typography,{variant:"subtitle2",gutterBottom:!0,children:"2. ✅ Factory functions pour la réutilisabilité"}),e.jsx(o.Paper,{sx:{p:2,backgroundColor:"grey.100"},children:e.jsx("pre",{style:{margin:0,fontSize:"0.875rem",overflow:"auto"},children:`const createViewButton = <T extends string>(
|
|
134
|
+
value: T,
|
|
135
|
+
icon: ReactNode,
|
|
136
|
+
disabled = false
|
|
137
|
+
) => ({ value, icon, disabled } as const);
|
|
138
|
+
|
|
139
|
+
const buttons = [
|
|
140
|
+
createViewButton("cards", <CardsIcon />),
|
|
141
|
+
createViewButton("table", <TableIcon />, true)
|
|
142
|
+
] as const;`})})]}),e.jsxs(u.Box,{sx:{mb:2},children:[e.jsx(t.Typography,{variant:"subtitle2",gutterBottom:!0,children:"3. ✅ Types helper pour éviter la répétition"}),e.jsx(o.Paper,{sx:{p:2,backgroundColor:"grey.100"},children:e.jsx("pre",{style:{margin:0,fontSize:"0.875rem",overflow:"auto"},children:`type ViewType = (typeof buttons)[number]["value"];
|
|
143
|
+
|
|
144
|
+
const [view, setView] = useState<ViewType>("cards");
|
|
145
|
+
|
|
146
|
+
const handleChange = useCallback((value: ViewType) => {
|
|
147
|
+
// value est automatiquement typé !
|
|
148
|
+
setView(value);
|
|
149
|
+
}, []);`})})]}),e.jsxs(u.Box,{children:[e.jsx(t.Typography,{variant:"subtitle2",gutterBottom:!0,children:"4. ✅ Handler avec typage explicite"}),e.jsx(o.Paper,{sx:{p:2,backgroundColor:"grey.100"},children:e.jsx("pre",{style:{margin:0,fontSize:"0.875rem",overflow:"auto"},children:`<ButtonGroup
|
|
150
|
+
buttonList={buttons}
|
|
151
|
+
viewMode={view}
|
|
152
|
+
onChange={handleChange} // ← Pas de type 'any' !
|
|
153
|
+
/>`})})]})]}),e.jsxs(o.Paper,{sx:{p:2,mt:2,backgroundColor:"error.light",color:"error.contrastText"},children:[e.jsx(t.Typography,{variant:"subtitle2",gutterBottom:!0,children:"❌ À éviter"}),e.jsxs(t.Typography,{variant:"body2",component:"div",children:["• Oublier ",e.jsx("code",{children:"as const"})," après les tableaux",e.jsx("br",{}),"• Utiliser des handlers sans typage explicite",e.jsx("br",{}),"• Définir des valeurs en dur sans constantes",e.jsx("br",{}),"• Ignorer les warnings TypeScript"]})]})]})},parameters:{controls:{disable:!0},actions:{disable:!0},docs:{description:{story:"Cette story présente les meilleures pratiques pour utiliser le ButtonGroup avec un typage TypeScript optimal. Elle montre comment structurer votre code pour éviter les types 'any' et maximiser la sécurité de type."}}}};exports.AvecBoutonsDesactives=A;exports.AvecTexteOptionnel=O;exports.BonnesPratiques=F;exports.CasUtilisationComplexe=U;exports.Controlable=P;exports.Default=G;exports.OptionsEtendues=E;exports.OrientationVerticale=R;exports.Synchronisation=H;exports.TaillesDifferentes=D;exports.TypageGenerique=L;exports.VariantesDecouleurs=k;exports.default=I;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import {
|
|
3
|
-
declare const meta: Meta<typeof
|
|
2
|
+
import { ButtonGroup } from '../ButtonGroup';
|
|
3
|
+
declare const meta: Meta<typeof ButtonGroup>;
|
|
4
4
|
export default meta;
|
|
5
|
-
type Story = StoryObj<typeof
|
|
5
|
+
type Story = StoryObj<typeof ButtonGroup>;
|
|
6
6
|
export declare const Default: Story;
|
|
7
7
|
export declare const Controlable: Story;
|
|
8
8
|
export declare const TypageGenerique: Story;
|
|
9
9
|
export declare const VariantesDecouleurs: Story;
|
|
10
10
|
export declare const TaillesDifferentes: Story;
|
|
11
11
|
export declare const OrientationVerticale: Story;
|
|
12
|
+
export declare const AvecTexteOptionnel: Story;
|
|
12
13
|
export declare const AvecBoutonsDesactives: Story;
|
|
13
14
|
export declare const OptionsEtendues: Story;
|
|
14
15
|
export declare const Synchronisation: Story;
|