@dhis2-ui/modal 7.10.2 → 7.11.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/build/cjs/modal/close-button.js +38 -0
- package/build/cjs/modal/features/can_be_closed/index.js +6 -0
- package/build/cjs/modal/features/can_be_closed.feature +7 -2
- package/build/cjs/modal/modal.js +6 -2
- package/build/es/modal/close-button.js +23 -0
- package/build/es/modal/features/can_be_closed/index.js +6 -0
- package/build/es/modal/features/can_be_closed.feature +7 -2
- package/build/es/modal/modal.js +5 -2
- package/package.json +7 -6
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.CloseButton = void 0;
|
|
7
|
+
|
|
8
|
+
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
9
|
+
|
|
10
|
+
var _uiConstants = require("@dhis2/ui-constants");
|
|
11
|
+
|
|
12
|
+
var _uiIcons = require("@dhis2/ui-icons");
|
|
13
|
+
|
|
14
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
15
|
+
|
|
16
|
+
var _react = _interopRequireDefault(require("react"));
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
const createClickHandler = onClick => event => {
|
|
21
|
+
onClick({}, event);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const CloseButton = ({
|
|
25
|
+
onClick
|
|
26
|
+
}) => /*#__PURE__*/_react.default.createElement("button", {
|
|
27
|
+
"data-test": "dhis2-modal-close-button",
|
|
28
|
+
onClick: createClickHandler(onClick),
|
|
29
|
+
className: _style.default.dynamic([["3281559950", [_uiConstants.colors.grey700, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey200, _uiConstants.theme.focus, _uiConstants.colors.grey300]]])
|
|
30
|
+
}, /*#__PURE__*/_react.default.createElement(_uiIcons.IconCross16, null), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
31
|
+
id: "3281559950",
|
|
32
|
+
dynamic: [_uiConstants.colors.grey700, _uiConstants.colors.grey200, _uiConstants.colors.grey900, _uiConstants.colors.grey200, _uiConstants.theme.focus, _uiConstants.colors.grey300]
|
|
33
|
+
}, [`button.__jsx-style-dynamic-selector{background-color:transparent;color:${_uiConstants.colors.grey700};border:none;outline:none;padding:4px 4px 0px;border-radius:3px;position:absolute;top:0px;right:0px;}`, `button.__jsx-style-dynamic-selector:hover{background-color:${_uiConstants.colors.grey200};color:${_uiConstants.colors.grey900};}`, `button.__jsx-style-dynamic-selector:focus{background-color:${_uiConstants.colors.grey200};outline:3px solid ${_uiConstants.theme.focus};}`, "button.__jsx-style-dynamic-selector:focus.__jsx-style-dynamic-selector:not(:focus-visible){outline:none;}", `button.__jsx-style-dynamic-selector:active{background-color:${_uiConstants.colors.grey300};}`]));
|
|
34
|
+
|
|
35
|
+
exports.CloseButton = CloseButton;
|
|
36
|
+
CloseButton.propTypes = {
|
|
37
|
+
onClick: _propTypes.default.func
|
|
38
|
+
};
|
|
@@ -18,4 +18,10 @@ var _steps = require("cypress-cucumber-preprocessor/steps");
|
|
|
18
18
|
});
|
|
19
19
|
(0, _steps.When)('the Screencover is clicked below the modal', () => {
|
|
20
20
|
cy.get('[data-test="dhis2-uicore-layer"]').click('bottom');
|
|
21
|
+
});
|
|
22
|
+
(0, _steps.Given)('a Modal with onClose handler is rendered', () => {
|
|
23
|
+
cy.visitStory('Modal', 'With onClose');
|
|
24
|
+
});
|
|
25
|
+
(0, _steps.When)('the close button is clicked', () => {
|
|
26
|
+
cy.get('[data-test="dhis2-modal-close-button"]').click();
|
|
21
27
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Feature: The Modal has an onClose api that triggers when clicking anywhere outside the modal
|
|
1
|
+
Feature: The Modal has an onClose api that triggers when clicking anywhere outside the modal or on the close button
|
|
2
2
|
|
|
3
3
|
Scenario: The user clicks on the Screencover above a top-aligned modal
|
|
4
4
|
Given a top-aligned Modal with onClose handler is rendered
|
|
@@ -8,4 +8,9 @@ Feature: The Modal has an onClose api that triggers when clicking anywhere outsi
|
|
|
8
8
|
Scenario: The user clicks on the Screencover below a bottom-aligned modal
|
|
9
9
|
Given a bottom-aligned Modal with onClose handler is rendered
|
|
10
10
|
When the Screencover is clicked below the modal
|
|
11
|
-
Then the onClose handler is called
|
|
11
|
+
Then the onClose handler is called
|
|
12
|
+
|
|
13
|
+
Scenario: The user clicks on the close button
|
|
14
|
+
Given a Modal with onClose handler is rendered
|
|
15
|
+
When the close button is clicked
|
|
16
|
+
Then the onClose handler is called
|
package/build/cjs/modal/modal.js
CHANGED
|
@@ -21,6 +21,8 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
21
21
|
|
|
22
22
|
var _react = _interopRequireDefault(require("react"));
|
|
23
23
|
|
|
24
|
+
var _closeButton = require("./close-button.js");
|
|
25
|
+
|
|
24
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
27
|
|
|
26
28
|
const resolveLayerStyles = hide => ({
|
|
@@ -58,7 +60,9 @@ const Modal = ({
|
|
|
58
60
|
large,
|
|
59
61
|
fluid
|
|
60
62
|
}) || "")
|
|
61
|
-
}, /*#__PURE__*/_react.default.createElement(_card.Card, null, /*#__PURE__*/_react.default.createElement(
|
|
63
|
+
}, /*#__PURE__*/_react.default.createElement(_card.Card, null, onClose && /*#__PURE__*/_react.default.createElement(_closeButton.CloseButton, {
|
|
64
|
+
onClick: onClose
|
|
65
|
+
}), /*#__PURE__*/_react.default.createElement("div", {
|
|
62
66
|
className: _style.default.dynamic([["1701687214", [2 * _uiConstants.spacersNum.dp64, 2 * _uiConstants.spacersNum.dp64, 2 * _uiConstants.spacersNum.dp64, 2 * _uiConstants.spacersNum.dp64]]])
|
|
63
67
|
}, children))), layerStyles.styles), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
64
68
|
id: "1701687214",
|
|
@@ -81,6 +85,6 @@ Modal.propTypes = {
|
|
|
81
85
|
position: _uiConstants.sharedPropTypes.insideAlignmentPropType,
|
|
82
86
|
small: _uiConstants.sharedPropTypes.sizePropType,
|
|
83
87
|
|
|
84
|
-
/** Callback used when
|
|
88
|
+
/** Callback used when the Modal closes */
|
|
85
89
|
onClose: _propTypes.default.func
|
|
86
90
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import _JSXStyle from "styled-jsx/style";
|
|
2
|
+
import { colors, theme } from '@dhis2/ui-constants';
|
|
3
|
+
import { IconCross16 } from '@dhis2/ui-icons';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
const createClickHandler = onClick => event => {
|
|
8
|
+
onClick({}, event);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const CloseButton = ({
|
|
12
|
+
onClick
|
|
13
|
+
}) => /*#__PURE__*/React.createElement("button", {
|
|
14
|
+
"data-test": "dhis2-modal-close-button",
|
|
15
|
+
onClick: createClickHandler(onClick),
|
|
16
|
+
className: _JSXStyle.dynamic([["3281559950", [colors.grey700, colors.grey200, colors.grey900, colors.grey200, theme.focus, colors.grey300]]])
|
|
17
|
+
}, /*#__PURE__*/React.createElement(IconCross16, null), /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
18
|
+
id: "3281559950",
|
|
19
|
+
dynamic: [colors.grey700, colors.grey200, colors.grey900, colors.grey200, theme.focus, colors.grey300]
|
|
20
|
+
}, [`button.__jsx-style-dynamic-selector{background-color:transparent;color:${colors.grey700};border:none;outline:none;padding:4px 4px 0px;border-radius:3px;position:absolute;top:0px;right:0px;}`, `button.__jsx-style-dynamic-selector:hover{background-color:${colors.grey200};color:${colors.grey900};}`, `button.__jsx-style-dynamic-selector:focus{background-color:${colors.grey200};outline:3px solid ${theme.focus};}`, "button.__jsx-style-dynamic-selector:focus.__jsx-style-dynamic-selector:not(:focus-visible){outline:none;}", `button.__jsx-style-dynamic-selector:active{background-color:${colors.grey300};}`]));
|
|
21
|
+
CloseButton.propTypes = {
|
|
22
|
+
onClick: PropTypes.func
|
|
23
|
+
};
|
|
@@ -15,4 +15,10 @@ Given('a bottom-aligned Modal with onClose handler is rendered', () => {
|
|
|
15
15
|
});
|
|
16
16
|
When('the Screencover is clicked below the modal', () => {
|
|
17
17
|
cy.get('[data-test="dhis2-uicore-layer"]').click('bottom');
|
|
18
|
+
});
|
|
19
|
+
Given('a Modal with onClose handler is rendered', () => {
|
|
20
|
+
cy.visitStory('Modal', 'With onClose');
|
|
21
|
+
});
|
|
22
|
+
When('the close button is clicked', () => {
|
|
23
|
+
cy.get('[data-test="dhis2-modal-close-button"]').click();
|
|
18
24
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Feature: The Modal has an onClose api that triggers when clicking anywhere outside the modal
|
|
1
|
+
Feature: The Modal has an onClose api that triggers when clicking anywhere outside the modal or on the close button
|
|
2
2
|
|
|
3
3
|
Scenario: The user clicks on the Screencover above a top-aligned modal
|
|
4
4
|
Given a top-aligned Modal with onClose handler is rendered
|
|
@@ -8,4 +8,9 @@ Feature: The Modal has an onClose api that triggers when clicking anywhere outsi
|
|
|
8
8
|
Scenario: The user clicks on the Screencover below a bottom-aligned modal
|
|
9
9
|
Given a bottom-aligned Modal with onClose handler is rendered
|
|
10
10
|
When the Screencover is clicked below the modal
|
|
11
|
-
Then the onClose handler is called
|
|
11
|
+
Then the onClose handler is called
|
|
12
|
+
|
|
13
|
+
Scenario: The user clicks on the close button
|
|
14
|
+
Given a Modal with onClose handler is rendered
|
|
15
|
+
When the close button is clicked
|
|
16
|
+
Then the onClose handler is called
|
package/build/es/modal/modal.js
CHANGED
|
@@ -6,6 +6,7 @@ import { spacers, spacersNum, sharedPropTypes } from '@dhis2/ui-constants';
|
|
|
6
6
|
import cx from 'classnames';
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
8
|
import React from 'react';
|
|
9
|
+
import { CloseButton } from './close-button.js';
|
|
9
10
|
|
|
10
11
|
const resolveLayerStyles = hide => ({
|
|
11
12
|
styles: /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
@@ -42,7 +43,9 @@ export const Modal = ({
|
|
|
42
43
|
large,
|
|
43
44
|
fluid
|
|
44
45
|
}) || "")
|
|
45
|
-
}, /*#__PURE__*/React.createElement(Card, null, /*#__PURE__*/React.createElement(
|
|
46
|
+
}, /*#__PURE__*/React.createElement(Card, null, onClose && /*#__PURE__*/React.createElement(CloseButton, {
|
|
47
|
+
onClick: onClose
|
|
48
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
46
49
|
className: _JSXStyle.dynamic([["1701687214", [2 * spacersNum.dp64, 2 * spacersNum.dp64, 2 * spacersNum.dp64, 2 * spacersNum.dp64]]])
|
|
47
50
|
}, children))), layerStyles.styles), /*#__PURE__*/React.createElement(_JSXStyle, {
|
|
48
51
|
id: "1701687214",
|
|
@@ -63,6 +66,6 @@ Modal.propTypes = {
|
|
|
63
66
|
position: sharedPropTypes.insideAlignmentPropType,
|
|
64
67
|
small: sharedPropTypes.sizePropType,
|
|
65
68
|
|
|
66
|
-
/** Callback used when
|
|
69
|
+
/** Callback used when the Modal closes */
|
|
67
70
|
onClose: PropTypes.func
|
|
68
71
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhis2-ui/modal",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.11.0",
|
|
4
4
|
"description": "UI Modal",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,11 +32,12 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@dhis2/prop-types": "^3.0.0-beta.1",
|
|
35
|
-
"@dhis2-ui/card": "7.
|
|
36
|
-
"@dhis2-ui/center": "7.
|
|
37
|
-
"@dhis2-ui/layer": "7.
|
|
38
|
-
"@dhis2-ui/portal": "7.
|
|
39
|
-
"@dhis2/ui-constants": "7.
|
|
35
|
+
"@dhis2-ui/card": "7.11.0",
|
|
36
|
+
"@dhis2-ui/center": "7.11.0",
|
|
37
|
+
"@dhis2-ui/layer": "7.11.0",
|
|
38
|
+
"@dhis2-ui/portal": "7.11.0",
|
|
39
|
+
"@dhis2/ui-constants": "7.11.0",
|
|
40
|
+
"@dhis2/ui-icons": "7.11.0",
|
|
40
41
|
"classnames": "^2.3.1",
|
|
41
42
|
"prop-types": "^15.7.2"
|
|
42
43
|
},
|