@justeattakeaway/pie-modal 0.9.0 → 0.10.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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +15 -0
- package/README.md +14 -6
- package/dist/index.js +166 -142
- package/dist/react.js +0 -0
- package/dist/types/index.d.ts +0 -0
- package/dist/types/packages/components/pie-modal/src/defs.d.ts +20 -0
- package/dist/types/packages/components/pie-modal/src/defs.d.ts.map +1 -1
- package/dist/types/packages/components/pie-modal/src/index.d.ts +34 -18
- package/dist/types/packages/components/pie-modal/src/index.d.ts.map +1 -1
- package/dist/types/packages/components/pie-modal/src/react.d.ts +0 -0
- package/dist/types/packages/components/pie-modal/src/react.d.ts.map +0 -0
- package/dist/types/react.d.ts +0 -0
- package/package.json +1 -1
- package/src/defs.ts +26 -0
- package/src/index.ts +93 -53
- package/src/modal.scss +5 -0
- package/test/component/pie-modal.spec.ts +289 -6
- package/test/helpers/index.ts +29 -0
- package/test/visual/pie-modal.spec.ts +80 -17
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
[
|
|
1
|
+
[2:59:55 PM] @custom-elements-manifest/analyzer: Created new manifest.
|
|
2
2
|
react wrapper has been added!
|
|
3
3
|
[36mvite v4.3.9 [32mbuilding for production...[36m[39m
|
|
4
4
|
transforming...
|
|
5
5
|
[32m✓[39m 23 modules transformed.
|
|
6
6
|
rendering chunks...
|
|
7
7
|
computing gzip size...
|
|
8
|
-
[2mdist/[22m[36mindex.js [39m[1m[
|
|
8
|
+
[2mdist/[22m[36mindex.js [39m[1m[2m13.21 kB[22m[1m[22m[2m │ gzip: 4.16 kB[22m
|
|
9
9
|
[2mdist/[22m[36mreact.js [39m[1m[2m59.04 kB[22m[1m[22m[2m │ gzip: 15.92 kB[22m
|
|
10
|
-
|
|
11
|
-
[vite:dts] Start generate declaration files
|
|
12
|
-
[32m✓ built in
|
|
13
|
-
[vite:dts] Declaration files built in
|
|
14
|
-
|
|
10
|
+
[32m
|
|
11
|
+
[36m[vite:dts][32m Start generate declaration files...[39m
|
|
12
|
+
[32m✓ built in 10.22s[39m
|
|
13
|
+
[32m[36m[vite:dts][32m Declaration files built in 9231ms.
|
|
14
|
+
[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @justeattakeaway/pie-modal
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [Added] - Add returnFocusAfterCloseSelector prop ([#599](https://github.com/justeattakeaway/pie/pull/599)) by [@xander-marjoram](https://github.com/xander-marjoram)
|
|
8
|
+
|
|
9
|
+
[Changed] - Extract `renderTestPieModal` into test helper file so it can be used for component tests too
|
|
10
|
+
[Added] - Add README documentation for new props
|
|
11
|
+
|
|
12
|
+
- [Fixed] - Fix console errors when switching between stories ([#599](https://github.com/justeattakeaway/pie/pull/599)) by [@xander-marjoram](https://github.com/xander-marjoram)
|
|
13
|
+
|
|
14
|
+
- [Added] - New `isFullWidthBelowMid` prop for pie-modal ([#600](https://github.com/justeattakeaway/pie/pull/600)) by [@LTurns](https://github.com/LTurns)
|
|
15
|
+
|
|
16
|
+
- [Added] isDismissible prop and tests ([#588](https://github.com/justeattakeaway/pie/pull/588)) by [@kevinrodrigues](https://github.com/kevinrodrigues)
|
|
17
|
+
|
|
3
18
|
## 0.9.0
|
|
4
19
|
|
|
5
20
|
### 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
|
|
60
|
-
|
|
61
|
-
|
|
|
62
|
-
|
|
63
|
-
|
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import { property as
|
|
4
|
-
import { property as
|
|
5
|
-
var
|
|
6
|
-
for (var
|
|
7
|
-
(
|
|
8
|
-
return
|
|
1
|
+
import { nothing as x, unsafeCSS as D, LitElement as B } from "lit";
|
|
2
|
+
import { html as z, unsafeStatic as E } 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
|
|
11
|
-
class e extends
|
|
10
|
+
const k = (n) => {
|
|
11
|
+
class e extends n {
|
|
12
12
|
constructor() {
|
|
13
13
|
super(...arguments), this.dir = "";
|
|
14
14
|
}
|
|
@@ -22,168 +22,180 @@ const R = (i) => {
|
|
|
22
22
|
* will not be reactive and is only computed once
|
|
23
23
|
*/
|
|
24
24
|
get isRTL() {
|
|
25
|
-
var
|
|
26
|
-
return this.dir === "ltr" ? !1 : this.dir === "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
|
|
30
|
-
|
|
29
|
+
return A([
|
|
30
|
+
T({ type: String })
|
|
31
31
|
], e.prototype, "dir", 2), e;
|
|
32
|
-
},
|
|
33
|
-
const
|
|
34
|
-
Object.defineProperty(
|
|
32
|
+
}, C = (n, e, t) => function(i, d) {
|
|
33
|
+
const l = `#${d}`;
|
|
34
|
+
Object.defineProperty(i, d, {
|
|
35
35
|
get() {
|
|
36
|
-
return this[
|
|
36
|
+
return this[l];
|
|
37
37
|
},
|
|
38
|
-
set(
|
|
39
|
-
const
|
|
40
|
-
e.includes(
|
|
41
|
-
`<${
|
|
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[
|
|
44
|
+
), this[l] = t), this.requestUpdate(d, p);
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
|
-
},
|
|
48
|
-
const
|
|
49
|
-
Object.defineProperty(t,
|
|
47
|
+
}, R = (n) => function(t, o) {
|
|
48
|
+
const i = `#${o}`;
|
|
49
|
+
Object.defineProperty(t, o, {
|
|
50
50
|
get() {
|
|
51
|
-
return this[
|
|
51
|
+
return this[i];
|
|
52
52
|
},
|
|
53
53
|
set(d) {
|
|
54
|
-
const
|
|
55
|
-
(d == null || typeof d == "string" && d.trim() === "") && console.error(`<${
|
|
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(
|
|
60
|
-
if (Array.isArray(
|
|
61
|
-
for (var e = 0, t = Array(
|
|
62
|
-
t[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(
|
|
65
|
+
return Array.from(n);
|
|
66
66
|
}
|
|
67
|
-
var
|
|
67
|
+
var O = !1;
|
|
68
68
|
if (typeof window < "u") {
|
|
69
|
-
var
|
|
69
|
+
var S = {
|
|
70
70
|
get passive() {
|
|
71
|
-
|
|
71
|
+
O = !0;
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
|
-
window.addEventListener("testPassive", null,
|
|
74
|
+
window.addEventListener("testPassive", null, S), window.removeEventListener("testPassive", null, S);
|
|
75
75
|
}
|
|
76
|
-
var
|
|
77
|
-
return
|
|
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
|
-
},
|
|
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 (
|
|
85
|
-
var t = !!e && e.reserveScrollBarGap === !0,
|
|
86
|
-
if (t &&
|
|
87
|
-
var
|
|
88
|
-
|
|
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
|
-
|
|
91
|
+
h === void 0 && (h = document.body.style.overflow, document.body.style.overflow = "hidden");
|
|
92
92
|
}, V = function() {
|
|
93
|
-
|
|
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 (
|
|
97
|
-
|
|
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,
|
|
103
|
-
document.body.style.position = "fixed", document.body.style.top = -t, document.body.style.left = -
|
|
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 =
|
|
106
|
-
d && t >=
|
|
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
|
-
},
|
|
112
|
-
if (
|
|
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 =
|
|
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
|
-
},
|
|
116
|
+
}, W = function(e) {
|
|
117
117
|
return e ? e.scrollHeight - e.scrollTop <= e.clientHeight : !1;
|
|
118
118
|
}, N = function(e, t) {
|
|
119
|
-
var
|
|
120
|
-
return M(e.target) ? !1 : t && t.scrollTop === 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 (!
|
|
127
|
-
return
|
|
126
|
+
if (!c.some(function(i) {
|
|
127
|
+
return i.targetElement === e;
|
|
128
128
|
})) {
|
|
129
|
-
var
|
|
129
|
+
var o = {
|
|
130
130
|
targetElement: e,
|
|
131
131
|
options: t || {}
|
|
132
132
|
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}, e.ontouchmove = function(
|
|
136
|
-
|
|
137
|
-
},
|
|
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
|
-
|
|
144
|
+
c = c.filter(function(t) {
|
|
145
145
|
return t.targetElement !== e;
|
|
146
|
-
}),
|
|
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
|
-
`,
|
|
150
|
-
var
|
|
151
|
-
for (var
|
|
152
|
-
(
|
|
153
|
-
return
|
|
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
|
|
156
|
-
class
|
|
155
|
+
const w = "pie-modal";
|
|
156
|
+
class a extends k(B) {
|
|
157
157
|
constructor() {
|
|
158
|
-
super(), this.
|
|
159
|
-
this.
|
|
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
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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:
|
|
168
|
+
right: l = 0
|
|
167
169
|
} = t || {};
|
|
168
|
-
if (
|
|
170
|
+
if (o === 0 && i === 0 && d === 0 && l === 0)
|
|
169
171
|
return;
|
|
170
|
-
(e.clientY <
|
|
171
|
-
}, this.
|
|
172
|
-
const
|
|
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(
|
|
183
|
-
}, this.
|
|
178
|
+
this.dispatchEvent(t);
|
|
179
|
+
}, this.renderCloseButton = () => z`
|
|
180
|
+
<pie-icon-button
|
|
181
|
+
@click="${() => {
|
|
182
|
+
this.isOpen = !1;
|
|
183
|
+
}}"
|
|
184
|
+
variant="ghost-secondary"
|
|
185
|
+
class="c-modal-closeBtn"
|
|
186
|
+
data-test-id="modal-close-button"></pie-icon-button>`, this.addEventListener("click", (e) => this._handleDialogLightDismiss(e));
|
|
187
|
+
}
|
|
188
|
+
connectedCallback() {
|
|
189
|
+
super.connectedCallback(), document.addEventListener(v, this._handleModalOpened.bind(this)), document.addEventListener(_, this._handleModalClosed.bind(this));
|
|
190
|
+
}
|
|
191
|
+
disconnectedCallback() {
|
|
192
|
+
document.removeEventListener(v, this._handleModalOpened.bind(this)), document.removeEventListener(_, this._handleModalClosed.bind(this)), super.disconnectedCallback();
|
|
184
193
|
}
|
|
185
194
|
firstUpdated(e) {
|
|
186
|
-
|
|
195
|
+
var t, o;
|
|
196
|
+
(t = this._dialog) == null || t.addEventListener("cancel", (i) => this._handleDialogCancelEvent(i)), this._handleModalOpenStateOnFirstRender(e), (o = this._dialog) == null || o.addEventListener("close", () => {
|
|
197
|
+
this.isOpen = !1;
|
|
198
|
+
});
|
|
187
199
|
}
|
|
188
200
|
updated(e) {
|
|
189
201
|
this._handleModalOpenStateChanged(e);
|
|
@@ -192,48 +204,51 @@ class s extends R(x) {
|
|
|
192
204
|
* Opens the dialog element and disables page scrolling
|
|
193
205
|
*/
|
|
194
206
|
_handleModalOpened() {
|
|
195
|
-
var e;
|
|
196
|
-
Y(this), (e = this._dialog) == null ||
|
|
207
|
+
var e, t, o;
|
|
208
|
+
Y(this), !((e = this._dialog) != null && e.hasAttribute("open") || !((t = this._dialog) != null && t.isConnected)) && ((o = this._dialog) == null || o.showModal());
|
|
197
209
|
}
|
|
198
210
|
/**
|
|
199
211
|
* Closes the dialog element and re-enables page scrolling
|
|
200
212
|
*/
|
|
201
213
|
_handleModalClosed() {
|
|
202
214
|
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();
|
|
215
|
+
U(this), (e = this._dialog) == null || e.close(), this._returnFocus();
|
|
210
216
|
}
|
|
211
217
|
// Handles the value of the isOpen property on first render of the component
|
|
212
218
|
_handleModalOpenStateOnFirstRender(e) {
|
|
213
|
-
e.get("isOpen") === void 0 && this.isOpen && this.
|
|
219
|
+
e.get("isOpen") === void 0 && this.isOpen && this._dispatchModalCustomEvent(v);
|
|
214
220
|
}
|
|
215
221
|
// Handles changes to the modal isOpen property by dispatching any appropriate events
|
|
216
222
|
_handleModalOpenStateChanged(e) {
|
|
217
223
|
const t = e.get("isOpen");
|
|
218
|
-
t !== void 0 && (t ? this.
|
|
224
|
+
t !== void 0 && (t ? this._dispatchModalCustomEvent(_) : this._dispatchModalCustomEvent(v));
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Return focus to the specified element, providing the selector is valid
|
|
228
|
+
* and the chosen element can be found.
|
|
229
|
+
* Fails silently.
|
|
230
|
+
*/
|
|
231
|
+
_returnFocus() {
|
|
232
|
+
var t, o;
|
|
233
|
+
const e = (t = this.returnFocusAfterCloseSelector) == null ? void 0 : t.trim();
|
|
234
|
+
e && ((o = document.querySelector(e)) == null || o.focus());
|
|
219
235
|
}
|
|
220
236
|
render() {
|
|
221
237
|
const {
|
|
222
238
|
heading: e,
|
|
223
239
|
headingLevel: t = "h2",
|
|
224
|
-
size:
|
|
225
|
-
|
|
226
|
-
|
|
240
|
+
size: o,
|
|
241
|
+
isFullWidthBelowMid: i
|
|
242
|
+
} = this, d = E(t);
|
|
243
|
+
return z`
|
|
227
244
|
<dialog
|
|
228
245
|
id="dialog"
|
|
229
|
-
|
|
230
|
-
|
|
246
|
+
class="c-modal"
|
|
247
|
+
size="${o}"
|
|
248
|
+
?isFullWidthBelowMid=${i}>
|
|
231
249
|
<header>
|
|
232
|
-
<${
|
|
233
|
-
|
|
234
|
-
@click="${this._triggerCloseModal}"
|
|
235
|
-
variant="ghost-secondary"
|
|
236
|
-
class="c-modal-closeBtn"></pie-icon-button>
|
|
250
|
+
<${d} class="c-modal-heading">${e}</${d}>
|
|
251
|
+
${this.isDismissible ? this.renderCloseButton() : x}
|
|
237
252
|
</header>
|
|
238
253
|
<article class="c-modal-content">
|
|
239
254
|
<slot></slot>
|
|
@@ -242,28 +257,37 @@ class s extends R(x) {
|
|
|
242
257
|
`;
|
|
243
258
|
}
|
|
244
259
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
],
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
260
|
+
a.styles = D(X);
|
|
261
|
+
s([
|
|
262
|
+
u({ type: String }),
|
|
263
|
+
R(w)
|
|
264
|
+
], a.prototype, "heading", 2);
|
|
265
|
+
s([
|
|
266
|
+
u(),
|
|
267
|
+
C(w, G, "h2")
|
|
268
|
+
], a.prototype, "headingLevel", 2);
|
|
269
|
+
s([
|
|
270
|
+
u({ type: Boolean, reflect: !0 })
|
|
271
|
+
], a.prototype, "isDismissible", 2);
|
|
272
|
+
s([
|
|
273
|
+
u({ type: Boolean })
|
|
274
|
+
], a.prototype, "isFullWidthBelowMid", 2);
|
|
275
|
+
s([
|
|
276
|
+
u({ type: Boolean })
|
|
277
|
+
], a.prototype, "isOpen", 2);
|
|
278
|
+
s([
|
|
279
|
+
u()
|
|
280
|
+
], a.prototype, "returnFocusAfterCloseSelector", 2);
|
|
281
|
+
s([
|
|
282
|
+
u(),
|
|
283
|
+
C(w, J, "medium")
|
|
284
|
+
], a.prototype, "size", 2);
|
|
285
|
+
s([
|
|
286
|
+
L("dialog")
|
|
287
|
+
], a.prototype, "_dialog", 2);
|
|
288
|
+
customElements.define(w, a);
|
|
265
289
|
export {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
290
|
+
a as PieModal,
|
|
291
|
+
G as headingLevels,
|
|
292
|
+
J as sizes
|
|
269
293
|
};
|
package/dist/react.js
CHANGED
|
File without changes
|
package/dist/types/index.d.ts
CHANGED
|
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;
|
|
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"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LitElement } from 'lit';
|
|
1
|
+
import { LitElement, TemplateResult } from 'lit';
|
|
2
2
|
import type { DependentMap } from '@justeattakeaway/pie-webc-core';
|
|
3
3
|
import { ModalProps, headingLevels, sizes } from './defs';
|
|
4
4
|
export { type ModalProps, headingLevels, sizes };
|
|
@@ -8,12 +8,17 @@ declare const PieModal_base: (new (...args: any[]) => {
|
|
|
8
8
|
isRTL: boolean;
|
|
9
9
|
}) & typeof LitElement;
|
|
10
10
|
export declare class PieModal extends PieModal_base {
|
|
11
|
-
isOpen: boolean;
|
|
12
11
|
heading: string;
|
|
13
12
|
headingLevel: ModalProps['headingLevel'];
|
|
13
|
+
isDismissible: boolean;
|
|
14
|
+
isFullWidthBelowMid: boolean;
|
|
15
|
+
isOpen: boolean;
|
|
16
|
+
returnFocusAfterCloseSelector?: string;
|
|
14
17
|
size: ModalProps['size'];
|
|
15
18
|
_dialog?: HTMLDialogElement;
|
|
16
19
|
constructor();
|
|
20
|
+
connectedCallback(): void;
|
|
21
|
+
disconnectedCallback(): void;
|
|
17
22
|
firstUpdated(changedProperties: DependentMap<ModalProps>): void;
|
|
18
23
|
updated(changedProperties: DependentMap<ModalProps>): void;
|
|
19
24
|
/**
|
|
@@ -25,34 +30,45 @@ export declare class PieModal extends PieModal_base {
|
|
|
25
30
|
*/
|
|
26
31
|
private _handleModalClosed;
|
|
27
32
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
33
|
+
* Prevents the user from dismissing the dialog via the `cancel`
|
|
34
|
+
* event (ESC key) when `isDismissible` is set to false.
|
|
35
|
+
*
|
|
36
|
+
* @param {Event} event - The event object.
|
|
30
37
|
*/
|
|
31
|
-
private
|
|
32
|
-
connectedCallback(): void;
|
|
33
|
-
disconnectedCallback(): void;
|
|
38
|
+
private _handleDialogCancelEvent;
|
|
34
39
|
private _handleModalOpenStateOnFirstRender;
|
|
35
40
|
private _handleModalOpenStateChanged;
|
|
36
|
-
render(): import("lit-html").TemplateResult;
|
|
37
41
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
42
|
+
* Return focus to the specified element, providing the selector is valid
|
|
43
|
+
* and the chosen element can be found.
|
|
44
|
+
* Fails silently.
|
|
45
|
+
*/
|
|
46
|
+
private _returnFocus;
|
|
47
|
+
render(): TemplateResult;
|
|
48
|
+
/**
|
|
49
|
+
* Dismisses the modal on backdrop click if `isDismissible` is `true`.
|
|
50
|
+
* @param {MouseEvent} event - the click event targetting the modal/backdrop
|
|
40
51
|
*/
|
|
41
52
|
private _handleDialogLightDismiss;
|
|
42
53
|
/**
|
|
43
|
-
*
|
|
44
|
-
*
|
|
54
|
+
* Note: We should aim to have a shareable event helper system to allow
|
|
55
|
+
* us to share this across components in-future.
|
|
56
|
+
*
|
|
57
|
+
* Dispatch a custom event.
|
|
58
|
+
*
|
|
59
|
+
* To be used whenever we have behavioural events we want to
|
|
60
|
+
* bubble up through the modal.
|
|
45
61
|
*
|
|
46
|
-
* @
|
|
62
|
+
* @param {string} eventType
|
|
47
63
|
*/
|
|
48
|
-
private
|
|
64
|
+
private _dispatchModalCustomEvent;
|
|
49
65
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
66
|
+
* Template for the close button element. Called within the
|
|
67
|
+
* main render function.
|
|
52
68
|
*
|
|
53
|
-
* @
|
|
69
|
+
* @private
|
|
54
70
|
*/
|
|
55
|
-
private
|
|
71
|
+
private renderCloseButton;
|
|
56
72
|
static styles: import("lit").CSSResult;
|
|
57
73
|
}
|
|
58
74
|
declare global {
|