|
1 | | -import { expect, fn, within } from 'storybook/test' |
| 1 | +import type { Meta, StoryObj } from '@storybook/vue3-vite' |
| 2 | + |
| 3 | +import { expect, within } from '@storybook/test' |
2 | 4 |
|
3 | 5 | import VIcon from '../VIcon/VIcon.vue' |
4 | 6 |
|
5 | 7 | import DsfrButtonGroup from './DsfrButtonGroup.vue' |
6 | 8 |
|
7 | 9 | /** |
8 | | - * [Voir quand l’utiliser sur la documentation du DSFR](https://www.systeme-de-design.gouv.fr/version-courante/fr/composants/groupe-de-boutons) |
| 10 | + * [Voir quand l'utiliser sur la documentation du DSFR](https://www.systeme-de-design.gouv.fr/version-courante/fr/composants/groupe-de-boutons) |
9 | 11 | */ |
10 | | -export default { |
| 12 | +const meta = { |
11 | 13 | component: DsfrButtonGroup, |
12 | 14 | title: 'Composants/DsfrButtonGroup', |
13 | 15 | tags: ['bouton'], |
14 | 16 | argTypes: { |
15 | 17 | buttons: { |
16 | 18 | control: 'object', |
17 | 19 | description: |
18 | | - 'Tableau d’objets, chaque objet contiendra les props à passer à DsfrButton', |
19 | | - }, |
20 | | - inline: { |
21 | | - control: 'boolean', |
22 | | - deprecated: true, |
23 | | - description: |
24 | | - '**Déprécié:** Indique si le groupe de boutons doit toujours apparaître en empilement horizontal. *Utiliser `inlineLayoutWhen` à la place.*', |
| 20 | + 'Tableau d\'objets, chaque objet contiendra les props à passer à DsfrButton', |
25 | 21 | }, |
26 | 22 | inlineLayoutWhen: { |
27 | 23 | control: 'radio', |
@@ -52,68 +48,69 @@ export default { |
52 | 48 | align: { |
53 | 49 | control: 'radio', |
54 | 50 | options: ['default', 'center', 'right'], |
55 | | - description: 'Indique l’alignement du groupe de boutons', |
| 51 | + description: 'Indique l\'alignement du groupe de boutons', |
56 | 52 | }, |
57 | | - onClick: { action: fn() }, |
58 | 53 | }, |
59 | | -} |
| 54 | +} satisfies Meta<typeof DsfrButtonGroup> |
60 | 55 |
|
61 | | -export const GroupeDeBoutons = (args) => ({ |
62 | | - components: { |
63 | | - DsfrButtonGroup, |
64 | | - VIcon, |
65 | | - }, |
66 | | - data () { |
67 | | - return { |
68 | | - ...args, |
69 | | - buttons: args.buttons.map((btn) => ({ ...btn, onClick: args.onClick })), |
70 | | - } |
| 56 | +export default meta |
| 57 | + |
| 58 | +type Story = StoryObj<typeof meta> |
| 59 | + |
| 60 | +export const GroupeDeBoutons: Story = { |
| 61 | + args: { |
| 62 | + align: 'center', |
| 63 | + inlineLayoutWhen: 'never', |
| 64 | + reverse: false, |
| 65 | + iconRight: false, |
| 66 | + size: 'medium', |
| 67 | + buttons: [ |
| 68 | + { |
| 69 | + label: 'Label 1', |
| 70 | + icon: 'ri-checkbox-circle-line', |
| 71 | + }, |
| 72 | + { |
| 73 | + label: 'Label 2', |
| 74 | + secondary: true, |
| 75 | + icon: 'ri-checkbox-circle-line', |
| 76 | + }, |
| 77 | + { |
| 78 | + label: 'Label 3', |
| 79 | + icon: 'ri-checkbox-circle-line', |
| 80 | + }, |
| 81 | + { |
| 82 | + label: 'Label 4', |
| 83 | + secondary: true, |
| 84 | + icon: 'ri-checkbox-circle-line', |
| 85 | + }, |
| 86 | + ], |
71 | 87 | }, |
72 | | - template: ` |
73 | | - <DsfrButtonGroup |
74 | | - :buttons="buttons" |
75 | | - :size="size" |
76 | | - :align="align" |
77 | | - :inline="inline" |
78 | | - :inline-layout-when="inlineLayoutWhen" |
79 | | - :icon-right="iconRight" |
80 | | - :reverse="reverse" |
81 | | - /> |
82 | | - `, |
83 | | -}) |
84 | | -GroupeDeBoutons.args = { |
85 | | - align: 'center', |
86 | | - inlineLayoutWhen: 'never', |
87 | | - reverse: false, |
88 | | - iconRight: false, |
89 | | - size: 'medium', |
90 | | - inline: undefined, |
91 | | - buttons: [ |
92 | | - { |
93 | | - label: 'Label 1', |
94 | | - icon: 'ri-checkbox-circle-line', |
95 | | - }, |
96 | | - { |
97 | | - label: 'Label 2', |
98 | | - secondary: true, |
99 | | - icon: 'ri-checkbox-circle-line', |
100 | | - }, |
101 | | - { |
102 | | - label: 'Label 3', |
103 | | - icon: 'ri-checkbox-circle-line', |
| 88 | + render: (args) => ({ |
| 89 | + components: { |
| 90 | + DsfrButtonGroup, |
| 91 | + VIcon, |
104 | 92 | }, |
105 | | - { |
106 | | - label: 'Label 4', |
107 | | - secondary: true, |
108 | | - icon: 'ri-checkbox-circle-line', |
| 93 | + setup () { |
| 94 | + const buttons = (args.buttons || []).map((btn) => ({ ...btn, onClick: () => {} })) |
| 95 | + return { args, buttons } |
109 | 96 | }, |
110 | | - ], |
111 | | -} |
112 | | -GroupeDeBoutons.play = async ({ canvasElement }) => { |
113 | | - const canvas = within(canvasElement) |
114 | | - const buttons = canvas.getAllByRole('button') |
115 | | - expect(buttons).toHaveLength(4) |
116 | | - for (const button of buttons) { |
117 | | - expect(button).toBeVisible() |
118 | | - } |
| 97 | + template: ` |
| 98 | + <DsfrButtonGroup |
| 99 | + :buttons="buttons" |
| 100 | + :size="args.size" |
| 101 | + :align="args.align" |
| 102 | + :inline-layout-when="args.inlineLayoutWhen" |
| 103 | + :icon-right="args.iconRight" |
| 104 | + :reverse="args.reverse" |
| 105 | + /> |
| 106 | + `, |
| 107 | + }), |
| 108 | + play: async ({ canvasElement }) => { |
| 109 | + const canvas = within(canvasElement) |
| 110 | + const buttons = canvas.getAllByRole('button') |
| 111 | + expect(buttons).toHaveLength(4) |
| 112 | + for (const button of buttons) { |
| 113 | + expect(button).toBeVisible() |
| 114 | + } |
| 115 | + }, |
119 | 116 | } |
0 commit comments