@justeattakeaway/pie-modal 0.9.0 → 0.11.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.
@@ -1,14 +1,14 @@
1
- [13:51:16] @custom-elements-manifest/analyzer: Created new manifest.
1
+ [5:08:22 PM] @custom-elements-manifest/analyzer: Created new manifest.
2
2
  react wrapper has been added!
3
3
  vite v4.3.9 building for production...
4
4
  transforming...
5
- ✓ 23 modules transformed.
5
+ ✓ 25 modules transformed.
6
6
  rendering chunks...
7
7
  computing gzip size...
8
- dist/index.js 12.03 kB │ gzip: 3.79 kB
8
+ dist/index.js 13.38 kB │ gzip: 4.21 kB
9
9
  dist/react.js 59.04 kB │ gzip: 15.92 kB
10
-
11
- [vite:dts] Start generate declaration files...
12
- ✓ built in 4.35s
13
- [vite:dts] Declaration files built in 3800ms.
14
-
10
+ 
11
+ [vite:dts] Start generate declaration files...
12
+ ✓ built in 10.29s
13
+ [vite:dts] Declaration files built in 9310ms.
14
+ 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @justeattakeaway/pie-modal
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [Changed] - Ensure component implements it's props interface ([#611](https://github.com/justeattakeaway/pie/pull/611)) by [@jamieomaguire](https://github.com/jamieomaguire)
8
+
9
+ - [Fixed] - Added IconClose to Visual tests and modal ([#604](https://github.com/justeattakeaway/pie/pull/604)) by [@ashleynolan](https://github.com/ashleynolan)
10
+
11
+ ## 0.10.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [Added] - Add returnFocusAfterCloseSelector prop ([#599](https://github.com/justeattakeaway/pie/pull/599)) by [@xander-marjoram](https://github.com/xander-marjoram)
16
+
17
+ [Changed] - Extract `renderTestPieModal` into test helper file so it can be used for component tests too
18
+ [Added] - Add README documentation for new props
19
+
20
+ - [Fixed] - Fix console errors when switching between stories ([#599](https://github.com/justeattakeaway/pie/pull/599)) by [@xander-marjoram](https://github.com/xander-marjoram)
21
+
22
+ - [Added] - New `isFullWidthBelowMid` prop for pie-modal ([#600](https://github.com/justeattakeaway/pie/pull/600)) by [@LTurns](https://github.com/LTurns)
23
+
24
+ - [Added] isDismissible prop and tests ([#588](https://github.com/justeattakeaway/pie/pull/588)) by [@kevinrodrigues](https://github.com/kevinrodrigues)
25
+
3
26
  ## 0.9.0
4
27
 
5
28
  ### Minor Changes
package/README.md CHANGED
@@ -14,6 +14,7 @@
14
14
  2. [Local Development](#local-development)
15
15
  3. [Importing the component](#importing-the-component)
16
16
  4. [Props](#props)
17
+ 5. [Testing](#testing)
17
18
 
18
19
  # pie-modal
19
20
 
@@ -56,12 +57,19 @@ import { PieModal } from '@justeattakeaway/pie-modal/dist/react';
56
57
 
57
58
  ## Props
58
59
 
59
- | Property | Type | Default | Description |
60
- |----------------|-----------|---------|-------------------------------------------------------|
61
- | isOpen | `Boolean` | `false` | Controls if the modal element is open or closed |
62
- | heading* | `String` | - | Sets the heading of the modal |
63
- | headingLevel | `String` | `h2` | Allows you to set the heading tag (from `h1` to `h6`) |
64
-
60
+ | Property | Type | Default | Description |
61
+ |---|---|---|---|
62
+ | headingLevel | `String` | `h2` | |
63
+
64
+ | Property | Type | Default | Description |
65
+ |---|---|---|---|
66
+ | heading | `String` | n/a (Required) | The heading text of the modal |
67
+ | headingLevel | `String` | `h2` | The HTML tag to use for the modal's heading (can be `h1`-`h6`) |
68
+ | isDismissible | `Boolean` | `false` | If true, the modal includes a close button and can be dismissed by clicking on the backdrop or pressing the Esc key |
69
+ | isFullWidthBelowMid | `Boolean` | `false` | If true and the page is narrower than the mid breakpoint, a **medium-sized** modal will take up the full width of the screen. |
70
+ | isOpen | `Boolean` | `false` | Controls if the modal element is open or closed |
71
+ | size | `String` | `medium` | Determines the maximum width of the modal. Large modals will expand to fill the entire page width at narrow viewports. Can be `small`, `medium` or `large`. |
72
+ | returnFocusAfterCloseSelector | `String` | `undefined` | If provided, focus will be sent to the first element that matches this selector when the modal is closed. If not provided, the `dialog` element will return focus to the element that opened the modal. |
65
73
 
66
74
  In your markup or JSX, you can then use these to set the properties for the `pie-modal` component:
67
75
 
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
- import { unsafeCSS as C, LitElement as x } from "lit";
2
- import { unsafeStatic as E, html as L } from "lit/static-html.js";
3
- import { property as y, query as T } from "lit/decorators.js";
4
- import { property as $ } from "lit/decorators/property.js";
5
- var D = Object.defineProperty, B = Object.getOwnPropertyDescriptor, k = (i, e, t, n) => {
6
- for (var o = n > 1 ? void 0 : n ? B(e, t) : e, d = i.length - 1, a; d >= 0; d--)
7
- (a = i[d]) && (o = (n ? a(e, t, o) : a(o)) || o);
8
- return n && o && D(e, t, o), o;
1
+ import { nothing as x, unsafeCSS as D, LitElement as B } from "lit";
2
+ import { unsafeStatic as E, html as z } from "lit/static-html.js";
3
+ import { property as u, query as L } from "lit/decorators.js";
4
+ import { property as T } from "lit/decorators/property.js";
5
+ var $ = Object.defineProperty, F = Object.getOwnPropertyDescriptor, A = (n, e, t, o) => {
6
+ for (var i = o > 1 ? void 0 : o ? F(e, t) : e, d = n.length - 1, l; d >= 0; d--)
7
+ (l = n[d]) && (i = (o ? l(e, t, i) : l(i)) || i);
8
+ return o && i && $(e, t, i), i;
9
9
  };
10
- const R = (i) => {
11
- class e extends i {
10
+ const k = (n) => {
11
+ class e extends n {
12
12
  constructor() {
13
13
  super(...arguments), this.dir = "";
14
14
  }
@@ -22,168 +22,173 @@ const R = (i) => {
22
22
  * will not be reactive and is only computed once
23
23
  */
24
24
  get isRTL() {
25
- var n;
26
- return this.dir === "ltr" ? !1 : this.dir === "rtl" || ((n = window == null ? void 0 : window.getComputedStyle(this)) == null ? void 0 : n.direction) === "rtl";
25
+ var o;
26
+ return this.dir === "ltr" ? !1 : this.dir === "rtl" || ((o = window == null ? void 0 : window.getComputedStyle(this)) == null ? void 0 : o.direction) === "rtl";
27
27
  }
28
28
  }
29
- return k([
30
- $({ type: String })
29
+ return A([
30
+ T({ type: String })
31
31
  ], e.prototype, "dir", 2), e;
32
- }, S = (i, e, t) => function(o, d) {
33
- const a = `#${d}`;
34
- Object.defineProperty(o, d, {
32
+ }, C = (n, e, t) => function(i, d) {
33
+ const l = `#${d}`;
34
+ Object.defineProperty(i, d, {
35
35
  get() {
36
- return this[a];
36
+ return this[l];
37
37
  },
38
- set(f) {
39
- const m = this[a];
40
- e.includes(f) ? this[a] = f : (console.error(
41
- `<${i}> Invalid value "${f}" provided for property "${d}".`,
38
+ set(m) {
39
+ const p = this[l];
40
+ e.includes(m) ? this[l] = m : (console.error(
41
+ `<${n}> Invalid value "${m}" provided for property "${d}".`,
42
42
  `Must be one of: ${e.join(" | ")}.`,
43
43
  `Falling back to default value: "${t}"`
44
- ), this[a] = t), this.requestUpdate(d, m);
44
+ ), this[l] = t), this.requestUpdate(d, p);
45
45
  }
46
46
  });
47
- }, A = (i) => function(t, n) {
48
- const o = `#${n}`;
49
- Object.defineProperty(t, n, {
47
+ }, R = (n) => function(t, o) {
48
+ const i = `#${o}`;
49
+ Object.defineProperty(t, o, {
50
50
  get() {
51
- return this[o];
51
+ return this[i];
52
52
  },
53
53
  set(d) {
54
- const a = this[o];
55
- (d == null || typeof d == "string" && d.trim() === "") && console.error(`<${i}> Missing required attribute "${n}"`), this[o] = d, this.requestUpdate(n, a);
54
+ const l = this[i];
55
+ (d == null || typeof d == "string" && d.trim() === "") && console.error(`<${n}> Missing required attribute "${o}"`), this[i] = d, this.requestUpdate(o, l);
56
56
  }
57
57
  });
58
58
  };
59
- function q(i) {
60
- if (Array.isArray(i)) {
61
- for (var e = 0, t = Array(i.length); e < i.length; e++)
62
- t[e] = i[e];
59
+ function q(n) {
60
+ if (Array.isArray(n)) {
61
+ for (var e = 0, t = Array(n.length); e < n.length; e++)
62
+ t[e] = n[e];
63
63
  return t;
64
64
  } else
65
- return Array.from(i);
65
+ return Array.from(n);
66
66
  }
67
- var _ = !1;
67
+ var O = !1;
68
68
  if (typeof window < "u") {
69
- var z = {
69
+ var S = {
70
70
  get passive() {
71
- _ = !0;
71
+ O = !0;
72
72
  }
73
73
  };
74
- window.addEventListener("testPassive", null, z), window.removeEventListener("testPassive", null, z);
74
+ window.addEventListener("testPassive", null, S), window.removeEventListener("testPassive", null, S);
75
75
  }
76
- var p = typeof window < "u" && window.navigator && window.navigator.platform && (/iP(ad|hone|od)/.test(window.navigator.platform) || window.navigator.platform === "MacIntel" && window.navigator.maxTouchPoints > 1), r = [], v = !1, P = -1, c = void 0, l = void 0, u = void 0, M = function(e) {
77
- return r.some(function(t) {
76
+ var g = typeof window < "u" && window.navigator && window.navigator.platform && (/iP(ad|hone|od)/.test(window.navigator.platform) || window.navigator.platform === "MacIntel" && window.navigator.maxTouchPoints > 1), c = [], y = !1, P = -1, h = void 0, r = void 0, f = void 0, M = function(e) {
77
+ return c.some(function(t) {
78
78
  return !!(t.options.allowTouchMove && t.options.allowTouchMove(e));
79
79
  });
80
- }, g = function(e) {
80
+ }, b = function(e) {
81
81
  var t = e || window.event;
82
82
  return M(t.target) || t.touches.length > 1 ? !0 : (t.preventDefault && t.preventDefault(), !1);
83
83
  }, I = function(e) {
84
- if (u === void 0) {
85
- var t = !!e && e.reserveScrollBarGap === !0, n = window.innerWidth - document.documentElement.clientWidth;
86
- if (t && n > 0) {
87
- var o = parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right"), 10);
88
- u = document.body.style.paddingRight, document.body.style.paddingRight = o + n + "px";
84
+ if (f === void 0) {
85
+ var t = !!e && e.reserveScrollBarGap === !0, o = window.innerWidth - document.documentElement.clientWidth;
86
+ if (t && o > 0) {
87
+ var i = parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right"), 10);
88
+ f = document.body.style.paddingRight, document.body.style.paddingRight = i + o + "px";
89
89
  }
90
90
  }
91
- c === void 0 && (c = document.body.style.overflow, document.body.style.overflow = "hidden");
91
+ h === void 0 && (h = document.body.style.overflow, document.body.style.overflow = "hidden");
92
92
  }, V = function() {
93
- u !== void 0 && (document.body.style.paddingRight = u, u = void 0), c !== void 0 && (document.body.style.overflow = c, c = void 0);
93
+ f !== void 0 && (document.body.style.paddingRight = f, f = void 0), h !== void 0 && (document.body.style.overflow = h, h = void 0);
94
94
  }, j = function() {
95
95
  return window.requestAnimationFrame(function() {
96
- if (l === void 0) {
97
- l = {
96
+ if (r === void 0) {
97
+ r = {
98
98
  position: document.body.style.position,
99
99
  top: document.body.style.top,
100
100
  left: document.body.style.left
101
101
  };
102
- var e = window, t = e.scrollY, n = e.scrollX, o = e.innerHeight;
103
- document.body.style.position = "fixed", document.body.style.top = -t, document.body.style.left = -n, setTimeout(function() {
102
+ var e = window, t = e.scrollY, o = e.scrollX, i = e.innerHeight;
103
+ document.body.style.position = "fixed", document.body.style.top = -t, document.body.style.left = -o, setTimeout(function() {
104
104
  return window.requestAnimationFrame(function() {
105
- var d = o - window.innerHeight;
106
- d && t >= o && (document.body.style.top = -(t + d));
105
+ var d = i - window.innerHeight;
106
+ d && t >= i && (document.body.style.top = -(t + d));
107
107
  });
108
108
  }, 300);
109
109
  }
110
110
  });
111
- }, F = function() {
112
- if (l !== void 0) {
111
+ }, H = function() {
112
+ if (r !== void 0) {
113
113
  var e = -parseInt(document.body.style.top, 10), t = -parseInt(document.body.style.left, 10);
114
- document.body.style.position = l.position, document.body.style.top = l.top, document.body.style.left = l.left, window.scrollTo(t, e), l = void 0;
114
+ document.body.style.position = r.position, document.body.style.top = r.top, document.body.style.left = r.left, window.scrollTo(t, e), r = void 0;
115
115
  }
116
- }, H = function(e) {
116
+ }, W = function(e) {
117
117
  return e ? e.scrollHeight - e.scrollTop <= e.clientHeight : !1;
118
118
  }, N = function(e, t) {
119
- var n = e.targetTouches[0].clientY - P;
120
- return M(e.target) ? !1 : t && t.scrollTop === 0 && n > 0 || H(t) && n < 0 ? g(e) : (e.stopPropagation(), !0);
119
+ var o = e.targetTouches[0].clientY - P;
120
+ return M(e.target) ? !1 : t && t.scrollTop === 0 && o > 0 || W(t) && o < 0 ? b(e) : (e.stopPropagation(), !0);
121
121
  }, Y = function(e, t) {
122
122
  if (!e) {
123
123
  console.error("disableBodyScroll unsuccessful - targetElement must be provided when calling disableBodyScroll on IOS devices.");
124
124
  return;
125
125
  }
126
- if (!r.some(function(o) {
127
- return o.targetElement === e;
126
+ if (!c.some(function(i) {
127
+ return i.targetElement === e;
128
128
  })) {
129
- var n = {
129
+ var o = {
130
130
  targetElement: e,
131
131
  options: t || {}
132
132
  };
133
- r = [].concat(q(r), [n]), p ? j() : I(t), p && (e.ontouchstart = function(o) {
134
- o.targetTouches.length === 1 && (P = o.targetTouches[0].clientY);
135
- }, e.ontouchmove = function(o) {
136
- o.targetTouches.length === 1 && N(o, e);
137
- }, v || (document.addEventListener("touchmove", g, _ ? { passive: !1 } : void 0), v = !0));
133
+ c = [].concat(q(c), [o]), g ? j() : I(t), g && (e.ontouchstart = function(i) {
134
+ i.targetTouches.length === 1 && (P = i.targetTouches[0].clientY);
135
+ }, e.ontouchmove = function(i) {
136
+ i.targetTouches.length === 1 && N(i, e);
137
+ }, y || (document.addEventListener("touchmove", b, O ? { passive: !1 } : void 0), y = !0));
138
138
  }
139
139
  }, U = function(e) {
140
140
  if (!e) {
141
141
  console.error("enableBodyScroll unsuccessful - targetElement must be provided when calling enableBodyScroll on IOS devices.");
142
142
  return;
143
143
  }
144
- r = r.filter(function(t) {
144
+ c = c.filter(function(t) {
145
145
  return t.targetElement !== e;
146
- }), p && (e.ontouchstart = null, e.ontouchmove = null, v && r.length === 0 && (document.removeEventListener("touchmove", g, _ ? { passive: !1 } : void 0), v = !1)), p ? F() : V();
146
+ }), g && (e.ontouchstart = null, e.ontouchmove = null, y && c.length === 0 && (document.removeEventListener("touchmove", b, O ? { passive: !1 } : void 0), y = !1)), g ? H() : V();
147
147
  };
148
- const X = `.c-modal{--modal-size-s: 450px;--modal-size-m: 600px;--modal-size-l: 1080px;--modal-border-radius: var(--dt-radius-rounded-d);--modal-font: var(--dt-font-interactive-m-family);--modal-bg-color: var(--dt-color-container-default);--modal-elevation: var(--dt-elevation-04);border-radius:var(--modal-border-radius);border:none;box-shadow:var(--modal-elevation);font-family:var(--modal-font);background-color:var(--modal-bg-color);padding:0;--modal-max-inline-size: var(--modal-size-m);--modal-inline-size: 75%;max-inline-size:var(--modal-max-inline-size);inline-size:var(--modal-inline-size)}.c-modal[size=small]{--modal-max-inline-size: var(--modal-size-s)}.c-modal[size=large]{--modal-max-inline-size: var(--modal-size-l);--modal-inline-size: 100%}@media (min-width: 768px){.c-modal[size=large]{--modal-inline-size: 75%}}.c-modal::backdrop{background:rgba(0,0,0,.5)}.c-modal .c-modal-heading{--modal-header-font-size: calc(var(--dt-font-heading-m-size--wide) * 1px);--modal-header-font-line-height: calc(var(--dt-font-heading-m-line-height--wide) * 1px);--modal-header-font-weight: var(--dt-font-heading-m-weight);--modal-header-padding: var(--dt-spacing-e);--modal-header-padding-block-end: var(--dt-spacing-d);font-size:var(--modal-header-font-size);line-height:var(--modal-header-font-line-height);font-weight:var(--modal-header-font-weight);margin:0;padding-block:var(--modal-header-padding) var(--modal-header-padding-block-end);padding-inline:var(--modal-header-padding)}.c-modal .c-modal-content{--modal-content-font-size: calc(var(--dt-font-size-16) * 1px);--modal-content-font-weight: var(--dt-font-weight-regular);--modal-content-line-height: calc(var(--dt-font-size-16-line-height) * 1px);--modal-content-padding: var(--dt-spacing-e);--modal-content-padding-block-start: var(--dt-spacing-a);font-size:var(--modal-content-font-size);line-height:var(--modal-content-line-height);font-weight:var(--modal-content-font-weight);padding-block:var(--modal-content-padding-block-start) var(--modal-content-padding);padding-inline:var(--modal-content-padding);overflow-y:scroll;max-block-size:300px}.c-modal .c-modal-closeBtn{position:absolute;inset-inline-end:var(--dt-spacing-d);inset-block-start:var(--dt-spacing-d)}
149
- `, W = ["h1", "h2", "h3", "h4", "h5", "h6"], G = ["small", "medium", "large"], w = "pie-modal-close", O = "pie-modal-open";
150
- var J = Object.defineProperty, Q = Object.getOwnPropertyDescriptor, h = (i, e, t, n) => {
151
- for (var o = n > 1 ? void 0 : n ? Q(e, t) : e, d = i.length - 1, a; d >= 0; d--)
152
- (a = i[d]) && (o = (n ? a(e, t, o) : a(o)) || o);
153
- return n && o && J(e, t, o), o;
148
+ const X = `.c-modal{--modal-size-s: 450px;--modal-size-m: 600px;--modal-size-l: 1080px;--modal-border-radius: var(--dt-radius-rounded-d);--modal-font: var(--dt-font-interactive-m-family);--modal-bg-color: var(--dt-color-container-default);--modal-elevation: var(--dt-elevation-04);border-radius:var(--modal-border-radius);border:none;box-shadow:var(--modal-elevation);font-family:var(--modal-font);background-color:var(--modal-bg-color);padding:0;--modal-max-inline-size: var(--modal-size-m);--modal-inline-size: 75%;max-inline-size:var(--modal-max-inline-size);inline-size:var(--modal-inline-size)}.c-modal[size=small]{--modal-max-inline-size: var(--modal-size-s)}@media (max-width: 768px){.c-modal[size=medium][isfullwidthbelowmid]{--modal-inline-size: 100%}}.c-modal[size=large]{--modal-max-inline-size: var(--modal-size-l);--modal-inline-size: 100%}@media (min-width: 768px){.c-modal[size=large]{--modal-inline-size: 75%}}.c-modal::backdrop{background:rgba(0,0,0,.5)}.c-modal .c-modal-heading{--modal-header-font-size: calc(var(--dt-font-heading-m-size--wide) * 1px);--modal-header-font-line-height: calc(var(--dt-font-heading-m-line-height--wide) * 1px);--modal-header-font-weight: var(--dt-font-heading-m-weight);--modal-header-padding: var(--dt-spacing-e);--modal-header-padding-block-end: var(--dt-spacing-d);font-size:var(--modal-header-font-size);line-height:var(--modal-header-font-line-height);font-weight:var(--modal-header-font-weight);margin:0;padding-block:var(--modal-header-padding) var(--modal-header-padding-block-end);padding-inline:var(--modal-header-padding)}.c-modal .c-modal-content{--modal-content-font-size: calc(var(--dt-font-size-16) * 1px);--modal-content-font-weight: var(--dt-font-weight-regular);--modal-content-line-height: calc(var(--dt-font-size-16-line-height) * 1px);--modal-content-padding: var(--dt-spacing-e);--modal-content-padding-block-start: var(--dt-spacing-a);font-size:var(--modal-content-font-size);line-height:var(--modal-content-line-height);font-weight:var(--modal-content-font-weight);padding-block:var(--modal-content-padding-block-start) var(--modal-content-padding);padding-inline:var(--modal-content-padding);overflow-y:scroll;max-block-size:300px}.c-modal .c-modal-closeBtn{position:absolute;inset-inline-end:var(--dt-spacing-d);inset-block-start:var(--dt-spacing-d)}
149
+ `, G = ["h1", "h2", "h3", "h4", "h5", "h6"], J = ["small", "medium", "large"], _ = "pie-modal-close", v = "pie-modal-open";
150
+ var Q = Object.defineProperty, Z = Object.getOwnPropertyDescriptor, s = (n, e, t, o) => {
151
+ for (var i = o > 1 ? void 0 : o ? Z(e, t) : e, d = n.length - 1, l; d >= 0; d--)
152
+ (l = n[d]) && (i = (o ? l(e, t, i) : l(i)) || i);
153
+ return o && i && Q(e, t, i), i;
154
154
  };
155
- const b = "pie-modal";
156
- class s extends R(x) {
155
+ const w = "pie-modal";
156
+ class a extends k(B) {
157
157
  constructor() {
158
- super(), this.isOpen = !1, this.headingLevel = "h2", this.size = "medium", this._triggerCloseModal = () => {
159
- this.isOpen = !1;
158
+ super(), this.headingLevel = "h2", this.isDismissible = !1, this.isFullWidthBelowMid = !1, this.isOpen = !1, this.size = "medium", this._handleDialogCancelEvent = (e) => {
159
+ this.isDismissible || e.preventDefault();
160
160
  }, this._handleDialogLightDismiss = (e) => {
161
- var m;
162
- const t = (m = this._dialog) == null ? void 0 : m.getBoundingClientRect(), {
163
- top: n = 0,
164
- bottom: o = 0,
161
+ var p;
162
+ if (!this.isDismissible)
163
+ return;
164
+ const t = (p = this._dialog) == null ? void 0 : p.getBoundingClientRect(), {
165
+ top: o = 0,
166
+ bottom: i = 0,
165
167
  left: d = 0,
166
- right: a = 0
168
+ right: l = 0
167
169
  } = t || {};
168
- if (n === 0 && o === 0 && d === 0 && a === 0)
170
+ if (o === 0 && i === 0 && d === 0 && l === 0)
169
171
  return;
170
- (e.clientY < n || e.clientY > o || e.clientX < d || e.clientX > a) && (this.isOpen = !1);
171
- }, this._dispatchModalCloseEvent = () => {
172
- const e = new CustomEvent(w, {
173
- bubbles: !0,
174
- composed: !0
175
- });
176
- this.dispatchEvent(e);
177
- }, this._dispatchModalOpenEvent = () => {
178
- const e = new CustomEvent(O, {
172
+ (e.clientY < o || e.clientY > i || e.clientX < d || e.clientX > l) && (this.isOpen = !1);
173
+ }, this._dispatchModalCustomEvent = (e) => {
174
+ const t = new CustomEvent(e, {
179
175
  bubbles: !0,
180
176
  composed: !0
181
177
  });
182
- this.dispatchEvent(e);
178
+ this.dispatchEvent(t);
183
179
  }, this.addEventListener("click", (e) => this._handleDialogLightDismiss(e));
184
180
  }
181
+ connectedCallback() {
182
+ super.connectedCallback(), document.addEventListener(v, this._handleModalOpened.bind(this)), document.addEventListener(_, this._handleModalClosed.bind(this));
183
+ }
184
+ disconnectedCallback() {
185
+ document.removeEventListener(v, this._handleModalOpened.bind(this)), document.removeEventListener(_, this._handleModalClosed.bind(this)), super.disconnectedCallback();
186
+ }
185
187
  firstUpdated(e) {
186
- this._handleModalOpenStateOnFirstRender(e);
188
+ var t, o;
189
+ (t = this._dialog) == null || t.addEventListener("cancel", (i) => this._handleDialogCancelEvent(i)), this._handleModalOpenStateOnFirstRender(e), (o = this._dialog) == null || o.addEventListener("close", () => {
190
+ this.isOpen = !1;
191
+ });
187
192
  }
188
193
  updated(e) {
189
194
  this._handleModalOpenStateChanged(e);
@@ -192,48 +197,51 @@ class s extends R(x) {
192
197
  * Opens the dialog element and disables page scrolling
193
198
  */
194
199
  _handleModalOpened() {
195
- var e;
196
- Y(this), (e = this._dialog) == null || e.showModal();
200
+ var e, t, o;
201
+ Y(this), !((e = this._dialog) != null && e.hasAttribute("open") || !((t = this._dialog) != null && t.isConnected)) && ((o = this._dialog) == null || o.showModal());
197
202
  }
198
203
  /**
199
204
  * Closes the dialog element and re-enables page scrolling
200
205
  */
201
206
  _handleModalClosed() {
202
207
  var e;
203
- U(this), (e = this._dialog) == null || e.close();
204
- }
205
- connectedCallback() {
206
- super.connectedCallback(), document.addEventListener(O, this._handleModalOpened.bind(this)), document.addEventListener(w, this._handleModalClosed.bind(this));
207
- }
208
- disconnectedCallback() {
209
- document.removeEventListener(O, this._handleModalOpened.bind(this)), document.removeEventListener(w, this._handleModalClosed.bind(this)), super.disconnectedCallback();
208
+ U(this), (e = this._dialog) == null || e.close(), this._returnFocus();
210
209
  }
211
210
  // Handles the value of the isOpen property on first render of the component
212
211
  _handleModalOpenStateOnFirstRender(e) {
213
- e.get("isOpen") === void 0 && this.isOpen && this._dispatchModalOpenEvent();
212
+ e.get("isOpen") === void 0 && this.isOpen && this._dispatchModalCustomEvent(v);
214
213
  }
215
214
  // Handles changes to the modal isOpen property by dispatching any appropriate events
216
215
  _handleModalOpenStateChanged(e) {
217
216
  const t = e.get("isOpen");
218
- t !== void 0 && (t ? this._dispatchModalCloseEvent() : this._dispatchModalOpenEvent());
217
+ t !== void 0 && (t ? this._dispatchModalCustomEvent(_) : this._dispatchModalCustomEvent(v));
218
+ }
219
+ /**
220
+ * Return focus to the specified element, providing the selector is valid
221
+ * and the chosen element can be found.
222
+ * Fails silently.
223
+ */
224
+ _returnFocus() {
225
+ var t, o;
226
+ const e = (t = this.returnFocusAfterCloseSelector) == null ? void 0 : t.trim();
227
+ e && ((o = document.querySelector(e)) == null || o.focus());
219
228
  }
220
229
  render() {
221
230
  const {
222
231
  heading: e,
223
232
  headingLevel: t = "h2",
224
- size: n
225
- } = this, o = E(t);
226
- return L`
233
+ size: o,
234
+ isFullWidthBelowMid: i
235
+ } = this, d = E(t);
236
+ return z`
227
237
  <dialog
228
238
  id="dialog"
229
- size="${n}"
230
- class="c-modal">
239
+ class="c-modal"
240
+ size="${o}"
241
+ ?isFullWidthBelowMid=${i}>
231
242
  <header>
232
- <${o} class="c-modal-heading">${e}</${o}>
233
- <pie-icon-button
234
- @click="${this._triggerCloseModal}"
235
- variant="ghost-secondary"
236
- class="c-modal-closeBtn"></pie-icon-button>
243
+ <${d} class="c-modal-heading">${e}</${d}>
244
+ ${this.isDismissible ? this.renderCloseButton() : x}
237
245
  </header>
238
246
  <article class="c-modal-content">
239
247
  <slot></slot>
@@ -241,29 +249,55 @@ class s extends R(x) {
241
249
  </dialog>
242
250
  `;
243
251
  }
252
+ /**
253
+ * Template for the close button element. Called within the
254
+ * main render function.
255
+ *
256
+ * @private
257
+ */
258
+ renderCloseButton() {
259
+ return z`
260
+ <pie-icon-button
261
+ @click="${() => {
262
+ this.isOpen = !1;
263
+ }}"
264
+ variant="ghost-secondary"
265
+ class="c-modal-closeBtn"
266
+ data-test-id="modal-close-button"><icon-close /></pie-icon-button>
267
+ `;
268
+ }
244
269
  }
245
- s.styles = C(X);
246
- h([
247
- y({ type: Boolean })
248
- ], s.prototype, "isOpen", 2);
249
- h([
250
- y({ type: String }),
251
- A(b)
252
- ], s.prototype, "heading", 2);
253
- h([
254
- y(),
255
- S(b, W, "h2")
256
- ], s.prototype, "headingLevel", 2);
257
- h([
258
- y(),
259
- S(b, G, "medium")
260
- ], s.prototype, "size", 2);
261
- h([
262
- T("dialog")
263
- ], s.prototype, "_dialog", 2);
264
- customElements.define(b, s);
270
+ a.styles = D(X);
271
+ s([
272
+ u({ type: String }),
273
+ R(w)
274
+ ], a.prototype, "heading", 2);
275
+ s([
276
+ u(),
277
+ C(w, G, "h2")
278
+ ], a.prototype, "headingLevel", 2);
279
+ s([
280
+ u({ type: Boolean, reflect: !0 })
281
+ ], a.prototype, "isDismissible", 2);
282
+ s([
283
+ u({ type: Boolean })
284
+ ], a.prototype, "isFullWidthBelowMid", 2);
285
+ s([
286
+ u({ type: Boolean })
287
+ ], a.prototype, "isOpen", 2);
288
+ s([
289
+ u()
290
+ ], a.prototype, "returnFocusAfterCloseSelector", 2);
291
+ s([
292
+ u(),
293
+ C(w, J, "medium")
294
+ ], a.prototype, "size", 2);
295
+ s([
296
+ L("dialog")
297
+ ], a.prototype, "_dialog", 2);
298
+ customElements.define(w, a);
265
299
  export {
266
- s as PieModal,
267
- W as headingLevels,
268
- G as sizes
300
+ a as PieModal,
301
+ G as headingLevels,
302
+ J as sizes
269
303
  };
package/dist/react.js CHANGED
File without changes
File without changes
@@ -13,6 +13,26 @@ export interface ModalProps {
13
13
  * When true, the modal will be open.
14
14
  */
15
15
  isOpen: boolean;
16
+ /**
17
+ * When set to `true`:
18
+ * 1. The close button within the modal will be visible.
19
+ * 2. The user can dismiss the modal via the ESCAPE key, clicking the backdrop
20
+ * or via a close button.
21
+ *
22
+ * When set to `false`:
23
+ * 1. The close button within the modal will be hidden.
24
+ * 2. The user can NOT dismiss the modal via the ESCAPE key or clicking the backdrop.
25
+ *
26
+ */
27
+ isDismissible: boolean;
28
+ /**
29
+ * This controls whether a *medium-sized* modal will cover the full width of the page when below the mid breakpoint.
30
+ */
31
+ isFullWidthBelowMid: boolean;
32
+ /**
33
+ * The selector for the element that you would like focus to be returned to when the modal is closed, e.g., #skipToMain
34
+ */
35
+ returnFocusAfterCloseSelector?: string;
16
36
  /**
17
37
  * The size of the modal; this controls how wide it will appear on the page.
18
38
  */
@@ -1 +1 @@
1
- {"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../../src/defs.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,+CAAgD,CAAC;AAC3E,eAAO,MAAM,KAAK,uCAAwC,CAAC;AAE3D,MAAM,WAAW,UAAU;IACvB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,YAAY,EAAE,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;IAC3C;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,IAAI,EAAE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC;CAC9B;AAED;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,mBAAmB,CAAC"}
1
+ {"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../../src/defs.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,+CAAgD,CAAC;AAC3E,eAAO,MAAM,KAAK,uCAAwC,CAAC;AAE3D,MAAM,WAAW,UAAU;IACvB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,YAAY,EAAE,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;IAE3C;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAEhB;;;;;;;;;;OAUG;IACH,aAAa,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,mBAAmB,EAAE,OAAO,CAAC;IAE7B;;OAEG;IACH,6BAA6B,CAAC,EAAE,MAAM,CAAC;IAEvC;;OAEG;IACH,IAAI,EAAE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC;CAC9B;AAED;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,oBAAoB,CAAC;AAEtD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,mBAAmB,CAAC"}