@synerise/ds-modal 0.16.18 → 0.17.0
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 +11 -0
- package/README.md +91 -26
- package/dist/Elements/ModalFooter/ModalFooter.d.ts +4 -0
- package/dist/Elements/ModalFooter/ModalFooter.js +39 -0
- package/dist/Elements/ModalFooter/ModalFooter.spec.d.ts +1 -0
- package/dist/Elements/ModalFooter/ModalFooter.spec.js +96 -0
- package/dist/Elements/ModalFooter/ModalFooter.styles.d.ts +2 -0
- package/dist/Elements/ModalFooter/ModalFooter.styles.js +9 -0
- package/dist/Elements/ModalFooter/index.d.ts +1 -0
- package/dist/Elements/ModalFooter/index.js +1 -0
- package/dist/Elements/ModalTitle/ModalTitle.d.ts +5 -0
- package/dist/Elements/ModalTitle/ModalTitle.js +34 -0
- package/dist/Elements/ModalTitle/ModalTitle.spec.d.ts +1 -0
- package/dist/Elements/ModalTitle/ModalTitle.spec.js +84 -0
- package/dist/Elements/ModalTitle/ModalTitle.styles.d.ts +7 -0
- package/dist/Elements/ModalTitle/ModalTitle.styles.js +24 -0
- package/dist/Elements/ModalTitle/index.d.ts +2 -0
- package/dist/Elements/ModalTitle/index.js +2 -0
- package/dist/Modal.d.ts +13 -28
- package/dist/Modal.js +44 -115
- package/dist/Modal.spec.d.ts +1 -0
- package/dist/Modal.spec.js +75 -0
- package/dist/Modal.styles.d.ts +0 -9
- package/dist/Modal.styles.js +3 -34
- package/dist/Modal.types.d.ts +18 -6
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
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
|
+
# [0.17.0](https://github.com/synerise/synerise-design/compare/@synerise/ds-modal@0.16.18...@synerise/ds-modal@0.17.0) (2023-08-20)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **modal:** create modal footer, header and refactor modal ([ab3603f](https://github.com/synerise/synerise-design/commit/ab3603f5d8ac379ad1700b4a9904f340cd50315a))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [0.16.18](https://github.com/synerise/synerise-design/compare/@synerise/ds-modal@0.16.17...@synerise/ds-modal@0.16.18) (2023-07-26)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @synerise/ds-modal
|
package/README.md
CHANGED
|
@@ -3,47 +3,112 @@ id: modal
|
|
|
3
3
|
title: Modal
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
Modal UI Component
|
|
6
|
+
# Modal UI Component
|
|
7
|
+
|
|
8
|
+
The Modal component provides a flexible and customizable way to display modal dialogs in your React applications. It offers various options and configurations to control the appearance and behavior of the modal dialogs.
|
|
7
9
|
|
|
8
10
|
## Demo
|
|
9
11
|
|
|
10
12
|
<iframe src="/storybook-static/iframe.html?id=components-modal--default"></iframe>
|
|
11
13
|
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Install the Modal component using npm:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @synerise/ds-core
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Deprecated Features
|
|
23
|
+
Some features of the Modal component have been deprecated. Please refer to the [API](#api) and [FOOTER](#modalfooter) section for more information on deprecated features.
|
|
24
|
+
|
|
12
25
|
## API
|
|
13
26
|
|
|
27
|
+
**(Deprecated)** type Props is deprecated - recommended is using ModalProps
|
|
28
|
+
|
|
29
|
+
## ModalProps
|
|
30
|
+
|
|
14
31
|
| Property | Description | Type | Default | Version |
|
|
15
|
-
|
|
32
|
+
|---------------------|------------------------------------------------------------------------------------------------------------|----------------------------------------------------------|-------------------------------------------------| ------- |
|
|
33
|
+
| description | The modal dialog's description | string | - |
|
|
34
|
+
| headerActions | Append additional content to header actions space | React.ReactNode | - |
|
|
35
|
+
| size | The modal size | `small` / `medium` / `large` / `extraLarge`/ `fullSize`. | - |
|
|
36
|
+
| bodyBackground | Set color for body of modal | `white` / `grey` | `white` |
|
|
37
|
+
| blank | Modal with header which contains only close button | Boolean | `false` |
|
|
38
|
+
| titleContainerStyle | The modal title's container styles object | React.CSSProperties / undefined | - |
|
|
39
|
+
| settingButtonText | Text of the setting button | string | `Setting` |
|
|
40
|
+
| texts | Labels to render | `{ okButton: string; cancelButton: string }` | `{ okButton: 'Apply', cancelButton: 'Cancel' }` |
|
|
41
|
+
| children | Children element to render | `{ okButton: string; cancelButton: string }` | - |
|
|
42
|
+
| visible | Whether the modal dialog is visible or not | boolean | `false` |
|
|
43
|
+
| confirmLoading | Whether to apply loading visual effect for OK button or not | boolean | `false` |
|
|
44
|
+
| title | The modal dialog's title | string / ReactNode | - |
|
|
45
|
+
| closable | Whether a close (x) button is visible on top right of the modal dialog or not | boolean | `true` |
|
|
46
|
+
| onOk | Specify a function that will be called when a user clicks the OK button | function(e) | - |
|
|
47
|
+
| onCancel | Specify a function that will be called when a user clicks mask, close button on top right or Cancel button | function(e) | - |
|
|
16
48
|
| afterClose | Specify a function that will be called when modal is closed completely. | function | - |
|
|
17
|
-
| bodyStyle | Body style for modal body element. Such as height, padding etc. | object | {} |
|
|
18
|
-
| cancelText | Text of the Cancel button | string / ReactNode | `Cancel` |
|
|
19
49
|
| centered | Centered Modal | Boolean | `false` |
|
|
20
|
-
|
|
|
21
|
-
| closeIcon | custom close icon | ReactNode | - |
|
|
22
|
-
| confirmLoading | Whether to apply loading visual effect for OK button or not | boolean | `false` |
|
|
23
|
-
| destroyOnClose | Whether to unmount child components on onClose | boolean | `false` |
|
|
50
|
+
| width | Width of the modal dialog | string / number | 520 |
|
|
24
51
|
| footer | Footer content, set as `footer={null}` when you don't need default buttons | string / ReactNode | OK and Cancel buttons |
|
|
25
|
-
| forceRender | Force render Modal | boolean | `false` |
|
|
26
|
-
| getContainer | Return the mount node for Modal | HTMLElement / () => HTMLElement / Selectors /`false` | document.body |
|
|
27
|
-
| mask | Whether show mask or not. | Boolean | `true` |
|
|
28
|
-
| maskClosable | Whether to close the modal dialog when the mask (area outside the modal) is clicked | boolean | `true` |
|
|
29
|
-
| maskStyle | Style for modal's mask element. | object | {} |
|
|
30
52
|
| okText | Text of the OK button | string / ReactNode | `OK` |
|
|
31
53
|
| okType | Button `type` of the OK button | string | `primary` |
|
|
54
|
+
| cancelText | Text of the Cancel button | string / ReactNode | `Cancel` |
|
|
55
|
+
| maskClosable | Whether to close the modal dialog when the mask (area outside the modal) is clicked | boolean | `true` |
|
|
56
|
+
| forceRender | Force render Modal | boolean | `false` |
|
|
32
57
|
| okButtonProps | The ok button props | [ButtonProps](/components/button) | - |
|
|
33
58
|
| cancelButtonProps | The cancel button props | [ButtonProps](/components/button) | - |
|
|
59
|
+
| destroyOnClose | Whether to unmount child components on onClose | boolean | `false` |
|
|
34
60
|
| style | Style of floating layer, typically used at least for adjusting the position. | object | - |
|
|
35
|
-
| title | The modal dialog's title | string / ReactNode | - |
|
|
36
|
-
| titleContainerStyle | The modal title's container styles object | React.CSSProperties / undefined | - |
|
|
37
|
-
| description | The modal dialog's description | string | - |
|
|
38
|
-
| size | The modal size | `small` / `medium` / `large` / `extraLarge`/ `fullSize`. | - |
|
|
39
|
-
| visible | Whether the modal dialog is visible or not | boolean | `false` |
|
|
40
|
-
| width | Width of the modal dialog | string / number | 520 |
|
|
41
61
|
| wrapClassName | The class name of the container of the modal dialog | string | - |
|
|
62
|
+
| getContainer | Return the mount node for Modal | HTMLElement / () => HTMLElement / Selectors /`false` | document.body |
|
|
42
63
|
| zIndex | The `z-index` of the Modal | Number | 1000 |
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
64
|
+
| bodyStyle | Body style for modal body element. Such as height, padding etc. | object | {} |
|
|
65
|
+
| mask | Whether show mask or not. | Boolean | `true` |
|
|
66
|
+
| closeIcon | custom close icon | ReactNode | - |
|
|
67
|
+
| maskStyle | Style for modal's mask element. | object | {} |
|
|
68
|
+
|
|
69
|
+
and it is extended by props for ModalFooterBuilder:
|
|
70
|
+
|
|
71
|
+
| Property | Description | Type | Default | Version |
|
|
72
|
+
|----------------|--------------------------------------------------------------|-----------------------|---------| ------- |
|
|
73
|
+
| prefix | Element in footer, before Cancel Button | ReactNode | - |
|
|
74
|
+
| infix | Element in footer between Cancel Button nad before Ok Button | ReactNode | - |
|
|
75
|
+
| suffix | Element in footer, after Ok Button | ReactNode | - |
|
|
76
|
+
| okButton | Custom OK button in footer | ReactNode | - |
|
|
77
|
+
| cancelButton | Custom Cancel button in footer | ReactNode | - |
|
|
78
|
+
|
|
79
|
+
## ModalTitle
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
type ModalTitleProps = Pick<
|
|
83
|
+
ModalProps,
|
|
84
|
+
| 'headerActions'
|
|
85
|
+
| 'onCancel'
|
|
86
|
+
| 'titleContainerStyle'
|
|
87
|
+
| 'blank'
|
|
88
|
+
| 'description'
|
|
89
|
+
| 'title'
|
|
90
|
+
>;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## ModalFooter
|
|
94
|
+
```bash
|
|
95
|
+
export type ModalFooterProps = Pick<
|
|
96
|
+
ModalProps,
|
|
97
|
+
| 'prefix'
|
|
98
|
+
| 'infix'
|
|
99
|
+
| 'suffix'
|
|
100
|
+
| 'okButton'
|
|
101
|
+
| 'cancelButton'
|
|
102
|
+
| 'CustomFooterButton'
|
|
103
|
+
| 'DSButton'
|
|
104
|
+
| 'texts'
|
|
105
|
+
| 'onOk'
|
|
106
|
+
| 'onCancel'
|
|
107
|
+
| 'cancelText'
|
|
108
|
+
| 'okText'
|
|
109
|
+
| 'cancelButtonProps'
|
|
110
|
+
| 'okType'
|
|
111
|
+
| 'okButtonProps'
|
|
112
|
+
>;
|
|
113
|
+
```
|
|
114
|
+
**(Deprecated)** method buildModalFooter - use ModalFooter Component instead
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ModalProps } from '../../Modal.types';
|
|
3
|
+
export declare type ModalFooterProps = Pick<ModalProps, 'prefix' | 'infix' | 'suffix' | 'okButton' | 'cancelButton' | 'CustomFooterButton' | 'DSButton' | 'texts' | 'onOk' | 'onCancel' | 'cancelText' | 'okText' | 'cancelButtonProps' | 'okType' | 'okButtonProps'>;
|
|
4
|
+
export declare const ModalFooter: ({ CustomFooterButton, DSButton, prefix, infix, suffix, ...antModalProps }: ModalFooterProps) => JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var _excluded = ["CustomFooterButton", "DSButton", "prefix", "infix", "suffix"];
|
|
2
|
+
|
|
3
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
|
+
|
|
5
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
6
|
+
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import Button from '@synerise/ds-button';
|
|
9
|
+
import * as S from './ModalFooter.styles';
|
|
10
|
+
export var ModalFooter = function ModalFooter(_ref) {
|
|
11
|
+
var _ref$CustomFooterButt = _ref.CustomFooterButton,
|
|
12
|
+
CustomFooterButton = _ref$CustomFooterButt === void 0 ? Button : _ref$CustomFooterButt,
|
|
13
|
+
_ref$DSButton = _ref.DSButton,
|
|
14
|
+
DSButton = _ref$DSButton === void 0 ? Button : _ref$DSButton,
|
|
15
|
+
prefix = _ref.prefix,
|
|
16
|
+
infix = _ref.infix,
|
|
17
|
+
suffix = _ref.suffix,
|
|
18
|
+
antModalProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
19
|
+
|
|
20
|
+
var onOk = antModalProps.onOk,
|
|
21
|
+
onCancel = antModalProps.onCancel,
|
|
22
|
+
_antModalProps$texts = antModalProps.texts,
|
|
23
|
+
texts = _antModalProps$texts === void 0 ? {
|
|
24
|
+
okButton: 'Apply',
|
|
25
|
+
cancelButton: 'Cancel'
|
|
26
|
+
} : _antModalProps$texts;
|
|
27
|
+
var CustomButton = CustomFooterButton || DSButton;
|
|
28
|
+
return /*#__PURE__*/React.createElement(S.FooterContainer, {
|
|
29
|
+
"data-testid": "modal-footer"
|
|
30
|
+
}, prefix, antModalProps.cancelButton || /*#__PURE__*/React.createElement(CustomButton, _extends({
|
|
31
|
+
type: "ghost",
|
|
32
|
+
onClick: onCancel,
|
|
33
|
+
disabled: !onCancel
|
|
34
|
+
}, antModalProps.cancelButtonProps), antModalProps.cancelText || (texts == null ? void 0 : texts.cancelButton)), infix, antModalProps.okButton || /*#__PURE__*/React.createElement(CustomButton, _extends({
|
|
35
|
+
type: antModalProps.okType || 'primary',
|
|
36
|
+
onClick: onOk,
|
|
37
|
+
disabled: !onOk
|
|
38
|
+
}, antModalProps.okButtonProps), antModalProps.okText || (texts == null ? void 0 : texts.okButton)), suffix);
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import { renderWithProvider } from '@synerise/ds-utils/dist/testing';
|
|
5
|
+
import Button from '@synerise/ds-button';
|
|
6
|
+
import { ModalFooter } from './ModalFooter';
|
|
7
|
+
describe('ModalFooter', function () {
|
|
8
|
+
var onOkMock = jest.fn();
|
|
9
|
+
var onCancelMock = jest.fn();
|
|
10
|
+
|
|
11
|
+
var CustomButtonMock = function CustomButtonMock(_ref) {
|
|
12
|
+
var children = _ref.children,
|
|
13
|
+
onClick = _ref.onClick,
|
|
14
|
+
disabled = _ref.disabled;
|
|
15
|
+
return /*#__PURE__*/React.createElement(Button, {
|
|
16
|
+
onClick: onClick,
|
|
17
|
+
disabled: disabled
|
|
18
|
+
}, "Custom ", children);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
beforeEach(function () {
|
|
22
|
+
jest.clearAllMocks();
|
|
23
|
+
});
|
|
24
|
+
it('renders default cancel and apply buttons', function () {
|
|
25
|
+
renderWithProvider( /*#__PURE__*/React.createElement(ModalFooter, {
|
|
26
|
+
onCancel: onCancelMock,
|
|
27
|
+
onOk: onOkMock
|
|
28
|
+
}));
|
|
29
|
+
var cancelButton = screen.getByText('Cancel');
|
|
30
|
+
var okButton = screen.getByText('Apply');
|
|
31
|
+
expect(cancelButton).toBeInTheDocument();
|
|
32
|
+
expect(okButton).toBeInTheDocument();
|
|
33
|
+
});
|
|
34
|
+
it('renders custom cancel and apply buttons', function () {
|
|
35
|
+
var customTexts = {
|
|
36
|
+
cancelButton: 'Custom Cancel',
|
|
37
|
+
okButton: 'Custom Apply'
|
|
38
|
+
};
|
|
39
|
+
renderWithProvider( /*#__PURE__*/React.createElement(ModalFooter, {
|
|
40
|
+
onCancel: onCancelMock,
|
|
41
|
+
onOk: onOkMock,
|
|
42
|
+
texts: customTexts
|
|
43
|
+
}));
|
|
44
|
+
var cancelButton = screen.getByText('Custom Cancel');
|
|
45
|
+
var okButton = screen.getByText('Custom Apply');
|
|
46
|
+
expect(cancelButton).toBeInTheDocument();
|
|
47
|
+
expect(okButton).toBeInTheDocument();
|
|
48
|
+
});
|
|
49
|
+
it('calls onOk and onCancel callbacks when buttons are clicked', function () {
|
|
50
|
+
renderWithProvider( /*#__PURE__*/React.createElement(ModalFooter, {
|
|
51
|
+
onCancel: onCancelMock,
|
|
52
|
+
onOk: onOkMock
|
|
53
|
+
}));
|
|
54
|
+
var cancelButton = screen.getByText('Cancel');
|
|
55
|
+
var okButton = screen.getByText('Apply');
|
|
56
|
+
userEvent.click(cancelButton);
|
|
57
|
+
expect(onCancelMock).toBeCalledTimes(1);
|
|
58
|
+
userEvent.click(okButton);
|
|
59
|
+
expect(onOkMock).toBeCalledTimes(1);
|
|
60
|
+
});
|
|
61
|
+
it('renders prefix, infix and suffix elements in the footer', function () {
|
|
62
|
+
var prefixNode = /*#__PURE__*/React.createElement("div", {
|
|
63
|
+
"data-testid": "prefix"
|
|
64
|
+
}, "Prefix Node");
|
|
65
|
+
var infixNode = /*#__PURE__*/React.createElement("div", {
|
|
66
|
+
"data-testid": "infix"
|
|
67
|
+
}, "Infix Node");
|
|
68
|
+
var suffixNode = /*#__PURE__*/React.createElement("div", {
|
|
69
|
+
"data-testid": "suffix"
|
|
70
|
+
}, "Suffix Node");
|
|
71
|
+
renderWithProvider( /*#__PURE__*/React.createElement(ModalFooter, {
|
|
72
|
+
onCancel: onCancelMock,
|
|
73
|
+
onOk: onOkMock,
|
|
74
|
+
prefix: prefixNode,
|
|
75
|
+
suffix: suffixNode,
|
|
76
|
+
infix: infixNode
|
|
77
|
+
}));
|
|
78
|
+
var prefixElement = screen.getByTestId('prefix');
|
|
79
|
+
var infixElement = screen.getByTestId('infix');
|
|
80
|
+
var suffixElement = screen.getByTestId('suffix');
|
|
81
|
+
expect(prefixElement).toBeInTheDocument();
|
|
82
|
+
expect(infixElement).toBeInTheDocument();
|
|
83
|
+
expect(suffixElement).toBeInTheDocument();
|
|
84
|
+
});
|
|
85
|
+
it('renders custom DSButton component for cancel and apply buttons', function () {
|
|
86
|
+
renderWithProvider( /*#__PURE__*/React.createElement(ModalFooter, {
|
|
87
|
+
onCancel: onCancelMock,
|
|
88
|
+
onOk: onOkMock,
|
|
89
|
+
CustomFooterButton: CustomButtonMock
|
|
90
|
+
}));
|
|
91
|
+
var cancelButton = screen.getByText('Custom Cancel');
|
|
92
|
+
var okButton = screen.getByText('Custom Apply');
|
|
93
|
+
expect(cancelButton).toHaveTextContent('Custom Cancel');
|
|
94
|
+
expect(okButton).toHaveTextContent('Custom Apply');
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import styled from 'styled-components';
|
|
2
|
+
export var FooterContainer = styled.div.withConfig({
|
|
3
|
+
displayName: "ModalFooterstyles__FooterContainer",
|
|
4
|
+
componentId: "sc-1h4mu26-0"
|
|
5
|
+
})(["display:flex;align-items:center;justify-content:flex-end;"]);
|
|
6
|
+
export var CustomFooterContainer = styled.div.withConfig({
|
|
7
|
+
displayName: "ModalFooterstyles__CustomFooterContainer",
|
|
8
|
+
componentId: "sc-1h4mu26-1"
|
|
9
|
+
})(["display:flex;flex-wrap:nowrap;"]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ModalFooter';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ModalFooter';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ModalProps } from '../../Modal.types';
|
|
3
|
+
declare type ModalTitleProps = Pick<ModalProps, 'headerActions' | 'onCancel' | 'titleContainerStyle' | 'blank' | 'description' | 'title'>;
|
|
4
|
+
export declare const ModalTitle: ({ headerActions, blank, titleContainerStyle, onCancel, title, description, }: ModalTitleProps) => JSX.Element;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Button from '@synerise/ds-button';
|
|
3
|
+
import Icon, { CloseM } from '@synerise/ds-icon';
|
|
4
|
+
import * as S from './ModalTitle.styles';
|
|
5
|
+
export var ModalTitle = function ModalTitle(_ref) {
|
|
6
|
+
var headerActions = _ref.headerActions,
|
|
7
|
+
blank = _ref.blank,
|
|
8
|
+
titleContainerStyle = _ref.titleContainerStyle,
|
|
9
|
+
onCancel = _ref.onCancel,
|
|
10
|
+
title = _ref.title,
|
|
11
|
+
description = _ref.description;
|
|
12
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, blank && onCancel && /*#__PURE__*/React.createElement(Button, {
|
|
13
|
+
mode: "single-icon",
|
|
14
|
+
"data-testid": "modal-close",
|
|
15
|
+
className: "close-modal",
|
|
16
|
+
type: "ghost",
|
|
17
|
+
onClick: onCancel
|
|
18
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
19
|
+
component: /*#__PURE__*/React.createElement(CloseM, null)
|
|
20
|
+
})), title && /*#__PURE__*/React.createElement(S.TitleContainer, {
|
|
21
|
+
style: titleContainerStyle,
|
|
22
|
+
"data-testid": "modal-title"
|
|
23
|
+
}, /*#__PURE__*/React.createElement(S.Title, {
|
|
24
|
+
level: 3
|
|
25
|
+
}, title), /*#__PURE__*/React.createElement(S.ActionButtons, null, headerActions, onCancel && /*#__PURE__*/React.createElement(Button, {
|
|
26
|
+
mode: "single-icon",
|
|
27
|
+
"data-testid": "modal-close",
|
|
28
|
+
className: "close-modal",
|
|
29
|
+
type: "ghost",
|
|
30
|
+
onClick: onCancel
|
|
31
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
32
|
+
component: /*#__PURE__*/React.createElement(CloseM, null)
|
|
33
|
+
})))), description && /*#__PURE__*/React.createElement(S.Description, null, description));
|
|
34
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import { renderWithProvider } from '@synerise/ds-utils/dist/testing';
|
|
4
|
+
import userEvent from '@testing-library/user-event';
|
|
5
|
+
import { ModalTitle } from './ModalTitle';
|
|
6
|
+
describe('ModalTitle', function () {
|
|
7
|
+
var onCancelMock = jest.fn();
|
|
8
|
+
var title = 'Test Title';
|
|
9
|
+
var description = 'Test Description';
|
|
10
|
+
beforeEach(function () {
|
|
11
|
+
jest.clearAllMocks();
|
|
12
|
+
});
|
|
13
|
+
it('should render title and description when props are provided', function () {
|
|
14
|
+
renderWithProvider( /*#__PURE__*/React.createElement(ModalTitle, {
|
|
15
|
+
title: title,
|
|
16
|
+
description: description
|
|
17
|
+
}));
|
|
18
|
+
var titleElement = screen.getByText(title);
|
|
19
|
+
var descriptionElement = screen.getByText(description);
|
|
20
|
+
expect(titleElement).toBeInTheDocument();
|
|
21
|
+
expect(descriptionElement).toBeInTheDocument();
|
|
22
|
+
});
|
|
23
|
+
it('should render close button when blank is true and onCancel is provided', function () {
|
|
24
|
+
renderWithProvider( /*#__PURE__*/React.createElement(ModalTitle, {
|
|
25
|
+
blank: true,
|
|
26
|
+
onCancel: onCancelMock
|
|
27
|
+
}));
|
|
28
|
+
var closeButton = screen.getByTestId('modal-close');
|
|
29
|
+
expect(closeButton).toBeInTheDocument();
|
|
30
|
+
});
|
|
31
|
+
it('should call onCancel when the close button is clicked', function () {
|
|
32
|
+
renderWithProvider( /*#__PURE__*/React.createElement(ModalTitle, {
|
|
33
|
+
blank: true,
|
|
34
|
+
onCancel: onCancelMock
|
|
35
|
+
}));
|
|
36
|
+
var closeButton = screen.getByTestId('modal-close');
|
|
37
|
+
userEvent.click(closeButton);
|
|
38
|
+
expect(onCancelMock).toHaveBeenCalled();
|
|
39
|
+
});
|
|
40
|
+
it('should not render close button when blank is true but onCancel is not provided', function () {
|
|
41
|
+
render( /*#__PURE__*/React.createElement(ModalTitle, {
|
|
42
|
+
blank: true
|
|
43
|
+
}));
|
|
44
|
+
var closeButton = screen.queryByTestId('modal-close');
|
|
45
|
+
expect(closeButton).not.toBeInTheDocument();
|
|
46
|
+
});
|
|
47
|
+
it('should render headerActions when provided', function () {
|
|
48
|
+
// eslint-disable-next-line react/button-has-type
|
|
49
|
+
var headerActions = /*#__PURE__*/React.createElement("button", {
|
|
50
|
+
onClick: jest.fn()
|
|
51
|
+
}, "Test Action");
|
|
52
|
+
renderWithProvider( /*#__PURE__*/React.createElement(ModalTitle, {
|
|
53
|
+
title: title,
|
|
54
|
+
headerActions: headerActions
|
|
55
|
+
}));
|
|
56
|
+
var headerActionsElement = screen.getByText('Test Action');
|
|
57
|
+
expect(headerActionsElement).toBeInTheDocument();
|
|
58
|
+
});
|
|
59
|
+
it('should not render headerActions when not provided', function () {
|
|
60
|
+
renderWithProvider( /*#__PURE__*/React.createElement(ModalTitle, {
|
|
61
|
+
title: title
|
|
62
|
+
}));
|
|
63
|
+
var headerActionsElement = screen.queryByText('Test Action');
|
|
64
|
+
expect(headerActionsElement).not.toBeInTheDocument();
|
|
65
|
+
});
|
|
66
|
+
it('should render custom title container style when provided', function () {
|
|
67
|
+
var customStyle = {
|
|
68
|
+
backgroundColor: 'red'
|
|
69
|
+
};
|
|
70
|
+
renderWithProvider( /*#__PURE__*/React.createElement(ModalTitle, {
|
|
71
|
+
title: title,
|
|
72
|
+
titleContainerStyle: customStyle
|
|
73
|
+
}));
|
|
74
|
+
var titleContainer = screen.getByTestId('modal-title');
|
|
75
|
+
expect(titleContainer).toHaveStyle(customStyle);
|
|
76
|
+
});
|
|
77
|
+
it('should not render description when description prop is not provided', function () {
|
|
78
|
+
renderWithProvider( /*#__PURE__*/React.createElement(ModalTitle, {
|
|
79
|
+
title: "Test Title"
|
|
80
|
+
}));
|
|
81
|
+
var descriptionElement = screen.queryByText('Test Description');
|
|
82
|
+
expect(descriptionElement).not.toBeInTheDocument();
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const TitleContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
3
|
+
export declare const Title: import("styled-components").StyledComponent<import("react").FC<Pick<import("antd/lib/typography/Base").BlockProps & {
|
|
4
|
+
level?: 3 | 1 | 5 | 2 | 4 | undefined;
|
|
5
|
+
}, "type" | "className" | "id" | "style" | "title" | "aria-label" | "children" | "disabled" | "prefixCls" | "code" | "mark" | "keyboard" | "editable" | "copyable" | "ellipsis" | "underline" | "delete" | "level">>, any, {}, never>;
|
|
6
|
+
export declare const ActionButtons: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
7
|
+
export declare const Description: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Typography from '@synerise/ds-typography';
|
|
2
|
+
import styled from 'styled-components';
|
|
3
|
+
export var TitleContainer = styled.div.withConfig({
|
|
4
|
+
displayName: "ModalTitlestyles__TitleContainer",
|
|
5
|
+
componentId: "hnk65g-0"
|
|
6
|
+
})(["display:flex;align-items:center;flex-wrap:nowrap;&&{.close-modal{line-height:1;}}"]);
|
|
7
|
+
export var Title = styled(Typography.Title).withConfig({
|
|
8
|
+
displayName: "ModalTitlestyles__Title",
|
|
9
|
+
componentId: "hnk65g-1"
|
|
10
|
+
})(["width:100%;color:", ";white-space:nowrap;overflow:hidden;text-overflow:ellipsis;&&{margin:0;}"], function (props) {
|
|
11
|
+
return props.theme.palette['grey-800'];
|
|
12
|
+
});
|
|
13
|
+
export var ActionButtons = styled.div.withConfig({
|
|
14
|
+
displayName: "ModalTitlestyles__ActionButtons",
|
|
15
|
+
componentId: "hnk65g-2"
|
|
16
|
+
})(["display:flex;flex-direction:row;align-items:center;.ant-btn{margin:0 4px;}.close-modal{padding:0;display:flex;align-items:center;justify-content:center;margin-right:0;}"]);
|
|
17
|
+
export var Description = styled.div.withConfig({
|
|
18
|
+
displayName: "ModalTitlestyles__Description",
|
|
19
|
+
componentId: "hnk65g-3"
|
|
20
|
+
})(["font-size:13px;font-weight:normal;line-height:18px;color:", ";display:block;padding:12px 0 0;margin:14px 0 0;background-image:linear-gradient( to right,", " 33%,rgba(255,255,255,0) 0% );background-repeat:repeat-x;background-size:4px 1px;background-position:top;"], function (props) {
|
|
21
|
+
return props.theme.palette['grey-600'];
|
|
22
|
+
}, function (props) {
|
|
23
|
+
return props.theme.palette['grey-300'];
|
|
24
|
+
});
|
package/dist/Modal.d.ts
CHANGED
|
@@ -1,31 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
import type { ButtonProps } from 'antd/lib/button';
|
|
1
|
+
/// <reference types="react" />
|
|
3
2
|
import '@synerise/ds-core/dist/js/style';
|
|
3
|
+
import { ModalFooterProps } from './Elements/ModalFooter';
|
|
4
|
+
import type { ModalProps } from './Modal.types';
|
|
4
5
|
import './style/index.less';
|
|
5
|
-
|
|
6
|
-
export declare
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
/** @deprecated */
|
|
7
|
+
export declare const buildModalFooter: (props: ModalFooterProps) => JSX.Element;
|
|
8
|
+
export declare const Modal: {
|
|
9
|
+
(props: ModalProps): JSX.Element;
|
|
10
|
+
info: import("antd/lib/modal/confirm").ModalFunc;
|
|
11
|
+
success: import("antd/lib/modal/confirm").ModalFunc;
|
|
12
|
+
error: import("antd/lib/modal/confirm").ModalFunc;
|
|
13
|
+
warning: import("antd/lib/modal/confirm").ModalFunc;
|
|
14
|
+
confirm: import("antd/lib/modal/confirm").ModalFunc;
|
|
13
15
|
};
|
|
14
|
-
export
|
|
15
|
-
declare class ModalProxy extends React.Component<Props> {
|
|
16
|
-
static defaultProps: {
|
|
17
|
-
closable: boolean;
|
|
18
|
-
bodyBackground: string;
|
|
19
|
-
texts: {
|
|
20
|
-
okButton: string;
|
|
21
|
-
cancelButton: string;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
static info: import("antd/lib/modal/confirm").ModalFunc;
|
|
25
|
-
static success: import("antd/lib/modal/confirm").ModalFunc;
|
|
26
|
-
static error: import("antd/lib/modal/confirm").ModalFunc;
|
|
27
|
-
static warning: import("antd/lib/modal/confirm").ModalFunc;
|
|
28
|
-
static confirm: import("antd/lib/modal/confirm").ModalFunc;
|
|
29
|
-
render(): React.ReactNode;
|
|
30
|
-
}
|
|
31
|
-
export default ModalProxy;
|
|
16
|
+
export default Modal;
|
package/dist/Modal.js
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
|
-
var _excluded = ["
|
|
2
|
-
_excluded2 = ["texts", "bodyBackground", "closable", "headerActions", "title", "description", "size", "blank", "settingButtonText", "titleContainerStyle"];
|
|
3
|
-
|
|
4
|
-
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
|
5
|
-
|
|
6
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
1
|
+
var _excluded = ["texts", "bodyBackground", "headerActions", "title", "description", "size", "blank", "settingButtonText", "titleContainerStyle"];
|
|
7
2
|
|
|
8
3
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
9
4
|
|
|
10
5
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
11
6
|
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import Icon, { CloseM } from '@synerise/ds-icon';
|
|
15
|
-
import Button from '@synerise/ds-button';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import classnames from 'classnames';
|
|
16
9
|
import '@synerise/ds-core/dist/js/style';
|
|
10
|
+
import { Modal as AntModal } from 'antd';
|
|
11
|
+
import { ModalFooter } from './Elements/ModalFooter';
|
|
12
|
+
import { ModalTitle } from './Elements/ModalTitle';
|
|
17
13
|
import "./style/index.css";
|
|
18
|
-
import classnames from 'classnames';
|
|
19
14
|
import * as S from './Modal.styles';
|
|
20
15
|
var mapSizeToWidth = {
|
|
21
16
|
small: 520,
|
|
@@ -24,108 +19,42 @@ var mapSizeToWidth = {
|
|
|
24
19
|
extraLarge: 1280,
|
|
25
20
|
fullSize: '100%'
|
|
26
21
|
};
|
|
27
|
-
|
|
28
|
-
var _ref$DSButton = _ref.DSButton,
|
|
29
|
-
DSButton = _ref$DSButton === void 0 ? Button : _ref$DSButton,
|
|
30
|
-
prefix = _ref.prefix,
|
|
31
|
-
infix = _ref.infix,
|
|
32
|
-
suffix = _ref.suffix,
|
|
33
|
-
antModalProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
34
|
-
|
|
35
|
-
var onOk = antModalProps.onOk,
|
|
36
|
-
onCancel = antModalProps.onCancel,
|
|
37
|
-
texts = antModalProps.texts;
|
|
38
|
-
return /*#__PURE__*/React.createElement(S.FooterContainer, null, prefix, antModalProps.cancelButton || /*#__PURE__*/React.createElement(DSButton, _extends({
|
|
39
|
-
type: "ghost",
|
|
40
|
-
onClick: onCancel,
|
|
41
|
-
disabled: !onCancel
|
|
42
|
-
}, antModalProps.cancelButtonProps), antModalProps.cancelText || (texts == null ? void 0 : texts.cancelButton)), infix, antModalProps.okButton || /*#__PURE__*/React.createElement(DSButton, _extends({
|
|
43
|
-
type: antModalProps.okType || 'primary',
|
|
44
|
-
onClick: onOk,
|
|
45
|
-
disabled: !onOk
|
|
46
|
-
}, antModalProps.okButtonProps), antModalProps.okText || (texts == null ? void 0 : texts.okButton)), suffix);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
var ModalProxy = /*#__PURE__*/function (_React$Component) {
|
|
50
|
-
_inheritsLoose(ModalProxy, _React$Component);
|
|
51
|
-
|
|
52
|
-
function ModalProxy() {
|
|
53
|
-
return _React$Component.apply(this, arguments) || this;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
var _proto = ModalProxy.prototype;
|
|
57
|
-
|
|
58
|
-
_proto.render = function render() {
|
|
59
|
-
var _this$props = this.props,
|
|
60
|
-
texts = _this$props.texts,
|
|
61
|
-
bodyBackground = _this$props.bodyBackground,
|
|
62
|
-
closable = _this$props.closable,
|
|
63
|
-
headerActions = _this$props.headerActions,
|
|
64
|
-
title = _this$props.title,
|
|
65
|
-
description = _this$props.description,
|
|
66
|
-
size = _this$props.size,
|
|
67
|
-
blank = _this$props.blank,
|
|
68
|
-
settingButtonText = _this$props.settingButtonText,
|
|
69
|
-
titleContainerStyle = _this$props.titleContainerStyle,
|
|
70
|
-
antModalProps = _objectWithoutPropertiesLoose(_this$props, _excluded2);
|
|
71
|
-
|
|
72
|
-
var handleOnClose = antModalProps.onCancel;
|
|
73
|
-
var className = classnames("bodybg-" + bodyBackground, antModalProps.className, {
|
|
74
|
-
'modal-blank': Boolean(blank)
|
|
75
|
-
}, {
|
|
76
|
-
'with-description': Boolean(description)
|
|
77
|
-
});
|
|
78
|
-
var titleContainer = /*#__PURE__*/React.createElement(React.Fragment, null, blank && closable && /*#__PURE__*/React.createElement(Button, {
|
|
79
|
-
mode: "single-icon",
|
|
80
|
-
"data-testid": "modal-close",
|
|
81
|
-
className: "close-modal",
|
|
82
|
-
type: "ghost",
|
|
83
|
-
onClick: handleOnClose
|
|
84
|
-
}, /*#__PURE__*/React.createElement(Icon, {
|
|
85
|
-
component: /*#__PURE__*/React.createElement(CloseM, null)
|
|
86
|
-
})), title && /*#__PURE__*/React.createElement(S.TitleContainer, {
|
|
87
|
-
style: titleContainerStyle
|
|
88
|
-
}, /*#__PURE__*/React.createElement(S.Title, {
|
|
89
|
-
level: 3
|
|
90
|
-
}, title), /*#__PURE__*/React.createElement(S.ActionButtons, null, headerActions, closable && /*#__PURE__*/React.createElement(Button, {
|
|
91
|
-
mode: "single-icon",
|
|
92
|
-
"data-testid": "modal-close",
|
|
93
|
-
className: "close-modal",
|
|
94
|
-
type: "ghost",
|
|
95
|
-
onClick: handleOnClose
|
|
96
|
-
}, /*#__PURE__*/React.createElement(Icon, {
|
|
97
|
-
component: /*#__PURE__*/React.createElement(CloseM, null)
|
|
98
|
-
})))), description && /*#__PURE__*/React.createElement(S.Description, null, description));
|
|
99
|
-
var footerContainer = antModalProps.footer || buildModalFooter(this.props);
|
|
100
|
-
return /*#__PURE__*/React.createElement(S.AntdModal, _extends({}, antModalProps, {
|
|
101
|
-
className: className,
|
|
102
|
-
width: !size ? undefined : mapSizeToWidth[size],
|
|
103
|
-
closable: false,
|
|
104
|
-
title: (title || description || blank) && titleContainer,
|
|
105
|
-
footer: antModalProps.footer !== null ? footerContainer : null
|
|
106
|
-
}));
|
|
107
|
-
};
|
|
22
|
+
/** @deprecated */
|
|
108
23
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
texts
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
24
|
+
export var buildModalFooter = function buildModalFooter(props) {
|
|
25
|
+
return /*#__PURE__*/React.createElement(ModalFooter, props);
|
|
26
|
+
};
|
|
27
|
+
export var Modal = function Modal(props) {
|
|
28
|
+
var _antModalProps$footer;
|
|
29
|
+
|
|
30
|
+
var texts = props.texts,
|
|
31
|
+
_props$bodyBackground = props.bodyBackground,
|
|
32
|
+
bodyBackground = _props$bodyBackground === void 0 ? 'white' : _props$bodyBackground,
|
|
33
|
+
headerActions = props.headerActions,
|
|
34
|
+
title = props.title,
|
|
35
|
+
description = props.description,
|
|
36
|
+
size = props.size,
|
|
37
|
+
blank = props.blank,
|
|
38
|
+
settingButtonText = props.settingButtonText,
|
|
39
|
+
titleContainerStyle = props.titleContainerStyle,
|
|
40
|
+
antModalProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
41
|
+
|
|
42
|
+
var className = classnames("bodybg-" + bodyBackground, antModalProps.className, {
|
|
43
|
+
'modal-blank': Boolean(blank)
|
|
44
|
+
}, {
|
|
45
|
+
'with-description': Boolean(description)
|
|
46
|
+
});
|
|
47
|
+
return /*#__PURE__*/React.createElement(S.AntdModal, _extends({}, antModalProps, {
|
|
48
|
+
className: className,
|
|
49
|
+
width: size && mapSizeToWidth[size],
|
|
50
|
+
closable: false,
|
|
51
|
+
title: (title || description || blank) && /*#__PURE__*/React.createElement(ModalTitle, props),
|
|
52
|
+
footer: (_antModalProps$footer = antModalProps.footer) != null ? _antModalProps$footer : /*#__PURE__*/React.createElement(ModalFooter, props)
|
|
53
|
+
}));
|
|
54
|
+
};
|
|
55
|
+
Modal.info = AntModal.info;
|
|
56
|
+
Modal.success = AntModal.success;
|
|
57
|
+
Modal.error = AntModal.error;
|
|
58
|
+
Modal.warning = AntModal.warning;
|
|
59
|
+
Modal.confirm = AntModal.confirm;
|
|
60
|
+
export default Modal;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { screen } from '@testing-library/react';
|
|
3
|
+
import { renderWithProvider } from '@synerise/ds-utils/dist/testing';
|
|
4
|
+
import Modal from './Modal';
|
|
5
|
+
describe('Modal', function () {
|
|
6
|
+
var titleMock = 'Test Title';
|
|
7
|
+
var descriptionMock = 'Test Description';
|
|
8
|
+
beforeEach(function () {
|
|
9
|
+
jest.clearAllMocks();
|
|
10
|
+
});
|
|
11
|
+
it('should not render modal if there is no visible prop or visible is false', function () {
|
|
12
|
+
renderWithProvider( /*#__PURE__*/React.createElement(Modal, {
|
|
13
|
+
title: titleMock,
|
|
14
|
+
description: descriptionMock
|
|
15
|
+
}));
|
|
16
|
+
var modalDialog = screen.queryByRole('document');
|
|
17
|
+
expect(modalDialog).not.toBeInTheDocument();
|
|
18
|
+
});
|
|
19
|
+
it('should render title, description, and blank correctly', function () {
|
|
20
|
+
renderWithProvider( /*#__PURE__*/React.createElement(Modal, {
|
|
21
|
+
title: titleMock,
|
|
22
|
+
description: descriptionMock,
|
|
23
|
+
visible: true
|
|
24
|
+
}));
|
|
25
|
+
var titleElement = screen.getByText(titleMock);
|
|
26
|
+
var descriptionElement = screen.getByText(descriptionMock);
|
|
27
|
+
expect(titleElement).toBeInTheDocument();
|
|
28
|
+
expect(descriptionElement).toBeInTheDocument();
|
|
29
|
+
});
|
|
30
|
+
it('should not render title and description when blank, title and description is false', function () {
|
|
31
|
+
renderWithProvider( /*#__PURE__*/React.createElement(Modal, {
|
|
32
|
+
visible: true
|
|
33
|
+
}));
|
|
34
|
+
var titleElement = screen.queryByText(titleMock);
|
|
35
|
+
var descriptionElement = screen.queryByText(descriptionMock);
|
|
36
|
+
var closeButton = screen.queryByTestId('modal-close');
|
|
37
|
+
expect(titleElement).not.toBeInTheDocument();
|
|
38
|
+
expect(descriptionElement).not.toBeInTheDocument();
|
|
39
|
+
expect(closeButton).not.toBeInTheDocument();
|
|
40
|
+
});
|
|
41
|
+
it('should render headerActions when provided', function () {
|
|
42
|
+
// eslint-disable-next-line react/button-has-type
|
|
43
|
+
var headerActions = /*#__PURE__*/React.createElement("button", {
|
|
44
|
+
onClick: jest.fn()
|
|
45
|
+
}, "Test Action");
|
|
46
|
+
renderWithProvider( /*#__PURE__*/React.createElement(Modal, {
|
|
47
|
+
title: titleMock,
|
|
48
|
+
headerActions: headerActions,
|
|
49
|
+
visible: true
|
|
50
|
+
}));
|
|
51
|
+
var headerActionsElement = screen.getByText('Test Action');
|
|
52
|
+
expect(headerActionsElement).toBeInTheDocument();
|
|
53
|
+
});
|
|
54
|
+
it('should render custom size correctly', function () {
|
|
55
|
+
renderWithProvider( /*#__PURE__*/React.createElement(Modal, {
|
|
56
|
+
title: "Test Title",
|
|
57
|
+
size: "medium",
|
|
58
|
+
visible: true
|
|
59
|
+
}));
|
|
60
|
+
var modalDialog = screen.getByRole('document');
|
|
61
|
+
expect(modalDialog).toHaveStyle({
|
|
62
|
+
width: '792px'
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
it('should show custom footer if its in props', function () {
|
|
66
|
+
renderWithProvider( /*#__PURE__*/React.createElement(Modal, {
|
|
67
|
+
footer: /*#__PURE__*/React.createElement("div", null, "Custom Footer"),
|
|
68
|
+
visible: true
|
|
69
|
+
}));
|
|
70
|
+
var customFooter = screen.getByText('Custom Footer');
|
|
71
|
+
var defaultFooter = screen.queryByTestId('modal-footer');
|
|
72
|
+
expect(customFooter).toBeInTheDocument();
|
|
73
|
+
expect(defaultFooter).not.toBeInTheDocument();
|
|
74
|
+
});
|
|
75
|
+
});
|
package/dist/Modal.styles.d.ts
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { ModalProps } from 'antd/lib/modal';
|
|
3
|
-
export declare const TitleContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
4
|
-
export declare const Title: import("styled-components").StyledComponent<import("react").FC<Pick<import("antd/lib/typography/Base").BlockProps & {
|
|
5
|
-
level?: 1 | 2 | 3 | 5 | 4 | undefined;
|
|
6
|
-
}, "code" | "mark" | "style" | "title" | "type" | "editable" | "copyable" | "disabled" | "ellipsis" | "underline" | "delete" | "keyboard" | "id" | "prefixCls" | "className" | "children" | "aria-label" | "level">>, any, {}, never>;
|
|
7
|
-
export declare const Description: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
8
|
-
export declare const ActionButtons: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
9
|
-
export declare const FooterContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
10
|
-
export declare const CustomFooterContainer: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
11
2
|
export declare const SettingButton: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
12
3
|
export declare const ButtonsWrapper: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
13
4
|
export declare const AntdModal: import("styled-components").StyledComponent<any, any, object & ModalProps, string | number | symbol>;
|
package/dist/Modal.styles.js
CHANGED
|
@@ -1,47 +1,16 @@
|
|
|
1
1
|
import styled from 'styled-components';
|
|
2
|
-
import Typography from '@synerise/ds-typography';
|
|
3
2
|
import Modal from 'antd/lib/modal';
|
|
4
|
-
export var TitleContainer = styled.div.withConfig({
|
|
5
|
-
displayName: "Modalstyles__TitleContainer",
|
|
6
|
-
componentId: "jdspxw-0"
|
|
7
|
-
})(["display:flex;align-items:center;flex-wrap:nowrap;&&{.close-modal{line-height:1;}}"]);
|
|
8
|
-
export var Title = styled(Typography.Title).withConfig({
|
|
9
|
-
displayName: "Modalstyles__Title",
|
|
10
|
-
componentId: "jdspxw-1"
|
|
11
|
-
})(["width:100%;color:", ";white-space:nowrap;overflow:hidden;text-overflow:ellipsis;&&{margin:0;}"], function (props) {
|
|
12
|
-
return props.theme.palette['grey-800'];
|
|
13
|
-
});
|
|
14
|
-
export var Description = styled.div.withConfig({
|
|
15
|
-
displayName: "Modalstyles__Description",
|
|
16
|
-
componentId: "jdspxw-2"
|
|
17
|
-
})(["font-size:13px;font-weight:normal;line-height:18px;color:", ";display:block;padding:12px 0 0;margin:14px 0 0;background-image:linear-gradient( to right,", " 33%,rgba(255,255,255,0) 0% );background-repeat:repeat-x;background-size:4px 1px;background-position:top;"], function (props) {
|
|
18
|
-
return props.theme.palette['grey-600'];
|
|
19
|
-
}, function (props) {
|
|
20
|
-
return props.theme.palette['grey-300'];
|
|
21
|
-
});
|
|
22
|
-
export var ActionButtons = styled.div.withConfig({
|
|
23
|
-
displayName: "Modalstyles__ActionButtons",
|
|
24
|
-
componentId: "jdspxw-3"
|
|
25
|
-
})(["display:flex;flex-direction:row;align-items:center;.ant-btn{margin:0 4px;}.close-modal{padding:0;display:flex;align-items:center;justify-content:center;margin-right:0;}"]);
|
|
26
|
-
export var FooterContainer = styled.div.withConfig({
|
|
27
|
-
displayName: "Modalstyles__FooterContainer",
|
|
28
|
-
componentId: "jdspxw-4"
|
|
29
|
-
})(["display:flex;align-items:center;justify-content:flex-end;"]);
|
|
30
|
-
export var CustomFooterContainer = styled.div.withConfig({
|
|
31
|
-
displayName: "Modalstyles__CustomFooterContainer",
|
|
32
|
-
componentId: "jdspxw-5"
|
|
33
|
-
})(["display:flex;flex-wrap:nowrap;"]);
|
|
34
3
|
export var SettingButton = styled.div.withConfig({
|
|
35
4
|
displayName: "Modalstyles__SettingButton",
|
|
36
|
-
componentId: "jdspxw-
|
|
5
|
+
componentId: "jdspxw-0"
|
|
37
6
|
})(["display:flex;width:100%;"]);
|
|
38
7
|
export var ButtonsWrapper = styled.div.withConfig({
|
|
39
8
|
displayName: "Modalstyles__ButtonsWrapper",
|
|
40
|
-
componentId: "jdspxw-
|
|
9
|
+
componentId: "jdspxw-1"
|
|
41
10
|
})(["display:flex;"]); // FIXME: Exported variable 'AntdModal' has or is using name 'ModalInterface' from external module (probabli Antd's types issue)
|
|
42
11
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
12
|
|
|
44
13
|
export var AntdModal = styled(Modal).withConfig({
|
|
45
14
|
displayName: "Modalstyles__AntdModal",
|
|
46
|
-
componentId: "jdspxw-
|
|
15
|
+
componentId: "jdspxw-2"
|
|
47
16
|
})([""]);
|
package/dist/Modal.types.d.ts
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import type { CSSProperties, ComponentType, ReactNode } from 'react';
|
|
2
|
+
import { ButtonProps } from '@synerise/ds-button';
|
|
3
|
+
import { ModalProps as AntdModalProps } from 'antd/lib/modal';
|
|
4
|
+
export declare type Props = ModalProps;
|
|
5
|
+
export declare type ModalProps = {
|
|
4
6
|
description?: string;
|
|
5
|
-
headerActions?:
|
|
7
|
+
headerActions?: ReactNode;
|
|
6
8
|
size?: 'small' | 'medium' | 'large' | 'extraLarge' | 'fullSize';
|
|
7
9
|
bodyBackground?: 'white' | 'grey';
|
|
8
10
|
blank?: boolean;
|
|
9
|
-
titleContainerStyle?:
|
|
11
|
+
titleContainerStyle?: CSSProperties;
|
|
10
12
|
settingButtonText?: string;
|
|
11
13
|
texts?: {
|
|
12
14
|
okButton?: string;
|
|
13
15
|
cancelButton?: string;
|
|
14
16
|
};
|
|
15
|
-
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
} & AntdModalProps & ModalFooterBuilder;
|
|
19
|
+
export declare type ModalFooterBuilder = {
|
|
20
|
+
prefix?: ReactNode;
|
|
21
|
+
infix?: ReactNode;
|
|
22
|
+
suffix?: ReactNode;
|
|
23
|
+
okButton?: ReactNode;
|
|
24
|
+
cancelButton?: ReactNode;
|
|
25
|
+
DSButton?: ComponentType<ButtonProps>;
|
|
26
|
+
CustomFooterButton?: ComponentType<ButtonProps>;
|
|
27
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
1
|
export { default, buildModalFooter } from './Modal';
|
|
2
|
+
export { ModalTitle } from './Elements/ModalTitle';
|
|
3
|
+
export { ModalFooter } from './Elements/ModalFooter';
|
|
4
|
+
export type { TitleContainer } from './Elements/ModalTitle';
|
|
5
|
+
export type { Props, ModalProps } from './Modal.types';
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synerise/ds-modal",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Modal UI Component for the Synerise Design System",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "synerise/synerise-design",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
],
|
|
33
33
|
"types": "dist/index.d.ts",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@synerise/ds-button": "^0.
|
|
35
|
+
"@synerise/ds-button": "^0.18.0",
|
|
36
36
|
"@synerise/ds-icon": "^0.58.0",
|
|
37
37
|
"@synerise/ds-typography": "^0.12.8",
|
|
38
38
|
"classnames": "^2.2.6"
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@synerise/ds-utils": "^0.19.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "0795eb5071d9160e429731ba8f8807c1ae509085"
|
|
49
49
|
}
|