@citygross/components 0.16.25 → 0.16.26

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.
@@ -2,9 +2,10 @@ import React, { useId, useRef, useMemo, useEffect } from 'react';
2
2
  import { createPortal } from 'react-dom';
3
3
  import { theme } from '@citygross/design-tokens';
4
4
  import { Icons } from '@citygross/icons';
5
+ import { H2 } from '@citygross/typography';
5
6
  import { toggleInert, escapeKeyboardEventHandler } from '@citygross/utils';
6
7
  import { CgButton } from '../CgButton/CgButton.js';
7
- import { Overlay, Frame, Header, Title, Footer } from './Modal.styles.js';
8
+ import { Overlay, Frame, Header, Footer } from './Modal.styles.js';
8
9
  import { EButtonVariant } from '../CgButton/CgButton.types.js';
9
10
 
10
11
  var EModalSize;
@@ -26,8 +27,8 @@ var getPortalRoot = function (portalHostSelector) {
26
27
  return (_a = hostElement === null || hostElement === void 0 ? void 0 : hostElement.parentElement) !== null && _a !== void 0 ? _a : document.body;
27
28
  };
28
29
  var Modal = function (_a) {
29
- var _b, _c;
30
- var children = _a.children, inertSelectors = _a.inertSelectors, _d = _a.labelCancel, labelCancel = _d === void 0 ? 'Avbryt' : _d, _e = _a.labelCta, labelCta = _e === void 0 ? 'Okej' : _e, onClose = _a.onClose, onConfirm = _a.onConfirm, portalHostSelector = _a.portalHostSelector, _f = _a.size, size = _f === void 0 ? EModalSize.medium : _f, title = _a.title, variant = _a.variant;
30
+ var _b, _c, _d;
31
+ var children = _a.children, inertSelectors = _a.inertSelectors, _e = _a.labelCancel, labelCancel = _e === void 0 ? 'Avbryt' : _e, _f = _a.labelCta, labelCta = _f === void 0 ? 'Okej' : _f, _g = _a.noOverlay, noOverlay = _g === void 0 ? false : _g, onClose = _a.onClose, onConfirm = _a.onConfirm, portalHostSelector = _a.portalHostSelector, _h = _a.size, size = _h === void 0 ? EModalSize.medium : _h, title = _a.title, variant = _a.variant;
31
32
  var titleId = useId();
32
33
  var modalRef = useRef(null);
33
34
  var cancelButtonRef = useRef(null);
@@ -64,7 +65,7 @@ var Modal = function (_a) {
64
65
  (_b = modalRef.current) === null || _b === void 0 ? void 0 : _b.focus();
65
66
  });
66
67
  return function () {
67
- restoreInert === null || restoreInert === void 0 ? void 0 : restoreInert();
68
+ restoreInert();
68
69
  body.style.overflow = previousBodyOverflow;
69
70
  html.style.overflow = previousHtmlOverflow;
70
71
  document.removeEventListener('keydown', handleEscape);
@@ -75,12 +76,12 @@ var Modal = function (_a) {
75
76
  }, [inertSelectors, onClose, variant]);
76
77
  if (!portalRoot)
77
78
  return null;
78
- return createPortal(React.createElement(Overlay, { onClick: onClose },
79
+ return createPortal(React.createElement(Overlay, { noOverlay: noOverlay, onClick: onClose },
79
80
  React.createElement(Frame, { "aria-labelledby": titleId, "aria-modal": "true", onClick: function (event) { return event.stopPropagation(); }, ref: modalRef, role: variant === EModalVariant.destructive ? 'alertdialog' : 'dialog', size: size },
80
81
  React.createElement(Header, null,
81
- React.createElement(Title, { fontWeight: "semiBold", id: titleId }, title),
82
+ React.createElement(H2, { color: (_b = theme.palette) === null || _b === void 0 ? void 0 : _b.darkest, id: titleId }, title),
82
83
  variant !== EModalVariant.destructive && (React.createElement(CgButton, { "aria-label": labelCancel, circle: true, onClick: onClose, variant: EButtonVariant.ghost },
83
- React.createElement(Icons.Cross, { "aria-hidden": "true", height: (_b = theme.spacings) === null || _b === void 0 ? void 0 : _b.sm2, width: (_c = theme.spacings) === null || _c === void 0 ? void 0 : _c.sm2 })))),
84
+ React.createElement(Icons.Cross, { "aria-hidden": "true", height: (_c = theme.spacings) === null || _c === void 0 ? void 0 : _c.sm2, width: (_d = theme.spacings) === null || _d === void 0 ? void 0 : _d.sm2 })))),
84
85
  children,
85
86
  React.createElement(Footer, null,
86
87
  React.createElement(CgButton, { onClick: onConfirm, variant: EButtonVariant.primary }, labelCta),
@@ -1 +1 @@
1
- {"version":3,"file":"Modal.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"Modal.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,12 +1,11 @@
1
1
  import { __makeTemplateObject } from '../../../../_virtual/_tslib.js';
2
- import { BodyText } from '@citygross/typography';
3
2
  import styled from 'styled-components';
4
3
  import { EModalSize } from './Modal.js';
5
4
 
6
5
  var Overlay = styled.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n background: ", ";\n box-sizing: border-box;\n display: flex;\n align-items: center;\n justify-content: center;\n inset: 0;\n min-height: 100%;\n overflow-y: auto;\n padding: ", ";\n position: fixed;\n z-index: ", ";\n"], ["\n background: ", ";\n box-sizing: border-box;\n display: flex;\n align-items: center;\n justify-content: center;\n inset: 0;\n min-height: 100%;\n overflow-y: auto;\n padding: ", ";\n position: fixed;\n z-index: ", ";\n"])), function (_a) {
7
- var _b;
8
- var theme = _a.theme;
9
- return (_b = theme.palette) === null || _b === void 0 ? void 0 : _b.darkOverlay;
6
+ var _b, _c;
7
+ var theme = _a.theme, noOverlay = _a.noOverlay;
8
+ return noOverlay ? (_b = theme.palette) === null || _b === void 0 ? void 0 : _b.transparent : (_c = theme.palette) === null || _c === void 0 ? void 0 : _c.darkOverlay;
10
9
  }, function (_a) {
11
10
  var _b, _c, _d;
12
11
  var theme = _a.theme;
@@ -52,12 +51,7 @@ var Header = styled.div(templateObject_3 || (templateObject_3 = __makeTemplateOb
52
51
  var theme = _a.theme;
53
52
  return (_b = theme.spacings) === null || _b === void 0 ? void 0 : _b.sm;
54
53
  });
55
- var Title = styled(BodyText)(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n font-size: ", "px;\n"], ["\n font-size: ", "px;\n"])), function (_a) {
56
- var _b, _c;
57
- var theme = _a.theme;
58
- return (_c = (_b = theme.typography) === null || _b === void 0 ? void 0 : _b.size) === null || _c === void 0 ? void 0 : _c.s4;
59
- });
60
- var Footer = styled.div(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n display: flex;\n gap: ", "px;\n margin-top: ", "px;\n width: 100%;\n\n > * {\n flex: 1 1 0;\n min-width: 0;\n }\n"], ["\n display: flex;\n gap: ", "px;\n margin-top: ", "px;\n width: 100%;\n\n > * {\n flex: 1 1 0;\n min-width: 0;\n }\n"])), function (_a) {
54
+ var Footer = styled.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n display: flex;\n gap: ", "px;\n margin-top: ", "px;\n width: 100%;\n\n > * {\n flex: 1 1 0;\n min-width: 0;\n }\n"], ["\n display: flex;\n gap: ", "px;\n margin-top: ", "px;\n width: 100%;\n\n > * {\n flex: 1 1 0;\n min-width: 0;\n }\n"])), function (_a) {
61
55
  var _b;
62
56
  var theme = _a.theme;
63
57
  return (_b = theme.spacings) === null || _b === void 0 ? void 0 : _b.sm;
@@ -66,7 +60,7 @@ var Footer = styled.div(templateObject_5 || (templateObject_5 = __makeTemplateOb
66
60
  var theme = _a.theme;
67
61
  return (_b = theme.spacings) === null || _b === void 0 ? void 0 : _b.lg;
68
62
  });
69
- var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5;
63
+ var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
70
64
 
71
- export { Footer, Frame, Header, Overlay, Title };
65
+ export { Footer, Frame, Header, Overlay };
72
66
  //# sourceMappingURL=Modal.styles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Modal.styles.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"Modal.styles.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -528,31 +528,32 @@ var selectKeyboardEventHandler = function (_a) {
528
528
 
529
529
  var toggleInert = function (_a) {
530
530
  var elements = _a.elements, isInert = _a.isInert;
531
- var snapshots = elements
532
- .filter(function (element) { return Boolean(element); })
533
- .map(function (element) { return ({
531
+ var list = elements.filter(function (element) {
532
+ return Boolean(element);
533
+ });
534
+ if (!isInert) {
535
+ list.forEach(function (element) {
536
+ var hadInert = element.hasAttribute('inert');
537
+ if (!hadInert) {
538
+ element.removeAttribute('inert');
539
+ }
540
+ });
541
+ return function () { };
542
+ }
543
+ var snapshots = list.map(function (element) { return ({
534
544
  element: element,
535
- hadInert: element.hasAttribute('inert')
545
+ setByThisCall: !element.hasAttribute('inert')
536
546
  }); });
537
547
  snapshots.forEach(function (_a) {
538
- var element = _a.element, hadInert = _a.hadInert;
539
- if (isInert) {
540
- if (!hadInert) {
541
- element.setAttribute('inert', '');
542
- }
543
- return;
544
- }
545
- if (!hadInert) {
546
- element.removeAttribute('inert');
548
+ var element = _a.element, setByThisCall = _a.setByThisCall;
549
+ if (setByThisCall) {
550
+ element.setAttribute('inert', '');
547
551
  }
548
552
  });
549
553
  return function () {
550
554
  snapshots.forEach(function (_a) {
551
- var element = _a.element, hadInert = _a.hadInert;
552
- if (hadInert) {
553
- element.setAttribute('inert', '');
554
- }
555
- else {
555
+ var element = _a.element, setByThisCall = _a.setByThisCall;
556
+ if (setByThisCall) {
556
557
  element.removeAttribute('inert');
557
558
  }
558
559
  });