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