@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 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 { LitElement, TemplateResult } from 'lit';
2
- import type { DependentMap } from '@justeattakeaway/pie-webc-core';
3
- import { type AriaProps, type ActionProps, type ModalProps, headingLevels, sizes } from './defs';
4
- export { type ModalProps, headingLevels, sizes };
5
- declare const componentSelector = "pie-modal";
6
- declare const PieModal_base: (new (...args: any[]) => {
7
- dir: "ltr" | "rtl" | "auto";
8
- isRTL: boolean;
9
- }) & typeof LitElement;
10
- /**
11
- * @event {CustomEvent} pie-modal-open - when the modal is opened.
12
- * @event {CustomEvent} pie-modal-close - when the modal is closed.
13
- * @event {CustomEvent} pie-modal-back - when the modal back button is clicked.
14
- */
15
- export declare class PieModal extends PieModal_base implements ModalProps {
16
- aria: AriaProps;
17
- heading: string;
18
- headingLevel: ModalProps['headingLevel'];
19
- hasBackButton: boolean;
20
- hasStackedActions: boolean;
21
- isDismissible: boolean;
22
- isFooterPinned: boolean;
23
- isFullWidthBelowMid: boolean;
24
- isLoading: boolean;
25
- isOpen: boolean;
26
- leadingAction: ActionProps;
27
- position: ModalProps['position'];
28
- returnFocusAfterCloseSelector?: string;
29
- size: ModalProps['size'];
30
- supportingAction: ActionProps;
31
- private _dialog?;
32
- private _backButtonClicked;
33
- static styles: import("lit").CSSResult;
34
- constructor();
35
- connectedCallback(): void;
36
- disconnectedCallback(): void;
37
- firstUpdated(changedProperties: DependentMap<ModalProps>): void;
38
- updated(changedProperties: DependentMap<ModalProps>): void;
39
- /**
40
- * Opens the dialog element and disables page scrolling
41
- */
42
- private _handleModalOpened;
43
- /**
44
- * Closes the dialog element and re-enables page scrolling
45
- */
46
- private _handleModalClosed;
47
- /**
48
- * Prevents the user from dismissing the dialog via the `cancel`
49
- * event (ESC key) when `isDismissible` is set to false.
50
- *
51
- * @param {Event} event - The event object.
52
- */
53
- private _handleDialogCancelEvent;
54
- private _handleModalOpenStateOnFirstRender;
55
- private _handleModalOpenStateChanged;
56
- /**
57
- * Return focus to the specified element, providing the selector is valid
58
- * and the chosen element can be found.
59
- */
60
- private _returnFocus;
61
- /**
62
- * Template for the close button element. Called within the
63
- * main render function.
64
- *
65
- * @private
66
- */
67
- private renderCloseButton;
68
- /**
69
- * Template for the back button element. Called within the
70
- * main render function.
71
- *
72
- * @private
73
- */
74
- private renderBackButton;
75
- /**
76
- * Render leadingAction button depending on prop availability.
77
- *
78
- * 1. If the prop `leadingAction` is not provided, the button is not rendered.
79
- * 2. If the prop `leadingAction` is provided but any of the optional properties
80
- * are not provided, they fall back to their default values.
81
- *
82
- * @private
83
- */
84
- private renderLeadingAction;
85
- /**
86
- * Render supportingAction button depending on prop availability.
87
- *
88
- * 1. If the prop `supportingAction` is not provided, the button is not rendered.
89
- * 2. If the prop `supportingAction` is provided but any of the optional properties
90
- * are not provided, they fall back to their default values.
91
- * 3. If `supportingAction` is provided but not `leadingAction`, log a warning and do
92
- * not render `supportingAction`.
93
- *
94
- * @private
95
- */
96
- private renderSupportingAction;
97
- /**
98
- * Renders the modal inner content and footer of the modal.
99
- * @private
100
- */
101
- private renderModalContentAndFooter;
102
- render(): TemplateResult;
103
- /**
104
- * Dismisses the modal on backdrop click if `isDismissible` is `true`.
105
- * @param {MouseEvent} event - the click event targetting the modal/backdrop
106
- */
107
- private _handleDialogLightDismiss;
108
- /**
109
- * Note: We should aim to have a shareable event helper system to allow
110
- * us to share this across components in-future.
111
- *
112
- * Dispatch a custom event.
113
- *
114
- * To be used whenever we have behavioural events we want to
115
- * bubble up through the modal.
116
- *
117
- * @param {string} eventType
118
- */
119
- private _dispatchModalCustomEvent;
120
- }
121
- declare global {
122
- interface HTMLElementTagNameMap {
123
- [componentSelector]: PieModal;
124
- }
125
- }
126
- //# sourceMappingURL=index.d.ts.map
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 { }