@trackunit/react-modal 1.6.61 → 1.7.1

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.
package/index.cjs.js CHANGED
@@ -108,14 +108,33 @@ const ModalBackdrop = ({ children, onClick }) => {
108
108
  * - Modals are used to present critical information or request user input needed to complete a user's workflow.
109
109
  * - Modals interrupt a user's workflow by design.
110
110
  * - The modal component provides a foundation for creating dialogs, lightboxes, etc.
111
+ * - Modals should always be used with the `useModal` hook.
111
112
  *
112
- * - Modals should be used with the `useModal` hook.
113
- * - const modal = useModal();
114
- * - <Modal {...modal} />
113
+ * @example
114
+ * ```tsx
115
+ * const parentComponent = () => {
116
+ * const modal = useModal();
117
+ *
118
+ * return (
119
+ * <ChildComponent {...modal} />
120
+ * );
121
+ * };
122
+ *
123
+ * const childComponent = ({...modalProps}: UseModalReturnValue) => {
124
+ * return (
125
+ * <Modal {...modalProps}>
126
+ * <CardHeader onClose={modalProps.close} heading="My Modal" />
127
+ * <CardBody>
128
+ * <p>This is a modal</p>
129
+ * </CardBody>
130
+ * </Modal>
131
+ * );
132
+ * };
133
+ * ```
115
134
  */
116
- const Modal = ({ children, isOpen, role, dataTestId, className, containerClassName, onBackdropClick, floatingUi, ref, }) => {
135
+ const Modal = ({ children, isOpen, role = "dialog", dataTestId, className, containerClassName, onBackdropClick, floatingUi, ref, }) => {
117
136
  const { rootElement, refs, floatingStyles, context, getFloatingProps } = floatingUi;
118
- return (jsxRuntime.jsx(reactComponents.Portal, { root: rootElement, children: isOpen ? (jsxRuntime.jsx(react$1.FloatingFocusManager, { context: context, children: jsxRuntime.jsx("div", { ref: refs.setFloating, style: { ...floatingStyles, zIndex: uiDesignTokens.zIndex.overlay }, ...getFloatingProps(), children: jsxRuntime.jsx(ModalBackdrop, { onClick: onBackdropClick, children: jsxRuntime.jsx("div", { className: cvaModalContainer({ className: containerClassName }), ref: ref, role: role, children: jsxRuntime.jsx(reactComponents.Card, { className: cvaModalCard({ className }), dataTestId: dataTestId, children: children }) }) }) }) })) : null }));
137
+ return (jsxRuntime.jsx(reactComponents.Portal, { root: rootElement, children: isOpen ? (jsxRuntime.jsx(react$1.FloatingFocusManager, { context: context, children: jsxRuntime.jsx("div", { ref: refs.setFloating, style: { ...floatingStyles, zIndex: uiDesignTokens.zIndex.overlay }, ...getFloatingProps(), children: jsxRuntime.jsx(ModalBackdrop, { onClick: onBackdropClick, children: jsxRuntime.jsx("div", { "aria-modal": true, className: cvaModalContainer({ className: containerClassName }), ref: ref, role: role, children: jsxRuntime.jsx(reactComponents.Card, { className: cvaModalCard({ className }), dataTestId: dataTestId, children: children }) }) }) }) })) : null }));
119
138
  };
120
139
  Modal.displayName = "Modal";
121
140
 
package/index.esm.js CHANGED
@@ -106,14 +106,33 @@ const ModalBackdrop = ({ children, onClick }) => {
106
106
  * - Modals are used to present critical information or request user input needed to complete a user's workflow.
107
107
  * - Modals interrupt a user's workflow by design.
108
108
  * - The modal component provides a foundation for creating dialogs, lightboxes, etc.
109
+ * - Modals should always be used with the `useModal` hook.
109
110
  *
110
- * - Modals should be used with the `useModal` hook.
111
- * - const modal = useModal();
112
- * - <Modal {...modal} />
111
+ * @example
112
+ * ```tsx
113
+ * const parentComponent = () => {
114
+ * const modal = useModal();
115
+ *
116
+ * return (
117
+ * <ChildComponent {...modal} />
118
+ * );
119
+ * };
120
+ *
121
+ * const childComponent = ({...modalProps}: UseModalReturnValue) => {
122
+ * return (
123
+ * <Modal {...modalProps}>
124
+ * <CardHeader onClose={modalProps.close} heading="My Modal" />
125
+ * <CardBody>
126
+ * <p>This is a modal</p>
127
+ * </CardBody>
128
+ * </Modal>
129
+ * );
130
+ * };
131
+ * ```
113
132
  */
114
- const Modal = ({ children, isOpen, role, dataTestId, className, containerClassName, onBackdropClick, floatingUi, ref, }) => {
133
+ const Modal = ({ children, isOpen, role = "dialog", dataTestId, className, containerClassName, onBackdropClick, floatingUi, ref, }) => {
115
134
  const { rootElement, refs, floatingStyles, context, getFloatingProps } = floatingUi;
116
- return (jsx(Portal, { root: rootElement, children: isOpen ? (jsx(FloatingFocusManager, { context: context, children: jsx("div", { ref: refs.setFloating, style: { ...floatingStyles, zIndex: zIndex.overlay }, ...getFloatingProps(), children: jsx(ModalBackdrop, { onClick: onBackdropClick, children: jsx("div", { className: cvaModalContainer({ className: containerClassName }), ref: ref, role: role, children: jsx(Card, { className: cvaModalCard({ className }), dataTestId: dataTestId, children: children }) }) }) }) })) : null }));
135
+ return (jsx(Portal, { root: rootElement, children: isOpen ? (jsx(FloatingFocusManager, { context: context, children: jsx("div", { ref: refs.setFloating, style: { ...floatingStyles, zIndex: zIndex.overlay }, ...getFloatingProps(), children: jsx(ModalBackdrop, { onClick: onBackdropClick, children: jsx("div", { "aria-modal": true, className: cvaModalContainer({ className: containerClassName }), ref: ref, role: role, children: jsx(Card, { className: cvaModalCard({ className }), dataTestId: dataTestId, children: children }) }) }) }) })) : null }));
117
136
  };
118
137
  Modal.displayName = "Modal";
119
138
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-modal",
3
- "version": "1.6.61",
3
+ "version": "1.7.1",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -8,14 +8,14 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "react": "19.0.0",
11
- "@trackunit/react-components": "1.8.15",
12
- "@trackunit/react-core-hooks": "1.6.46",
13
- "@trackunit/css-class-variance-utilities": "1.6.43",
14
- "@trackunit/i18n-library-translation": "1.6.47",
15
- "@trackunit/react-test-setup": "1.3.43",
11
+ "@trackunit/react-components": "1.8.18",
12
+ "@trackunit/react-core-hooks": "1.6.48",
13
+ "@trackunit/css-class-variance-utilities": "1.6.45",
14
+ "@trackunit/i18n-library-translation": "1.6.49",
15
+ "@trackunit/react-test-setup": "1.3.45",
16
16
  "@floating-ui/react": "^0.26.25",
17
17
  "@floating-ui/react-dom": "2.1.2",
18
- "@trackunit/ui-design-tokens": "1.6.45"
18
+ "@trackunit/ui-design-tokens": "1.6.47"
19
19
  },
20
20
  "module": "./index.esm.js",
21
21
  "main": "./index.cjs.js",
@@ -1,19 +1,50 @@
1
- import { PropsWithChildren } from "react";
1
+ import { AriaRole, PropsWithChildren } from "react";
2
2
  import { BaseUseModalActionArgs, UseModalReturnValue } from "./useModal";
3
3
  export type ModalProps<TOnCloseFnArgs extends BaseUseModalActionArgs = [], TOnOpenFnArgs extends BaseUseModalActionArgs = []> = {
4
- role?: string;
4
+ /**
5
+ * The aria role for the modal.
6
+ */
7
+ role?: AriaRole;
8
+ /**
9
+ * The classes for the modal.
10
+ */
5
11
  className?: string;
12
+ /**
13
+ * The classes for the container of the modal.
14
+ */
6
15
  containerClassName?: string;
16
+ /**
17
+ * The test ID applied to the modal.
18
+ */
7
19
  dataTestId?: string;
8
20
  } & PropsWithChildren<UseModalReturnValue<TOnCloseFnArgs, TOnOpenFnArgs>>;
9
21
  /**
10
22
  * - Modals are used to present critical information or request user input needed to complete a user's workflow.
11
23
  * - Modals interrupt a user's workflow by design.
12
24
  * - The modal component provides a foundation for creating dialogs, lightboxes, etc.
25
+ * - Modals should always be used with the `useModal` hook.
13
26
  *
14
- * - Modals should be used with the `useModal` hook.
15
- * - const modal = useModal();
16
- * - <Modal {...modal} />
27
+ * @example
28
+ * ```tsx
29
+ * const parentComponent = () => {
30
+ * const modal = useModal();
31
+ *
32
+ * return (
33
+ * <ChildComponent {...modal} />
34
+ * );
35
+ * };
36
+ *
37
+ * const childComponent = ({...modalProps}: UseModalReturnValue) => {
38
+ * return (
39
+ * <Modal {...modalProps}>
40
+ * <CardHeader onClose={modalProps.close} heading="My Modal" />
41
+ * <CardBody>
42
+ * <p>This is a modal</p>
43
+ * </CardBody>
44
+ * </Modal>
45
+ * );
46
+ * };
47
+ * ```
17
48
  */
18
49
  export declare const Modal: {
19
50
  <TOnCloseFnArgs extends BaseUseModalActionArgs = [], TOnOpenFnArgs extends BaseUseModalActionArgs = []>({ children, isOpen, role, dataTestId, className, containerClassName, onBackdropClick, floatingUi, ref, }: ModalProps<TOnCloseFnArgs, TOnOpenFnArgs>): import("react/jsx-runtime").JSX.Element;
@@ -1,15 +1,15 @@
1
1
  import { Meta, StoryObj } from "@storybook/react-webpack5";
2
2
  import { Modal } from "./Modal";
3
+ import { UseModalReturnValue } from "./useModal";
3
4
  type Story = StoryObj<typeof Modal>;
4
5
  declare const meta: Meta<typeof Modal>;
5
6
  export default meta;
6
7
  export declare const packageName: () => import("react/jsx-runtime").JSX.Element;
7
- export declare const OverviewTemplate: () => import("react/jsx-runtime").JSX.Element;
8
+ export declare const OverviewTemplate: ({ ...modalProps }: UseModalReturnValue) => import("react/jsx-runtime").JSX.Element;
8
9
  export declare const Default: Story;
9
10
  export declare const IncorrectUsageErrorModal: (closeOnOutsideClick: true) => import("react/jsx-runtime").JSX.Element;
10
11
  export declare const CorrectUsagePrimaryAction: (closeOnOutsideClick: true) => import("react/jsx-runtime").JSX.Element;
11
12
  export declare const IncorrectUsageLongText: (closeOnOutsideClick: true) => import("react/jsx-runtime").JSX.Element;
12
13
  export declare const CorrectUsageImportantAction: (closeOnOutsideClick: true) => import("react/jsx-runtime").JSX.Element;
13
- export declare const IncorrectAccessibility: (closeOnOutsideClick: false) => import("react/jsx-runtime").JSX.Element;
14
14
  export declare const CorrectAccessibility: (closeOnOutsideClick: true) => import("react/jsx-runtime").JSX.Element;
15
15
  export declare const CorrectStateManagement: () => import("react/jsx-runtime").JSX.Element;
@@ -24,13 +24,37 @@ type FloatingUiProps = {
24
24
  getFloatingProps: UseInteractionsReturn["getFloatingProps"];
25
25
  };
26
26
  export type UseModalReturnValue<TOnCloseFnArgs extends BaseUseModalActionArgs = [], TOnOpenFnArgs extends BaseUseModalActionArgs = []> = {
27
+ /**
28
+ * The ref for the modal.
29
+ */
27
30
  ref: Ref<HTMLDivElement>;
31
+ /**
32
+ * Whether the modal is open.
33
+ */
28
34
  isOpen: boolean;
35
+ /**
36
+ * Whether the modal should close when the user clicks outside of the modal.
37
+ */
29
38
  closeOnOutsideClick: boolean;
39
+ /**
40
+ * The callback function to call when the user clicks outside of the modal.
41
+ */
30
42
  onBackdropClick: () => void;
43
+ /**
44
+ * A function to call for opening the modal.
45
+ */
31
46
  open: OnOpenFn<TOnOpenFnArgs>;
47
+ /**
48
+ * A function to call for toggling the modal visibility.
49
+ */
32
50
  toggle: (...args: TOnOpenFnArgs | TOnCloseFnArgs) => void;
51
+ /**
52
+ * A function to call for closing the modal.
53
+ */
33
54
  close: OnCloseFn<TOnCloseFnArgs>;
55
+ /**
56
+ * The floating UI properties for the modal.
57
+ */
34
58
  floatingUi: FloatingUiProps;
35
59
  };
36
60
  /**