@elliemae/ds-dialog 2.3.0-alpha.8 → 2.3.0-next.10
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/cjs/DSDialog.js +131 -0
- package/cjs/DSDialogDatatestid.js +10 -0
- package/cjs/defaultProps.js +19 -0
- package/cjs/index.js +70 -0
- package/cjs/propTypes.js +31 -0
- package/cjs/sharedTypes.js +7 -0
- package/cjs/styles.js +145 -0
- package/cjs/utils.js +35 -0
- package/esm/DSDialog.js +119 -0
- package/esm/DSDialogDatatestid.js +6 -0
- package/esm/defaultProps.js +15 -0
- package/{dist/esm → esm}/index.js +19 -48
- package/esm/propTypes.js +23 -0
- package/esm/sharedTypes.js +5 -0
- package/esm/styles.js +125 -0
- package/esm/utils.js +28 -0
- package/package.json +35 -41
- package/types/DSDialog.d.ts +376 -0
- package/types/DSDialogDatatestid.d.ts +4 -0
- package/types/defaultProps.d.ts +2 -0
- package/types/index.d.ts +52 -0
- package/types/propTypes.d.ts +388 -0
- package/types/sharedTypes.d.ts +6 -0
- package/types/styles.d.ts +23 -0
- package/types/tests/DSDialog.test.d.ts +1 -0
- package/types/utils.d.ts +20 -0
- package/dist/cjs/DSDialog.js +0 -99
- package/dist/cjs/DSDialog.js.map +0 -7
- package/dist/cjs/DSDialogDatatestid.js +0 -38
- package/dist/cjs/DSDialogDatatestid.js.map +0 -7
- package/dist/cjs/DSDialogInternalTypes.js +0 -27
- package/dist/cjs/DSDialogInternalTypes.js.map +0 -7
- package/dist/cjs/DSDialogTypes.js +0 -27
- package/dist/cjs/DSDialogTypes.js.map +0 -7
- package/dist/cjs/defaultProps.js +0 -45
- package/dist/cjs/defaultProps.js.map +0 -7
- package/dist/cjs/index.js +0 -94
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/propTypes.js +0 -46
- package/dist/cjs/propTypes.js.map +0 -7
- package/dist/cjs/styles.js +0 -151
- package/dist/cjs/styles.js.map +0 -7
- package/dist/cjs/utils.js +0 -55
- package/dist/cjs/utils.js.map +0 -7
- package/dist/esm/DSDialog.js +0 -75
- package/dist/esm/DSDialog.js.map +0 -7
- package/dist/esm/DSDialogDatatestid.js +0 -9
- package/dist/esm/DSDialogDatatestid.js.map +0 -7
- package/dist/esm/DSDialogInternalTypes.js +0 -2
- package/dist/esm/DSDialogInternalTypes.js.map +0 -7
- package/dist/esm/DSDialogTypes.js +0 -2
- package/dist/esm/DSDialogTypes.js.map +0 -7
- package/dist/esm/defaultProps.js +0 -16
- package/dist/esm/defaultProps.js.map +0 -7
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/propTypes.js +0 -17
- package/dist/esm/propTypes.js.map +0 -7
- package/dist/esm/styles.js +0 -122
- package/dist/esm/styles.js.map +0 -7
- package/dist/esm/utils.js +0 -26
- package/dist/esm/utils.js.map +0 -7
package/cjs/DSDialog.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
var _jsx = require('@babel/runtime/helpers/jsx');
|
|
7
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
8
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
9
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
10
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
11
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
12
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
13
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
14
|
+
var ReactDOM = require('react-dom');
|
|
15
|
+
var react = require('react');
|
|
16
|
+
var dsPropsHelpers = require('@elliemae/ds-props-helpers');
|
|
17
|
+
var styles = require('./styles.js');
|
|
18
|
+
var propTypes = require('./propTypes.js');
|
|
19
|
+
var defaultProps = require('./defaultProps.js');
|
|
20
|
+
var utils = require('./utils.js');
|
|
21
|
+
var DSDialogDatatestid = require('./DSDialogDatatestid.js');
|
|
22
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
23
|
+
|
|
24
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
25
|
+
|
|
26
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
27
|
+
var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
|
|
28
|
+
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
|
|
29
|
+
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
|
|
30
|
+
|
|
31
|
+
const _excluded = ["children", "isOpen", "onClickOutside", "onClose", "centered", "size", "removeAutoFocus", "zIndex"],
|
|
32
|
+
_excluded2 = ["className"];
|
|
33
|
+
|
|
34
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
35
|
+
|
|
36
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
37
|
+
|
|
38
|
+
const DSDialog = props => {
|
|
39
|
+
var _FixedBody;
|
|
40
|
+
|
|
41
|
+
const propsWithDefault = dsPropsHelpers.useMemoMergePropsWithDefault(props, defaultProps.defaultProps);
|
|
42
|
+
const [bodyInfo, setBodyInfo] = react.useState({
|
|
43
|
+
overflow: false,
|
|
44
|
+
padding: '0px'
|
|
45
|
+
});
|
|
46
|
+
dsPropsHelpers.useValidateTypescriptPropTypes(propsWithDefault, propTypes.propTypes);
|
|
47
|
+
|
|
48
|
+
const {
|
|
49
|
+
children,
|
|
50
|
+
isOpen,
|
|
51
|
+
onClickOutside,
|
|
52
|
+
onClose,
|
|
53
|
+
centered,
|
|
54
|
+
size,
|
|
55
|
+
removeAutoFocus,
|
|
56
|
+
zIndex
|
|
57
|
+
} = propsWithDefault,
|
|
58
|
+
rest = _objectWithoutProperties__default["default"](propsWithDefault, _excluded);
|
|
59
|
+
|
|
60
|
+
const containerRef = react.useRef(null);
|
|
61
|
+
const handleOutsideClick = react.useCallback(e => {
|
|
62
|
+
if (e.target.dataset.portalbg) onClickOutside();
|
|
63
|
+
}, [onClickOutside]);
|
|
64
|
+
const handleOnKeyDown = react.useCallback(e => {
|
|
65
|
+
if (e.key === 'Escape') onClose();
|
|
66
|
+
}, [onClose]);
|
|
67
|
+
|
|
68
|
+
const _useGetGlobalAttribut = dsPropsHelpers.useGetGlobalAttributes(propsWithDefault, {
|
|
69
|
+
onClick: handleOutsideClick,
|
|
70
|
+
onKeyDown: handleOnKeyDown
|
|
71
|
+
}),
|
|
72
|
+
{
|
|
73
|
+
className
|
|
74
|
+
} = _useGetGlobalAttribut,
|
|
75
|
+
restOfGlobalAttributes = _objectWithoutProperties__default["default"](_useGetGlobalAttribut, _excluded2);
|
|
76
|
+
|
|
77
|
+
react.useEffect(() => {
|
|
78
|
+
var _window$getComputedSt;
|
|
79
|
+
|
|
80
|
+
const body = document.getElementsByTagName('body')[0];
|
|
81
|
+
const {
|
|
82
|
+
offsetHeight,
|
|
83
|
+
scrollHeight
|
|
84
|
+
} = body;
|
|
85
|
+
const padding = (_window$getComputedSt = window.getComputedStyle(body, null)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.getPropertyValue('padding-right');
|
|
86
|
+
if (!isOpen) return setBodyInfo({
|
|
87
|
+
overflow: false,
|
|
88
|
+
padding: '0px'
|
|
89
|
+
});
|
|
90
|
+
return setBodyInfo({
|
|
91
|
+
overflow: offsetHeight < scrollHeight,
|
|
92
|
+
padding
|
|
93
|
+
});
|
|
94
|
+
}, [isOpen]);
|
|
95
|
+
react.useEffect(() => {
|
|
96
|
+
var _containerRef$current;
|
|
97
|
+
|
|
98
|
+
if (isOpen && !removeAutoFocus) containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.focus();
|
|
99
|
+
}, [isOpen, removeAutoFocus]);
|
|
100
|
+
|
|
101
|
+
if (isOpen) {
|
|
102
|
+
return /*#__PURE__*/ReactDOM__default["default"].createPortal( /*#__PURE__*/_jsx__default["default"](styles.StyledDialogBackground, {
|
|
103
|
+
className: className,
|
|
104
|
+
onClick: handleOutsideClick,
|
|
105
|
+
"data-portalbg": true,
|
|
106
|
+
"data-testid": DSDialogDatatestid.DSDialogDatatestid.BACKGROUND,
|
|
107
|
+
zIndex: zIndex
|
|
108
|
+
}, void 0, _FixedBody || (_FixedBody = /*#__PURE__*/_jsx__default["default"](styles.FixedBody, {
|
|
109
|
+
bodyInfo: bodyInfo
|
|
110
|
+
})), /*#__PURE__*/jsxRuntime.jsx(styles.StyledDialogContainer, _objectSpread(_objectSpread(_objectSpread({
|
|
111
|
+
role: "dialog",
|
|
112
|
+
"aria-modal": true,
|
|
113
|
+
ref: containerRef,
|
|
114
|
+
tabIndex: !removeAutoFocus ? 0 : undefined
|
|
115
|
+
}, utils.getSpaceProps(rest)), {}, {
|
|
116
|
+
size: size,
|
|
117
|
+
centered: centered,
|
|
118
|
+
"data-testid": DSDialogDatatestid.DSDialogDatatestid.CONTAINER
|
|
119
|
+
}, restOfGlobalAttributes), {}, {
|
|
120
|
+
children: children
|
|
121
|
+
}))), document.getElementsByTagName('body')[0]);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return null;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const DSDialogWithSchema = dsPropsHelpers.describe(DSDialog);
|
|
128
|
+
DSDialogWithSchema.propTypes = propTypes.propTypes;
|
|
129
|
+
|
|
130
|
+
exports.DSDialog = DSDialog;
|
|
131
|
+
exports.DSDialogWithSchema = DSDialogWithSchema;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var utils = require('./utils.js');
|
|
6
|
+
|
|
7
|
+
const noop = () => {};
|
|
8
|
+
|
|
9
|
+
const defaultProps = {
|
|
10
|
+
isOpen: false,
|
|
11
|
+
centered: false,
|
|
12
|
+
size: utils.DSDialogSizes.DEFAULT,
|
|
13
|
+
removeAutoFocus: false,
|
|
14
|
+
onClickOutside: noop,
|
|
15
|
+
onClose: noop,
|
|
16
|
+
zIndex: 10
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
exports.defaultProps = defaultProps;
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var reactDesc = require('react-desc');
|
|
6
|
+
var dsPropsHelpers = require('@elliemae/ds-props-helpers');
|
|
7
|
+
var styles = require('./styles.js');
|
|
8
|
+
var DSDialog = require('./DSDialog.js');
|
|
9
|
+
var DSDialogDatatestid = require('./DSDialogDatatestid.js');
|
|
10
|
+
var utils = require('./utils.js');
|
|
11
|
+
|
|
12
|
+
styles.DSDialogBody.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
13
|
+
styles.DSDialogHeader.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
14
|
+
styles.DSDialogFooter.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
15
|
+
styles.DSDialogSeparator.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
16
|
+
styles.DSDialogTitle.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
17
|
+
styles.DSDialogAddon.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
18
|
+
styles.DSDialogDefaultLayout.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
19
|
+
styles.DSDialogPrimaryMessage.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
20
|
+
styles.DSDialogSecondaryMessage.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
21
|
+
styles.DSDialogBody.displayName = 'DSDialogBody';
|
|
22
|
+
styles.DSDialogHeader.displayName = 'DSDialogHeader';
|
|
23
|
+
styles.DSDialogFooter.displayName = 'DSDialogFooter';
|
|
24
|
+
styles.DSDialogSeparator.displayName = 'DSDialogSeparator';
|
|
25
|
+
styles.DSDialogTitle.displayName = 'DSDialogTitle';
|
|
26
|
+
styles.DSDialogAddon.displayName = 'DSDialogAddon';
|
|
27
|
+
styles.DSDialogDefaultLayout.displayName = 'DSDialogDefaultLayout';
|
|
28
|
+
styles.DSDialogPrimaryMessage.displayName = 'DSDialogPrimaryMessage';
|
|
29
|
+
styles.DSDialogSecondaryMessage.displayName = 'DSDialogSecondaryMessage';
|
|
30
|
+
const DSDialogBodyWithSchema = reactDesc.describe(styles.DSDialogBody);
|
|
31
|
+
const DSDialogHeaderWithSchema = reactDesc.describe(styles.DSDialogHeader);
|
|
32
|
+
const DSDialogFooterWithSchema = reactDesc.describe(styles.DSDialogFooter);
|
|
33
|
+
const DSDialogSeparatorWithSchema = reactDesc.describe(styles.DSDialogSeparator);
|
|
34
|
+
const DSDialogTitleWithSchema = reactDesc.describe(styles.DSDialogTitle);
|
|
35
|
+
const DSDialogAddonWithSchema = reactDesc.describe(styles.DSDialogAddon);
|
|
36
|
+
const DSDialogDefaultLayoutWithSchema = reactDesc.describe(styles.DSDialogDefaultLayout);
|
|
37
|
+
const DSDialogPrimaryMessageWithSchema = reactDesc.describe(styles.DSDialogPrimaryMessage);
|
|
38
|
+
const DSDialogSecondaryMessageWithSchema = reactDesc.describe(styles.DSDialogSecondaryMessage);
|
|
39
|
+
DSDialogBodyWithSchema.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
40
|
+
DSDialogHeaderWithSchema.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
41
|
+
DSDialogFooterWithSchema.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
42
|
+
DSDialogSeparatorWithSchema.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
43
|
+
DSDialogTitleWithSchema.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
44
|
+
DSDialogAddonWithSchema.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
45
|
+
DSDialogDefaultLayoutWithSchema.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
46
|
+
DSDialogPrimaryMessageWithSchema.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
47
|
+
DSDialogSecondaryMessageWithSchema.propTypes = dsPropsHelpers.globalAttributesPropTypes;
|
|
48
|
+
|
|
49
|
+
exports.DSDialogAddon = styles.DSDialogAddon;
|
|
50
|
+
exports.DSDialogBody = styles.DSDialogBody;
|
|
51
|
+
exports.DSDialogDefaultLayout = styles.DSDialogDefaultLayout;
|
|
52
|
+
exports.DSDialogFooter = styles.DSDialogFooter;
|
|
53
|
+
exports.DSDialogHeader = styles.DSDialogHeader;
|
|
54
|
+
exports.DSDialogPrimaryMessage = styles.DSDialogPrimaryMessage;
|
|
55
|
+
exports.DSDialogSecondaryMessage = styles.DSDialogSecondaryMessage;
|
|
56
|
+
exports.DSDialogSeparator = styles.DSDialogSeparator;
|
|
57
|
+
exports.DSDialogTitle = styles.DSDialogTitle;
|
|
58
|
+
exports.DSDialog = DSDialog.DSDialog;
|
|
59
|
+
exports.DSDialogWithSchema = DSDialog.DSDialogWithSchema;
|
|
60
|
+
exports.DSDialogDatatestid = DSDialogDatatestid.DSDialogDatatestid;
|
|
61
|
+
exports.DSDialogSizes = utils.DSDialogSizes;
|
|
62
|
+
exports.DSDialogAddonWithSchema = DSDialogAddonWithSchema;
|
|
63
|
+
exports.DSDialogBodyWithSchema = DSDialogBodyWithSchema;
|
|
64
|
+
exports.DSDialogDefaultLayoutWithSchema = DSDialogDefaultLayoutWithSchema;
|
|
65
|
+
exports.DSDialogFooterWithSchema = DSDialogFooterWithSchema;
|
|
66
|
+
exports.DSDialogHeaderWithSchema = DSDialogHeaderWithSchema;
|
|
67
|
+
exports.DSDialogPrimaryMessageWithSchema = DSDialogPrimaryMessageWithSchema;
|
|
68
|
+
exports.DSDialogSecondaryMessageWithSchema = DSDialogSecondaryMessageWithSchema;
|
|
69
|
+
exports.DSDialogSeparatorWithSchema = DSDialogSeparatorWithSchema;
|
|
70
|
+
exports.DSDialogTitleWithSchema = DSDialogTitleWithSchema;
|
package/cjs/propTypes.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
8
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
9
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
10
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
11
|
+
var dsPropsHelpers = require('@elliemae/ds-props-helpers');
|
|
12
|
+
var utils = require('./utils.js');
|
|
13
|
+
|
|
14
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
+
|
|
16
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
17
|
+
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
+
const propTypes = _objectSpread(_objectSpread({}, dsPropsHelpers.globalAttributesPropTypes), {}, {
|
|
22
|
+
isOpen: dsPropsHelpers.PropTypes.bool.description('Whether the Dialog is open or not.').defaultValue(false),
|
|
23
|
+
children: dsPropsHelpers.PropTypes.node.description('Nested components.').isRequired,
|
|
24
|
+
centered: dsPropsHelpers.PropTypes.bool.description('Centers the Dialog.').defaultValue(false),
|
|
25
|
+
removeAutoFocus: dsPropsHelpers.PropTypes.bool.description('Removes focus in the Dialog container when is open. If you want to focus an specific element in the Dialog, it should be set to true.').defaultValue(false),
|
|
26
|
+
onClickOutside: dsPropsHelpers.PropTypes.func.description('Callback that should be used to close the modal when the user clicks outside.').defaultValue(() => {}),
|
|
27
|
+
onClose: dsPropsHelpers.PropTypes.func.description('Callback triggered with ESC key.').defaultValue(() => {}),
|
|
28
|
+
size: dsPropsHelpers.PropTypes.oneOf(utils.DSDialogSizesArrayValues).description("Dialog's width size.").defaultValue(utils.DSDialogSizes.DEFAULT)
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
exports.propTypes = propTypes;
|
package/cjs/styles.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _taggedTemplateLiteral = require('@babel/runtime/helpers/taggedTemplateLiteral');
|
|
6
|
+
var styled = require('styled-components');
|
|
7
|
+
var dsSystem = require('@elliemae/ds-system');
|
|
8
|
+
var styledComponents = require('@xstyled/styled-components');
|
|
9
|
+
var utils = require('./utils.js');
|
|
10
|
+
|
|
11
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
+
|
|
13
|
+
var _taggedTemplateLiteral__default = /*#__PURE__*/_interopDefaultLegacy(_taggedTemplateLiteral);
|
|
14
|
+
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
15
|
+
|
|
16
|
+
var _templateObject;
|
|
17
|
+
const FixedBody = dsSystem.createGlobalStyle(_templateObject || (_templateObject = _taggedTemplateLiteral__default["default"](["\n body {\n overflow: hidden;\n \n ", "\n }\n"])), _ref => {
|
|
18
|
+
let {
|
|
19
|
+
bodyInfo
|
|
20
|
+
} = _ref;
|
|
21
|
+
return bodyInfo.overflow ? "padding-right: calc( ".concat(bodyInfo.padding, " + 15px ) !important;") : "";
|
|
22
|
+
});
|
|
23
|
+
const StyledDialogBackground = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
24
|
+
componentId: "sc-106vqwv-0"
|
|
25
|
+
})(["position:fixed;top:0;bottom:0;width:100%;height:100%;background:rgba(37,41,47,50%);overflow-y:auto;z-index:", ";"], _ref2 => {
|
|
26
|
+
let {
|
|
27
|
+
zIndex
|
|
28
|
+
} = _ref2;
|
|
29
|
+
return zIndex;
|
|
30
|
+
});
|
|
31
|
+
const StyledDialogContainer = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
32
|
+
componentId: "sc-106vqwv-1"
|
|
33
|
+
})(["height:fit-content;position:absolute;top:0;bottom:0;left:0;right:0;margin:", ";width:", ";min-width:300px;box-shadow:0 10px 20px 0 ", ";background:", ";overflow-y:auto;", " &:focus{outline:none;}"], _ref3 => {
|
|
34
|
+
let {
|
|
35
|
+
centered
|
|
36
|
+
} = _ref3;
|
|
37
|
+
return centered ? 'auto' : '20vh auto auto auto';
|
|
38
|
+
}, _ref4 => {
|
|
39
|
+
let {
|
|
40
|
+
size
|
|
41
|
+
} = _ref4;
|
|
42
|
+
return utils.allSizes[size];
|
|
43
|
+
}, _ref5 => {
|
|
44
|
+
let {
|
|
45
|
+
theme
|
|
46
|
+
} = _ref5;
|
|
47
|
+
return theme.colors.neutral[500];
|
|
48
|
+
}, _ref6 => {
|
|
49
|
+
let {
|
|
50
|
+
theme
|
|
51
|
+
} = _ref6;
|
|
52
|
+
return theme.colors.neutral['000'];
|
|
53
|
+
}, styledComponents.space);
|
|
54
|
+
const DSDialogTitle = /*#__PURE__*/styled__default["default"].h3.withConfig({
|
|
55
|
+
componentId: "sc-106vqwv-2"
|
|
56
|
+
})(["font-size:", ";display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;line-height:28px;margin:0;"], _ref7 => {
|
|
57
|
+
let {
|
|
58
|
+
theme
|
|
59
|
+
} = _ref7;
|
|
60
|
+
return theme.fontSizes.title[700];
|
|
61
|
+
});
|
|
62
|
+
const DSDialogAddon = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
63
|
+
componentId: "sc-106vqwv-3"
|
|
64
|
+
})([""]);
|
|
65
|
+
const DSDialogHeader = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
66
|
+
componentId: "sc-106vqwv-4"
|
|
67
|
+
})(["display:grid;align-items:center;grid-auto-flow:column;min-height:", ";padding:10px ", ";& ", " + ", "{align-self:flex-start;justify-self:flex-end;}& ", ":only-child{justify-self:flex-end;}", " ", ""], _ref8 => {
|
|
68
|
+
let {
|
|
69
|
+
theme
|
|
70
|
+
} = _ref8;
|
|
71
|
+
return theme.space.m;
|
|
72
|
+
}, _ref9 => {
|
|
73
|
+
let {
|
|
74
|
+
theme
|
|
75
|
+
} = _ref9;
|
|
76
|
+
return theme.space.xs;
|
|
77
|
+
}, DSDialogTitle, DSDialogAddon, DSDialogAddon, styledComponents.space, styledComponents.sizing);
|
|
78
|
+
const DSDialogSeparator = /*#__PURE__*/styled__default["default"].hr.attrs(() => ({
|
|
79
|
+
'aria-hidden': true
|
|
80
|
+
})).withConfig({
|
|
81
|
+
componentId: "sc-106vqwv-5"
|
|
82
|
+
})(["margin:0;border-top:1px solid ", ";"], _ref10 => {
|
|
83
|
+
let {
|
|
84
|
+
theme
|
|
85
|
+
} = _ref10;
|
|
86
|
+
return theme.colors.neutral['080'];
|
|
87
|
+
});
|
|
88
|
+
const DSDialogBody = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
89
|
+
componentId: "sc-106vqwv-6"
|
|
90
|
+
})(["padding:", ";overflow-y:auto;", " ", " ", " ", ""], _ref11 => {
|
|
91
|
+
let {
|
|
92
|
+
theme
|
|
93
|
+
} = _ref11;
|
|
94
|
+
return theme.space.xs;
|
|
95
|
+
}, styledComponents.layout, styledComponents.space, styledComponents.flexboxes, styledComponents.sizing);
|
|
96
|
+
const DSDialogPrimaryMessage = /*#__PURE__*/styled__default["default"].h3.withConfig({
|
|
97
|
+
componentId: "sc-106vqwv-7"
|
|
98
|
+
})(["margin:0;"]);
|
|
99
|
+
const DSDialogSecondaryMessage = /*#__PURE__*/styled__default["default"].p.withConfig({
|
|
100
|
+
componentId: "sc-106vqwv-8"
|
|
101
|
+
})(["margin:0;color:", ";"], _ref12 => {
|
|
102
|
+
let {
|
|
103
|
+
theme
|
|
104
|
+
} = _ref12;
|
|
105
|
+
return theme.colors.neutral[500];
|
|
106
|
+
});
|
|
107
|
+
const DSDialogDefaultLayout = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
108
|
+
componentId: "sc-106vqwv-9"
|
|
109
|
+
})(["display:grid;grid-auto-flow:row;justify-items:center;align-items:center;grid-gap:", ";", "{text-align:center;}"], _ref13 => {
|
|
110
|
+
let {
|
|
111
|
+
theme
|
|
112
|
+
} = _ref13;
|
|
113
|
+
return theme.space.xxs;
|
|
114
|
+
}, DSDialogSecondaryMessage);
|
|
115
|
+
const DSDialogFooter = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
116
|
+
componentId: "sc-106vqwv-10"
|
|
117
|
+
})(["display:grid;grid-auto-flow:column;align-items:center;justify-content:flex-end;grid-gap:", ";min-height:", ";padding:0 ", ";", " ", " ", ""], _ref14 => {
|
|
118
|
+
let {
|
|
119
|
+
theme
|
|
120
|
+
} = _ref14;
|
|
121
|
+
return theme.space.xxs;
|
|
122
|
+
}, _ref15 => {
|
|
123
|
+
let {
|
|
124
|
+
theme
|
|
125
|
+
} = _ref15;
|
|
126
|
+
return theme.space.m;
|
|
127
|
+
}, _ref16 => {
|
|
128
|
+
let {
|
|
129
|
+
theme
|
|
130
|
+
} = _ref16;
|
|
131
|
+
return theme.space.xs;
|
|
132
|
+
}, styledComponents.space, styledComponents.flexboxes, styledComponents.sizing);
|
|
133
|
+
|
|
134
|
+
exports.DSDialogAddon = DSDialogAddon;
|
|
135
|
+
exports.DSDialogBody = DSDialogBody;
|
|
136
|
+
exports.DSDialogDefaultLayout = DSDialogDefaultLayout;
|
|
137
|
+
exports.DSDialogFooter = DSDialogFooter;
|
|
138
|
+
exports.DSDialogHeader = DSDialogHeader;
|
|
139
|
+
exports.DSDialogPrimaryMessage = DSDialogPrimaryMessage;
|
|
140
|
+
exports.DSDialogSecondaryMessage = DSDialogSecondaryMessage;
|
|
141
|
+
exports.DSDialogSeparator = DSDialogSeparator;
|
|
142
|
+
exports.DSDialogTitle = DSDialogTitle;
|
|
143
|
+
exports.FixedBody = FixedBody;
|
|
144
|
+
exports.StyledDialogBackground = StyledDialogBackground;
|
|
145
|
+
exports.StyledDialogContainer = StyledDialogContainer;
|
package/cjs/utils.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
8
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
9
|
+
|
|
10
|
+
const getSpaceProps = props => Object.fromEntries(Object.entries(props).filter(_ref => {
|
|
11
|
+
let [key] = _ref;
|
|
12
|
+
return /^[pm][xytblr]?$/.exec(key);
|
|
13
|
+
}));
|
|
14
|
+
const DSDialogSizes = {
|
|
15
|
+
DEFAULT: 'default',
|
|
16
|
+
SMALL: 'small',
|
|
17
|
+
MEDIUM: 'medium',
|
|
18
|
+
LARGE: 'large',
|
|
19
|
+
XLARGE: 'x-large',
|
|
20
|
+
XXLARGE: 'xx-large'
|
|
21
|
+
};
|
|
22
|
+
const DSDialogSizesArrayValues = Object.values(DSDialogSizes);
|
|
23
|
+
const allSizes = {
|
|
24
|
+
default: '576px',
|
|
25
|
+
small: '320px',
|
|
26
|
+
medium: '656px',
|
|
27
|
+
large: '848px',
|
|
28
|
+
'x-large': '1042px',
|
|
29
|
+
'xx-large': '1440px'
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.DSDialogSizes = DSDialogSizes;
|
|
33
|
+
exports.DSDialogSizesArrayValues = DSDialogSizesArrayValues;
|
|
34
|
+
exports.allSizes = allSizes;
|
|
35
|
+
exports.getSpaceProps = getSpaceProps;
|
package/esm/DSDialog.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
7
|
+
import _jsx from '@babel/runtime/helpers/esm/jsx';
|
|
8
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
|
|
9
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
10
|
+
import ReactDOM from 'react-dom';
|
|
11
|
+
import { useState, useRef, useCallback, useEffect } from 'react';
|
|
12
|
+
import { describe, useMemoMergePropsWithDefault, useValidateTypescriptPropTypes, useGetGlobalAttributes } from '@elliemae/ds-props-helpers';
|
|
13
|
+
import { StyledDialogBackground, FixedBody, StyledDialogContainer } from './styles.js';
|
|
14
|
+
import { propTypes } from './propTypes.js';
|
|
15
|
+
import { defaultProps } from './defaultProps.js';
|
|
16
|
+
import { getSpaceProps } from './utils.js';
|
|
17
|
+
import { DSDialogDatatestid } from './DSDialogDatatestid.js';
|
|
18
|
+
import { jsx } from 'react/jsx-runtime';
|
|
19
|
+
|
|
20
|
+
const _excluded = ["children", "isOpen", "onClickOutside", "onClose", "centered", "size", "removeAutoFocus", "zIndex"],
|
|
21
|
+
_excluded2 = ["className"];
|
|
22
|
+
|
|
23
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
24
|
+
|
|
25
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
26
|
+
|
|
27
|
+
const DSDialog = props => {
|
|
28
|
+
var _FixedBody;
|
|
29
|
+
|
|
30
|
+
const propsWithDefault = useMemoMergePropsWithDefault(props, defaultProps);
|
|
31
|
+
const [bodyInfo, setBodyInfo] = useState({
|
|
32
|
+
overflow: false,
|
|
33
|
+
padding: '0px'
|
|
34
|
+
});
|
|
35
|
+
useValidateTypescriptPropTypes(propsWithDefault, propTypes);
|
|
36
|
+
|
|
37
|
+
const {
|
|
38
|
+
children,
|
|
39
|
+
isOpen,
|
|
40
|
+
onClickOutside,
|
|
41
|
+
onClose,
|
|
42
|
+
centered,
|
|
43
|
+
size,
|
|
44
|
+
removeAutoFocus,
|
|
45
|
+
zIndex
|
|
46
|
+
} = propsWithDefault,
|
|
47
|
+
rest = _objectWithoutProperties(propsWithDefault, _excluded);
|
|
48
|
+
|
|
49
|
+
const containerRef = useRef(null);
|
|
50
|
+
const handleOutsideClick = useCallback(e => {
|
|
51
|
+
if (e.target.dataset.portalbg) onClickOutside();
|
|
52
|
+
}, [onClickOutside]);
|
|
53
|
+
const handleOnKeyDown = useCallback(e => {
|
|
54
|
+
if (e.key === 'Escape') onClose();
|
|
55
|
+
}, [onClose]);
|
|
56
|
+
|
|
57
|
+
const _useGetGlobalAttribut = useGetGlobalAttributes(propsWithDefault, {
|
|
58
|
+
onClick: handleOutsideClick,
|
|
59
|
+
onKeyDown: handleOnKeyDown
|
|
60
|
+
}),
|
|
61
|
+
{
|
|
62
|
+
className
|
|
63
|
+
} = _useGetGlobalAttribut,
|
|
64
|
+
restOfGlobalAttributes = _objectWithoutProperties(_useGetGlobalAttribut, _excluded2);
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
var _window$getComputedSt;
|
|
68
|
+
|
|
69
|
+
const body = document.getElementsByTagName('body')[0];
|
|
70
|
+
const {
|
|
71
|
+
offsetHeight,
|
|
72
|
+
scrollHeight
|
|
73
|
+
} = body;
|
|
74
|
+
const padding = (_window$getComputedSt = window.getComputedStyle(body, null)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.getPropertyValue('padding-right');
|
|
75
|
+
if (!isOpen) return setBodyInfo({
|
|
76
|
+
overflow: false,
|
|
77
|
+
padding: '0px'
|
|
78
|
+
});
|
|
79
|
+
return setBodyInfo({
|
|
80
|
+
overflow: offsetHeight < scrollHeight,
|
|
81
|
+
padding
|
|
82
|
+
});
|
|
83
|
+
}, [isOpen]);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
var _containerRef$current;
|
|
86
|
+
|
|
87
|
+
if (isOpen && !removeAutoFocus) containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.focus();
|
|
88
|
+
}, [isOpen, removeAutoFocus]);
|
|
89
|
+
|
|
90
|
+
if (isOpen) {
|
|
91
|
+
return /*#__PURE__*/ReactDOM.createPortal( /*#__PURE__*/_jsx(StyledDialogBackground, {
|
|
92
|
+
className: className,
|
|
93
|
+
onClick: handleOutsideClick,
|
|
94
|
+
"data-portalbg": true,
|
|
95
|
+
"data-testid": DSDialogDatatestid.BACKGROUND,
|
|
96
|
+
zIndex: zIndex
|
|
97
|
+
}, void 0, _FixedBody || (_FixedBody = /*#__PURE__*/_jsx(FixedBody, {
|
|
98
|
+
bodyInfo: bodyInfo
|
|
99
|
+
})), /*#__PURE__*/jsx(StyledDialogContainer, _objectSpread(_objectSpread(_objectSpread({
|
|
100
|
+
role: "dialog",
|
|
101
|
+
"aria-modal": true,
|
|
102
|
+
ref: containerRef,
|
|
103
|
+
tabIndex: !removeAutoFocus ? 0 : undefined
|
|
104
|
+
}, getSpaceProps(rest)), {}, {
|
|
105
|
+
size: size,
|
|
106
|
+
centered: centered,
|
|
107
|
+
"data-testid": DSDialogDatatestid.CONTAINER
|
|
108
|
+
}, restOfGlobalAttributes), {}, {
|
|
109
|
+
children: children
|
|
110
|
+
}))), document.getElementsByTagName('body')[0]);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return null;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const DSDialogWithSchema = describe(DSDialog);
|
|
117
|
+
DSDialogWithSchema.propTypes = propTypes;
|
|
118
|
+
|
|
119
|
+
export { DSDialog, DSDialogWithSchema };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DSDialogSizes } from './utils.js';
|
|
2
|
+
|
|
3
|
+
const noop = () => {};
|
|
4
|
+
|
|
5
|
+
const defaultProps = {
|
|
6
|
+
isOpen: false,
|
|
7
|
+
centered: false,
|
|
8
|
+
size: DSDialogSizes.DEFAULT,
|
|
9
|
+
removeAutoFocus: false,
|
|
10
|
+
onClickOutside: noop,
|
|
11
|
+
onClose: noop,
|
|
12
|
+
zIndex: 10
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { defaultProps };
|