Skip to content

Commit 190dd60

Browse files
committed
refactor(DsfrTableCell): ♻️ convertit les stories au format CSF3
## Pourquoi les changements ont été faits : - migration vers Storybook 9 avec format CSF3 - passage de l'Options API à la Composition API dans les stories ## Quelles modifications ont été apportées : - définit la meta avec typage Meta<typeof DsfrTableCell> - convertit 4 stories en StoryObj avec render functions - remplace data() par setup() retournant args - préserve la logique onClick dans CelluleDeTableauComplexe avec computedCellAttrs - DsfrTableCell.vue conserve son withDefaults (valeur par défaut présente)
1 parent 13bdf56 commit 190dd60

File tree

1 file changed

+99
-101
lines changed

1 file changed

+99
-101
lines changed
Lines changed: 99 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import type { Meta, StoryObj } from '@storybook/vue3'
2+
3+
import { fn } from '@storybook/test'
14
import { setup } from '@storybook/vue3-vite'
2-
import { fn } from 'storybook/test'
35

46
import DsfrTag from '../DsfrTag/DsfrTag.vue'
57

@@ -11,15 +13,15 @@ setup((app) => {
1113
app.component('DsfrTag', DsfrTag) // Composant utilisé dans les stories CelluleDeTableauAvecComposant et CelluleDeTableauComplexe
1214
})
1315

14-
export default {
16+
const meta = {
1517
component: DsfrTableCell,
1618
title: 'Composants/DsfrTableCell',
1719
argTypes: {
1820
title: { control: 'text' },
1921
headers: {
2022
control: 'object',
2123
description:
22-
'Liste des en-têtes du tableau (tableau de string). *N.B. : Ne fait pas partie du composant.*',
24+
'Liste des en-têtes du tableau (tableau de string). *N.B. : Ne fait pas partie du composant.*',
2325
},
2426
field: {
2527
control: 'string',
@@ -31,7 +33,10 @@ export default {
3133
'Fonction pour montrer le clic sur une cellule (Ici seulement pour "Cellule de tableau complexe")',
3234
},
3335
},
34-
}
36+
} as Meta<typeof DsfrTableCell>
37+
38+
export default meta
39+
type Story = StoryObj<typeof meta>
3540

3641
const title = 'Utilisateurs'
3742
const headers = ['Nom']
@@ -55,132 +60,125 @@ const cellAttrs = {
5560
style: 'font-style: italic',
5661
}
5762

58-
export const CelluleDeTableauSimple = (args) => ({
59-
components: {
60-
DsfrTable,
61-
DsfrTableCell,
62-
DsfrTableHeaders,
63-
},
64-
65-
data () {
66-
return {
67-
...args,
68-
}
63+
export const CelluleDeTableauSimple: Story = {
64+
args: {
65+
title,
66+
headers,
67+
field: simpleField,
6968
},
70-
71-
template: `
72-
<DsfrTable
73-
:title="title"
74-
>
75-
<template #header>
76-
<DsfrTableHeaders :headers="headers" />
77-
</template>
78-
<tr>
79-
<DsfrTableCell :field="field" />
80-
</tr>
81-
</DsfrTable>
82-
`,
83-
})
84-
CelluleDeTableauSimple.args = {
85-
title,
86-
headers,
87-
field: simpleField,
69+
render: (args) => ({
70+
components: {
71+
DsfrTable,
72+
DsfrTableCell,
73+
DsfrTableHeaders,
74+
},
75+
setup () {
76+
return { args }
77+
},
78+
template: `
79+
<DsfrTable
80+
:title="args.title"
81+
>
82+
<template #header>
83+
<DsfrTableHeaders :headers="args.headers" />
84+
</template>
85+
<tr>
86+
<DsfrTableCell :field="args.field" />
87+
</tr>
88+
</DsfrTable>
89+
`,
90+
}),
8891
}
8992

90-
export const CelluleDeTableauAvecElementHtml = (args) => ({
91-
components: {
92-
DsfrTable,
93-
DsfrTableCell,
94-
DsfrTableHeaders,
95-
},
96-
97-
data () {
98-
return {
99-
...args,
100-
}
93+
export const CelluleDeTableauAvecElementHtml: Story = {
94+
args: {
95+
title,
96+
headers,
97+
field: fieldWithComponentSimple,
10198
},
102-
103-
template: `
99+
render: (args) => ({
100+
components: {
101+
DsfrTable,
102+
DsfrTableCell,
103+
DsfrTableHeaders,
104+
},
105+
setup () {
106+
return { args }
107+
},
108+
template: `
104109
<DsfrTable
105-
:title="title"
110+
:title="args.title"
106111
>
107112
<template #header>
108-
<DsfrTableHeaders :headers="headers" />
113+
<DsfrTableHeaders :headers="args.headers" />
109114
</template>
110115
<tr>
111-
<DsfrTableCell :field="field" />
116+
<DsfrTableCell :field="args.field" />
112117
</tr>
113118
</DsfrTable>
114-
`,
115-
})
116-
CelluleDeTableauAvecElementHtml.args = {
117-
title,
118-
headers,
119-
field: fieldWithComponentSimple,
119+
`,
120+
}),
120121
}
121122

122-
export const CelluleDeTableauAvecComposant = (args) => ({
123-
components: {
124-
DsfrTable,
125-
DsfrTableCell,
126-
DsfrTableHeaders,
123+
export const CelluleDeTableauAvecComposant: Story = {
124+
args: {
125+
title,
126+
headers,
127+
field: fieldWithComponent,
127128
},
128-
129-
data () {
130-
return {
131-
...args,
132-
}
133-
},
134-
135-
template: `
129+
render: (args) => ({
130+
components: {
131+
DsfrTable,
132+
DsfrTableCell,
133+
DsfrTableHeaders,
134+
},
135+
setup () {
136+
return { args }
137+
},
138+
template: `
136139
<DsfrTable
137-
:title="title"
140+
:title="args.title"
138141
>
139142
<template #header>
140-
<DsfrTableHeaders :headers="headers" />
143+
<DsfrTableHeaders :headers="args.headers" />
141144
</template>
142145
<tr>
143-
<DsfrTableCell :field="field" />
146+
<DsfrTableCell :field="args.field" />
144147
</tr>
145148
</DsfrTable>
146-
`,
147-
})
148-
CelluleDeTableauAvecComposant.args = {
149-
title,
150-
headers,
151-
field: fieldWithComponent,
149+
`,
150+
}),
152151
}
153152

154-
export const CelluleDeTableauComplexe = (args) => ({
155-
components: {
156-
DsfrTable,
157-
DsfrTableCell,
158-
DsfrTableHeaders,
159-
},
160-
161-
data () {
162-
return {
163-
...args,
164-
cellAttrs: { ...cellAttrs, onClick: () => args.onClickCell(args.field) },
165-
}
153+
export const CelluleDeTableauComplexe: Story = {
154+
args: {
155+
title,
156+
headers,
157+
field: fieldWithComponent,
158+
cellAttrs,
159+
onClickCell: fn(),
166160
},
167-
168-
template: `
161+
render: (args) => ({
162+
components: {
163+
DsfrTable,
164+
DsfrTableCell,
165+
DsfrTableHeaders,
166+
},
167+
setup () {
168+
const computedCellAttrs = { ...args.cellAttrs, onClick: () => args.onClickCell(args.field) }
169+
return { args, computedCellAttrs }
170+
},
171+
template: `
169172
<DsfrTable
170-
:title="title"
173+
:title="args.title"
171174
>
172175
<template #header>
173-
<DsfrTableHeaders :headers="headers" />
176+
<DsfrTableHeaders :headers="args.headers" />
174177
</template>
175178
<tr>
176-
<DsfrTableCell :field="field" :cell-attrs="cellAttrs" />
179+
<DsfrTableCell :field="args.field" :cell-attrs="computedCellAttrs" />
177180
</tr>
178181
</DsfrTable>
179-
`,
180-
})
181-
CelluleDeTableauComplexe.args = {
182-
title,
183-
headers,
184-
field: fieldWithComponent,
185-
cellAttrs,
182+
`,
183+
}),
186184
}

0 commit comments

Comments
 (0)