@elliemae/ds-dialog 2.4.1-rc.2 → 2.4.1-rc.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/cjs/DSDialog.js +9 -143
- package/cjs/DSDialogCTX.js +21 -0
- package/cjs/config/useDialog.js +97 -0
- package/cjs/defaultProps.js +3 -1
- package/cjs/parts/DSDialogPortal.js +32 -0
- package/cjs/parts/dialogContent/DSDialogContent.js +87 -0
- package/cjs/parts/dialogContent/useDialogContent.js +46 -0
- package/cjs/styles.js +39 -34
- package/esm/DSDialog.js +10 -141
- package/esm/DSDialogCTX.js +17 -0
- package/esm/config/useDialog.js +89 -0
- package/esm/defaultProps.js +3 -1
- package/esm/parts/DSDialogPortal.js +23 -0
- package/esm/parts/dialogContent/DSDialogContent.js +77 -0
- package/esm/parts/dialogContent/useDialogContent.js +42 -0
- package/esm/styles.js +39 -34
- package/package.json +25 -5
- package/types/DSDialog.d.ts +1 -1
- package/types/DSDialogCTX.d.ts +3 -0
- package/types/config/useDialog.d.ts +3 -0
- package/types/parts/DSDialogPortal.d.ts +2 -0
- package/types/parts/dialogContent/DSDialogContent.d.ts +2 -0
- package/types/parts/dialogContent/useDialogContent.d.ts +5 -0
- package/types/propTypes.d.ts +9 -2
- package/types/sharedTypes.d.ts +10 -1
- package/types/styles.d.ts +1 -1
- package/types/utils.d.ts +3 -3
package/cjs/DSDialog.js
CHANGED
|
@@ -3,158 +3,24 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var _jsx = require('@babel/runtime/helpers/jsx');
|
|
6
|
-
|
|
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 lodash = require('lodash');
|
|
6
|
+
require('react');
|
|
17
7
|
var dsPropsHelpers = require('@elliemae/ds-props-helpers');
|
|
18
|
-
var styles = require('./styles.js');
|
|
19
8
|
var propTypes = require('./propTypes.js');
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
9
|
+
var useDialog = require('./config/useDialog.js');
|
|
10
|
+
var DSDialogPortal = require('./parts/DSDialogPortal.js');
|
|
11
|
+
var DSDialogCTX = require('./DSDialogCTX.js');
|
|
24
12
|
|
|
25
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
26
14
|
|
|
27
15
|
var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
|
|
28
|
-
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
29
|
-
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
|
|
30
|
-
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
|
|
31
16
|
|
|
32
|
-
|
|
33
|
-
_excluded2 = ["className"];
|
|
34
|
-
|
|
35
|
-
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; }
|
|
36
|
-
|
|
37
|
-
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; }
|
|
17
|
+
var _DSDialogPortal;
|
|
38
18
|
|
|
39
19
|
const DSDialog = props => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
overflow: false,
|
|
45
|
-
paddingRight: '0px',
|
|
46
|
-
scrollbarWidth: '0px'
|
|
47
|
-
});
|
|
48
|
-
dsPropsHelpers.useValidateTypescriptPropTypes(propsWithDefault, propTypes.propTypes);
|
|
49
|
-
|
|
50
|
-
const {
|
|
51
|
-
children,
|
|
52
|
-
isOpen,
|
|
53
|
-
onClickOutside,
|
|
54
|
-
onClose,
|
|
55
|
-
centered,
|
|
56
|
-
size,
|
|
57
|
-
removeAutoFocus,
|
|
58
|
-
zIndex
|
|
59
|
-
} = propsWithDefault,
|
|
60
|
-
rest = _objectWithoutProperties__default["default"](propsWithDefault, _excluded);
|
|
61
|
-
|
|
62
|
-
const containerRef = react.useRef(null);
|
|
63
|
-
const focusContainer = react.useCallback(() => {
|
|
64
|
-
var _containerRef$current, _containerRef$current2, _containerRef$current3;
|
|
65
|
-
|
|
66
|
-
const isContainerOrChildFocused = (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.contains(document.activeElement);
|
|
67
|
-
if (!isContainerOrChildFocused) (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : (_containerRef$current3 = _containerRef$current2.focus) === null || _containerRef$current3 === void 0 ? void 0 : _containerRef$current3.call(_containerRef$current2);
|
|
68
|
-
}, []);
|
|
69
|
-
react.useEffect(() => {
|
|
70
|
-
document.addEventListener('focusin', focusContainer);
|
|
71
|
-
return () => document.removeEventListener('focusin', focusContainer);
|
|
72
|
-
}, [focusContainer]);
|
|
73
|
-
const handleOutsideClick = react.useCallback(e => {
|
|
74
|
-
if (e.target.dataset.portalbg) onClickOutside();
|
|
75
|
-
}, [onClickOutside]);
|
|
76
|
-
const handleOnKeyDown = react.useCallback(e => {
|
|
77
|
-
if (e.key === 'Escape') onClose();
|
|
78
|
-
}, [onClose]);
|
|
79
|
-
|
|
80
|
-
const _useGetGlobalAttribut = dsPropsHelpers.useGetGlobalAttributes(propsWithDefault, {
|
|
81
|
-
onClick: handleOutsideClick,
|
|
82
|
-
onKeyDown: handleOnKeyDown
|
|
83
|
-
}),
|
|
84
|
-
{
|
|
85
|
-
className
|
|
86
|
-
} = _useGetGlobalAttribut,
|
|
87
|
-
restOfGlobalAttributes = _objectWithoutProperties__default["default"](_useGetGlobalAttribut, _excluded2);
|
|
88
|
-
|
|
89
|
-
const calculateScrollbar = react.useCallback(() => {
|
|
90
|
-
const body = document.getElementsByTagName('body')[0];
|
|
91
|
-
const {
|
|
92
|
-
clientWidth
|
|
93
|
-
} = body;
|
|
94
|
-
setBodyInfo(prev => _objectSpread(_objectSpread({}, prev), {}, {
|
|
95
|
-
scrollbarWidth: "".concat(window.innerWidth - clientWidth, "px")
|
|
96
|
-
}));
|
|
97
|
-
}, []);
|
|
98
|
-
const debouncedCalculateScrollbar = react.useMemo(() => lodash.debounce(calculateScrollbar, 300), [calculateScrollbar]);
|
|
99
|
-
react.useEffect(() => {
|
|
100
|
-
calculateScrollbar();
|
|
101
|
-
}, [calculateScrollbar]);
|
|
102
|
-
react.useEffect(() => {
|
|
103
|
-
window.addEventListener('resize', debouncedCalculateScrollbar);
|
|
104
|
-
return () => {
|
|
105
|
-
window.removeEventListener('resize', debouncedCalculateScrollbar);
|
|
106
|
-
};
|
|
107
|
-
}, [calculateScrollbar, debouncedCalculateScrollbar]);
|
|
108
|
-
react.useEffect(() => {
|
|
109
|
-
if (isOpen) {
|
|
110
|
-
var _window$getComputedSt;
|
|
111
|
-
|
|
112
|
-
const body = document.getElementsByTagName('body')[0];
|
|
113
|
-
const {
|
|
114
|
-
clientHeight,
|
|
115
|
-
scrollHeight
|
|
116
|
-
} = body;
|
|
117
|
-
const paddingRight = (_window$getComputedSt = window.getComputedStyle(body, null)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.getPropertyValue('padding-right');
|
|
118
|
-
setBodyInfo(prev => _objectSpread(_objectSpread({}, prev), {}, {
|
|
119
|
-
overflow: scrollHeight > clientHeight,
|
|
120
|
-
paddingRight
|
|
121
|
-
}));
|
|
122
|
-
} else setBodyInfo(prev => _objectSpread(_objectSpread({}, prev), {}, {
|
|
123
|
-
overflow: false,
|
|
124
|
-
paddingRight: '0px'
|
|
125
|
-
}));
|
|
126
|
-
}, [isOpen]);
|
|
127
|
-
react.useEffect(() => {
|
|
128
|
-
var _containerRef$current4;
|
|
129
|
-
|
|
130
|
-
if (isOpen && !removeAutoFocus) containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current4 = containerRef.current) === null || _containerRef$current4 === void 0 ? void 0 : _containerRef$current4.focus();
|
|
131
|
-
}, [isOpen, removeAutoFocus]);
|
|
132
|
-
|
|
133
|
-
if (isOpen) {
|
|
134
|
-
return /*#__PURE__*/ReactDOM__default["default"].createPortal( /*#__PURE__*/_jsx__default["default"](styles.StyledDialogBackground, {
|
|
135
|
-
className: className,
|
|
136
|
-
onClick: handleOutsideClick,
|
|
137
|
-
"data-portalbg": true,
|
|
138
|
-
"data-testid": DSDialogDatatestid.DSDialogDatatestid.BACKGROUND,
|
|
139
|
-
zIndex: zIndex
|
|
140
|
-
}, void 0, _FixedBody || (_FixedBody = /*#__PURE__*/_jsx__default["default"](styles.FixedBody, {
|
|
141
|
-
bodyInfo: bodyInfo
|
|
142
|
-
})), /*#__PURE__*/jsxRuntime.jsx(styles.StyledDialogContainer, _objectSpread(_objectSpread(_objectSpread({
|
|
143
|
-
role: "dialog",
|
|
144
|
-
"aria-modal": true,
|
|
145
|
-
ref: containerRef,
|
|
146
|
-
tabIndex: !removeAutoFocus ? 0 : undefined
|
|
147
|
-
}, utils.getSpaceProps(rest)), {}, {
|
|
148
|
-
centered: centered,
|
|
149
|
-
"data-testid": DSDialogDatatestid.DSDialogDatatestid.CONTAINER,
|
|
150
|
-
onKeyDown: handleOnKeyDown
|
|
151
|
-
}, restOfGlobalAttributes), {}, {
|
|
152
|
-
size: size,
|
|
153
|
-
children: children
|
|
154
|
-
}))), document.getElementsByTagName('body')[0]);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return null;
|
|
20
|
+
const ctx = useDialog.useDialog(props);
|
|
21
|
+
return /*#__PURE__*/_jsx__default["default"](DSDialogCTX.DSDialogContext.Provider, {
|
|
22
|
+
value: ctx
|
|
23
|
+
}, void 0, _DSDialogPortal || (_DSDialogPortal = /*#__PURE__*/_jsx__default["default"](DSDialogPortal.DSDialogPortal, {})));
|
|
158
24
|
};
|
|
159
25
|
|
|
160
26
|
const DSDialogWithSchema = dsPropsHelpers.describe(DSDialog);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var defaultProps = require('./defaultProps.js');
|
|
7
|
+
|
|
8
|
+
const defaultContext = {
|
|
9
|
+
props: defaultProps.defaultProps,
|
|
10
|
+
actualPortalRef: /*#__PURE__*/react.createRef(),
|
|
11
|
+
containerRef: /*#__PURE__*/react.createRef(),
|
|
12
|
+
portalClassName: '',
|
|
13
|
+
portalInfo: {
|
|
14
|
+
overflow: false,
|
|
15
|
+
paddingRight: '0px',
|
|
16
|
+
scrollbarWidth: '0px'
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const DSDialogContext = /*#__PURE__*/react.createContext(defaultContext);
|
|
20
|
+
|
|
21
|
+
exports.DSDialogContext = DSDialogContext;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
7
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
8
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
9
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
10
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
11
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
12
|
+
var react = require('react');
|
|
13
|
+
var lodash = require('lodash');
|
|
14
|
+
var uid = require('uid');
|
|
15
|
+
var dsPropsHelpers = require('@elliemae/ds-props-helpers');
|
|
16
|
+
var defaultProps = require('../defaultProps.js');
|
|
17
|
+
var propTypes = require('../propTypes.js');
|
|
18
|
+
|
|
19
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
20
|
+
|
|
21
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
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__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; }
|
|
26
|
+
const useDialog = props => {
|
|
27
|
+
dsPropsHelpers.useValidateTypescriptPropTypes(props, propTypes.propTypes);
|
|
28
|
+
const propsWithDefault = dsPropsHelpers.useMemoMergePropsWithDefault(props, defaultProps.defaultProps);
|
|
29
|
+
const {
|
|
30
|
+
portalRef,
|
|
31
|
+
isOpen
|
|
32
|
+
} = propsWithDefault;
|
|
33
|
+
const actualPortalRef = react.useRef(null);
|
|
34
|
+
const containerRef = react.useRef(null);
|
|
35
|
+
const [portalInfo, setPortalInfo] = react.useState({
|
|
36
|
+
paddingRight: '0px',
|
|
37
|
+
scrollbarWidth: '0px',
|
|
38
|
+
overflow: false
|
|
39
|
+
});
|
|
40
|
+
const portalClassName = react.useMemo(() => "ds-dialog-".concat(uid.uid(8)), []);
|
|
41
|
+
react.useEffect(() => {
|
|
42
|
+
if (portalRef) actualPortalRef.current = portalRef.current;else actualPortalRef.current = document.getElementsByTagName('body')['0'];
|
|
43
|
+
}, [portalRef]);
|
|
44
|
+
react.useLayoutEffect(() => {
|
|
45
|
+
if (actualPortalRef.current) {
|
|
46
|
+
if (isOpen) {
|
|
47
|
+
actualPortalRef.current.classList.add(portalClassName);
|
|
48
|
+
} else {
|
|
49
|
+
actualPortalRef.current.classList.remove(portalClassName);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}, [actualPortalRef, isOpen, portalClassName]);
|
|
53
|
+
react.useEffect(() => {
|
|
54
|
+
if (actualPortalRef.current) {
|
|
55
|
+
var _window$getComputedSt;
|
|
56
|
+
|
|
57
|
+
const paddingRight = (_window$getComputedSt = window.getComputedStyle(actualPortalRef.current, null)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.getPropertyValue('padding-right');
|
|
58
|
+
setPortalInfo(prev => _objectSpread(_objectSpread({}, prev), {}, {
|
|
59
|
+
paddingRight
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
}, []);
|
|
63
|
+
const calculateScrollbarAndOverflow = react.useCallback(() => {
|
|
64
|
+
if (actualPortalRef.current) {
|
|
65
|
+
const body = actualPortalRef.current;
|
|
66
|
+
const {
|
|
67
|
+
clientWidth,
|
|
68
|
+
clientHeight,
|
|
69
|
+
scrollHeight
|
|
70
|
+
} = body;
|
|
71
|
+
setPortalInfo(prev => _objectSpread(_objectSpread({}, prev), {}, {
|
|
72
|
+
scrollbarWidth: "".concat(window.innerWidth - clientWidth, "px"),
|
|
73
|
+
overflow: scrollHeight > clientHeight
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
}, [actualPortalRef]);
|
|
77
|
+
const debouncedCalculateScrollbarAndOverflow = react.useMemo(() => lodash.debounce(calculateScrollbarAndOverflow, 300), [calculateScrollbarAndOverflow]);
|
|
78
|
+
react.useEffect(() => {
|
|
79
|
+
window.addEventListener('resize', debouncedCalculateScrollbarAndOverflow);
|
|
80
|
+
return () => {
|
|
81
|
+
window.removeEventListener('resize', debouncedCalculateScrollbarAndOverflow);
|
|
82
|
+
};
|
|
83
|
+
}, [calculateScrollbarAndOverflow, debouncedCalculateScrollbarAndOverflow]);
|
|
84
|
+
react.useEffect(() => {
|
|
85
|
+
calculateScrollbarAndOverflow();
|
|
86
|
+
}, [calculateScrollbarAndOverflow]);
|
|
87
|
+
const ctx = react.useMemo(() => ({
|
|
88
|
+
props: propsWithDefault,
|
|
89
|
+
actualPortalRef,
|
|
90
|
+
containerRef,
|
|
91
|
+
portalInfo,
|
|
92
|
+
portalClassName
|
|
93
|
+
}), [portalClassName, portalInfo, propsWithDefault]);
|
|
94
|
+
return ctx;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
exports.useDialog = useDialog;
|
package/cjs/defaultProps.js
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _jsx = require('@babel/runtime/helpers/jsx');
|
|
6
|
+
var ReactDOM = require('react-dom');
|
|
7
|
+
var react = require('react');
|
|
8
|
+
var DSDialogCTX = require('../DSDialogCTX.js');
|
|
9
|
+
var DSDialogContent = require('./dialogContent/DSDialogContent.js');
|
|
10
|
+
|
|
11
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
+
|
|
13
|
+
var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
|
|
14
|
+
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
|
|
15
|
+
|
|
16
|
+
var _DSDialogContent;
|
|
17
|
+
const DSDialogPortal = () => {
|
|
18
|
+
const {
|
|
19
|
+
props: {
|
|
20
|
+
isOpen
|
|
21
|
+
},
|
|
22
|
+
actualPortalRef
|
|
23
|
+
} = react.useContext(DSDialogCTX.DSDialogContext);
|
|
24
|
+
|
|
25
|
+
if (isOpen && actualPortalRef.current) {
|
|
26
|
+
return /*#__PURE__*/ReactDOM__default["default"].createPortal(_DSDialogContent || (_DSDialogContent = /*#__PURE__*/_jsx__default["default"](DSDialogContent.DSDialogContent, {})), actualPortalRef.current);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
exports.DSDialogPortal = DSDialogPortal;
|
|
@@ -0,0 +1,87 @@
|
|
|
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 _jsx = require('@babel/runtime/helpers/jsx');
|
|
12
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
13
|
+
var react = require('react');
|
|
14
|
+
var dsPropsHelpers = require('@elliemae/ds-props-helpers');
|
|
15
|
+
var styles = require('../../styles.js');
|
|
16
|
+
var utils = require('../../utils.js');
|
|
17
|
+
var DSDialogDatatestid = require('../../DSDialogDatatestid.js');
|
|
18
|
+
var DSDialogCTX = require('../../DSDialogCTX.js');
|
|
19
|
+
var useDialogContent = require('./useDialogContent.js');
|
|
20
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
21
|
+
|
|
22
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
23
|
+
|
|
24
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
25
|
+
var _jsx__default = /*#__PURE__*/_interopDefaultLegacy(_jsx);
|
|
26
|
+
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutProperties);
|
|
27
|
+
|
|
28
|
+
const _excluded = ["removeAutoFocus", "zIndex", "centered", "size", "children"],
|
|
29
|
+
_excluded2 = ["className"];
|
|
30
|
+
|
|
31
|
+
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; }
|
|
32
|
+
|
|
33
|
+
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; }
|
|
34
|
+
const DSDialogContent = () => {
|
|
35
|
+
const {
|
|
36
|
+
handleOutsideClick,
|
|
37
|
+
handleOnKeyDown
|
|
38
|
+
} = useDialogContent.useDialogContent();
|
|
39
|
+
const {
|
|
40
|
+
props,
|
|
41
|
+
containerRef,
|
|
42
|
+
portalInfo,
|
|
43
|
+
portalClassName
|
|
44
|
+
} = react.useContext(DSDialogCTX.DSDialogContext);
|
|
45
|
+
|
|
46
|
+
const {
|
|
47
|
+
removeAutoFocus,
|
|
48
|
+
zIndex,
|
|
49
|
+
centered,
|
|
50
|
+
size,
|
|
51
|
+
children
|
|
52
|
+
} = props,
|
|
53
|
+
rest = _objectWithoutProperties__default["default"](props, _excluded);
|
|
54
|
+
|
|
55
|
+
const _useGetGlobalAttribut = dsPropsHelpers.useGetGlobalAttributes(props, {
|
|
56
|
+
onClick: handleOutsideClick,
|
|
57
|
+
onKeyDown: handleOnKeyDown
|
|
58
|
+
}),
|
|
59
|
+
{
|
|
60
|
+
className
|
|
61
|
+
} = _useGetGlobalAttribut,
|
|
62
|
+
restOfGlobalAttributes = _objectWithoutProperties__default["default"](_useGetGlobalAttribut, _excluded2);
|
|
63
|
+
|
|
64
|
+
return /*#__PURE__*/_jsx__default["default"](styles.StyledDialogBackground, {
|
|
65
|
+
className: className,
|
|
66
|
+
onClick: handleOutsideClick,
|
|
67
|
+
"data-portalbg": true,
|
|
68
|
+
"data-testid": DSDialogDatatestid.DSDialogDatatestid.BACKGROUND,
|
|
69
|
+
zIndex: zIndex
|
|
70
|
+
}, void 0, /*#__PURE__*/_jsx__default["default"](styles.PortalStyles, {
|
|
71
|
+
portalInfo: portalInfo,
|
|
72
|
+
portalClassName: portalClassName
|
|
73
|
+
}), /*#__PURE__*/jsxRuntime.jsx(styles.StyledDialogContainer, _objectSpread(_objectSpread(_objectSpread({
|
|
74
|
+
role: "dialog",
|
|
75
|
+
"aria-modal": true,
|
|
76
|
+
ref: containerRef,
|
|
77
|
+
tabIndex: !removeAutoFocus ? 0 : undefined
|
|
78
|
+
}, utils.getSpaceProps(rest)), {}, {
|
|
79
|
+
centered: centered,
|
|
80
|
+
"data-testid": DSDialogDatatestid.DSDialogDatatestid.CONTAINER
|
|
81
|
+
}, restOfGlobalAttributes), {}, {
|
|
82
|
+
size: size,
|
|
83
|
+
children: children
|
|
84
|
+
})));
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
exports.DSDialogContent = DSDialogContent;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var DSDialogCTX = require('../../DSDialogCTX.js');
|
|
7
|
+
|
|
8
|
+
const useDialogContent = () => {
|
|
9
|
+
const {
|
|
10
|
+
props: {
|
|
11
|
+
onClickOutside,
|
|
12
|
+
onClose,
|
|
13
|
+
removeAutoFocus
|
|
14
|
+
},
|
|
15
|
+
containerRef
|
|
16
|
+
} = react.useContext(DSDialogCTX.DSDialogContext);
|
|
17
|
+
const handleOutsideClick = react.useCallback(e => {
|
|
18
|
+
if (e.target.dataset.portalbg) onClickOutside();
|
|
19
|
+
}, [onClickOutside]);
|
|
20
|
+
const handleOnKeyDown = react.useCallback(e => {
|
|
21
|
+
if (e.key === 'Escape') onClose();
|
|
22
|
+
}, [onClose]);
|
|
23
|
+
react.useEffect(() => {
|
|
24
|
+
var _containerRef$current;
|
|
25
|
+
|
|
26
|
+
if (!removeAutoFocus) containerRef === null || containerRef === void 0 ? void 0 : (_containerRef$current = containerRef.current) === null || _containerRef$current === void 0 ? void 0 : _containerRef$current.focus();
|
|
27
|
+
}, [containerRef, removeAutoFocus]);
|
|
28
|
+
const focusContainer = react.useCallback(() => {
|
|
29
|
+
setTimeout(() => {
|
|
30
|
+
var _containerRef$current2, _containerRef$current3, _containerRef$current4;
|
|
31
|
+
|
|
32
|
+
const isContainerOrChildFocused = (_containerRef$current2 = containerRef.current) === null || _containerRef$current2 === void 0 ? void 0 : _containerRef$current2.contains(document.activeElement);
|
|
33
|
+
if (!isContainerOrChildFocused) (_containerRef$current3 = containerRef.current) === null || _containerRef$current3 === void 0 ? void 0 : (_containerRef$current4 = _containerRef$current3.focus) === null || _containerRef$current4 === void 0 ? void 0 : _containerRef$current4.call(_containerRef$current3);
|
|
34
|
+
});
|
|
35
|
+
}, [containerRef]);
|
|
36
|
+
react.useEffect(() => {
|
|
37
|
+
document.addEventListener('focusin', focusContainer);
|
|
38
|
+
return () => document.removeEventListener('focusin', focusContainer);
|
|
39
|
+
}, [focusContainer]);
|
|
40
|
+
return {
|
|
41
|
+
handleOutsideClick,
|
|
42
|
+
handleOnKeyDown
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
exports.useDialogContent = useDialogContent;
|
package/cjs/styles.js
CHANGED
|
@@ -14,49 +14,54 @@ var _taggedTemplateLiteral__default = /*#__PURE__*/_interopDefaultLegacy(_tagged
|
|
|
14
14
|
var styled__default = /*#__PURE__*/_interopDefaultLegacy(styled);
|
|
15
15
|
|
|
16
16
|
var _templateObject;
|
|
17
|
-
const
|
|
17
|
+
const PortalStyles = dsSystem.createGlobalStyle(_templateObject || (_templateObject = _taggedTemplateLiteral__default["default"](["\n ", " {\n overflow: hidden;\n ", "\n }\n"])), _ref => {
|
|
18
18
|
let {
|
|
19
|
-
|
|
19
|
+
portalClassName
|
|
20
20
|
} = _ref;
|
|
21
|
-
return
|
|
21
|
+
return ".".concat(portalClassName);
|
|
22
|
+
}, _ref2 => {
|
|
23
|
+
let {
|
|
24
|
+
portalInfo
|
|
25
|
+
} = _ref2;
|
|
26
|
+
return portalInfo.overflow ? "padding-right: calc( ".concat(portalInfo.paddingRight, " + ").concat(portalInfo.scrollbarWidth, " ) !important;") : "";
|
|
22
27
|
});
|
|
23
28
|
const StyledDialogBackground = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
24
29
|
componentId: "sc-106vqwv-0"
|
|
25
|
-
})(["position:
|
|
30
|
+
})(["position:absolute;top:0;bottom:0;left:0;width:100%;height:100%;background:rgba(37,41,47,50%);overflow-y:auto;z-index:", ";"], _ref3 => {
|
|
26
31
|
let {
|
|
27
32
|
zIndex
|
|
28
|
-
} =
|
|
33
|
+
} = _ref3;
|
|
29
34
|
return zIndex;
|
|
30
35
|
});
|
|
31
36
|
const StyledDialogContainer = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
32
37
|
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;}"],
|
|
38
|
+
})(["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;}"], _ref4 => {
|
|
34
39
|
let {
|
|
35
40
|
centered
|
|
36
|
-
} =
|
|
41
|
+
} = _ref4;
|
|
37
42
|
return centered ? 'auto' : '20vh auto auto auto';
|
|
38
|
-
},
|
|
43
|
+
}, _ref5 => {
|
|
39
44
|
let {
|
|
40
45
|
size
|
|
41
|
-
} =
|
|
46
|
+
} = _ref5;
|
|
42
47
|
return utils.allSizes[size];
|
|
43
|
-
},
|
|
48
|
+
}, _ref6 => {
|
|
44
49
|
let {
|
|
45
50
|
theme
|
|
46
|
-
} =
|
|
51
|
+
} = _ref6;
|
|
47
52
|
return theme.colors.neutral[500];
|
|
48
|
-
},
|
|
53
|
+
}, _ref7 => {
|
|
49
54
|
let {
|
|
50
55
|
theme
|
|
51
|
-
} =
|
|
56
|
+
} = _ref7;
|
|
52
57
|
return theme.colors.neutral['000'];
|
|
53
58
|
}, styledComponents.space);
|
|
54
59
|
const DSDialogTitle = /*#__PURE__*/styled__default["default"].h3.withConfig({
|
|
55
60
|
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;"],
|
|
61
|
+
})(["font-size:", ";display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;line-height:28px;margin:0;"], _ref8 => {
|
|
57
62
|
let {
|
|
58
63
|
theme
|
|
59
|
-
} =
|
|
64
|
+
} = _ref8;
|
|
60
65
|
return theme.fontSizes.title[700];
|
|
61
66
|
});
|
|
62
67
|
const DSDialogAddon = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
@@ -64,33 +69,33 @@ const DSDialogAddon = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
|
64
69
|
})([""]);
|
|
65
70
|
const DSDialogHeader = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
66
71
|
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;}", " ", ""],
|
|
72
|
+
})(["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;}", " ", ""], _ref9 => {
|
|
68
73
|
let {
|
|
69
74
|
theme
|
|
70
|
-
} =
|
|
75
|
+
} = _ref9;
|
|
71
76
|
return theme.space.m;
|
|
72
|
-
},
|
|
77
|
+
}, _ref10 => {
|
|
73
78
|
let {
|
|
74
79
|
theme
|
|
75
|
-
} =
|
|
80
|
+
} = _ref10;
|
|
76
81
|
return theme.space.xs;
|
|
77
82
|
}, DSDialogTitle, DSDialogAddon, DSDialogAddon, styledComponents.space, styledComponents.sizing);
|
|
78
83
|
const DSDialogSeparator = /*#__PURE__*/styled__default["default"].hr.attrs(() => ({
|
|
79
84
|
'aria-hidden': true
|
|
80
85
|
})).withConfig({
|
|
81
86
|
componentId: "sc-106vqwv-5"
|
|
82
|
-
})(["margin:0;border-top:1px solid ", ";"],
|
|
87
|
+
})(["margin:0;border-top:1px solid ", ";"], _ref11 => {
|
|
83
88
|
let {
|
|
84
89
|
theme
|
|
85
|
-
} =
|
|
90
|
+
} = _ref11;
|
|
86
91
|
return theme.colors.neutral['080'];
|
|
87
92
|
});
|
|
88
93
|
const DSDialogBody = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
89
94
|
componentId: "sc-106vqwv-6"
|
|
90
|
-
})(["padding:", ";overflow-y:auto;", " ", " ", " ", ""],
|
|
95
|
+
})(["padding:", ";overflow-y:auto;", " ", " ", " ", ""], _ref12 => {
|
|
91
96
|
let {
|
|
92
97
|
theme
|
|
93
|
-
} =
|
|
98
|
+
} = _ref12;
|
|
94
99
|
return theme.space.xs;
|
|
95
100
|
}, styledComponents.layout, styledComponents.space, styledComponents.flexboxes, styledComponents.sizing);
|
|
96
101
|
const DSDialogPrimaryMessage = /*#__PURE__*/styled__default["default"].h3.withConfig({
|
|
@@ -98,36 +103,36 @@ const DSDialogPrimaryMessage = /*#__PURE__*/styled__default["default"].h3.withCo
|
|
|
98
103
|
})(["margin:0;"]);
|
|
99
104
|
const DSDialogSecondaryMessage = /*#__PURE__*/styled__default["default"].p.withConfig({
|
|
100
105
|
componentId: "sc-106vqwv-8"
|
|
101
|
-
})(["margin:0;color:", ";"],
|
|
106
|
+
})(["margin:0;color:", ";"], _ref13 => {
|
|
102
107
|
let {
|
|
103
108
|
theme
|
|
104
|
-
} =
|
|
109
|
+
} = _ref13;
|
|
105
110
|
return theme.colors.neutral[500];
|
|
106
111
|
});
|
|
107
112
|
const DSDialogDefaultLayout = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
108
113
|
componentId: "sc-106vqwv-9"
|
|
109
|
-
})(["display:grid;grid-auto-flow:row;justify-items:center;align-items:center;grid-gap:", ";", "{text-align:center;}"],
|
|
114
|
+
})(["display:grid;grid-auto-flow:row;justify-items:center;align-items:center;grid-gap:", ";", "{text-align:center;}"], _ref14 => {
|
|
110
115
|
let {
|
|
111
116
|
theme
|
|
112
|
-
} =
|
|
117
|
+
} = _ref14;
|
|
113
118
|
return theme.space.xxs;
|
|
114
119
|
}, DSDialogSecondaryMessage);
|
|
115
120
|
const DSDialogFooter = /*#__PURE__*/styled__default["default"].div.withConfig({
|
|
116
121
|
componentId: "sc-106vqwv-10"
|
|
117
|
-
})(["display:grid;grid-auto-flow:column;align-items:center;justify-content:flex-end;grid-gap:", ";min-height:", ";padding:0 ", ";", " ", " ", ""],
|
|
122
|
+
})(["display:grid;grid-auto-flow:column;align-items:center;justify-content:flex-end;grid-gap:", ";min-height:", ";padding:0 ", ";", " ", " ", ""], _ref15 => {
|
|
118
123
|
let {
|
|
119
124
|
theme
|
|
120
|
-
} =
|
|
125
|
+
} = _ref15;
|
|
121
126
|
return theme.space.xxs;
|
|
122
|
-
},
|
|
127
|
+
}, _ref16 => {
|
|
123
128
|
let {
|
|
124
129
|
theme
|
|
125
|
-
} =
|
|
130
|
+
} = _ref16;
|
|
126
131
|
return theme.space.m;
|
|
127
|
-
},
|
|
132
|
+
}, _ref17 => {
|
|
128
133
|
let {
|
|
129
134
|
theme
|
|
130
|
-
} =
|
|
135
|
+
} = _ref17;
|
|
131
136
|
return theme.space.xs;
|
|
132
137
|
}, styledComponents.space, styledComponents.flexboxes, styledComponents.sizing);
|
|
133
138
|
|
|
@@ -140,6 +145,6 @@ exports.DSDialogPrimaryMessage = DSDialogPrimaryMessage;
|
|
|
140
145
|
exports.DSDialogSecondaryMessage = DSDialogSecondaryMessage;
|
|
141
146
|
exports.DSDialogSeparator = DSDialogSeparator;
|
|
142
147
|
exports.DSDialogTitle = DSDialogTitle;
|
|
143
|
-
exports.
|
|
148
|
+
exports.PortalStyles = PortalStyles;
|
|
144
149
|
exports.StyledDialogBackground = StyledDialogBackground;
|
|
145
150
|
exports.StyledDialogContainer = StyledDialogContainer;
|