@axa-fr/design-system-look-and-feel-react 0.2.0-beta.336 → 0.2.0-beta.338

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,7 @@ type ModalProps = {
9
9
  isOpen: boolean;
10
10
  hasCloseBtn?: boolean;
11
11
  onClose?: () => void;
12
+ onClickOutside?: () => void;
12
13
  title: string;
13
14
  subtitle?: string;
14
15
  iconTitle?: ReactNode;
@@ -19,5 +20,5 @@ type ModalProps = {
19
20
  tertiary?: ButtonAction;
20
21
  };
21
22
  };
22
- export declare const Modal: ({ isOpen, hasCloseBtn, onClose, children, title, subtitle, iconTitle, actions, fullWidthButtons, }: PropsWithChildren<ModalProps>) => import("react/jsx-runtime").JSX.Element;
23
+ export declare const Modal: ({ isOpen, hasCloseBtn, onClose, onClickOutside, children, title, subtitle, iconTitle, actions, fullWidthButtons, }: PropsWithChildren<ModalProps>) => import("react/jsx-runtime").JSX.Element;
23
24
  export {};
@@ -4,7 +4,7 @@ import close from "@material-symbols/svg-400/outlined/close.svg";
4
4
  import { ButtonClient as Button, Variants as ButtonVariants, } from "../Button/Button";
5
5
  import "@axa-fr/design-system-look-and-feel-css/dist/Modal/Modal.scss";
6
6
  import { Svg } from "../Svg";
7
- export const Modal = ({ isOpen, hasCloseBtn = true, onClose, children, title, subtitle, iconTitle, actions, fullWidthButtons, }) => {
7
+ export const Modal = ({ isOpen, hasCloseBtn = true, onClose, onClickOutside, children, title, subtitle, iconTitle, actions, fullWidthButtons, }) => {
8
8
  const [isModalOpen, setIsModalOpen] = useState(isOpen);
9
9
  const modalRef = useRef(null);
10
10
  const idTitle = useId();
@@ -35,10 +35,19 @@ export const Modal = ({ isOpen, hasCloseBtn = true, onClose, children, title, su
35
35
  onClose?.();
36
36
  setIsModalOpen(false);
37
37
  };
38
+ const handleClickOutside = () => {
39
+ if (onClickOutside) {
40
+ onClickOutside();
41
+ setIsModalOpen(false);
42
+ }
43
+ else {
44
+ handleCloseModal();
45
+ }
46
+ };
38
47
  const handleKeyDown = (event) => {
39
48
  if (event.key === "Escape") {
40
49
  handleCloseModal();
41
50
  }
42
51
  };
43
- return (_jsxs("dialog", { ref: modalRef, onKeyDown: handleKeyDown, onClick: (e) => e.target === modalRef.current && handleCloseModal(), className: "af-modal", "aria-labelledby": idTitle, "aria-describedby": idContent, children: [_jsxs("div", { id: idTitle, className: "af-modal__top", children: [iconTitle, _jsxs("h2", { className: "af-modal__top-title", children: [_jsxs("div", { children: [_jsx("div", { className: "af-modal__top-title-text", children: title }), subtitle && (_jsx("span", { className: "af-modal__top-title-subtitle", children: subtitle }))] }), hasCloseBtn && (_jsx(Button, { className: "af-modal__top-title-close-btn", onClick: handleCloseModal, type: "button", "aria-label": "close", children: _jsx(Svg, { src: close, width: 32, height: 32 }) }))] })] }), _jsxs("div", { id: idContent, className: "af-modal__content", children: [children, actions && (_jsxs("div", { className: `af-modal__actions${fullWidthButtons ? " af-modal__actions--fullWidth" : ""} `, children: [actions?.primary && (_jsx(Button, { variant: ButtonVariants.primary, onClick: actions?.primary.callback, disabled: actions?.primary.disabled, children: actions?.primary.text })), actions?.secondary && (_jsx(Button, { variant: ButtonVariants.secondary, onClick: actions?.secondary.callback, disabled: actions?.secondary.disabled, children: actions?.secondary.text })), actions?.tertiary && (_jsx(Button, { variant: ButtonVariants.tertiary, onClick: actions?.tertiary.callback, disabled: actions?.tertiary.disabled, children: actions?.tertiary.text }))] }))] })] }));
52
+ return (_jsxs("dialog", { ref: modalRef, onKeyDown: handleKeyDown, onClick: (e) => e.target === modalRef.current && handleClickOutside(), className: "af-modal", "aria-labelledby": idTitle, "aria-describedby": idContent, children: [_jsxs("div", { id: idTitle, className: "af-modal__top", children: [iconTitle, _jsxs("h2", { className: "af-modal__top-title", children: [_jsxs("div", { children: [_jsx("div", { className: "af-modal__top-title-text", children: title }), subtitle && (_jsx("span", { className: "af-modal__top-title-subtitle", children: subtitle }))] }), hasCloseBtn && (_jsx(Button, { className: "af-modal__top-title-close-btn", onClick: handleCloseModal, type: "button", "aria-label": "close", children: _jsx(Svg, { src: close, width: 32, height: 32 }) }))] })] }), _jsxs("div", { id: idContent, className: "af-modal__content", children: [children, actions && (_jsxs("div", { className: `af-modal__actions${fullWidthButtons ? " af-modal__actions--fullWidth" : ""} `, children: [actions?.primary && (_jsx(Button, { variant: ButtonVariants.primary, onClick: actions?.primary.callback, disabled: actions?.primary.disabled, children: actions?.primary.text })), actions?.secondary && (_jsx(Button, { variant: ButtonVariants.secondary, onClick: actions?.secondary.callback, disabled: actions?.secondary.disabled, children: actions?.secondary.text })), actions?.tertiary && (_jsx(Button, { variant: ButtonVariants.tertiary, onClick: actions?.tertiary.callback, disabled: actions?.tertiary.disabled, children: actions?.tertiary.text }))] }))] })] }));
44
53
  };
@@ -1,20 +1,7 @@
1
1
  import { Meta, StoryObj } from "@storybook/react";
2
- import { ReactNode } from "react";
3
- import { ButtonAction, Modal } from "./Modal";
2
+ import { Modal } from "./Modal";
4
3
  declare const meta: Meta<typeof Modal>;
5
4
  export default meta;
6
- type StoryProps = Omit<React.ComponentProps<typeof Modal>, "isOpen" | "hasCloseBtn" | "onClose" | "title" | "iconTitle" | "fullWidthButtons" | "actions"> & {
7
- isOpen: boolean;
8
- hasCloseBtn?: boolean;
9
- onClose?: () => void;
10
- title: string;
11
- iconTitle?: ReactNode;
12
- fullWidthButtons?: boolean;
13
- actions?: {
14
- primary?: ButtonAction;
15
- secondary?: ButtonAction;
16
- tertiary?: ButtonAction;
17
- };
18
- };
5
+ type StoryProps = React.ComponentProps<typeof Modal>;
19
6
  type Story = StoryObj<StoryProps>;
20
7
  export declare const Playground: Story;
@@ -13,7 +13,7 @@ const meta = {
13
13
  export default meta;
14
14
  const Container = (props) => {
15
15
  const [isOpen, setIsOpen] = useState(false);
16
- return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", onClick: () => setIsOpen(true), children: "open modal" }), _jsx(Modal, { ...props, isOpen: isOpen, onClose: () => setIsOpen(false), actions: {
16
+ return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", onClick: () => setIsOpen(true), children: "open modal" }), _jsx(Modal, { ...props, isOpen: isOpen, onClose: () => setIsOpen(false), onClickOutside: undefined, actions: {
17
17
  primary: { text: "Save", callback: () => setIsOpen(false) },
18
18
  secondary: { text: "Cancel", callback: () => setIsOpen(false) },
19
19
  tertiary: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/design-system-look-and-feel-react",
3
- "version": "0.2.0-beta.336",
3
+ "version": "0.2.0-beta.338",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {
@@ -41,7 +41,7 @@
41
41
  },
42
42
  "homepage": "https://github.com/AxaFrance/design-system#readme",
43
43
  "peerDependencies": {
44
- "@axa-fr/design-system-look-and-feel-css": "0.2.0-beta.336",
44
+ "@axa-fr/design-system-look-and-feel-css": "0.2.0-beta.338",
45
45
  "@material-symbols/svg-400": ">= 0.19.0",
46
46
  "react": ">= 18"
47
47
  },