Skip to content

Commit 20be8c1

Browse files
Abderrahman FAWZY DEVAbderrahman FAWZY DEV
authored andcommitted
feat(look&feel): fixed errors in modal stories and importing modal from apollo/lf
1 parent b9ed4cd commit 20be8c1

File tree

6 files changed

+178
-337
lines changed

6 files changed

+178
-337
lines changed

apps/look-and-feel-stories/src/Modal/FromApolloLF/Modal.stories.tsx

Lines changed: 0 additions & 112 deletions
This file was deleted.

apps/look-and-feel-stories/src/Modal/FromApolloLF/ModalCore.stories.tsx

Lines changed: 0 additions & 116 deletions
This file was deleted.

apps/look-and-feel-stories/src/Modal/Modal.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ export const YourComponent = () => {
6666
};
6767
```
6868

69-
<Canvas of={ModalCoreStories.DefaultModalStory} />
69+
<Canvas of={ModalCoreStories.ModalCore} />
7070

71-
<Controls of={ModalCoreStories.DefaultModalStory} />
71+
<Controls of={ModalCoreStories.ModalCore} />
7272

7373
## Modal
7474

@@ -94,6 +94,6 @@ Example of usage of Modal component :
9494
</BooleanModal>
9595
```
9696

97-
<Canvas of={ModalStories.DefaultModalStory} />
97+
<Canvas of={ModalStories.Playground} />
9898

99-
<Controls of={ModalStories.DefaultModalStory} />
99+
<Controls of={ModalStories.Playground} />
Lines changed: 89 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,112 @@
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";
36
import type { Meta, StoryObj } from "@storybook/react";
47
import { fn } from "@storybook/test";
5-
import { ComponentPropsWithRef, useRef } from "react";
8+
import { ComponentPropsWithRef, useLayoutEffect, useRef } from "react";
69

710
const meta: Meta<typeof Modal> = {
811
title: "Components/Modal",
912
component: Modal,
1013
parameters: {
1114
layout: "fullscreen",
15+
viewport: { defaultViewport: "desktop" },
1216
},
1317
args: {
14-
onSubmit: fn(),
18+
onClose: fn(),
1519
onCancel: fn(),
1620
},
1721
};
1822
export default meta;
1923

20-
type TDefaultModalStory = StoryObj<ComponentPropsWithRef<typeof Modal>>;
24+
type ModalStory = StoryObj<ComponentPropsWithRef<typeof Modal>>;
2125

22-
export const DefaultModalStory: TDefaultModalStory = {
26+
export const ModalContent: ModalStory = {
2327
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+
],
4644
args: {
47-
open: false,
45+
open: true,
4846
title: "Modal title",
47+
headingProps: {
48+
firstSubtitle: "Modal subtitle",
49+
},
50+
icon: bank,
51+
iconProps: { variant: "primary" },
4952
children:
5053
"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" },
55111
},
56112
};

0 commit comments

Comments
 (0)