@synerise/ds-modal 1.5.0 → 1.5.2
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/CHANGELOG.md +12 -0
- package/README.md +6 -0
- package/dist/Elements/ModalContent/ModalContent.d.ts +1 -1
- package/dist/Elements/ModalContent/ModalContent.js +9 -18
- package/dist/Elements/ModalContent/ModalContent.styles.js +2 -2
- package/dist/Elements/ModalTitle/ModalTitle.d.ts +1 -1
- package/dist/Elements/ModalTitle/ModalTitle.js +16 -5
- package/dist/Modal.js +15 -3
- package/dist/Modal.types.d.ts +140 -9
- package/dist/ShowModal.d.ts +1 -1
- package/dist/ShowModal.js +14 -4
- package/package.json +9 -8
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.5.2](https://github.com/synerise/synerise-design/compare/@synerise/ds-modal@1.5.1...@synerise/ds-modal@1.5.2) (2026-06-03)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **modal:** a11y and other tweaks ([cfbeb11](https://github.com/synerise/synerise-design/commit/cfbeb11c8e1a60d99885ec87e91783eb1800c8d9))
|
|
11
|
+
|
|
12
|
+
## [1.5.1](https://github.com/synerise/synerise-design/compare/@synerise/ds-modal@1.5.0...@synerise/ds-modal@1.5.1) (2026-05-26)
|
|
13
|
+
|
|
14
|
+
### Bug Fixes
|
|
15
|
+
|
|
16
|
+
- **modal:** imperative api leak ([baca840](https://github.com/synerise/synerise-design/commit/baca840aea23d21f7fd156668c2c3361158979a2))
|
|
17
|
+
|
|
6
18
|
# [1.5.0](https://github.com/synerise/synerise-design/compare/@synerise/ds-modal@1.4.14...@synerise/ds-modal@1.5.0) (2026-05-22)
|
|
7
19
|
|
|
8
20
|
### Features
|
package/README.md
CHANGED
|
@@ -118,6 +118,12 @@ ref.current?.scrollToBottom();
|
|
|
118
118
|
| `zIndex` | `z-index` of the modal | `number` | – |
|
|
119
119
|
| `className` | CSS class applied to the modal root | `string` | – |
|
|
120
120
|
| `style` | Inline styles applied to the modal root | `CSSProperties` | – |
|
|
121
|
+
| `ariaLabel` | Accessible name for the dialog. Used as a fallback when `title` is absent (e.g. `blank` modals) or is a non-text node | `string` | – |
|
|
122
|
+
| `closeButtonAriaLabel` | Accessible name for the close button. Defaults to the localised `DS.MODAL.CLOSE` translation | `string` | `Close` |
|
|
123
|
+
|
|
124
|
+
### Accessibility
|
|
125
|
+
|
|
126
|
+
The dialog container carries `role="dialog"` and `aria-modal="true"`. When a `title` is provided it is linked via `aria-labelledby`; otherwise pass `ariaLabel` to give the dialog an accessible name. A `description`, when present, is linked via `aria-describedby`. The close button's accessible name defaults to the localised `DS.MODAL.CLOSE` translation (`"Close"`), overridable with `closeButtonAriaLabel`. Focus is trapped while the modal is open and restored to the previously focused element on close, and `Escape` closes the modal when `onCancel` is set and `closable` is not `false`.
|
|
121
127
|
|
|
122
128
|
### Footer layout slots
|
|
123
129
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { ModalRef } from '../../Modal.types';
|
|
3
|
-
export declare const ModalContent: React.ForwardRefExoticComponent<Omit<import('../../Modal.types').ModalProps, "getContainer" | "open" | "destroyOnClose"> & {
|
|
3
|
+
export declare const ModalContent: React.ForwardRefExoticComponent<Omit<import('../../Modal.types').ModalProps, "getContainer" | "open" | "destroyOnClose" | "afterClose"> & {
|
|
4
4
|
closeModal: () => void;
|
|
5
5
|
hidden?: boolean;
|
|
6
6
|
} & React.RefAttributes<ModalRef>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useRef,
|
|
2
|
+
import { forwardRef, useRef, useId, useMemo, useCallback, useImperativeHandle } from "react";
|
|
3
3
|
import { useFocusTrap } from "@synerise/ds-utils";
|
|
4
4
|
import { SIZE_MAP } from "../../Modal.const.js";
|
|
5
5
|
import { ModalFooter } from "../ModalFooter/ModalFooter.js";
|
|
@@ -8,7 +8,6 @@ import { ModalRoot, ModalMask, ModalScrollWrap, ModalContainer, ModalBody, Modal
|
|
|
8
8
|
const ModalContent = forwardRef(({
|
|
9
9
|
children,
|
|
10
10
|
size = "small",
|
|
11
|
-
afterClose,
|
|
12
11
|
maxViewportHeight,
|
|
13
12
|
headerActions,
|
|
14
13
|
blank,
|
|
@@ -41,9 +40,13 @@ const ModalContent = forwardRef(({
|
|
|
41
40
|
maskClosable = true,
|
|
42
41
|
centered,
|
|
43
42
|
hidden,
|
|
43
|
+
ariaLabel,
|
|
44
|
+
closeButtonAriaLabel,
|
|
44
45
|
...rest
|
|
45
46
|
}, modalRef) => {
|
|
46
47
|
const scrollRef = useRef(null);
|
|
48
|
+
const titleId = useId();
|
|
49
|
+
const descriptionId = useId();
|
|
47
50
|
const DEFAULT_VIEWPORT_HEIGHT = 80;
|
|
48
51
|
const isFullscreen = size === "fullScreen";
|
|
49
52
|
const maxHeight = useMemo(() => {
|
|
@@ -55,11 +58,6 @@ const ModalContent = forwardRef(({
|
|
|
55
58
|
}
|
|
56
59
|
return void 0;
|
|
57
60
|
}, [maxViewportHeight]);
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
return () => {
|
|
60
|
-
afterClose?.();
|
|
61
|
-
};
|
|
62
|
-
}, []);
|
|
63
61
|
const scrollToTop = useCallback(() => {
|
|
64
62
|
scrollRef.current?.scrollTo(0, 0);
|
|
65
63
|
}, []);
|
|
@@ -83,15 +81,8 @@ const ModalContent = forwardRef(({
|
|
|
83
81
|
}
|
|
84
82
|
closeModal();
|
|
85
83
|
};
|
|
86
|
-
const handleOk =
|
|
87
|
-
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const onOkResult = onOk(event);
|
|
91
|
-
if (onOkResult?.then !== void 0) {
|
|
92
|
-
await onOkResult;
|
|
93
|
-
closeModal();
|
|
94
|
-
}
|
|
84
|
+
const handleOk = (event) => {
|
|
85
|
+
onOk?.(event);
|
|
95
86
|
};
|
|
96
87
|
const cancelClick = (event) => {
|
|
97
88
|
event.stopPropagation();
|
|
@@ -111,8 +102,8 @@ const ModalContent = forwardRef(({
|
|
|
111
102
|
useFocusTrap(containerRef, !hidden);
|
|
112
103
|
return /* @__PURE__ */ jsxs(ModalRoot, { "data-testid": "ds-modal", ...rest, $hidden: hidden, "data-visible": !hidden, onKeyDown: handleKeyDown, tabIndex: -1, ref: containerRef, children: [
|
|
113
104
|
/* @__PURE__ */ jsx(ModalMask, {}),
|
|
114
|
-
/* @__PURE__ */ jsx(ModalScrollWrap, { ref: scrollRef, onClick: handleMaskClick, children: /* @__PURE__ */ jsxs(ModalContainer, { onClick: cancelClick, role: "dialog", isFullscreen, $width: size && SIZE_MAP[size], maxHeight, centered, children: [
|
|
115
|
-
/* @__PURE__ */ jsx(ModalTitle, { headerActions, blank, titleContainerStyle, onCancel: closable && onCancel ? handleCancel : void 0, title, description, headerTabProps, headerBottomBar }),
|
|
105
|
+
/* @__PURE__ */ jsx(ModalScrollWrap, { ref: scrollRef, onClick: handleMaskClick, children: /* @__PURE__ */ jsxs(ModalContainer, { onClick: cancelClick, role: "dialog", "aria-modal": true, "aria-labelledby": title ? titleId : void 0, "aria-label": !title ? ariaLabel : void 0, "aria-describedby": description ? descriptionId : void 0, isFullscreen, $width: size && SIZE_MAP[size], maxHeight, centered, children: [
|
|
106
|
+
/* @__PURE__ */ jsx(ModalTitle, { headerActions, blank, titleContainerStyle, onCancel: closable && onCancel ? handleCancel : void 0, title, titleId, description, descriptionId, headerTabProps, headerBottomBar, closeButtonAriaLabel }),
|
|
116
107
|
/* @__PURE__ */ jsx(ModalBody, { greyBackground: bodyBackground === "grey", bodyFullWidth, style: bodyStyle, children: maxHeight && !disableScrollbar ? /* @__PURE__ */ jsx(ModalWrapper, { children: /* @__PURE__ */ jsx(Scrollbar, { absolute: true, children }) }) : children }),
|
|
117
108
|
/* @__PURE__ */ jsx(ModalFooter, { CustomFooterButton, prefix, infix, suffix, onOk: onOk ? handleOk : void 0, onCancel: onCancel ? handleCancel : void 0, texts, okButton, okButtonProps, cancelButton, cancelButtonProps, cancelText, okText, okType, footer })
|
|
118
109
|
] }) })
|
|
@@ -11,11 +11,11 @@ const ModalWrapper = /* @__PURE__ */ styled.div.withConfig({
|
|
|
11
11
|
const Scrollbar = /* @__PURE__ */ styled(ScrollbarBase).withConfig({
|
|
12
12
|
displayName: "ModalContentstyles__Scrollbar",
|
|
13
13
|
componentId: "sc-1sk67uc-2"
|
|
14
|
-
})(["display:flex;flex-direction:column;min-height:0;.scrollbar-container{min-height:0;}"]);
|
|
14
|
+
})(["display:flex;flex-direction:column;min-height:0;.scrollbar-container{min-height:0;}.ps__rail-y,.ps__rail-x{z-index:99;}"]);
|
|
15
15
|
const ModalBody = /* @__PURE__ */ styled.div.withConfig({
|
|
16
16
|
displayName: "ModalContentstyles__ModalBody",
|
|
17
17
|
componentId: "sc-1sk67uc-3"
|
|
18
|
-
})(["", " ", ""], (props) => !props.bodyFullWidth && `padding: 24px;`, (props) => props.greyBackground && `background: ${props.theme.palette["grey-050"]}
|
|
18
|
+
})(["", " ", " ", ""], (props) => !props.bodyFullWidth && `padding: 24px;`, (props) => props.greyBackground && `background: ${props.theme.palette["grey-050"]};`, (props) => !props.bodyFullWidth && css(["", "{.scrollbar-container{padding-right:24px;}}"], Scrollbar));
|
|
19
19
|
const ModalContainer = /* @__PURE__ */ styled.div.withConfig({
|
|
20
20
|
displayName: "ModalContentstyles__ModalContainer",
|
|
21
21
|
componentId: "sc-1sk67uc-4"
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
2
|
import { ModalTitleProps } from '../../Modal.types';
|
|
3
|
-
export declare const ModalTitle: ({ headerActions, blank, titleContainerStyle, onCancel, title, description, headerTabProps, headerBottomBar, }: ModalTitleProps) => React.JSX.Element;
|
|
3
|
+
export declare const ModalTitle: ({ headerActions, blank, titleContainerStyle, onCancel, title, titleId, description, descriptionId, headerTabProps, headerBottomBar, closeButtonAriaLabel, }: ModalTitleProps) => React.JSX.Element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useIntl } from "react-intl";
|
|
2
3
|
import Button from "@synerise/ds-button";
|
|
3
4
|
import Icon, { CloseM } from "@synerise/ds-icon";
|
|
4
5
|
import Tabs from "@synerise/ds-tabs";
|
|
@@ -9,21 +10,31 @@ const ModalTitle = ({
|
|
|
9
10
|
titleContainerStyle,
|
|
10
11
|
onCancel,
|
|
11
12
|
title,
|
|
13
|
+
titleId,
|
|
12
14
|
description,
|
|
15
|
+
descriptionId,
|
|
13
16
|
headerTabProps,
|
|
14
|
-
headerBottomBar
|
|
17
|
+
headerBottomBar,
|
|
18
|
+
closeButtonAriaLabel
|
|
15
19
|
}) => {
|
|
20
|
+
const {
|
|
21
|
+
formatMessage
|
|
22
|
+
} = useIntl();
|
|
23
|
+
const closeLabel = closeButtonAriaLabel ?? formatMessage({
|
|
24
|
+
id: "DS.MODAL.CLOSE",
|
|
25
|
+
defaultMessage: "Close"
|
|
26
|
+
});
|
|
16
27
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
17
|
-
blank && onCancel && /* @__PURE__ */ jsx(CloseButton, { mode: "single-icon", "data-testid": "modal-close", className: "close-modal", type: "ghost", onClick: onCancel, children: /* @__PURE__ */ jsx(Icon, { component: /* @__PURE__ */ jsx(CloseM, {}) }) }),
|
|
28
|
+
blank && onCancel && /* @__PURE__ */ jsx(CloseButton, { mode: "single-icon", "data-testid": "modal-close", className: "close-modal", type: "ghost", "aria-label": closeLabel, onClick: onCancel, children: /* @__PURE__ */ jsx(Icon, { component: /* @__PURE__ */ jsx(CloseM, {}) }) }),
|
|
18
29
|
(title || description || headerTabProps) && /* @__PURE__ */ jsxs(ModalTitleWrapper, { withDescription: !!description, withTabs: !!headerTabProps, children: [
|
|
19
30
|
title && /* @__PURE__ */ jsxs(TitleContainer, { style: titleContainerStyle, "data-testid": "modal-title", children: [
|
|
20
|
-
/* @__PURE__ */ jsx(Title, { level: 3, children: title }),
|
|
31
|
+
/* @__PURE__ */ jsx(Title, { level: 3, id: titleId, children: title }),
|
|
21
32
|
/* @__PURE__ */ jsxs(ActionButtons, { children: [
|
|
22
33
|
headerActions,
|
|
23
|
-
onCancel && /* @__PURE__ */ jsx(Button, { mode: "single-icon", "data-testid": "modal-close", className: "close-modal", type: "ghost", onClick: onCancel, children: /* @__PURE__ */ jsx(Icon, { component: /* @__PURE__ */ jsx(CloseM, {}) }) })
|
|
34
|
+
onCancel && /* @__PURE__ */ jsx(Button, { mode: "single-icon", "data-testid": "modal-close", className: "close-modal", type: "ghost", "aria-label": closeLabel, onClick: onCancel, children: /* @__PURE__ */ jsx(Icon, { component: /* @__PURE__ */ jsx(CloseM, {}) }) })
|
|
24
35
|
] })
|
|
25
36
|
] }),
|
|
26
|
-
description && /* @__PURE__ */ jsx(Description, { children: description }),
|
|
37
|
+
description && /* @__PURE__ */ jsx(Description, { id: descriptionId, children: description }),
|
|
27
38
|
headerTabProps && /* @__PURE__ */ jsx(TabsWrapper, { children: /* @__PURE__ */ jsx(Tabs, { ...headerTabProps }) })
|
|
28
39
|
] }),
|
|
29
40
|
headerBottomBar && /* @__PURE__ */ jsx(BottomBar, { children: headerBottomBar })
|
package/dist/Modal.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useState, useEffect } from "react";
|
|
2
|
+
import { forwardRef, useState, useRef, useEffect } from "react";
|
|
3
3
|
import { createPortal } from "react-dom";
|
|
4
4
|
import { ModalContent } from "./Elements/ModalContent/ModalContent.js";
|
|
5
5
|
const Modal = forwardRef(({
|
|
@@ -11,17 +11,29 @@ const Modal = forwardRef(({
|
|
|
11
11
|
}, ref) => {
|
|
12
12
|
const [isOpen, setIsOpen] = useState(open);
|
|
13
13
|
const [hasBeenOpened, setHasBeenOpened] = useState(open);
|
|
14
|
+
const prevOpenRef = useRef(open);
|
|
14
15
|
useEffect(() => {
|
|
15
16
|
setIsOpen(open);
|
|
16
17
|
if (open) {
|
|
17
18
|
setHasBeenOpened(true);
|
|
19
|
+
} else if (prevOpenRef.current) {
|
|
20
|
+
afterClose?.();
|
|
18
21
|
}
|
|
19
|
-
|
|
22
|
+
prevOpenRef.current = open;
|
|
23
|
+
}, [open, afterClose]);
|
|
24
|
+
const closeModal = () => {
|
|
25
|
+
setIsOpen((prev) => {
|
|
26
|
+
if (prev) {
|
|
27
|
+
afterClose?.();
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
});
|
|
31
|
+
};
|
|
20
32
|
const shouldRender = destroyOnClose ? isOpen : isOpen || hasBeenOpened;
|
|
21
33
|
if (!shouldRender) {
|
|
22
34
|
return null;
|
|
23
35
|
}
|
|
24
|
-
return createPortal(/* @__PURE__ */ jsx(ModalContent, { ...props,
|
|
36
|
+
return createPortal(/* @__PURE__ */ jsx(ModalContent, { ...props, ref, hidden: !isOpen, closeModal }), getContainer?.() || document.body);
|
|
25
37
|
});
|
|
26
38
|
export {
|
|
27
39
|
Modal,
|
package/dist/Modal.types.d.ts
CHANGED
|
@@ -1,72 +1,203 @@
|
|
|
1
1
|
import { CSSProperties, ComponentType, MouseEvent, ReactNode } from 'react';
|
|
2
2
|
import { ButtonProps, ButtonType } from '@synerise/ds-button';
|
|
3
3
|
import { TabsProps } from '@synerise/ds-tabs';
|
|
4
|
+
/**
|
|
5
|
+
* Predefined modal widths.
|
|
6
|
+
*
|
|
7
|
+
* - `small` — 520px
|
|
8
|
+
* - `medium` — 792px
|
|
9
|
+
* - `large` — 1044px
|
|
10
|
+
* - `extraLarge` — 1280px
|
|
11
|
+
* - `fullSize` — 100% width
|
|
12
|
+
* - `fullScreen` — 100%, `fixed`-positioned, covering the viewport
|
|
13
|
+
*/
|
|
4
14
|
export type ModalSize = 'small' | 'medium' | 'large' | 'extraLarge' | 'fullSize' | 'fullScreen';
|
|
15
|
+
/**
|
|
16
|
+
* Handler for the OK / Cancel buttons. May be synchronous or return a
|
|
17
|
+
* `Promise` — when a promise is returned, the modal stays open until it
|
|
18
|
+
* resolves.
|
|
19
|
+
*/
|
|
5
20
|
type ModalButtonHandler = ((e: MouseEvent<HTMLElement>) => void) | ((e: MouseEvent<HTMLElement>) => Promise<unknown>);
|
|
21
|
+
/** Props for the {@link Modal} component. */
|
|
6
22
|
export type ModalProps = {
|
|
7
23
|
/**
|
|
8
|
-
*
|
|
24
|
+
* Sub-title rendered with a dashed separator below the title.
|
|
25
|
+
* @deprecated this prop will be removed soon
|
|
9
26
|
*/
|
|
10
27
|
description?: ReactNode;
|
|
11
|
-
/**
|
|
28
|
+
/** Full-width bar rendered below the modal header. */
|
|
12
29
|
headerBottomBar?: ReactNode;
|
|
13
|
-
/** Actions rendered in the top-right area of the header */
|
|
30
|
+
/** Actions (buttons/icons) rendered in the top-right area of the header. */
|
|
14
31
|
headerActions?: ReactNode;
|
|
32
|
+
/** Modal header title. */
|
|
15
33
|
title?: ReactNode;
|
|
34
|
+
/** When provided, renders a `Tabs` component in the header. */
|
|
16
35
|
headerTabProps?: TabsProps;
|
|
36
|
+
/** Predefined modal width. @see {@link ModalSize} */
|
|
17
37
|
size?: ModalSize;
|
|
38
|
+
/**
|
|
39
|
+
* Accessible name for the dialog, exposed via `aria-label`. Used as a
|
|
40
|
+
* fallback when `title` is absent (e.g. `blank` modals) or is a non-text
|
|
41
|
+
* node. When `title` is set it takes precedence via `aria-labelledby`.
|
|
42
|
+
*/
|
|
43
|
+
ariaLabel?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Accessible name for the close button, exposed via `aria-label`. When
|
|
46
|
+
* omitted, falls back to the localised `DS.MODAL.CLOSE` translation
|
|
47
|
+
* (default message `'Close'`).
|
|
48
|
+
*/
|
|
49
|
+
closeButtonAriaLabel?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Background colour of the modal body.
|
|
52
|
+
* @defaultValue `'white'`
|
|
53
|
+
*/
|
|
18
54
|
bodyBackground?: 'white' | 'grey';
|
|
19
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* Renders a minimal modal without header/footer chrome; shows only a close
|
|
57
|
+
* button when `onCancel` is provided.
|
|
58
|
+
*/
|
|
20
59
|
blank?: boolean;
|
|
60
|
+
/** When `maxViewportHeight` is set, disables the built-in scrollbar wrapper. */
|
|
21
61
|
disableScrollbar?: boolean;
|
|
62
|
+
/** Removes the padding from the modal body. */
|
|
22
63
|
bodyFullWidth?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Vertically centres the modal in the viewport.
|
|
66
|
+
* @defaultValue `false`
|
|
67
|
+
*/
|
|
23
68
|
centered?: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Whether the close button is shown.
|
|
71
|
+
* @defaultValue `true`
|
|
72
|
+
*/
|
|
24
73
|
closable?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Whether clicking the backdrop closes the modal.
|
|
76
|
+
* @defaultValue `true`
|
|
77
|
+
*/
|
|
25
78
|
maskClosable?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Whether the modal is visible.
|
|
81
|
+
* @defaultValue `false`
|
|
82
|
+
*/
|
|
26
83
|
open?: boolean;
|
|
27
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* When `true`, unmounts children when the modal closes. When `false`
|
|
86
|
+
* (default), keeps children mounted but hidden.
|
|
87
|
+
* @defaultValue `false`
|
|
88
|
+
*/
|
|
28
89
|
destroyOnClose?: boolean;
|
|
90
|
+
/** Inline styles applied to the title container element. */
|
|
29
91
|
titleContainerStyle?: CSSProperties;
|
|
30
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Localised default button labels.
|
|
94
|
+
* @defaultValue `{ okButton: 'Apply', cancelButton: 'Cancel' }`
|
|
95
|
+
*/
|
|
31
96
|
texts?: {
|
|
97
|
+
/** Label for the OK / Apply button. */
|
|
32
98
|
okButton?: ReactNode;
|
|
99
|
+
/** Label for the Cancel button. */
|
|
33
100
|
cancelButton?: ReactNode;
|
|
34
101
|
};
|
|
102
|
+
/** Modal body content. */
|
|
35
103
|
children?: ReactNode;
|
|
36
|
-
/**
|
|
104
|
+
/**
|
|
105
|
+
* Constrains modal height to a percentage of the viewport and wraps children
|
|
106
|
+
* in a scrollbar. Pass `true` for 80 vh or a number for a custom value.
|
|
107
|
+
* Anchors the modal to the bottom of the viewport (sheet-style).
|
|
108
|
+
*/
|
|
37
109
|
maxViewportHeight?: true | number;
|
|
110
|
+
/**
|
|
111
|
+
* Returns the DOM node the modal portal mounts into.
|
|
112
|
+
* @defaultValue `document.body`
|
|
113
|
+
*/
|
|
38
114
|
getContainer?: () => HTMLElement;
|
|
115
|
+
/** Footer slot rendered before the cancel button. */
|
|
39
116
|
prefix?: ReactNode;
|
|
117
|
+
/** Footer slot rendered between the cancel and OK buttons. */
|
|
40
118
|
infix?: ReactNode;
|
|
119
|
+
/** Footer slot rendered after the OK button. */
|
|
41
120
|
suffix?: ReactNode;
|
|
121
|
+
/** Replaces the auto-generated OK button entirely. */
|
|
42
122
|
okButton?: ReactNode;
|
|
123
|
+
/** Replaces the auto-generated cancel button entirely. */
|
|
43
124
|
cancelButton?: ReactNode;
|
|
125
|
+
/**
|
|
126
|
+
* Custom button component used for the auto-generated ok/cancel buttons.
|
|
127
|
+
* @defaultValue `Button`
|
|
128
|
+
*/
|
|
44
129
|
CustomFooterButton?: ComponentType<ButtonProps>;
|
|
130
|
+
/**
|
|
131
|
+
* Called after each close transition (every `open: true → false`), matching
|
|
132
|
+
* antd Modal semantics. Does NOT fire on initial mount, and does NOT fire if
|
|
133
|
+
* the Modal is hard-unmounted while still open.
|
|
134
|
+
*/
|
|
45
135
|
afterClose?: () => void;
|
|
136
|
+
/**
|
|
137
|
+
* Custom footer content. `null` suppresses the footer entirely; a custom
|
|
138
|
+
* node overrides the auto-generated footer.
|
|
139
|
+
* @defaultValue auto-generated OK + Cancel buttons
|
|
140
|
+
*/
|
|
46
141
|
footer?: ReactNode;
|
|
142
|
+
/** Cancel/close handler; may return a `Promise`. @see {@link ModalButtonHandler} */
|
|
47
143
|
onCancel?: ModalButtonHandler;
|
|
144
|
+
/** Label for the cancel button (overrides `texts.cancelButton`). */
|
|
48
145
|
cancelText?: ReactNode;
|
|
146
|
+
/** Extra props forwarded to the cancel button. */
|
|
49
147
|
cancelButtonProps?: ButtonProps;
|
|
148
|
+
/** OK button handler; may return a `Promise`. @see {@link ModalButtonHandler} */
|
|
50
149
|
onOk?: ModalButtonHandler;
|
|
150
|
+
/** Label for the OK button (overrides `texts.okButton`). */
|
|
51
151
|
okText?: ReactNode;
|
|
152
|
+
/** Extra props forwarded to the OK button. */
|
|
52
153
|
okButtonProps?: ButtonProps;
|
|
154
|
+
/**
|
|
155
|
+
* Button type for the OK button.
|
|
156
|
+
* @defaultValue `'primary'`
|
|
157
|
+
*/
|
|
53
158
|
okType?: ButtonType;
|
|
159
|
+
/** Inline styles applied to the modal body element. */
|
|
54
160
|
bodyStyle?: CSSProperties;
|
|
161
|
+
/**
|
|
162
|
+
* `z-index` of the modal root.
|
|
163
|
+
* @defaultValue theme `zindex-modal`
|
|
164
|
+
*/
|
|
55
165
|
zIndex?: number;
|
|
166
|
+
/** CSS class applied to the modal root. */
|
|
56
167
|
className?: string;
|
|
168
|
+
/** Inline styles applied to the modal root. */
|
|
57
169
|
style?: CSSProperties;
|
|
58
170
|
};
|
|
59
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Props for the internal `ModalContent` element. Extends {@link ModalProps}
|
|
173
|
+
* minus the props handled by the `Modal` wrapper, plus the internal close
|
|
174
|
+
* callback and hidden state.
|
|
175
|
+
*/
|
|
176
|
+
export type ModalContentProps = Omit<ModalProps, 'getContainer' | 'open' | 'destroyOnClose' | 'afterClose'> & {
|
|
177
|
+
/** Closes the modal (drives the wrapper's open state). */
|
|
60
178
|
closeModal: () => void;
|
|
179
|
+
/** When `true`, the modal is kept mounted but visually hidden. */
|
|
61
180
|
hidden?: boolean;
|
|
62
181
|
};
|
|
63
|
-
|
|
182
|
+
/** Props for the `ModalTitle` header sub-component. */
|
|
183
|
+
export type ModalTitleProps = Pick<ModalContentProps, 'headerActions' | 'headerTabProps' | 'onCancel' | 'titleContainerStyle' | 'blank' | 'description' | 'title' | 'headerBottomBar' | 'closeButtonAriaLabel'> & {
|
|
184
|
+
/** Id applied to the title element, referenced by the dialog's `aria-labelledby`. */
|
|
185
|
+
titleId?: string;
|
|
186
|
+
/** Id applied to the description element, referenced by the dialog's `aria-describedby`. */
|
|
187
|
+
descriptionId?: string;
|
|
188
|
+
};
|
|
189
|
+
/** Props for the `ModalFooter` footer sub-component. */
|
|
64
190
|
export type ModalFooterProps = Pick<ModalContentProps, 'footer' | 'prefix' | 'infix' | 'suffix' | 'okButton' | 'cancelButton' | 'CustomFooterButton' | 'texts' | 'onOk' | 'onCancel' | 'cancelText' | 'okText' | 'cancelButtonProps' | 'okType' | 'okButtonProps'>;
|
|
191
|
+
/** Imperative handle returned by `showModal()`. */
|
|
65
192
|
export type ModalHandle = {
|
|
193
|
+
/** Unmounts the imperatively-rendered modal. */
|
|
66
194
|
destroy: () => void;
|
|
67
195
|
};
|
|
196
|
+
/** Ref handle exposed by `Modal` via `forwardRef` for scroll control. */
|
|
68
197
|
export type ModalRef = {
|
|
198
|
+
/** Scrolls the modal body to the top. */
|
|
69
199
|
scrollToTop: () => void;
|
|
200
|
+
/** Scrolls the modal body to the bottom. */
|
|
70
201
|
scrollToBottom: () => void;
|
|
71
202
|
};
|
|
72
203
|
export {};
|
package/dist/ShowModal.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ModalHandle, ModalProps } from './Modal.types';
|
|
2
|
-
export declare const showModal: ({ afterClose, ...initial }: ModalProps) => ModalHandle;
|
|
2
|
+
export declare const showModal: ({ onOk, afterClose, ...initial }: ModalProps) => ModalHandle;
|
package/dist/ShowModal.js
CHANGED
|
@@ -2,21 +2,31 @@ import { jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { setPortalContent } from "@synerise/ds-core";
|
|
3
3
|
import { Modal } from "./Modal.js";
|
|
4
4
|
let modalInstanceId = 0;
|
|
5
|
+
const isThenable = (value) => !!value && typeof value.then === "function";
|
|
5
6
|
const showModal = ({
|
|
7
|
+
onOk,
|
|
6
8
|
afterClose,
|
|
7
9
|
...initial
|
|
8
10
|
}) => {
|
|
9
11
|
const cleanup = () => {
|
|
10
12
|
setPortalContent(null);
|
|
11
13
|
};
|
|
14
|
+
const handle = {
|
|
15
|
+
destroy: cleanup
|
|
16
|
+
};
|
|
17
|
+
const handleOk = async (event) => {
|
|
18
|
+
const result = onOk?.(event);
|
|
19
|
+
if (isThenable(result)) {
|
|
20
|
+
await result;
|
|
21
|
+
handle.destroy();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
12
24
|
modalInstanceId += 1;
|
|
13
|
-
setPortalContent(/* @__PURE__ */ jsx(Modal, { ...initial, open: true, afterClose: () => {
|
|
25
|
+
setPortalContent(/* @__PURE__ */ jsx(Modal, { ...initial, open: true, onOk: onOk ? handleOk : void 0, afterClose: () => {
|
|
14
26
|
afterClose?.();
|
|
15
27
|
cleanup();
|
|
16
28
|
} }, modalInstanceId));
|
|
17
|
-
return
|
|
18
|
-
destroy: cleanup
|
|
19
|
-
};
|
|
29
|
+
return handle;
|
|
20
30
|
};
|
|
21
31
|
export {
|
|
22
32
|
showModal
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-modal",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "Modal UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "synerise/synerise-design",
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"sideEffects": false,
|
|
39
39
|
"types": "dist/index.d.ts",
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@synerise/ds-button": "^1.5.
|
|
42
|
-
"@synerise/ds-icon": "^1.18.
|
|
43
|
-
"@synerise/ds-scrollbar": "^1.4.
|
|
44
|
-
"@synerise/ds-tabs": "^1.1.
|
|
45
|
-
"@synerise/ds-typography": "^1.1.
|
|
46
|
-
"@synerise/ds-utils": "^1.9.
|
|
41
|
+
"@synerise/ds-button": "^1.5.31",
|
|
42
|
+
"@synerise/ds-icon": "^1.18.2",
|
|
43
|
+
"@synerise/ds-scrollbar": "^1.4.1",
|
|
44
|
+
"@synerise/ds-tabs": "^1.1.39",
|
|
45
|
+
"@synerise/ds-typography": "^1.1.24",
|
|
46
|
+
"@synerise/ds-utils": "^1.9.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"vitest": "4"
|
|
@@ -51,7 +51,8 @@
|
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@synerise/ds-core": "*",
|
|
53
53
|
"react": ">=16.9.0 <= 18.3.1",
|
|
54
|
+
"react-intl": ">=3.12.0 <= 6.8",
|
|
54
55
|
"styled-components": "^5.3.3"
|
|
55
56
|
},
|
|
56
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "5464a62f3d5e1620879a68832ef3f78096390b94"
|
|
57
58
|
}
|