@pingux/astro 2.0.3-alpha.1 → 2.0.3-alpha.3
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/lib/cjs/components/Modal/Modal.js +10 -3
- package/lib/cjs/components/Modal/Modal.stories.js +7 -0
- package/lib/cjs/components/Modal/Modal.styles.js +24 -2
- package/lib/cjs/components/Modal/tests/Modal.unit.test.js +35 -0
- package/lib/cjs/utils/devUtils/constants/modalSizes.js +9 -0
- package/lib/components/Modal/Modal.js +10 -3
- package/lib/components/Modal/Modal.stories.js +7 -0
- package/lib/components/Modal/Modal.styles.js +24 -2
- package/lib/components/Modal/tests/Modal.unit.test.js +35 -0
- package/lib/utils/devUtils/constants/modalSizes.js +1 -0
- package/package.json +1 -1
@@ -22,12 +22,14 @@ var _react = _interopRequireWildcard(require("react"));
|
|
22
22
|
var _reactAria = require("react-aria");
|
23
23
|
var _CloseIcon = _interopRequireDefault(require("mdi-react/CloseIcon"));
|
24
24
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
25
|
+
var _hooks = require("../../hooks");
|
26
|
+
var _modalSizes = require("../../utils/devUtils/constants/modalSizes");
|
25
27
|
var _Box = _interopRequireDefault(require("../Box"));
|
26
28
|
var _Icon = _interopRequireDefault(require("../Icon"));
|
27
29
|
var _IconButton = _interopRequireDefault(require("../IconButton"));
|
28
30
|
var _Text = _interopRequireDefault(require("../Text"));
|
29
31
|
var _react2 = require("@emotion/react");
|
30
|
-
var _excluded = ["className", "closeButton", "hasAutoFocus", "hasCloseButton", "id", "isClosedOnBlur", "isDismissable", "isKeyboardDismissDisabled", "isOpen", "role", "title", "onClose", "shouldCloseOnInteractOutside", "children", "contentProps", "containerProps"];
|
32
|
+
var _excluded = ["className", "closeButton", "hasAutoFocus", "hasCloseButton", "id", "isClosedOnBlur", "isDismissable", "isKeyboardDismissDisabled", "isOpen", "role", "size", "title", "onClose", "shouldCloseOnInteractOutside", "children", "contentProps", "containerProps"];
|
31
33
|
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
32
34
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
33
35
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
@@ -49,6 +51,7 @@ var Modal = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
49
51
|
isKeyboardDismissDisabled = props.isKeyboardDismissDisabled,
|
50
52
|
isOpen = props.isOpen,
|
51
53
|
role = props.role,
|
54
|
+
size = props.size,
|
52
55
|
title = props.title,
|
53
56
|
onClose = props.onClose,
|
54
57
|
shouldCloseOnInteractOutside = props.shouldCloseOnInteractOutside,
|
@@ -88,6 +91,8 @@ var Modal = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
88
91
|
var _useDialog = (0, _reactAria.useDialog)(contentProps, modalRef),
|
89
92
|
dialogProps = _useDialog.dialogProps,
|
90
93
|
titleProps = _useDialog.titleProps;
|
94
|
+
var _useStatusClasses = (0, _hooks.useStatusClasses)(className, (0, _defineProperty2["default"])({}, "is-".concat(size || 'custom'), size)),
|
95
|
+
classNames = _useStatusClasses.classNames;
|
91
96
|
return (0, _react2.jsx)(_reactAria.OverlayContainer, null, (0, _react2.jsx)(_Box["default"], (0, _extends2["default"])({
|
92
97
|
variant: "modal.container"
|
93
98
|
}, others, containerProps), (0, _react2.jsx)(_reactAria.FocusScope, {
|
@@ -95,14 +100,14 @@ var Modal = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
95
100
|
restoreFocus: true,
|
96
101
|
autoFocus: hasAutoFocus
|
97
102
|
}, (0, _react2.jsx)(_Box["default"], (0, _extends2["default"])({
|
98
|
-
variant: "modal.content"
|
103
|
+
variant: "modal.content",
|
104
|
+
className: classNames
|
99
105
|
}, propsContentProps, overlayProps, dialogProps, modalProps, {
|
100
106
|
ref: modalRef,
|
101
107
|
"aria-modal": true
|
102
108
|
}), hasCloseButton && (closeButton !== null && closeButton !== void 0 ? closeButton : (0, _react2.jsx)(_IconButton["default"], {
|
103
109
|
"aria-label": "Close modal window",
|
104
110
|
"data-id": "icon-button__close-modal-window",
|
105
|
-
size: 22,
|
106
111
|
variant: "modalCloseButton",
|
107
112
|
onPress: onClose
|
108
113
|
}, (0, _react2.jsx)(_Icon["default"], {
|
@@ -130,6 +135,8 @@ Modal.propTypes = {
|
|
130
135
|
isOpen: _propTypes["default"].bool,
|
131
136
|
/** The accessibility role for the dialog. */
|
132
137
|
role: _propTypes["default"].oneOf(['dialog', 'alertdialog']),
|
138
|
+
/** Sets the size of the modal container. */
|
139
|
+
size: _propTypes["default"].oneOf(_modalSizes.modalSizes),
|
133
140
|
/** The title for the modal. */
|
134
141
|
title: _propTypes["default"].node,
|
135
142
|
/**
|
@@ -10,6 +10,7 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/e
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
11
11
|
var _hooks = require("../../hooks");
|
12
12
|
var _index = require("../../index");
|
13
|
+
var _modalSizes = require("../../utils/devUtils/constants/modalSizes");
|
13
14
|
var _react2 = require("@emotion/react");
|
14
15
|
var _default = {
|
15
16
|
title: 'Components/Modal',
|
@@ -27,6 +28,12 @@ var _default = {
|
|
27
28
|
type: 'text'
|
28
29
|
}
|
29
30
|
},
|
31
|
+
size: {
|
32
|
+
control: {
|
33
|
+
type: 'select',
|
34
|
+
options: _modalSizes.modalSizes
|
35
|
+
}
|
36
|
+
},
|
30
37
|
hasCloseButton: {
|
31
38
|
defaultValue: true
|
32
39
|
},
|
@@ -43,7 +43,27 @@ var content = {
|
|
43
43
|
pl: 'lg',
|
44
44
|
maxWidth: '400px',
|
45
45
|
boxShadow: 'standard',
|
46
|
-
borderRadius: 3
|
46
|
+
borderRadius: 3,
|
47
|
+
'&.is-extra-small': {
|
48
|
+
maxWidth: 'none',
|
49
|
+
width: 'container.xs'
|
50
|
+
},
|
51
|
+
'&.is-small': {
|
52
|
+
maxWidth: 'none',
|
53
|
+
width: 'container.sm'
|
54
|
+
},
|
55
|
+
'&.is-medium': {
|
56
|
+
maxWidth: 'none',
|
57
|
+
width: 'container.md'
|
58
|
+
},
|
59
|
+
'&.is-large': {
|
60
|
+
maxWidth: 'none',
|
61
|
+
width: 'container.lg'
|
62
|
+
},
|
63
|
+
'&.is-full': {
|
64
|
+
maxWidth: 'none',
|
65
|
+
width: 'container.full'
|
66
|
+
}
|
47
67
|
};
|
48
68
|
var title = _objectSpread(_objectSpread({}, _Text.text.title), {}, {
|
49
69
|
mr: 'sm',
|
@@ -52,7 +72,9 @@ var title = _objectSpread(_objectSpread({}, _Text.text.title), {}, {
|
|
52
72
|
var modalCloseButton = {
|
53
73
|
position: 'absolute',
|
54
74
|
top: 14,
|
55
|
-
right: 10
|
75
|
+
right: 10,
|
76
|
+
width: '22px',
|
77
|
+
height: '22px'
|
56
78
|
};
|
57
79
|
exports.modalCloseButton = modalCloseButton;
|
58
80
|
var _default = {
|
@@ -181,4 +181,39 @@ test('should auto focus the first tabbable element if "hasAutoFocus" is true', f
|
|
181
181
|
});
|
182
182
|
var button = _testWrapper.screen.queryByRole('button');
|
183
183
|
expect(button).toHaveFocus();
|
184
|
+
});
|
185
|
+
test('should render sizes correctly with passed size prop', function () {
|
186
|
+
var _getComponent2 = getComponent({
|
187
|
+
size: 'extra-small'
|
188
|
+
}),
|
189
|
+
xsUnmount = _getComponent2.unmount;
|
190
|
+
var xsModal = _testWrapper.screen.getByRole('dialog');
|
191
|
+
expect(xsModal).toHaveClass('is-extra-small');
|
192
|
+
xsUnmount();
|
193
|
+
var _getComponent3 = getComponent({
|
194
|
+
size: 'small'
|
195
|
+
}),
|
196
|
+
sUnmount = _getComponent3.unmount;
|
197
|
+
var sModal = _testWrapper.screen.getByRole('dialog');
|
198
|
+
expect(sModal).toHaveClass('is-small');
|
199
|
+
sUnmount();
|
200
|
+
var _getComponent4 = getComponent({
|
201
|
+
size: 'medium'
|
202
|
+
}),
|
203
|
+
mUnmount = _getComponent4.unmount;
|
204
|
+
var mModal = _testWrapper.screen.getByRole('dialog');
|
205
|
+
expect(mModal).toHaveClass('is-medium');
|
206
|
+
mUnmount();
|
207
|
+
var _getComponent5 = getComponent({
|
208
|
+
size: 'large'
|
209
|
+
}),
|
210
|
+
lUnmount = _getComponent5.unmount;
|
211
|
+
var lModal = _testWrapper.screen.getByRole('dialog');
|
212
|
+
expect(lModal).toHaveClass('is-large');
|
213
|
+
lUnmount();
|
214
|
+
getComponent({
|
215
|
+
size: 'full'
|
216
|
+
});
|
217
|
+
var fModal = _testWrapper.screen.getByRole('dialog');
|
218
|
+
expect(fModal).toHaveClass('is-full');
|
184
219
|
});
|
@@ -0,0 +1,9 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
4
|
+
_Object$defineProperty(exports, "__esModule", {
|
5
|
+
value: true
|
6
|
+
});
|
7
|
+
exports.modalSizes = void 0;
|
8
|
+
var modalSizes = ['extra-small', 'small', 'medium', 'large', 'full'];
|
9
|
+
exports.modalSizes = modalSizes;
|
@@ -9,13 +9,15 @@ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object
|
|
9
9
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
10
10
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
11
11
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
12
|
-
var _excluded = ["className", "closeButton", "hasAutoFocus", "hasCloseButton", "id", "isClosedOnBlur", "isDismissable", "isKeyboardDismissDisabled", "isOpen", "role", "title", "onClose", "shouldCloseOnInteractOutside", "children", "contentProps", "containerProps"];
|
12
|
+
var _excluded = ["className", "closeButton", "hasAutoFocus", "hasCloseButton", "id", "isClosedOnBlur", "isDismissable", "isKeyboardDismissDisabled", "isOpen", "role", "size", "title", "onClose", "shouldCloseOnInteractOutside", "children", "contentProps", "containerProps"];
|
13
13
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
14
14
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
15
15
|
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
|
16
16
|
import { FocusScope, OverlayContainer, useDialog, useModal, useOverlay, usePreventScroll } from 'react-aria';
|
17
17
|
import CloseIcon from 'mdi-react/CloseIcon';
|
18
18
|
import PropTypes from 'prop-types';
|
19
|
+
import { useStatusClasses } from '../../hooks';
|
20
|
+
import { modalSizes } from '../../utils/devUtils/constants/modalSizes';
|
19
21
|
import Box from '../Box';
|
20
22
|
import Icon from '../Icon';
|
21
23
|
import IconButton from '../IconButton';
|
@@ -38,6 +40,7 @@ var Modal = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
38
40
|
isKeyboardDismissDisabled = props.isKeyboardDismissDisabled,
|
39
41
|
isOpen = props.isOpen,
|
40
42
|
role = props.role,
|
43
|
+
size = props.size,
|
41
44
|
title = props.title,
|
42
45
|
onClose = props.onClose,
|
43
46
|
shouldCloseOnInteractOutside = props.shouldCloseOnInteractOutside,
|
@@ -77,6 +80,8 @@ var Modal = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
77
80
|
var _useDialog = useDialog(contentProps, modalRef),
|
78
81
|
dialogProps = _useDialog.dialogProps,
|
79
82
|
titleProps = _useDialog.titleProps;
|
83
|
+
var _useStatusClasses = useStatusClasses(className, _defineProperty({}, "is-".concat(size || 'custom'), size)),
|
84
|
+
classNames = _useStatusClasses.classNames;
|
80
85
|
return ___EmotionJSX(OverlayContainer, null, ___EmotionJSX(Box, _extends({
|
81
86
|
variant: "modal.container"
|
82
87
|
}, others, containerProps), ___EmotionJSX(FocusScope, {
|
@@ -84,14 +89,14 @@ var Modal = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
84
89
|
restoreFocus: true,
|
85
90
|
autoFocus: hasAutoFocus
|
86
91
|
}, ___EmotionJSX(Box, _extends({
|
87
|
-
variant: "modal.content"
|
92
|
+
variant: "modal.content",
|
93
|
+
className: classNames
|
88
94
|
}, propsContentProps, overlayProps, dialogProps, modalProps, {
|
89
95
|
ref: modalRef,
|
90
96
|
"aria-modal": true
|
91
97
|
}), hasCloseButton && (closeButton !== null && closeButton !== void 0 ? closeButton : ___EmotionJSX(IconButton, {
|
92
98
|
"aria-label": "Close modal window",
|
93
99
|
"data-id": "icon-button__close-modal-window",
|
94
|
-
size: 22,
|
95
100
|
variant: "modalCloseButton",
|
96
101
|
onPress: onClose
|
97
102
|
}, ___EmotionJSX(Icon, {
|
@@ -119,6 +124,8 @@ Modal.propTypes = {
|
|
119
124
|
isOpen: PropTypes.bool,
|
120
125
|
/** The accessibility role for the dialog. */
|
121
126
|
role: PropTypes.oneOf(['dialog', 'alertdialog']),
|
127
|
+
/** Sets the size of the modal container. */
|
128
|
+
size: PropTypes.oneOf(modalSizes),
|
122
129
|
/** The title for the modal. */
|
123
130
|
title: PropTypes.node,
|
124
131
|
/**
|
@@ -2,6 +2,7 @@ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
|
2
2
|
import React from 'react';
|
3
3
|
import { useModalState } from '../../hooks';
|
4
4
|
import { Box, Button, Modal, OverlayProvider, Text } from '../../index';
|
5
|
+
import { modalSizes } from '../../utils/devUtils/constants/modalSizes';
|
5
6
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
6
7
|
export default {
|
7
8
|
title: 'Components/Modal',
|
@@ -19,6 +20,12 @@ export default {
|
|
19
20
|
type: 'text'
|
20
21
|
}
|
21
22
|
},
|
23
|
+
size: {
|
24
|
+
control: {
|
25
|
+
type: 'select',
|
26
|
+
options: modalSizes
|
27
|
+
}
|
28
|
+
},
|
22
29
|
hasCloseButton: {
|
23
30
|
defaultValue: true
|
24
31
|
},
|
@@ -36,7 +36,27 @@ var content = {
|
|
36
36
|
pl: 'lg',
|
37
37
|
maxWidth: '400px',
|
38
38
|
boxShadow: 'standard',
|
39
|
-
borderRadius: 3
|
39
|
+
borderRadius: 3,
|
40
|
+
'&.is-extra-small': {
|
41
|
+
maxWidth: 'none',
|
42
|
+
width: 'container.xs'
|
43
|
+
},
|
44
|
+
'&.is-small': {
|
45
|
+
maxWidth: 'none',
|
46
|
+
width: 'container.sm'
|
47
|
+
},
|
48
|
+
'&.is-medium': {
|
49
|
+
maxWidth: 'none',
|
50
|
+
width: 'container.md'
|
51
|
+
},
|
52
|
+
'&.is-large': {
|
53
|
+
maxWidth: 'none',
|
54
|
+
width: 'container.lg'
|
55
|
+
},
|
56
|
+
'&.is-full': {
|
57
|
+
maxWidth: 'none',
|
58
|
+
width: 'container.full'
|
59
|
+
}
|
40
60
|
};
|
41
61
|
var title = _objectSpread(_objectSpread({}, text.title), {}, {
|
42
62
|
mr: 'sm',
|
@@ -45,7 +65,9 @@ var title = _objectSpread(_objectSpread({}, text.title), {}, {
|
|
45
65
|
export var modalCloseButton = {
|
46
66
|
position: 'absolute',
|
47
67
|
top: 14,
|
48
|
-
right: 10
|
68
|
+
right: 10,
|
69
|
+
width: '22px',
|
70
|
+
height: '22px'
|
49
71
|
};
|
50
72
|
export default {
|
51
73
|
closeIcon: closeIcon,
|
@@ -179,4 +179,39 @@ test('should auto focus the first tabbable element if "hasAutoFocus" is true', f
|
|
179
179
|
});
|
180
180
|
var button = screen.queryByRole('button');
|
181
181
|
expect(button).toHaveFocus();
|
182
|
+
});
|
183
|
+
test('should render sizes correctly with passed size prop', function () {
|
184
|
+
var _getComponent2 = getComponent({
|
185
|
+
size: 'extra-small'
|
186
|
+
}),
|
187
|
+
xsUnmount = _getComponent2.unmount;
|
188
|
+
var xsModal = screen.getByRole('dialog');
|
189
|
+
expect(xsModal).toHaveClass('is-extra-small');
|
190
|
+
xsUnmount();
|
191
|
+
var _getComponent3 = getComponent({
|
192
|
+
size: 'small'
|
193
|
+
}),
|
194
|
+
sUnmount = _getComponent3.unmount;
|
195
|
+
var sModal = screen.getByRole('dialog');
|
196
|
+
expect(sModal).toHaveClass('is-small');
|
197
|
+
sUnmount();
|
198
|
+
var _getComponent4 = getComponent({
|
199
|
+
size: 'medium'
|
200
|
+
}),
|
201
|
+
mUnmount = _getComponent4.unmount;
|
202
|
+
var mModal = screen.getByRole('dialog');
|
203
|
+
expect(mModal).toHaveClass('is-medium');
|
204
|
+
mUnmount();
|
205
|
+
var _getComponent5 = getComponent({
|
206
|
+
size: 'large'
|
207
|
+
}),
|
208
|
+
lUnmount = _getComponent5.unmount;
|
209
|
+
var lModal = screen.getByRole('dialog');
|
210
|
+
expect(lModal).toHaveClass('is-large');
|
211
|
+
lUnmount();
|
212
|
+
getComponent({
|
213
|
+
size: 'full'
|
214
|
+
});
|
215
|
+
var fModal = screen.getByRole('dialog');
|
216
|
+
expect(fModal).toHaveClass('is-full');
|
182
217
|
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export var modalSizes = ['extra-small', 'small', 'medium', 'large', 'full'];
|