@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.
- package/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +23 -0
- package/README.md +14 -6
- package/dist/index.js +175 -141
- 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 +35 -19
- 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 +2 -1
- package/src/defs.ts +26 -0
- package/src/index.ts +98 -54
- 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
|
+
[5:08:22 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
|
-
[32m✓[39m
|
|
5
|
+
[32m✓[39m 25 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.38 kB[22m[1m[22m[2m │ gzip: 4.21 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.29s[39m
|
|
13
|
+
[32m[36m[vite:dts][32m Declaration files built in 9310ms.
|
|
14
|
+
[39m
|
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
|
|
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 { unsafeStatic as E, html as
|
|
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 { 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
|
|
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,173 @@ 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(
|
|
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
|
-
|
|
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 ||
|
|
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.
|
|
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.
|
|
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:
|
|
225
|
-
|
|
226
|
-
|
|
233
|
+
size: o,
|
|
234
|
+
isFullWidthBelowMid: i
|
|
235
|
+
} = this, d = E(t);
|
|
236
|
+
return z`
|
|
227
237
|
<dialog
|
|
228
238
|
id="dialog"
|
|
229
|
-
|
|
230
|
-
|
|
239
|
+
class="c-modal"
|
|
240
|
+
size="${o}"
|
|
241
|
+
?isFullWidthBelowMid=${i}>
|
|
231
242
|
<header>
|
|
232
|
-
<${
|
|
233
|
-
|
|
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
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
],
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
267
|
-
|
|
268
|
-
|
|
300
|
+
a as PieModal,
|
|
301
|
+
G as headingLevels,
|
|
302
|
+
J as sizes
|
|
269
303
|
};
|
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"}
|