@semcore/modal 2.3.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/lib/cjs/Modal.js +15 -12
- package/lib/cjs/Modal.js.map +1 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/style/modal.shadow.css +2 -2
- package/lib/es6/Modal.js +15 -12
- package/lib/es6/Modal.js.map +1 -1
- package/lib/es6/index.js.map +1 -1
- package/lib/es6/style/modal.shadow.css +2 -2
- package/lib/types/index.d.ts +37 -2
- package/package.json +4 -3
- package/src/{Modal.tsx → Modal.js} +18 -46
- package/src/index.d.ts +37 -0
- package/src/{index.tsx → index.js} +0 -0
- package/src/style/modal.shadow.css +2 -2
- package/lib/types/Modal.d.ts +0 -59
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
CHANGELOG.md standards are inspired by [keepachangelog.com](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
|
5
|
+
## [2.4.0] - 2022-01-18
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Up version icons and use new icon.
|
|
10
|
+
|
|
11
|
+
## [2.3.4] - 2021-9-13
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Changed overlay opacity from 80% to 60%
|
|
16
|
+
- Changed overlay opacity for the second modal window from 20% to 40%
|
|
17
|
+
|
|
18
|
+
## [2.3.3] - 2021-8-26
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- Add 'sideEffect=false' for more optimal build via webpack
|
|
23
|
+
|
|
24
|
+
## [2.3.2] - 2021-06-28
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- [TS] rewrite code from ts to js.
|
|
29
|
+
- [A11y] added role for `Window` and aria-label for `Close` and `Window`.
|
|
30
|
+
|
|
5
31
|
## [2.3.1] - 2021-04-28
|
|
6
32
|
|
|
7
33
|
### Changed
|
package/lib/cjs/Modal.js
CHANGED
|
@@ -41,7 +41,7 @@ var _flexBox = require("@semcore/flex-box");
|
|
|
41
41
|
|
|
42
42
|
var _outsideClick = _interopRequireDefault(require("@semcore/outside-click"));
|
|
43
43
|
|
|
44
|
-
var
|
|
44
|
+
var _l = _interopRequireDefault(require("@semcore/icon/Close/l"));
|
|
45
45
|
|
|
46
46
|
var _fire = _interopRequireDefault(require("@semcore/utils/lib/fire"));
|
|
47
47
|
|
|
@@ -64,15 +64,15 @@ var style = (
|
|
|
64
64
|
/*__reshadow_css_start__*/
|
|
65
65
|
_core.sstyled.insert(
|
|
66
66
|
/*__inner_css_start__*/
|
|
67
|
-
".
|
|
67
|
+
".___SWindow_n71dz_gg_{position:relative;border-radius:6px;background:#fff;box-sizing:border-box;margin:auto;padding:24px 32px 32px 32px}.___SWindow_n71dz_gg_:focus{outline:none}.___SOverlay_n71dz_gg_{position:fixed;top:0;bottom:0;left:0;right:0;margin:0;display:flex;justify-content:center;align-items:center;padding:40px;background:rgba(0,0,0,.6);overflow:auto;z-index:10005;-webkit-overflow-scrolling:touch}.___SOverlay_n71dz_gg_ .___SOverlay_n71dz_gg_{background:rgba(0,0,0,.4)}.___SClose_n71dz_gg_{display:inline-flex;position:absolute;right:0;top:0;padding:12px;color:#a6b0b3;cursor:pointer;z-index:1;border:none;background:none;outline:none}.___SClose_n71dz_gg_:hover{color:#929b9e}.___SClose_n71dz_gg_.__keyboardFocused_n71dz_gg_{box-shadow:0 0 0 3px rgba(43,148,225,.3)}@media (max-width:767px){.___SWindow_n71dz_gg_{min-width:60%}.___SOverlay_n71dz_gg_{padding:10px}}"
|
|
68
68
|
/*__inner_css_end__*/
|
|
69
|
-
, "
|
|
69
|
+
, "juwj6d_gg_")
|
|
70
70
|
/*__reshadow_css_end__*/
|
|
71
71
|
, {
|
|
72
|
-
"__SWindow": "
|
|
73
|
-
"__SOverlay": "
|
|
74
|
-
"__SClose": "
|
|
75
|
-
"_keyboardFocused": "
|
|
72
|
+
"__SWindow": "___SWindow_n71dz_gg_",
|
|
73
|
+
"__SOverlay": "___SOverlay_n71dz_gg_",
|
|
74
|
+
"__SClose": "___SClose_n71dz_gg_",
|
|
75
|
+
"_keyboardFocused": "__keyboardFocused_n71dz_gg_"
|
|
76
76
|
});
|
|
77
77
|
|
|
78
78
|
var ModalRoot = /*#__PURE__*/function (_Component) {
|
|
@@ -151,8 +151,7 @@ var ModalRoot = /*#__PURE__*/function (_Component) {
|
|
|
151
151
|
}
|
|
152
152
|
}]);
|
|
153
153
|
return ModalRoot;
|
|
154
|
-
}(_core.Component);
|
|
155
|
-
|
|
154
|
+
}(_core.Component);
|
|
156
155
|
|
|
157
156
|
(0, _defineProperty2["default"])(ModalRoot, "displayName", 'Modal');
|
|
158
157
|
(0, _defineProperty2["default"])(ModalRoot, "style", style);
|
|
@@ -187,7 +186,10 @@ function Window(props) {
|
|
|
187
186
|
"ref": windowRef,
|
|
188
187
|
"returnFocus": true,
|
|
189
188
|
"tabIndex": -1,
|
|
190
|
-
"autoFocus": true
|
|
189
|
+
"autoFocus": true,
|
|
190
|
+
"role": "dialog",
|
|
191
|
+
"aria-modal": true,
|
|
192
|
+
"aria-label": "Modal window"
|
|
191
193
|
}, _ref2))), /*#__PURE__*/_react["default"].createElement(_portal.PortalProvider, _ref5.cn("PortalProvider", {
|
|
192
194
|
"value": windowRef
|
|
193
195
|
}), closable && /*#__PURE__*/_react["default"].createElement(Modal.Close, null), /*#__PURE__*/_react["default"].createElement(Children, _ref5.cn("Children", {}))));
|
|
@@ -219,12 +221,13 @@ function Close(props) {
|
|
|
219
221
|
var SClose = _flexBox.Box;
|
|
220
222
|
return _ref7 = (0, _core.sstyled)(props.styles), /*#__PURE__*/_react["default"].createElement(SClose, _ref7.cn("SClose", _objectSpread({}, (0, _core.assignProps)({
|
|
221
223
|
"tag": "button",
|
|
222
|
-
"tabIndex": 0
|
|
224
|
+
"tabIndex": 0,
|
|
225
|
+
"aria-label": "Close"
|
|
223
226
|
}, _ref4))));
|
|
224
227
|
}
|
|
225
228
|
|
|
226
229
|
Close.defaultProps = {
|
|
227
|
-
children: /*#__PURE__*/_react["default"].createElement(
|
|
230
|
+
children: /*#__PURE__*/_react["default"].createElement(_l["default"], {
|
|
228
231
|
title: "Close"
|
|
229
232
|
})
|
|
230
233
|
};
|
package/lib/cjs/Modal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Modal.
|
|
1
|
+
{"version":3,"sources":["../../src/Modal.js"],"names":["ModalRoot","e","key","stopPropagation","asProps","duration","visible","onOutsideClick","handleOutsideClick","closable","onKeyDown","handleKeyDown","onClick","handleIconCloseClick","Children","disablePortal","advanceMode","Modal","Overlay","displayName","Window","Component","style","FocusLockWrapper","React","forwardRef","ref","tag","other","props","SWindow","styles","windowRef","Box","SOverlay","FadeInOut","overlayRef","Close","SClose","defaultProps","children","enhance"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAHA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;IAGMA,S;;;;;;;;;;;;;;;sGAQY,UAACC,CAAD,EAAO;AACrB,UAAIA,CAAC,CAACC,GAAF,KAAU,QAAd,EAAwB;AACtBD,QAAAA,CAAC,CAACE,eAAF;AACA,8EAAW,SAAX,EAAsB,UAAtB,EAAkCF,CAAlC;AACD;AACF,K;6GAEsB,UAACA,CAAD,EAAO;AAC5B,4EAAW,SAAX,EAAsB,cAAtB,EAAsCA,CAAtC;AACD,K;2GAEoB,UAACA,CAAD,EAAO;AAC1B,4EAAW,SAAX,EAAsB,gBAAtB,EAAwCA,CAAxC;AACD,K;;;;;;WAED,2BAAkB;AAAA,0BACc,KAAKG,OADnB;AAAA,UACRC,QADQ,iBACRA,QADQ;AAAA,UACEC,OADF,iBACEA,OADF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eACE,gCAAC,QAAD;AAAA,WAAkCK;AAAlC,4BACE,gCAAC,wBAAD;AAAA,YAAoBA,UAApB;AAAA,sBAAgD7B;AAAhD,mBACE,gCAAC,QAAD,2BADF,CADF,CADF;AAOD;;AAED,SAAS8B,KAAT,CAAeR,KAAf,EAAsB;AAAA;AAAA;;AACpB,MAAMS,MAAM,GAEML,YAFlB;AACA,iBAAO,mBAAQJ,KAAK,CAACE,MAAd,CAAP,eACE,gCAAC,MAAD;AAAA,WAAyB,QAAzB;AAAA,gBAA4C,CAA5C;AAAA,kBAA0D;AAA1D,cADF;AAGD;;AAEDM,KAAK,CAACE,YAAN,GAAqB;AACnBC,EAAAA,QAAQ,eAAE,gCAAC,aAAD;AAAW,IAAA,KAAK,EAAC;AAAjB;AADS,CAArB;AAIAH,KAAK,CAACI,OAAN,GAAgB,CAAC,uCAAD,CAAhB;AAEA,IAAMxB,KAAK,GAAG,sBAAgBjB,SAAhB,EAA2B;AACvCoB,EAAAA,MAAM,EAANA,MADuC;AAEvCF,EAAAA,OAAO,EAAPA,OAFuC;AAGvCmB,EAAAA,KAAK,EAALA;AAHuC,CAA3B,CAAd;eAMepB,K","sourcesContent":["import React, { useRef } from 'react';\nimport FocusLock from 'react-focus-lock';\nimport { FadeInOut } from '@semcore/animation';\nimport createComponent, { Component, sstyled, Root } from '@semcore/core';\nimport Portal, { PortalProvider } from '@semcore/portal';\nimport { Box } from '@semcore/flex-box';\nimport OutsideClick from '@semcore/outside-click';\nimport CloseIcon from '@semcore/icon/Close/l';\nimport fire from '@semcore/utils/lib/fire';\nimport usePreventScroll from '@semcore/utils/lib/use/usePreventScroll';\nimport findComponent from '@semcore/utils/lib/findComponent';\nimport keyboardFocusEnhance from '@semcore/utils/lib/enhances/keyboardFocusEnhance';\nimport style from './style/modal.shadow.css';\n\nclass ModalRoot extends Component {\n static displayName = 'Modal';\n static style = style;\n static defaultProps = {\n duration: 200,\n closable: true,\n };\n\n handleKeyDown = (e) => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n fire(this, 'onClose', 'onEscape', e);\n }\n };\n\n handleIconCloseClick = (e) => {\n fire(this, 'onClose', 'onCloseClick', e);\n };\n\n handleOutsideClick = (e) => {\n fire(this, 'onClose', 'onOutsideClick', e);\n };\n\n getOverlayProps() {\n const { duration, visible } = this.asProps;\n return {\n duration,\n visible,\n onOutsideClick: this.handleOutsideClick,\n };\n }\n\n getWindowProps() {\n const { visible, closable } = this.asProps;\n return {\n visible,\n closable,\n onKeyDown: this.handleKeyDown,\n };\n }\n\n getCloseProps() {\n return {\n onClick: this.handleIconCloseClick,\n };\n }\n\n render() {\n const { Children, disablePortal } = this.asProps;\n\n const advanceMode = !!findComponent(Children, [\n Modal.Overlay.displayName,\n Modal.Window.displayName,\n ]);\n\n return (\n <Portal disablePortal={disablePortal}>\n {advanceMode ? (\n <Children />\n ) : (\n <Modal.Overlay>\n <Root render={Modal.Window} />\n </Modal.Overlay>\n )}\n </Portal>\n );\n }\n}\n\nconst FocusLockWrapper = React.forwardRef(function({ tag, ...other }, ref) {\n return <FocusLock ref={ref} as={tag} lockProps={other} {...other} />;\n});\n\nfunction Window(props) {\n const SWindow = Root;\n const { Children, styles, visible, closable } = props;\n const windowRef = useRef(null);\n\n if (!visible) return null;\n\n return sstyled(styles)(\n <SWindow\n render={FocusLockWrapper}\n tag={Box}\n ref={windowRef}\n returnFocus={true}\n tabIndex={-1}\n autoFocus={true}\n role=\"dialog\"\n aria-modal={true}\n aria-label=\"Modal window\"\n >\n <PortalProvider value={windowRef}>\n {closable && <Modal.Close />}\n <Children />\n </PortalProvider>\n </SWindow>,\n );\n}\n\nfunction Overlay(props) {\n const SOverlay = Root;\n const { Children, styles, onOutsideClick, visible } = props;\n const overlayRef = useRef(null);\n usePreventScroll(visible);\n\n return sstyled(styles)(\n <SOverlay render={FadeInOut} ref={overlayRef}>\n <OutsideClick root={overlayRef} onOutsideClick={onOutsideClick}>\n <Children />\n </OutsideClick>\n </SOverlay>,\n );\n}\n\nfunction Close(props) {\n const SClose = Root;\n return sstyled(props.styles)(\n <SClose render={Box} tag=\"button\" tabIndex={0} aria-label=\"Close\" />,\n );\n}\n\nClose.defaultProps = {\n children: <CloseIcon title=\"Close\" />,\n};\n\nClose.enhance = [keyboardFocusEnhance()];\n\nconst Modal = createComponent(ModalRoot, {\n Window,\n Overlay,\n Close,\n});\n\nexport default Modal;\n"],"file":"Modal.js"}
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.
|
|
1
|
+
{"version":3,"sources":["../../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export { default } from './Modal';\nexport * from './Modal';\n"],"file":"index.js"}
|
|
@@ -24,13 +24,13 @@ SOverlay {
|
|
|
24
24
|
justify-content: center;
|
|
25
25
|
align-items: center;
|
|
26
26
|
padding: 40px;
|
|
27
|
-
background: rgba(0, 0, 0, 0.
|
|
27
|
+
background: rgba(0, 0, 0, 0.6);
|
|
28
28
|
overflow: auto;
|
|
29
29
|
z-index: 10005;
|
|
30
30
|
-webkit-overflow-scrolling: touch;
|
|
31
31
|
|
|
32
32
|
& SOverlay {
|
|
33
|
-
background: rgba(0, 0, 0, 0.
|
|
33
|
+
background: rgba(0, 0, 0, 0.4);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
package/lib/es6/Modal.js
CHANGED
|
@@ -28,7 +28,7 @@ import createComponent, { Component, sstyled, Root } from '@semcore/core';
|
|
|
28
28
|
import Portal, { PortalProvider } from '@semcore/portal';
|
|
29
29
|
import { Box } from '@semcore/flex-box';
|
|
30
30
|
import OutsideClick from '@semcore/outside-click';
|
|
31
|
-
import
|
|
31
|
+
import CloseIcon from '@semcore/icon/Close/l';
|
|
32
32
|
import fire from '@semcore/utils/lib/fire';
|
|
33
33
|
import usePreventScroll from '@semcore/utils/lib/use/usePreventScroll';
|
|
34
34
|
import findComponent from '@semcore/utils/lib/findComponent';
|
|
@@ -39,15 +39,15 @@ var style = (
|
|
|
39
39
|
/*__reshadow_css_start__*/
|
|
40
40
|
_sstyled.insert(
|
|
41
41
|
/*__inner_css_start__*/
|
|
42
|
-
".
|
|
42
|
+
".___SWindow_n71dz_gg_{position:relative;border-radius:6px;background:#fff;box-sizing:border-box;margin:auto;padding:24px 32px 32px 32px}.___SWindow_n71dz_gg_:focus{outline:none}.___SOverlay_n71dz_gg_{position:fixed;top:0;bottom:0;left:0;right:0;margin:0;display:flex;justify-content:center;align-items:center;padding:40px;background:rgba(0,0,0,.6);overflow:auto;z-index:10005;-webkit-overflow-scrolling:touch}.___SOverlay_n71dz_gg_ .___SOverlay_n71dz_gg_{background:rgba(0,0,0,.4)}.___SClose_n71dz_gg_{display:inline-flex;position:absolute;right:0;top:0;padding:12px;color:#a6b0b3;cursor:pointer;z-index:1;border:none;background:none;outline:none}.___SClose_n71dz_gg_:hover{color:#929b9e}.___SClose_n71dz_gg_.__keyboardFocused_n71dz_gg_{box-shadow:0 0 0 3px rgba(43,148,225,.3)}@media (max-width:767px){.___SWindow_n71dz_gg_{min-width:60%}.___SOverlay_n71dz_gg_{padding:10px}}"
|
|
43
43
|
/*__inner_css_end__*/
|
|
44
|
-
, "
|
|
44
|
+
, "juwj6d_gg_")
|
|
45
45
|
/*__reshadow_css_end__*/
|
|
46
46
|
, {
|
|
47
|
-
"__SWindow": "
|
|
48
|
-
"__SOverlay": "
|
|
49
|
-
"__SClose": "
|
|
50
|
-
"_keyboardFocused": "
|
|
47
|
+
"__SWindow": "___SWindow_n71dz_gg_",
|
|
48
|
+
"__SOverlay": "___SOverlay_n71dz_gg_",
|
|
49
|
+
"__SClose": "___SClose_n71dz_gg_",
|
|
50
|
+
"_keyboardFocused": "__keyboardFocused_n71dz_gg_"
|
|
51
51
|
});
|
|
52
52
|
|
|
53
53
|
var ModalRoot = /*#__PURE__*/function (_Component) {
|
|
@@ -131,8 +131,7 @@ var ModalRoot = /*#__PURE__*/function (_Component) {
|
|
|
131
131
|
}]);
|
|
132
132
|
|
|
133
133
|
return ModalRoot;
|
|
134
|
-
}(Component);
|
|
135
|
-
|
|
134
|
+
}(Component);
|
|
136
135
|
|
|
137
136
|
_defineProperty(ModalRoot, "displayName", 'Modal');
|
|
138
137
|
|
|
@@ -170,7 +169,10 @@ function Window(props) {
|
|
|
170
169
|
"ref": windowRef,
|
|
171
170
|
"returnFocus": true,
|
|
172
171
|
"tabIndex": -1,
|
|
173
|
-
"autoFocus": true
|
|
172
|
+
"autoFocus": true,
|
|
173
|
+
"role": "dialog",
|
|
174
|
+
"aria-modal": true,
|
|
175
|
+
"aria-label": "Modal window"
|
|
174
176
|
}, _ref2))), /*#__PURE__*/React.createElement(PortalProvider, _ref5.cn("PortalProvider", {
|
|
175
177
|
"value": windowRef
|
|
176
178
|
}), closable && /*#__PURE__*/React.createElement(Modal.Close, null), /*#__PURE__*/React.createElement(Children, _ref5.cn("Children", {}))));
|
|
@@ -202,12 +204,13 @@ function Close(props) {
|
|
|
202
204
|
var SClose = Box;
|
|
203
205
|
return _ref7 = sstyled(props.styles), /*#__PURE__*/React.createElement(SClose, _ref7.cn("SClose", _objectSpread({}, _assignProps4({
|
|
204
206
|
"tag": "button",
|
|
205
|
-
"tabIndex": 0
|
|
207
|
+
"tabIndex": 0,
|
|
208
|
+
"aria-label": "Close"
|
|
206
209
|
}, _ref4))));
|
|
207
210
|
}
|
|
208
211
|
|
|
209
212
|
Close.defaultProps = {
|
|
210
|
-
children: /*#__PURE__*/React.createElement(
|
|
213
|
+
children: /*#__PURE__*/React.createElement(CloseIcon, {
|
|
211
214
|
title: "Close"
|
|
212
215
|
})
|
|
213
216
|
};
|
package/lib/es6/Modal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Modal.
|
|
1
|
+
{"version":3,"sources":["../../src/Modal.js"],"names":["React","useRef","FocusLock","FadeInOut","createComponent","Component","sstyled","Root","Portal","PortalProvider","Box","OutsideClick","CloseIcon","fire","usePreventScroll","findComponent","keyboardFocusEnhance","ModalRoot","e","key","stopPropagation","asProps","duration","visible","onOutsideClick","handleOutsideClick","closable","onKeyDown","handleKeyDown","onClick","handleIconCloseClick","Children","disablePortal","advanceMode","Modal","Overlay","displayName","Window","style","FocusLockWrapper","forwardRef","ref","tag","other","props","SWindow","styles","windowRef","SOverlay","overlayRef","Close","SClose","defaultProps","children","enhance"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAOA,KAAP,IAAgBC,MAAhB,QAA8B,OAA9B;AACA,OAAOC,SAAP,MAAsB,kBAAtB;AACA,SAASC,SAAT,QAA0B,oBAA1B;AACA,OAAOC,eAAP,IAA0BC,SAA1B,EAAqCC,OAArC,EAA8CC,IAA9C,QAA0D,eAA1D;AACA,OAAOC,MAAP,IAAiBC,cAAjB,QAAuC,iBAAvC;AACA,SAASC,GAAT,QAAoB,mBAApB;AACA,OAAOC,YAAP,MAAyB,wBAAzB;AACA,OAAOC,SAAP,MAAsB,uBAAtB;AACA,OAAOC,IAAP,MAAiB,yBAAjB;AACA,OAAOC,gBAAP,MAA6B,yCAA7B;AACA,OAAOC,aAAP,MAA0B,kCAA1B;AACA,OAAOC,oBAAP,MAAiC,kDAAjC;;;;;;;;;;;;;;;;;;IAGMC,S;;;;;;;;;;;;;;;;oEAQY,UAACC,CAAD,EAAO;AACrB,UAAIA,CAAC,CAACC,GAAF,KAAU,QAAd,EAAwB;AACtBD,QAAAA,CAAC,CAACE,eAAF;AACAP,QAAAA,IAAI,gCAAO,SAAP,EAAkB,UAAlB,EAA8BK,CAA9B,CAAJ;AACD;AACF,K;;2EAEsB,UAACA,CAAD,EAAO;AAC5BL,MAAAA,IAAI,gCAAO,SAAP,EAAkB,cAAlB,EAAkCK,CAAlC,CAAJ;AACD,K;;yEAEoB,UAACA,CAAD,EAAO;AAC1BL,MAAAA,IAAI,gCAAO,SAAP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IpB,cAFJ;AAAA,MAEoBD,OAFpB,GAEgCqB,KAFhC,CAEoBrB,OAFpB;AAGtB,MAAM0B,UAAU,GAAGhD,MAAM,CAAC,IAAD,CAAzB;AACAa,EAAAA,gBAAgB,CAACS,OAAD,CAAhB;AAEA,iBAAOjB,OAAO,CAACwC,MAAD,CAAd,eACE,oBAAC,QAAD;AAAA,WAAkCG;AAAlC,4BACE,oBAAC,YAAD;AAAA,YAAoBA,UAApB;AAAA,sBAAgDzB;AAAhD,mBACE,oBAAC,QAAD,2BADF,CADF,CADF;AAOD;;AAED,SAAS0B,KAAT,CAAeN,KAAf,EAAsB;AAAA;AAAA;;AACpB,MAAMO,MAAM,GAEMzC,GAFlB;AACA,iBAAOJ,OAAO,CAACsC,KAAK,CAACE,MAAP,CAAd,eACE,oBAAC,MAAD;AAAA,WAAyB,QAAzB;AAAA,gBAA4C,CAA5C;AAAA,kBAA0D;AAA1D,cADF;AAGD;;AAEDI,KAAK,CAACE,YAAN,GAAqB;AACnBC,EAAAA,QAAQ,eAAE,oBAAC,SAAD;AAAW,IAAA,KAAK,EAAC;AAAjB;AADS,CAArB;AAIAH,KAAK,CAACI,OAAN,GAAgB,CAACtC,oBAAoB,EAArB,CAAhB;AAEA,IAAMkB,KAAK,GAAG9B,eAAe,CAACa,SAAD,EAAY;AACvCoB,EAAAA,MAAM,EAANA,MADuC;AAEvCF,EAAAA,OAAO,EAAPA,OAFuC;AAGvCe,EAAAA,KAAK,EAALA;AAHuC,CAAZ,CAA7B;AAMA,eAAehB,KAAf","sourcesContent":["import React, { useRef } from 'react';\nimport FocusLock from 'react-focus-lock';\nimport { FadeInOut } from '@semcore/animation';\nimport createComponent, { Component, sstyled, Root } from '@semcore/core';\nimport Portal, { PortalProvider } from '@semcore/portal';\nimport { Box } from '@semcore/flex-box';\nimport OutsideClick from '@semcore/outside-click';\nimport CloseIcon from '@semcore/icon/Close/l';\nimport fire from '@semcore/utils/lib/fire';\nimport usePreventScroll from '@semcore/utils/lib/use/usePreventScroll';\nimport findComponent from '@semcore/utils/lib/findComponent';\nimport keyboardFocusEnhance from '@semcore/utils/lib/enhances/keyboardFocusEnhance';\nimport style from './style/modal.shadow.css';\n\nclass ModalRoot extends Component {\n static displayName = 'Modal';\n static style = style;\n static defaultProps = {\n duration: 200,\n closable: true,\n };\n\n handleKeyDown = (e) => {\n if (e.key === 'Escape') {\n e.stopPropagation();\n fire(this, 'onClose', 'onEscape', e);\n }\n };\n\n handleIconCloseClick = (e) => {\n fire(this, 'onClose', 'onCloseClick', e);\n };\n\n handleOutsideClick = (e) => {\n fire(this, 'onClose', 'onOutsideClick', e);\n };\n\n getOverlayProps() {\n const { duration, visible } = this.asProps;\n return {\n duration,\n visible,\n onOutsideClick: this.handleOutsideClick,\n };\n }\n\n getWindowProps() {\n const { visible, closable } = this.asProps;\n return {\n visible,\n closable,\n onKeyDown: this.handleKeyDown,\n };\n }\n\n getCloseProps() {\n return {\n onClick: this.handleIconCloseClick,\n };\n }\n\n render() {\n const { Children, disablePortal } = this.asProps;\n\n const advanceMode = !!findComponent(Children, [\n Modal.Overlay.displayName,\n Modal.Window.displayName,\n ]);\n\n return (\n <Portal disablePortal={disablePortal}>\n {advanceMode ? (\n <Children />\n ) : (\n <Modal.Overlay>\n <Root render={Modal.Window} />\n </Modal.Overlay>\n )}\n </Portal>\n );\n }\n}\n\nconst FocusLockWrapper = React.forwardRef(function({ tag, ...other }, ref) {\n return <FocusLock ref={ref} as={tag} lockProps={other} {...other} />;\n});\n\nfunction Window(props) {\n const SWindow = Root;\n const { Children, styles, visible, closable } = props;\n const windowRef = useRef(null);\n\n if (!visible) return null;\n\n return sstyled(styles)(\n <SWindow\n render={FocusLockWrapper}\n tag={Box}\n ref={windowRef}\n returnFocus={true}\n tabIndex={-1}\n autoFocus={true}\n role=\"dialog\"\n aria-modal={true}\n aria-label=\"Modal window\"\n >\n <PortalProvider value={windowRef}>\n {closable && <Modal.Close />}\n <Children />\n </PortalProvider>\n </SWindow>,\n );\n}\n\nfunction Overlay(props) {\n const SOverlay = Root;\n const { Children, styles, onOutsideClick, visible } = props;\n const overlayRef = useRef(null);\n usePreventScroll(visible);\n\n return sstyled(styles)(\n <SOverlay render={FadeInOut} ref={overlayRef}>\n <OutsideClick root={overlayRef} onOutsideClick={onOutsideClick}>\n <Children />\n </OutsideClick>\n </SOverlay>,\n );\n}\n\nfunction Close(props) {\n const SClose = Root;\n return sstyled(props.styles)(\n <SClose render={Box} tag=\"button\" tabIndex={0} aria-label=\"Close\" />,\n );\n}\n\nClose.defaultProps = {\n children: <CloseIcon title=\"Close\" />,\n};\n\nClose.enhance = [keyboardFocusEnhance()];\n\nconst Modal = createComponent(ModalRoot, {\n Window,\n Overlay,\n Close,\n});\n\nexport default Modal;\n"],"file":"Modal.js"}
|
package/lib/es6/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.
|
|
1
|
+
{"version":3,"sources":["../../src/index.js"],"names":["default"],"mappings":"AAAA,SAASA,OAAT,QAAwB,SAAxB;AACA,cAAc,SAAd","sourcesContent":["export { default } from './Modal';\nexport * from './Modal';\n"],"file":"index.js"}
|
|
@@ -24,13 +24,13 @@ SOverlay {
|
|
|
24
24
|
justify-content: center;
|
|
25
25
|
align-items: center;
|
|
26
26
|
padding: 40px;
|
|
27
|
-
background: rgba(0, 0, 0, 0.
|
|
27
|
+
background: rgba(0, 0, 0, 0.6);
|
|
28
28
|
overflow: auto;
|
|
29
29
|
z-index: 10005;
|
|
30
30
|
-webkit-overflow-scrolling: touch;
|
|
31
31
|
|
|
32
32
|
& SOverlay {
|
|
33
|
-
background: rgba(0, 0, 0, 0.
|
|
33
|
+
background: rgba(0, 0, 0, 0.4);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,2 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import React, { ComponentProps } from 'react';
|
|
2
|
+
import { IFadeInOutProps } from '@semcore/animation';
|
|
3
|
+
import { CProps, PropGetterFn, ReturnEl } from '@semcore/core';
|
|
4
|
+
import { IPortalProps } from '@semcore/portal';
|
|
5
|
+
import { Box, IBoxProps } from '@semcore/flex-box';
|
|
6
|
+
|
|
7
|
+
export interface IModalProps extends IPortalProps, IBoxProps, IFadeInOutProps {
|
|
8
|
+
/** Duration of animation, ms
|
|
9
|
+
* @default 200
|
|
10
|
+
*/
|
|
11
|
+
duration?: number;
|
|
12
|
+
/** This property is responsible for the visibility of the modal window */
|
|
13
|
+
visible?: boolean;
|
|
14
|
+
/** Function called when the component is hidden */
|
|
15
|
+
onClose?: (
|
|
16
|
+
trigger: 'onOutsideClick' | 'onCloseClick' | 'onEscape',
|
|
17
|
+
e?: React.MouseEvent | React.KeyboardEvent,
|
|
18
|
+
) => void;
|
|
19
|
+
/** Displaying the close button(x) in the upper-right corner of the modal dialog
|
|
20
|
+
* @default true
|
|
21
|
+
* */
|
|
22
|
+
closable?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface IModalContext {
|
|
26
|
+
getOverlayProps: PropGetterFn;
|
|
27
|
+
getWindowProps: PropGetterFn;
|
|
28
|
+
getCloseProps: PropGetterFn;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare const Modal: (<T>(props: CProps<IModalProps & T, IModalContext>) => ReturnEl) & {
|
|
32
|
+
Window: <T>(props: ComponentProps<typeof Box> & T) => ReturnEl;
|
|
33
|
+
Overlay: <T>(props: ComponentProps<typeof Box> & T) => ReturnEl;
|
|
34
|
+
Close: <T>(props: ComponentProps<typeof Box> & T) => ReturnEl;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default Modal;
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semcore/modal",
|
|
3
3
|
"description": "SEMRush Modal Component",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.4.0",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/es6/index.js",
|
|
7
7
|
"typings": "lib/types/index.d.ts",
|
|
8
|
+
"sideEffects": false,
|
|
8
9
|
"author": "Roman Lysov <r.lysov@semrush.com>",
|
|
9
10
|
"license": "MIT",
|
|
10
11
|
"scripts": {
|
|
11
|
-
"build": "build",
|
|
12
|
+
"build": "build --source=js",
|
|
12
13
|
"test": "jest"
|
|
13
14
|
},
|
|
14
15
|
"dependencies": {
|
|
@@ -16,7 +17,7 @@
|
|
|
16
17
|
"@semcore/animation": "^1",
|
|
17
18
|
"@semcore/portal": "^2",
|
|
18
19
|
"@semcore/flex-box": "^4",
|
|
19
|
-
"@semcore/icon": "^2",
|
|
20
|
+
"@semcore/icon": "^2.16",
|
|
20
21
|
"@semcore/outside-click": "^2",
|
|
21
22
|
"react-focus-lock": "^2.3"
|
|
22
23
|
},
|
|
@@ -1,42 +1,18 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
2
|
import FocusLock from 'react-focus-lock';
|
|
3
|
-
import { FadeInOut
|
|
4
|
-
import createComponent, { Component,
|
|
5
|
-
import Portal, {
|
|
6
|
-
import { Box
|
|
3
|
+
import { FadeInOut } from '@semcore/animation';
|
|
4
|
+
import createComponent, { Component, sstyled, Root } from '@semcore/core';
|
|
5
|
+
import Portal, { PortalProvider } from '@semcore/portal';
|
|
6
|
+
import { Box } from '@semcore/flex-box';
|
|
7
7
|
import OutsideClick from '@semcore/outside-click';
|
|
8
|
-
import
|
|
8
|
+
import CloseIcon from '@semcore/icon/Close/l';
|
|
9
9
|
import fire from '@semcore/utils/lib/fire';
|
|
10
10
|
import usePreventScroll from '@semcore/utils/lib/use/usePreventScroll';
|
|
11
11
|
import findComponent from '@semcore/utils/lib/findComponent';
|
|
12
12
|
import keyboardFocusEnhance from '@semcore/utils/lib/enhances/keyboardFocusEnhance';
|
|
13
13
|
import style from './style/modal.shadow.css';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
/** Duration of animation, ms
|
|
17
|
-
* @default 200
|
|
18
|
-
*/
|
|
19
|
-
duration?: number;
|
|
20
|
-
/** This property is responsible for the visibility of the modal window */
|
|
21
|
-
visible?: boolean;
|
|
22
|
-
/** Function called when the component is hidden */
|
|
23
|
-
onClose?: (
|
|
24
|
-
trigger: 'onOutsideClick' | 'onCloseClick' | 'onEscape',
|
|
25
|
-
e?: React.MouseEvent | React.KeyboardEvent,
|
|
26
|
-
) => void;
|
|
27
|
-
/** Displaying the close button(x) in the upper-right corner of the modal dialog
|
|
28
|
-
* @default true
|
|
29
|
-
* */
|
|
30
|
-
closable?: boolean;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface IModalContext extends IModalProps {
|
|
34
|
-
getOverlayProps: PropGetter<ModalRoot['getOverlayProps']>;
|
|
35
|
-
getWindowProps: PropGetter<ModalRoot['getWindowProps']>;
|
|
36
|
-
getCloseProps: PropGetter<ModalRoot['getCloseProps']>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
class ModalRoot extends Component<IModalProps> {
|
|
15
|
+
class ModalRoot extends Component {
|
|
40
16
|
static displayName = 'Modal';
|
|
41
17
|
static style = style;
|
|
42
18
|
static defaultProps = {
|
|
@@ -105,15 +81,14 @@ class ModalRoot extends Component<IModalProps> {
|
|
|
105
81
|
}
|
|
106
82
|
}
|
|
107
83
|
|
|
108
|
-
|
|
109
|
-
const FocusLockWrapper = React.forwardRef<HTMLElement>(function ({ tag, ...other }, ref) {
|
|
84
|
+
const FocusLockWrapper = React.forwardRef(function({ tag, ...other }, ref) {
|
|
110
85
|
return <FocusLock ref={ref} as={tag} lockProps={other} {...other} />;
|
|
111
86
|
});
|
|
112
87
|
|
|
113
88
|
function Window(props) {
|
|
114
89
|
const SWindow = Root;
|
|
115
90
|
const { Children, styles, visible, closable } = props;
|
|
116
|
-
const windowRef = useRef
|
|
91
|
+
const windowRef = useRef(null);
|
|
117
92
|
|
|
118
93
|
if (!visible) return null;
|
|
119
94
|
|
|
@@ -125,6 +100,9 @@ function Window(props) {
|
|
|
125
100
|
returnFocus={true}
|
|
126
101
|
tabIndex={-1}
|
|
127
102
|
autoFocus={true}
|
|
103
|
+
role="dialog"
|
|
104
|
+
aria-modal={true}
|
|
105
|
+
aria-label="Modal window"
|
|
128
106
|
>
|
|
129
107
|
<PortalProvider value={windowRef}>
|
|
130
108
|
{closable && <Modal.Close />}
|
|
@@ -137,7 +115,7 @@ function Window(props) {
|
|
|
137
115
|
function Overlay(props) {
|
|
138
116
|
const SOverlay = Root;
|
|
139
117
|
const { Children, styles, onOutsideClick, visible } = props;
|
|
140
|
-
const overlayRef = useRef
|
|
118
|
+
const overlayRef = useRef(null);
|
|
141
119
|
usePreventScroll(visible);
|
|
142
120
|
|
|
143
121
|
return sstyled(styles)(
|
|
@@ -151,24 +129,18 @@ function Overlay(props) {
|
|
|
151
129
|
|
|
152
130
|
function Close(props) {
|
|
153
131
|
const SClose = Root;
|
|
154
|
-
return sstyled(props.styles)(
|
|
132
|
+
return sstyled(props.styles)(
|
|
133
|
+
<SClose render={Box} tag="button" tabIndex={0} aria-label="Close" />,
|
|
134
|
+
);
|
|
155
135
|
}
|
|
156
136
|
|
|
157
137
|
Close.defaultProps = {
|
|
158
|
-
children: <
|
|
138
|
+
children: <CloseIcon title="Close" />,
|
|
159
139
|
};
|
|
160
140
|
|
|
161
141
|
Close.enhance = [keyboardFocusEnhance()];
|
|
162
142
|
|
|
163
|
-
const Modal = createComponent
|
|
164
|
-
Merge<IModalProps, HTMLAttributes<HTMLDivElement>>,
|
|
165
|
-
{
|
|
166
|
-
Window: ComponentProps<typeof Box>;
|
|
167
|
-
Overlay: ComponentProps<typeof Box>;
|
|
168
|
-
Close: ComponentProps<typeof Box>;
|
|
169
|
-
},
|
|
170
|
-
IModalContext
|
|
171
|
-
>(ModalRoot, {
|
|
143
|
+
const Modal = createComponent(ModalRoot, {
|
|
172
144
|
Window,
|
|
173
145
|
Overlay,
|
|
174
146
|
Close,
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React, { ComponentProps } from 'react';
|
|
2
|
+
import { IFadeInOutProps } from '@semcore/animation';
|
|
3
|
+
import { CProps, PropGetterFn, ReturnEl } from '@semcore/core';
|
|
4
|
+
import { IPortalProps } from '@semcore/portal';
|
|
5
|
+
import { Box, IBoxProps } from '@semcore/flex-box';
|
|
6
|
+
|
|
7
|
+
export interface IModalProps extends IPortalProps, IBoxProps, IFadeInOutProps {
|
|
8
|
+
/** Duration of animation, ms
|
|
9
|
+
* @default 200
|
|
10
|
+
*/
|
|
11
|
+
duration?: number;
|
|
12
|
+
/** This property is responsible for the visibility of the modal window */
|
|
13
|
+
visible?: boolean;
|
|
14
|
+
/** Function called when the component is hidden */
|
|
15
|
+
onClose?: (
|
|
16
|
+
trigger: 'onOutsideClick' | 'onCloseClick' | 'onEscape',
|
|
17
|
+
e?: React.MouseEvent | React.KeyboardEvent,
|
|
18
|
+
) => void;
|
|
19
|
+
/** Displaying the close button(x) in the upper-right corner of the modal dialog
|
|
20
|
+
* @default true
|
|
21
|
+
* */
|
|
22
|
+
closable?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface IModalContext {
|
|
26
|
+
getOverlayProps: PropGetterFn;
|
|
27
|
+
getWindowProps: PropGetterFn;
|
|
28
|
+
getCloseProps: PropGetterFn;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare const Modal: (<T>(props: CProps<IModalProps & T, IModalContext>) => ReturnEl) & {
|
|
32
|
+
Window: <T>(props: ComponentProps<typeof Box> & T) => ReturnEl;
|
|
33
|
+
Overlay: <T>(props: ComponentProps<typeof Box> & T) => ReturnEl;
|
|
34
|
+
Close: <T>(props: ComponentProps<typeof Box> & T) => ReturnEl;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default Modal;
|
|
File without changes
|
|
@@ -24,13 +24,13 @@ SOverlay {
|
|
|
24
24
|
justify-content: center;
|
|
25
25
|
align-items: center;
|
|
26
26
|
padding: 40px;
|
|
27
|
-
background: rgba(0, 0, 0, 0.
|
|
27
|
+
background: rgba(0, 0, 0, 0.6);
|
|
28
28
|
overflow: auto;
|
|
29
29
|
z-index: 10005;
|
|
30
30
|
-webkit-overflow-scrolling: touch;
|
|
31
31
|
|
|
32
32
|
& SOverlay {
|
|
33
|
-
background: rgba(0, 0, 0, 0.
|
|
33
|
+
background: rgba(0, 0, 0, 0.4);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
package/lib/types/Modal.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import React, { ComponentProps } from 'react';
|
|
2
|
-
import { IFadeInOutProps } from '@semcore/animation';
|
|
3
|
-
import { Component, Merge, PropGetter } from '@semcore/core';
|
|
4
|
-
import { IPortalProps } from '@semcore/portal';
|
|
5
|
-
import { Box, IBoxProps } from '@semcore/flex-box';
|
|
6
|
-
export interface IModalProps extends IPortalProps, IBoxProps, IFadeInOutProps {
|
|
7
|
-
/** Duration of animation, ms
|
|
8
|
-
* @default 200
|
|
9
|
-
*/
|
|
10
|
-
duration?: number;
|
|
11
|
-
/** This property is responsible for the visibility of the modal window */
|
|
12
|
-
visible?: boolean;
|
|
13
|
-
/** Function called when the component is hidden */
|
|
14
|
-
onClose?: (trigger: 'onOutsideClick' | 'onCloseClick' | 'onEscape', e?: React.MouseEvent | React.KeyboardEvent) => void;
|
|
15
|
-
/** Displaying the close button(x) in the upper-right corner of the modal dialog
|
|
16
|
-
* @default true
|
|
17
|
-
* */
|
|
18
|
-
closable?: boolean;
|
|
19
|
-
}
|
|
20
|
-
export interface IModalContext extends IModalProps {
|
|
21
|
-
getOverlayProps: PropGetter<ModalRoot['getOverlayProps']>;
|
|
22
|
-
getWindowProps: PropGetter<ModalRoot['getWindowProps']>;
|
|
23
|
-
getCloseProps: PropGetter<ModalRoot['getCloseProps']>;
|
|
24
|
-
}
|
|
25
|
-
declare class ModalRoot extends Component<IModalProps> {
|
|
26
|
-
static displayName: string;
|
|
27
|
-
static style: {
|
|
28
|
-
[key: string]: string;
|
|
29
|
-
};
|
|
30
|
-
static defaultProps: {
|
|
31
|
-
duration: number;
|
|
32
|
-
closable: boolean;
|
|
33
|
-
};
|
|
34
|
-
handleKeyDown: (e: any) => void;
|
|
35
|
-
handleIconCloseClick: (e: any) => void;
|
|
36
|
-
handleOutsideClick: (e: any) => void;
|
|
37
|
-
getOverlayProps(): {
|
|
38
|
-
duration: number;
|
|
39
|
-
visible: boolean;
|
|
40
|
-
onOutsideClick: (e: any) => void;
|
|
41
|
-
};
|
|
42
|
-
getWindowProps(): {
|
|
43
|
-
visible: boolean;
|
|
44
|
-
closable: boolean;
|
|
45
|
-
onKeyDown: (e: any) => void;
|
|
46
|
-
};
|
|
47
|
-
getCloseProps(): {
|
|
48
|
-
onClick: (e: any) => void;
|
|
49
|
-
};
|
|
50
|
-
render(): JSX.Element;
|
|
51
|
-
}
|
|
52
|
-
declare const Modal: import("@semcore/core").ComponentType<Merge<IModalProps, React.HTMLAttributes<HTMLDivElement>>, {
|
|
53
|
-
Window: ComponentProps<typeof Box>;
|
|
54
|
-
Overlay: ComponentProps<typeof Box>;
|
|
55
|
-
Close: ComponentProps<typeof Box>;
|
|
56
|
-
}, IModalContext, {
|
|
57
|
-
[key: string]: (arg: unknown) => void;
|
|
58
|
-
}, null>;
|
|
59
|
-
export default Modal;
|