@cypress-design/react-modal 0.2.1 → 1.0.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/dist/index.umd.js CHANGED
@@ -7024,7 +7024,7 @@ function requireReactDom_development () {
7024
7024
  return a !== 0 && a < b ? a : b;
7025
7025
  }
7026
7026
  function lowerEventPriority(a, b) {
7027
- return a === 0 || a > b ? a : b;
7027
+ return a > b ? a : b;
7028
7028
  }
7029
7029
  function isHigherEventPriority(a, b) {
7030
7030
  return a !== 0 && a < b;
@@ -10145,7 +10145,7 @@ function requireReactDom_development () {
10145
10145
 
10146
10146
  var isCapturePhaseListener = false;
10147
10147
  var listenerSet = getEventListenerSet(targetElement);
10148
- var listenerSetKey = getListenerSetKey(domEventName, isCapturePhaseListener);
10148
+ var listenerSetKey = getListenerSetKey(domEventName);
10149
10149
 
10150
10150
  if (!listenerSet.has(listenerSetKey)) {
10151
10151
  addTrappedEventListener(targetElement, domEventName, IS_NON_DELEGATED, isCapturePhaseListener);
@@ -10542,7 +10542,7 @@ function requireReactDom_development () {
10542
10542
  }
10543
10543
  }
10544
10544
  function getListenerSetKey(domEventName, capture) {
10545
- return domEventName + "__" + (capture ? 'capture' : 'bubble');
10545
+ return domEventName + "__" + ('bubble');
10546
10546
  }
10547
10547
 
10548
10548
  var didWarnInvalidHydration = false;
@@ -30971,7 +30971,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
30971
30971
  };
30972
30972
 
30973
30973
  var compileReactIconProperties = function (_a) {
30974
- var body = _a.body, defs = _a.defs, compiledClasses = _a.compiledClasses, size = _a.size, name = _a.name, attributes = __rest(_a, ["body", "defs", "compiledClasses", "size", "name"]);
30974
+ var body = _a.body, defs = _a.defs, compiledClasses = _a.compiledClasses, size = _a.size, name = _a.name, alt = _a.alt, attributes = __rest(_a, ["body", "defs", "compiledClasses", "size", "name", "alt"]);
30975
30975
  var filteredAttributes = Object.keys(attributes).reduce(function (newAttributes, attrName) {
30976
30976
  if (!iconsRegistry.ICON_COLOR_PROP_NAMES.includes(attrName) &&
30977
30977
  attrName !== 'name') {
@@ -30982,6 +30982,7 @@ var compileReactIconProperties = function (_a) {
30982
30982
  }
30983
30983
  return newAttributes;
30984
30984
  }, {});
30985
+ // eslint-disable-next-line react-hooks/rules-of-hooks
30985
30986
  React__namespace.useEffect(function () {
30986
30987
  var iconFileId = "".concat(name, "_").concat(size);
30987
30988
  if (defs) {
@@ -30995,9 +30996,13 @@ var compileReactIconProperties = function (_a) {
30995
30996
  svgElement.innerHTML = defs;
30996
30997
  document.body.appendChild(svgElement);
30997
30998
  }
30998
- }, [defs]);
30999
+ }, [defs, name, size]);
30999
31000
  var componentProps = __assign({ width: size, height: size, viewBox: "0 0 ".concat(size, " ").concat(size), fill: 'none', dangerouslySetInnerHTML: {
31000
- __html: body,
31001
+ __html: alt
31002
+ ? "<title>".concat(alt.replace(/[><]/g, function (s) {
31003
+ return s === '>' ? '&gt;' : '&lt;';
31004
+ }), "</title>").concat(body)
31005
+ : body,
31001
31006
  }, className: undefined }, filteredAttributes);
31002
31007
  if (attributes.className) {
31003
31008
  compiledClasses.push(attributes.className);
@@ -31019,12 +31024,12 @@ function useIconProps(props, iconBodiesAndDefs, availableSizes, name) {
31019
31024
  }
31020
31025
  var IconActionDelete = function (props) { return React__namespace.createElement('svg', useIconProps(props, {
31021
31026
  "12": {
31022
- "body": "<path stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M1 11 11 1M1 1l10 10\" class=\"icon-dark\"/>"
31027
+ "body": "<path d=\"M1 11 11 1M1 1l10 10\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" class=\"icon-dark\"/>"
31023
31028
  }
31024
31029
  }, ["12"], "action-delete")); };
31025
31030
  var IconActionQuestionMarkCircle = function (props) { return React__namespace.createElement('svg', useIconProps(props, {
31026
31031
  "16": {
31027
- "body": "<path fill=\"#D0D2E0\" d=\"M13.657 13.657A8 8 0 1 1 2.343 2.343a8 8 0 0 1 11.314 11.314Z\" class=\"icon-light\"/><path fill=\"currentColor\" fill-rule=\"evenodd\" d=\"m1.845 2.535-.001.001A1 1 0 0 1 .146 1.48L1 2c-.854-.52-.854-.52-.853-.521v-.001l.001-.002.003-.004.005-.009.015-.023.042-.061A3.315 3.315 0 0 1 .87.707 3.452 3.452 0 0 1 3 0c1.099 0 1.911.432 2.414 1.113C5.879 1.743 6 2.478 6 3c0 .63-.173 1.147-.463 1.574-.272.402-.62.68-.871.873-.608.465-.655.516-.673.67a1 1 0 0 1-1.986-.234c.125-1.061.915-1.638 1.327-1.938l.117-.087c.229-.175.352-.29.43-.405C3.944 3.363 4 3.237 4 3c0-.259-.067-.525-.195-.7C3.714 2.179 3.526 2 3 2c-.437 0-.729.152-.913.294a1.316 1.316 0 0 0-.242.241ZM3 10a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z\" class=\"icon-dark\" clip-rule=\"evenodd\" style=\"transform:translate(5px,2.8px)\"/>"
31032
+ "body": "<path d=\"M13.657 13.657A8 8 0 1 1 2.343 2.343a8 8 0 0 1 11.314 11.314Z\" fill=\"#D0D2E0\" class=\"icon-light\"/><path fill-rule=\"evenodd\" style=\"transform:translate(5px,2.8px)\" clip-rule=\"evenodd\" d=\"m1.845 2.535-.001.001A1 1 0 0 1 .146 1.48L1 2c-.854-.52-.854-.52-.853-.521v-.001l.001-.002.003-.004.005-.009.015-.023.042-.061A3.315 3.315 0 0 1 .87.707 3.452 3.452 0 0 1 3 0c1.099 0 1.911.432 2.414 1.113C5.879 1.743 6 2.478 6 3c0 .63-.173 1.147-.463 1.574-.272.402-.62.68-.871.873-.608.465-.655.516-.673.67a1 1 0 0 1-1.986-.234c.125-1.061.915-1.638 1.327-1.938l.117-.087c.229-.175.352-.29.43-.405C3.944 3.363 4 3.237 4 3c0-.259-.067-.525-.195-.7C3.714 2.179 3.526 2 3 2c-.437 0-.729.152-.913.294a1.316 1.316 0 0 0-.242.241ZM3 10a1 1 0 1 0 0-2 1 1 0 0 0 0 2Z\" fill=\"currentColor\" class=\"icon-dark\"/>"
31028
31033
  }
31029
31034
  }, ["16"], "action-question-mark-circle")); };
31030
31035
 
@@ -31051,9 +31056,7 @@ function freeBodyScroll() {
31051
31056
  window.scrollTo({ top: scrollY });
31052
31057
  }
31053
31058
 
31054
- const ClassBackDrop = 'fixed left-0 top-0 z-[1000010] h-screen w-screen bg-gray-900/[.80] backdrop-blur-sm';
31055
- const ClassModalContainer = 'pointer-events-none fixed left-0 top-0 z-[1000020] h-full w-screen overflow-hidden flex items-center justify-center';
31056
- const ClassModal = 'pointer-events-auto relative flex flex-col rounded outline outline-4 outline-gray-500/[.40] bg-white';
31059
+ const ClassModal = 'pointer-events-auto fixed flex flex-col rounded outline outline-4 outline-gray-500/[.40] bg-white backdrop:bg-gray-900/[.80] backdrop:backdrop-blur-sm';
31057
31060
  const ClassModalStandardDimensions = 'max-h-[80vh] min-w-[200px] sm:min-w-[390px] max-w-[calc(100vw-32px)] sm:max-w-[70vw] shrink-0';
31058
31061
  const ClassModalFullscreenDimensions = 'h-[calc(100vh-32px)] sm:w-[calc(100vw-32px)]';
31059
31062
  const ClassTitleBox = 'flex shrink-0 items-center justify-between rounded-t-md border-b border-gray-100 p-[16px] px-16px sm:px-[24px]';
@@ -31065,37 +31068,51 @@ const ClassContent = 'overflow-y-auto p-[16px] sm:px-[24px]';
31065
31068
 
31066
31069
  var Modal = function (_a) {
31067
31070
  var _b = _a.show, show = _b === void 0 ? false : _b, title = _a.title, helpLink = _a.helpLink, onClose = _a.onClose, children = _a.children, _c = _a.fullscreen, fullscreen = _c === void 0 ? false : _c;
31071
+ var dialogRef = React__namespace.useRef(null);
31068
31072
  React__namespace.useEffect(function () {
31073
+ var _a, _b;
31069
31074
  if (show) {
31070
31075
  disableBodyScroll();
31076
+ (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.showModal();
31071
31077
  }
31072
31078
  else {
31079
+ (_b = dialogRef.current) === null || _b === void 0 ? void 0 : _b.close();
31073
31080
  freeBodyScroll();
31074
31081
  }
31075
- }, [show]);
31082
+ }, [show, onClose]);
31076
31083
  React__namespace.useEffect(function () { return function () {
31077
31084
  freeBodyScroll();
31078
31085
  }; }, []);
31086
+ var closeOnClickBackdrop = React__namespace.useCallback(function (event) {
31087
+ var _a;
31088
+ var rect = (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
31089
+ if (!rect)
31090
+ return;
31091
+ var isInDialog = rect.top <= event.clientY &&
31092
+ event.clientY <= rect.top + rect.height &&
31093
+ rect.left <= event.clientX &&
31094
+ event.clientX <= rect.left + rect.width;
31095
+ if (!isInDialog) {
31096
+ onClose === null || onClose === void 0 ? void 0 : onClose();
31097
+ }
31098
+ }, [onClose]);
31079
31099
  return (show &&
31080
- reactDomExports.createPortal(React__namespace.createElement("div", null,
31081
- React__namespace.createElement("div", { className: ClassBackDrop, onClick: function () { return onClose === null || onClose === void 0 ? void 0 : onClose(); } }),
31082
- React__namespace.createElement("div", { className: ClassModalContainer, tabIndex: -1, "aria-modal": "true", "aria-labelledby": "cy_modal_label", role: "dialog" },
31083
- React__namespace.createElement("div", { className: clsx(ClassModal, fullscreen
31084
- ? ClassModalFullscreenDimensions
31085
- : ClassModalStandardDimensions) },
31086
- React__namespace.createElement("div", { className: ClassTitleBox },
31087
- React__namespace.createElement("div", { id: "cy_modal_label", className: ClassTitle }, title),
31088
- helpLink ? React__namespace.createElement("div", { className: ClassHelpLinkDash }) : null,
31089
- helpLink ? (React__namespace.createElement("a", { href: helpLink, className: ClassHelpLink },
31090
- "Need help",
31091
- React__namespace.createElement(IconActionQuestionMarkCircle, { className: "ml-[4px]", "stroke-color": "indigo-500", "fill-color": "indigo-100" }))) : null,
31092
- React__namespace.createElement("div", { className: "grow" }),
31093
- React__namespace.createElement("button", { "aria-label": "Close", className: ClassCloseButton, onClick: function () { return onClose === null || onClose === void 0 ? void 0 : onClose(); } },
31094
- React__namespace.createElement(IconActionDelete, { className: "children:transition-all", "stroke-color": "gray-400", "hover-stroke-color": "gray-700", interactiveColorsOnGroup: true }))),
31095
- React__namespace.createElement("div", { className: ClassContent }, children)))), document.body));
31100
+ reactDomExports.createPortal(React__namespace.createElement("dialog", { ref: dialogRef, className: clsx(show ? ClassModal : null, fullscreen
31101
+ ? ClassModalFullscreenDimensions
31102
+ : ClassModalStandardDimensions), onClick: closeOnClickBackdrop },
31103
+ React__namespace.createElement("div", { className: ClassTitleBox },
31104
+ React__namespace.createElement("div", { id: "cy_modal_label", className: ClassTitle }, title),
31105
+ helpLink ? React__namespace.createElement("div", { className: ClassHelpLinkDash }) : null,
31106
+ helpLink ? (React__namespace.createElement("a", { href: helpLink, className: ClassHelpLink },
31107
+ "Need help",
31108
+ React__namespace.createElement(IconActionQuestionMarkCircle, { className: "ml-[4px]", "stroke-color": "indigo-500", "fill-color": "indigo-100" }))) : null,
31109
+ React__namespace.createElement("div", { className: "grow" }),
31110
+ React__namespace.createElement("button", { "aria-label": "Close", className: ClassCloseButton, onClick: function () { return onClose === null || onClose === void 0 ? void 0 : onClose(); } },
31111
+ React__namespace.createElement(IconActionDelete, { className: "children:transition-all", "stroke-color": "gray-400", "hover-stroke-color": "gray-700", interactiveColorsOnGroup: true }))),
31112
+ React__namespace.createElement("div", { className: ClassContent }, children)), document.body));
31096
31113
  };
31097
31114
 
31098
31115
  module.exports = Modal;
31099
31116
  //# sourceMappingURL=index.umd.js.map
31100
31117
 
31101
- /* <wind-keep class="ml-[4px] grow children:transition-all fixed left-0 top-0 z-[1000010] h-screen w-screen bg-gray-900/[.80] backdrop-blur-sm pointer-events-none z-[1000020] h-full overflow-hidden flex items-center justify-center pointer-events-auto relative flex-col rounded outline outline-4 outline-gray-500/[.40] bg-white max-h-[80vh] min-w-[200px] sm:min-w-[390px] max-w-[calc(100vw-32px)] sm:max-w-[70vw] shrink-0 h-[calc(100vh-32px)] sm:w-[calc(100vw-32px)] justify-between rounded-t-md border-b border-gray-100 p-[16px] sm:px-[24px] text-[18px] font-medium leading-[28px] text-gray-900 mx-[8px] h-[1px] w-[32px] bg-gray-100 text-[16px] font-normal leading-[24px] text-indigo-500 rounded-full border-transparent p-[4px] outline-none overflow-y-auto cy-modal-overflow-hidden cy-modal-overflow-scroll-x cy-modal-overflow-scroll-y"> */
31118
+ /* <wind-keep class="ml-[4px] grow pointer-events-auto fixed flex flex-col rounded outline outline-4 outline-gray-500/[.40] bg-white backdrop:bg-gray-900/[.80] backdrop:backdrop-blur-sm max-h-[80vh] min-w-[200px] sm:min-w-[390px] max-w-[calc(100vw-32px)] sm:max-w-[70vw] shrink-0 h-[calc(100vh-32px)] sm:w-[calc(100vw-32px)] items-center justify-between rounded-t-md border-b border-gray-100 p-[16px] sm:px-[24px] text-[18px] font-medium leading-[28px] text-gray-900 mx-[8px] h-[1px] w-[32px] bg-gray-100 text-[16px] font-normal leading-[24px] text-indigo-500 rounded-full border-transparent p-[4px] outline-none overflow-y-auto cy-modal-overflow-hidden cy-modal-overflow-scroll-x cy-modal-overflow-scroll-y"> */