@justeattakeaway/pie-modal 0.16.0 → 0.18.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/README.md +14 -0
- package/dist/{types/packages/components/pie-modal/src/index.d.ts → index.d.ts} +241 -126
- package/dist/index.js +965 -567
- package/dist/react.d.ts +249 -0
- package/dist/react.js +213 -206
- package/package.json +10 -2
- package/src/index.ts +11 -6
- package/src/modal.scss +1 -0
- package/.eslintignore +0 -6
- package/.turbo/turbo-build.log +0 -14
- package/CHANGELOG.md +0 -199
- package/dist/types/index.d.ts +0 -1
- package/dist/types/packages/components/pie-modal/src/defs.d.ts +0 -110
- package/dist/types/packages/components/pie-modal/src/defs.d.ts.map +0 -1
- package/dist/types/packages/components/pie-modal/src/index.d.ts.map +0 -1
- package/dist/types/packages/components/pie-modal/src/react.d.ts +0 -8
- package/dist/types/packages/components/pie-modal/src/react.d.ts.map +0 -1
- package/dist/types/react.d.ts +0 -1
- package/playwright/index.html +0 -56
- package/playwright/index.ts +0 -1
- package/playwright-lit-visual.config.ts +0 -4
- package/playwright-lit.config.ts +0 -4
- package/test/component/pie-modal.spec.ts +0 -816
- package/test/helpers/index.ts +0 -31
- package/test/visual/pie-modal.spec.ts +0 -494
- package/tsconfig.json +0 -8
- package/vite.config.js +0 -3
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
3. [Importing the component](#importing-the-component)
|
|
16
16
|
4. [Props](#props)
|
|
17
17
|
5. [Testing](#testing)
|
|
18
|
+
5. [Legacy browser support](#legacy-browser-support)
|
|
18
19
|
|
|
19
20
|
# pie-modal
|
|
20
21
|
|
|
@@ -118,3 +119,16 @@ Under scripts `test:visual` replace the environment variable with the below:
|
|
|
118
119
|
```bash
|
|
119
120
|
PERCY_TOKEN_PIE_MODAL=abcde
|
|
120
121
|
```
|
|
122
|
+
|
|
123
|
+
## Legacy browser support
|
|
124
|
+
|
|
125
|
+
`pie-modal` uses the Dialog element which might not be supported by legacy browsers.
|
|
126
|
+
|
|
127
|
+
To support them, `pie-modal` uses the [dialog-polyfill](https://github.com/GoogleChrome/dialog-polyfill) package. It works automatically and doesn't need any setup.
|
|
128
|
+
|
|
129
|
+
The polyfill comes with a few limitations, as noted on its [documentation page](https://github.com/GoogleChrome/dialog-polyfill#limitations):
|
|
130
|
+
- Dialogs should not be contained by parents that create a stacking context
|
|
131
|
+
- The browser's chrome may not always be accessible via the tab key
|
|
132
|
+
- Changes to the CSS top/bottom values while open aren't retained
|
|
133
|
+
|
|
134
|
+
For more details, check the package documentation mentioned above.
|
|
@@ -1,126 +1,241 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { DependentMap } from '@justeattakeaway/pie-webc-core';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
*
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*/
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
*
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
*
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
*
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
*
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
*
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
*
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
1
|
+
import type { CSSResult } from 'lit';
|
|
2
|
+
import type { DependentMap } from '@justeattakeaway/pie-webc-core';
|
|
3
|
+
import type { LitElement } from 'lit';
|
|
4
|
+
import { RTLComponentProps } from '@justeattakeaway/pie-webc-core';
|
|
5
|
+
import type { TemplateResult } from 'lit';
|
|
6
|
+
import { Variant } from '@justeattakeaway/pie-button/src/defs.ts';
|
|
7
|
+
|
|
8
|
+
export declare type ActionProps = {
|
|
9
|
+
/**
|
|
10
|
+
* The text to display inside the button.
|
|
11
|
+
*/
|
|
12
|
+
text: string;
|
|
13
|
+
/**
|
|
14
|
+
* The button variant.
|
|
15
|
+
*/
|
|
16
|
+
variant?: Variant;
|
|
17
|
+
/**
|
|
18
|
+
* The ARIA label for the button.
|
|
19
|
+
*/
|
|
20
|
+
ariaLabel?: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export declare type AriaProps = {
|
|
24
|
+
close?: string;
|
|
25
|
+
back?: string;
|
|
26
|
+
loading?: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export declare const headingLevels: readonly ["h1", "h2", "h3", "h4", "h5", "h6"];
|
|
30
|
+
|
|
31
|
+
export declare type ModalProps = RTLComponentProps & {
|
|
32
|
+
/**
|
|
33
|
+
* The ARIA labels used for the modal close and back buttons, as well as loading state.
|
|
34
|
+
*/
|
|
35
|
+
aria?: AriaProps;
|
|
36
|
+
/**
|
|
37
|
+
* When true, the modal will have a back button. This currently behaves the same as the close button.
|
|
38
|
+
*/
|
|
39
|
+
hasBackButton: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* When true, the modal will have a back button. This currently behaves the same as the close button.
|
|
42
|
+
*/
|
|
43
|
+
hasStackedActions: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* The text to display in the modal's heading.
|
|
46
|
+
*/
|
|
47
|
+
heading: string;
|
|
48
|
+
/**
|
|
49
|
+
* The HTML heading tag to use for the modal's heading. Can be h1-h6.
|
|
50
|
+
*/
|
|
51
|
+
headingLevel: typeof headingLevels[number];
|
|
52
|
+
/**
|
|
53
|
+
* When true, the modal will be open.
|
|
54
|
+
*/
|
|
55
|
+
isOpen: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* When set to `true`:
|
|
58
|
+
* 1. The close button within the modal will be visible.
|
|
59
|
+
* 2. The user can dismiss the modal via the ESCAPE key, clicking the backdrop
|
|
60
|
+
* or via a close button.
|
|
61
|
+
*
|
|
62
|
+
* When set to `false`:
|
|
63
|
+
* 1. The close button within the modal will be hidden.
|
|
64
|
+
* 2. The user can NOT dismiss the modal via the ESCAPE key or clicking the backdrop.
|
|
65
|
+
*
|
|
66
|
+
*/
|
|
67
|
+
isDismissible: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* When false, the modal footer will scroll with the content inside the modal body.
|
|
70
|
+
*/
|
|
71
|
+
isFooterPinned: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* This controls whether a *medium-sized* modal will cover the full width of the page when below the mid breakpoint.
|
|
74
|
+
*/
|
|
75
|
+
isFullWidthBelowMid: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* When true, displays a loading spinner in the modal.
|
|
78
|
+
*/
|
|
79
|
+
isLoading: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* The leading action configuration for the modal.
|
|
82
|
+
*/
|
|
83
|
+
leadingAction: ActionProps;
|
|
84
|
+
position: typeof positions[number];
|
|
85
|
+
/**
|
|
86
|
+
* The selector for the element that you would like focus to be returned to when the modal is closed, e.g., #skipToMain
|
|
87
|
+
*/
|
|
88
|
+
returnFocusAfterCloseSelector?: string;
|
|
89
|
+
/**
|
|
90
|
+
* The size of the modal; this controls how wide it will appear on the page.
|
|
91
|
+
*/
|
|
92
|
+
size: typeof sizes[number];
|
|
93
|
+
/**
|
|
94
|
+
* The supporting action configuration for the modal.
|
|
95
|
+
*/
|
|
96
|
+
supportingAction: ActionProps;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Event name for when the modal back button is clicked.
|
|
101
|
+
*
|
|
102
|
+
* @constant
|
|
103
|
+
*/
|
|
104
|
+
export declare const ON_MODAL_BACK_EVENT = "pie-modal-back";
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Event name for when the modal is closed.
|
|
108
|
+
*
|
|
109
|
+
* @constant
|
|
110
|
+
*/
|
|
111
|
+
export declare const ON_MODAL_CLOSE_EVENT = "pie-modal-close";
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Event name for when the modal is opened.
|
|
115
|
+
*
|
|
116
|
+
* @constant
|
|
117
|
+
*/
|
|
118
|
+
export declare const ON_MODAL_OPEN_EVENT = "pie-modal-open";
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @event {CustomEvent} pie-modal-open - when the modal is opened.
|
|
122
|
+
* @event {CustomEvent} pie-modal-close - when the modal is closed.
|
|
123
|
+
* @event {CustomEvent} pie-modal-back - when the modal back button is clicked.
|
|
124
|
+
*/
|
|
125
|
+
export declare class PieModal extends PieModal_base implements ModalProps {
|
|
126
|
+
aria: AriaProps;
|
|
127
|
+
heading: string;
|
|
128
|
+
headingLevel: ModalProps['headingLevel'];
|
|
129
|
+
hasBackButton: boolean;
|
|
130
|
+
hasStackedActions: boolean;
|
|
131
|
+
isDismissible: boolean;
|
|
132
|
+
isFooterPinned: boolean;
|
|
133
|
+
isFullWidthBelowMid: boolean;
|
|
134
|
+
isLoading: boolean;
|
|
135
|
+
isOpen: boolean;
|
|
136
|
+
leadingAction: ActionProps;
|
|
137
|
+
position: ModalProps['position'];
|
|
138
|
+
returnFocusAfterCloseSelector?: string;
|
|
139
|
+
size: ModalProps['size'];
|
|
140
|
+
supportingAction: ActionProps;
|
|
141
|
+
private _dialog?;
|
|
142
|
+
private _backButtonClicked;
|
|
143
|
+
static styles: CSSResult;
|
|
144
|
+
constructor();
|
|
145
|
+
connectedCallback(): void;
|
|
146
|
+
disconnectedCallback(): void;
|
|
147
|
+
firstUpdated(changedProperties: DependentMap<ModalProps>): void;
|
|
148
|
+
updated(changedProperties: DependentMap<ModalProps>): void;
|
|
149
|
+
/**
|
|
150
|
+
* Opens the dialog element and disables page scrolling
|
|
151
|
+
*/
|
|
152
|
+
private _handleModalOpened;
|
|
153
|
+
/**
|
|
154
|
+
* Closes the dialog element and re-enables page scrolling
|
|
155
|
+
*/
|
|
156
|
+
private _handleModalClosed;
|
|
157
|
+
/**
|
|
158
|
+
* Prevents the user from dismissing the dialog via the `cancel`
|
|
159
|
+
* event (ESC key) when `isDismissible` is set to false.
|
|
160
|
+
*
|
|
161
|
+
* @param {Event} event - The event object.
|
|
162
|
+
*/
|
|
163
|
+
private _handleDialogCancelEvent;
|
|
164
|
+
private _handleModalOpenStateOnFirstRender;
|
|
165
|
+
private _handleModalOpenStateChanged;
|
|
166
|
+
/**
|
|
167
|
+
* Return focus to the specified element, providing the selector is valid
|
|
168
|
+
* and the chosen element can be found.
|
|
169
|
+
*/
|
|
170
|
+
private _returnFocus;
|
|
171
|
+
/**
|
|
172
|
+
* Template for the close button element. Called within the
|
|
173
|
+
* main render function.
|
|
174
|
+
*
|
|
175
|
+
* @private
|
|
176
|
+
*/
|
|
177
|
+
private renderCloseButton;
|
|
178
|
+
/**
|
|
179
|
+
* Template for the back button element. Called within the
|
|
180
|
+
* main render function.
|
|
181
|
+
*
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
184
|
+
private renderBackButton;
|
|
185
|
+
/**
|
|
186
|
+
* Render leadingAction button depending on prop availability.
|
|
187
|
+
*
|
|
188
|
+
* 1. If the prop `leadingAction` is not provided, the button is not rendered.
|
|
189
|
+
* 2. If the prop `leadingAction` is provided but any of the optional properties
|
|
190
|
+
* are not provided, they fall back to their default values.
|
|
191
|
+
*
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
194
|
+
private renderLeadingAction;
|
|
195
|
+
/**
|
|
196
|
+
* Render supportingAction button depending on prop availability.
|
|
197
|
+
*
|
|
198
|
+
* 1. If the prop `supportingAction` is not provided, the button is not rendered.
|
|
199
|
+
* 2. If the prop `supportingAction` is provided but any of the optional properties
|
|
200
|
+
* are not provided, they fall back to their default values.
|
|
201
|
+
* 3. If `supportingAction` is provided but not `leadingAction`, log a warning and do
|
|
202
|
+
* not render `supportingAction`.
|
|
203
|
+
*
|
|
204
|
+
* @private
|
|
205
|
+
*/
|
|
206
|
+
private renderSupportingAction;
|
|
207
|
+
/**
|
|
208
|
+
* Renders the modal inner content and footer of the modal.
|
|
209
|
+
* @private
|
|
210
|
+
*/
|
|
211
|
+
private renderModalContentAndFooter;
|
|
212
|
+
render(): TemplateResult;
|
|
213
|
+
/**
|
|
214
|
+
* Dismisses the modal on backdrop click if `isDismissible` is `true`.
|
|
215
|
+
* @param {MouseEvent} event - the click event targetting the modal/backdrop
|
|
216
|
+
*/
|
|
217
|
+
private _handleDialogLightDismiss;
|
|
218
|
+
/**
|
|
219
|
+
* Note: We should aim to have a shareable event helper system to allow
|
|
220
|
+
* us to share this across components in-future.
|
|
221
|
+
*
|
|
222
|
+
* Dispatch a custom event.
|
|
223
|
+
*
|
|
224
|
+
* To be used whenever we have behavioural events we want to
|
|
225
|
+
* bubble up through the modal.
|
|
226
|
+
*
|
|
227
|
+
* @param {string} eventType
|
|
228
|
+
*/
|
|
229
|
+
private _dispatchModalCustomEvent;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
declare const PieModal_base: (new (...args: any[]) => {
|
|
233
|
+
dir: "ltr" | "rtl" | "auto";
|
|
234
|
+
isRTL: boolean;
|
|
235
|
+
}) & typeof LitElement;
|
|
236
|
+
|
|
237
|
+
export declare const positions: readonly ["top", "center"];
|
|
238
|
+
|
|
239
|
+
export declare const sizes: readonly ["small", "medium", "large"];
|
|
240
|
+
|
|
241
|
+
export { }
|