|
1 |
| -import { Button, Modal } from "@axa-fr/design-system-look-and-feel-react"; |
2 |
| -import home from "@material-symbols/svg-400/outlined/home-fill.svg"; |
| 1 | +import "./Modal.story.scss"; |
| 2 | + |
| 3 | +import { Button, Modal } from "@axa-fr/design-system-apollo-react/lf"; |
| 4 | +import bank from "@material-symbols/svg-700/rounded/account_balance.svg"; |
| 5 | +import { action } from "@storybook/addon-actions"; |
3 | 6 | import type { Meta, StoryObj } from "@storybook/react";
|
4 | 7 | import { fn } from "@storybook/test";
|
5 |
| -import { ComponentPropsWithRef, useRef } from "react"; |
| 8 | +import { ComponentPropsWithRef, useLayoutEffect, useRef } from "react"; |
6 | 9 |
|
7 | 10 | const meta: Meta<typeof Modal> = {
|
8 | 11 | title: "Components/Modal",
|
9 | 12 | component: Modal,
|
10 | 13 | parameters: {
|
11 | 14 | layout: "fullscreen",
|
| 15 | + viewport: { defaultViewport: "desktop" }, |
12 | 16 | },
|
13 | 17 | args: {
|
14 |
| - onSubmit: fn(), |
| 18 | + onClose: fn(), |
15 | 19 | onCancel: fn(),
|
16 | 20 | },
|
17 | 21 | };
|
18 | 22 | export default meta;
|
19 | 23 |
|
20 |
| -type TDefaultModalStory = StoryObj<ComponentPropsWithRef<typeof Modal>>; |
| 24 | +type ModalStory = StoryObj<ComponentPropsWithRef<typeof Modal>>; |
21 | 25 |
|
22 |
| -export const DefaultModalStory: TDefaultModalStory = { |
| 26 | +export const ModalContent: ModalStory = { |
23 | 27 | name: "Modal",
|
24 |
| - render: ({ children, ...args }) => { |
25 |
| - const ref = useRef<HTMLDialogElement>(null); |
26 |
| - return ( |
27 |
| - <> |
28 |
| - <Button onClick={() => ref.current?.showModal()}>Open the Modal</Button> |
29 |
| - <Modal |
30 |
| - {...args} |
31 |
| - ref={ref} |
32 |
| - onCancel={(e) => { |
33 |
| - args.onCancel(e as React.MouseEvent | React.KeyboardEvent); |
34 |
| - ref.current?.close(); |
35 |
| - }} |
36 |
| - onSubmit={(e) => { |
37 |
| - args?.onSubmit?.(e as React.MouseEvent | React.KeyboardEvent); |
38 |
| - // Submit the modal form |
39 |
| - }} |
40 |
| - > |
41 |
| - {children} |
42 |
| - </Modal> |
43 |
| - </> |
44 |
| - ); |
45 |
| - }, |
| 28 | + decorators: [ |
| 29 | + (Story, { args: { open, ...args } }) => { |
| 30 | + const modalRef = useRef<HTMLDialogElement>(null); |
| 31 | + |
| 32 | + useLayoutEffect(() => { |
| 33 | + if (open) { |
| 34 | + modalRef.current?.showModal(); |
| 35 | + return; |
| 36 | + } |
| 37 | + |
| 38 | + modalRef.current?.close(); |
| 39 | + }, [open]); |
| 40 | + |
| 41 | + return <Story args={{ ...args, ref: modalRef }} />; |
| 42 | + }, |
| 43 | + ], |
46 | 44 | args: {
|
47 |
| - open: false, |
| 45 | + open: true, |
48 | 46 | title: "Modal title",
|
| 47 | + headingProps: { |
| 48 | + firstSubtitle: "Modal subtitle", |
| 49 | + }, |
| 50 | + icon: bank, |
| 51 | + iconProps: { variant: "primary" }, |
49 | 52 | children:
|
50 | 53 | "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Curabitur pretium tincidunt lacus. Nulla gravida orci a odio. Nullam varius, turpis et commodo pharetra, est eros bibendum elit, nec luctus magna felis sollicitudin mauris",
|
51 |
| - cancelTitle: "Cancel", |
52 |
| - submitTitle: "Submit", |
53 |
| - subtitle: "Modal subtitle", |
54 |
| - iconTitle: home, |
| 54 | + secondaryButtonProps: { |
| 55 | + children: "Cancel", |
| 56 | + onClick: action("[Cancel] onClick"), |
| 57 | + }, |
| 58 | + primaryButtonProps: { |
| 59 | + children: "Submit", |
| 60 | + onClick: action("[Submit] onClick"), |
| 61 | + }, |
| 62 | + }, |
| 63 | +}; |
| 64 | + |
| 65 | +export const Playground: ModalStory = { |
| 66 | + decorators: [ |
| 67 | + (Story, { args: { secondaryButtonProps = {}, ...args } }) => { |
| 68 | + const ref = useRef<HTMLDialogElement>(null); |
| 69 | + |
| 70 | + const onClose = () => { |
| 71 | + args.onClose?.(); |
| 72 | + ref.current?.close(); |
| 73 | + }; |
| 74 | + |
| 75 | + const onClickSecondaryButton: React.MouseEventHandler< |
| 76 | + HTMLButtonElement |
| 77 | + > = (e) => { |
| 78 | + secondaryButtonProps.onClick?.(e); |
| 79 | + ref.current?.close(); |
| 80 | + }; |
| 81 | + |
| 82 | + return ( |
| 83 | + <> |
| 84 | + <div className="button-wrapper"> |
| 85 | + <Button onClick={() => ref.current?.showModal()}> |
| 86 | + Open the Modal |
| 87 | + </Button> |
| 88 | + </div> |
| 89 | + <Story |
| 90 | + args={{ |
| 91 | + ...args, |
| 92 | + ref, |
| 93 | + onClose, |
| 94 | + secondaryButtonProps: { |
| 95 | + ...secondaryButtonProps, |
| 96 | + onClick: onClickSecondaryButton, |
| 97 | + }, |
| 98 | + }} |
| 99 | + /> |
| 100 | + </> |
| 101 | + ); |
| 102 | + }, |
| 103 | + ], |
| 104 | + args: { ...ModalContent.args, open: undefined }, |
| 105 | +}; |
| 106 | + |
| 107 | +export const MobilePlayground: ModalStory = { |
| 108 | + ...Playground, |
| 109 | + parameters: { |
| 110 | + viewport: { defaultViewport: "mobile1" }, |
55 | 111 | },
|
56 | 112 | };
|
0 commit comments