@axa-fr/design-system-look-and-feel-react 0.2.0-beta.335 → 0.2.0-beta.337

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.
@@ -1,12 +1,11 @@
1
1
  import "@axa-fr/design-system-look-and-feel-css/dist/Form/Text/Text.scss";
2
2
  import { ComponentPropsWithRef, MouseEventHandler } from "react";
3
- type Props = Omit<ComponentPropsWithRef<"input">, "required"> & {
3
+ type Props = ComponentPropsWithRef<"input"> & {
4
4
  classModifier?: string;
5
5
  helper?: string;
6
6
  error?: string;
7
7
  description?: string;
8
8
  label?: string;
9
- required?: boolean;
10
9
  buttonLabel?: string;
11
10
  onButtonClick?: MouseEventHandler<HTMLButtonElement>;
12
11
  };
@@ -7,10 +7,10 @@ import { Variants } from "../../Button/Button";
7
7
  import { Svg } from "../../Svg";
8
8
  import { getComponentClassName } from "../../utilities";
9
9
  import { InputError } from "../InputError";
10
- const Text = forwardRef(({ className, classModifier = "", ...otherProps }, inputRef) => {
10
+ const Text = forwardRef(({ className, classModifier = "", label, description, helper, error, buttonLabel, onButtonClick, ...otherProps }, inputRef) => {
11
11
  const componentClassName = getComponentClassName(className, classModifier, "af-form__input-text");
12
- const { id, label, required, disabled, description, helper, error, buttonLabel, onButtonClick, } = otherProps;
13
- return (_jsxs("div", { className: "af-form__input-container", children: [_jsxs("label", { htmlFor: id, className: "af-form__input-label", children: [label, " ", required && _jsx("span", { children: " *" })] }), description && (_jsx("span", { className: "af-form__input-description", children: description })), buttonLabel && (_jsx(Button, { className: "af-form__input-more", variant: Variants.ghost, iconLeft: _jsx(Svg, { src: infoIcon }), onClick: onButtonClick, children: buttonLabel })), _jsx("input", { className: componentClassName, type: "text", ref: inputRef, required: required, disabled: disabled, "aria-invalid": Boolean(error), "aria-describedby": error ? `${id}-error` : undefined, ...otherProps }), helper && _jsx("span", { className: "af-form__input-helper", children: helper }), error && _jsx(InputError, { id: `${id}-error`, message: error })] }));
12
+ const { id, required } = otherProps;
13
+ return (_jsxs("div", { className: "af-form__input-container", children: [_jsxs("label", { htmlFor: id, className: "af-form__input-label", children: [label, " ", required && _jsx("span", { children: " *" })] }), description && (_jsx("span", { className: "af-form__input-description", children: description })), buttonLabel && (_jsx(Button, { className: "af-form__input-more", variant: Variants.ghost, iconLeft: _jsx(Svg, { src: infoIcon }), onClick: onButtonClick, children: buttonLabel })), _jsx("input", { className: componentClassName, type: "text", ref: inputRef, "aria-invalid": Boolean(error), "aria-describedby": error ? `${id}-error` : undefined, ...otherProps }), helper && _jsx("span", { className: "af-form__input-helper", children: helper }), error && _jsx(InputError, { id: `${id}-error`, message: error })] }));
14
14
  });
15
15
  Text.displayName = "Text";
16
16
  export { Text };
@@ -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.335",
3
+ "version": "0.2.0-beta.337",
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.335",
44
+ "@axa-fr/design-system-look-and-feel-css": "0.2.0-beta.337",
45
45
  "@material-symbols/svg-400": ">= 0.19.0",
46
46
  "react": ">= 18"
47
47
  },