|
1 | 1 | import { Button } from "../dist/Button"; |
2 | | -import type { ButtonProps } from "../dist/Button"; |
3 | 2 | import { sectionName } from "./sectionName"; |
4 | | -import { getStoryFactory } from "./getStory"; |
| 3 | +import { getStoryFactory, logCallbacks } from "./getStory"; |
5 | 4 |
|
6 | | -const { meta, getStory } = getStoryFactory<ButtonProps>({ |
| 5 | +const { meta, getStory } = getStoryFactory({ |
7 | 6 | sectionName, |
8 | | - wrappedComponent: { Button }, |
9 | | - description: ` |
| 7 | + "wrappedComponent": { Button }, |
| 8 | + "description": ` |
10 | 9 | - [See DSFR documentation](https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/bouton) |
11 | 10 | - [See source code](https://github.com/codegouvfr/react-dsfr/blob/main/src/Button.tsx)`, |
12 | | - "argTypes": { |
13 | | - "priority": { |
14 | | - "options": ((): ButtonProps["priority"][] => ["secondary", "tertiary"])(), |
15 | | - "control": { "type": "radio" } |
16 | | - }, |
17 | | - "label": { |
18 | | - "description": `Required` |
19 | | - }, |
20 | | - "href": { |
21 | | - "description": |
22 | | - "If set, Button component will render a <a> tag, otherwise, it will render a <button>" |
23 | | - }, |
24 | | - "type": { |
25 | | - "options": ((): ButtonProps["type"][] => ["button", "submit", "reset"])(), |
26 | | - "control": { "type": "radio" }, |
27 | | - "description": |
28 | | - "Type can only be set on <button> element. If the Button component has no href, it will render a <button> element. If type prop is not set, it will render a type='submit' attribute (default value for a <button> element" |
29 | | - }, |
30 | | - "onClick": { |
31 | | - "description": |
32 | | - "onClick callback, can only be set if Button has no href prop set (to prevent onClick='window.open()' type behavior)" |
33 | | - }, |
34 | | - "disabled": { |
35 | | - "description": |
36 | | - "Can only be set if Button has no href prop set (disabled can't be set on <a> element)" |
37 | | - }, |
38 | | - "target": { |
39 | | - "description": `Can only be set with a href attribute`, |
40 | | - "options": ((): ButtonProps["target"][] => ["_self", "_blank", "_parent", "_top"])() |
41 | | - }, |
42 | | - "size": { |
43 | | - "description": `Can only be set with a href attribute`, |
44 | | - "options": ((): ButtonProps["size"][] => ["sm", "lg"])() |
45 | | - } |
46 | | - }, |
47 | 11 | "disabledProps": ["lang"] |
48 | 12 | }); |
49 | 13 |
|
50 | 14 | export default meta; |
51 | 15 |
|
52 | 16 | export const Default = getStory({ |
53 | | - label: "Simple button" |
| 17 | + "label": "Simple button", |
| 18 | + ...logCallbacks(["onClick"]) |
54 | 19 | }); |
55 | 20 |
|
56 | 21 | export const ButtonSecondary = getStory({ |
57 | | - priority: "secondary", |
58 | | - label: "Simple button - secondary" |
| 22 | + "priority": "secondary", |
| 23 | + "label": "Simple button - secondary", |
| 24 | + ...logCallbacks(["onClick"]) |
59 | 25 | }); |
60 | 26 |
|
61 | 27 | export const ButtonTertiary = getStory({ |
62 | | - priority: "tertiary", |
63 | | - label: "Simple button - tertiary" |
| 28 | + "priority": "tertiary", |
| 29 | + "label": "Simple button - tertiary", |
| 30 | + ...logCallbacks(["onClick"]) |
64 | 31 | }); |
65 | 32 |
|
66 | 33 | export const ButtonDisabled = getStory({ |
67 | | - label: "Simple button - disabled", |
68 | | - disabled: true |
| 34 | + "label": "Simple button - disabled", |
| 35 | + "disabled": true, |
| 36 | + ...logCallbacks(["onClick"]) |
69 | 37 | }); |
70 | 38 |
|
71 | 39 | export const ButtonWithIconDefault = getStory({ |
72 | | - label: "Simple button with icon", |
73 | | - icon: { |
74 | | - name: "fr-icon-account-circle-fill" |
75 | | - } |
| 40 | + "label": "Simple button with icon", |
| 41 | + "icon": { |
| 42 | + iconId: "fr-icon-account-circle-fill" |
| 43 | + }, |
| 44 | + ...logCallbacks(["onClick"]) |
76 | 45 | }); |
77 | 46 |
|
78 | 47 | export const ButtonWithIconLeft = getStory({ |
79 | | - label: "Simple button with icon", |
80 | | - icon: { |
81 | | - name: "fr-icon-account-circle-fill", |
82 | | - position: "left" |
83 | | - } |
| 48 | + "label": "Simple button with icon", |
| 49 | + "icon": { |
| 50 | + "iconId": "fr-icon-account-circle-fill", |
| 51 | + "position": "left" |
| 52 | + }, |
| 53 | + ...logCallbacks(["onClick"]) |
84 | 54 | }); |
85 | 55 |
|
86 | 56 | export const ButtonWithIconRight = getStory({ |
87 | | - label: "Simple button with icon", |
88 | | - icon: { |
89 | | - name: "fr-icon-account-circle-fill", |
90 | | - position: "right" |
91 | | - } |
| 57 | + "label": "Simple button with icon", |
| 58 | + "icon": { |
| 59 | + "iconId": "fr-icon-account-circle-fill", |
| 60 | + "position": "right" |
| 61 | + }, |
| 62 | + ...logCallbacks(["onClick"]) |
92 | 63 | }); |
93 | 64 |
|
94 | 65 | export const DefaultAnchorButton = getStory({ |
95 | | - label: "Simple button - with href (anchor)", |
96 | | - href: "https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/bouton" |
| 66 | + "label": "Simple button - with href (anchor)", |
| 67 | + "linkProps": { |
| 68 | + "href": "https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/bouton", |
| 69 | + "target": "_blank" |
| 70 | + } |
97 | 71 | }); |
98 | 72 |
|
99 | 73 | export const DefaultAnchorButtonWithTargetBlank = getStory({ |
100 | | - label: "Simple button - with href (anchor) and target _blank", |
101 | | - target: "_blank", |
102 | | - href: "https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/bouton" |
| 74 | + "label": "Simple button - with href (anchor) and target _blank", |
| 75 | + "linkProps": { |
| 76 | + "target": "_blank", |
| 77 | + "href": "https://www.systeme-de-design.gouv.fr/elements-d-interface/composants/bouton" |
| 78 | + } |
103 | 79 | }); |
0 commit comments