@justeattakeaway/pie-modal 0.18.0 → 0.19.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-modal",
3
- "version": "0.18.0",
3
+ "version": "0.19.1",
4
4
  "description": "PIE design system modal built using web components",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -28,6 +28,7 @@
28
28
  "author": "JustEatTakeaway - Design System Web Team",
29
29
  "license": "Apache-2.0",
30
30
  "devDependencies": {
31
+ "@justeat/pie-design-tokens": "5.7.0",
31
32
  "@justeattakeaway/pie-button": "workspace:*",
32
33
  "@justeattakeaway/pie-components-config": "workspace:*",
33
34
  "@justeattakeaway/pie-icon-button": "workspace:*",
package/src/defs.ts CHANGED
@@ -133,3 +133,19 @@ export const ON_MODAL_OPEN_EVENT = 'pie-modal-open';
133
133
  * @constant
134
134
  */
135
135
  export const ON_MODAL_BACK_EVENT = 'pie-modal-back';
136
+
137
+ /**
138
+ * Event name for when the modal leading action is clicked.
139
+ *
140
+ * @constant
141
+ */
142
+ export const ON_MODAL_LEADING_ACTION_CLICK = 'pie-modal-leading-action-click';
143
+
144
+ /**
145
+ * Event name for when the modal supporting action is clicked.
146
+ *
147
+ * @constant
148
+ */
149
+ export const ON_MODAL_SUPPORTING_ACTION_CLICK = 'pie-modal-supporting-action-click';
150
+
151
+ export type ModalActionType = 'leading' | 'supporting';
package/src/index.ts CHANGED
@@ -19,12 +19,15 @@ import {
19
19
  type AriaProps,
20
20
  type ActionProps,
21
21
  type ModalProps,
22
+ type ModalActionType,
22
23
  headingLevels,
23
24
  positions,
24
25
  sizes,
25
26
  ON_MODAL_BACK_EVENT,
26
27
  ON_MODAL_CLOSE_EVENT,
27
28
  ON_MODAL_OPEN_EVENT,
29
+ ON_MODAL_LEADING_ACTION_CLICK,
30
+ ON_MODAL_SUPPORTING_ACTION_CLICK,
28
31
  } from './defs';
29
32
 
30
33
  // Valid values available to consumers
@@ -36,6 +39,8 @@ const componentSelector = 'pie-modal';
36
39
  * @event {CustomEvent} pie-modal-open - when the modal is opened.
37
40
  * @event {CustomEvent} pie-modal-close - when the modal is closed.
38
41
  * @event {CustomEvent} pie-modal-back - when the modal back button is clicked.
42
+ * @event {CustomEvent} pie-modal-leading-action-click - when the modal leading action is clicked.
43
+ * @event {CustomEvent} pie-modal-supporting-action-click - when the modal supporting action is clicked.
39
44
  */
40
45
  export class PieModal extends RtlMixin(LitElement) implements ModalProps {
41
46
  @property({ type: Object })
@@ -192,6 +197,16 @@ export class PieModal extends RtlMixin(LitElement) implements ModalProps {
192
197
  }
193
198
  }
194
199
 
200
+ private _handleActionClick (actionType: ModalActionType) : void {
201
+ if (actionType === 'leading') {
202
+ this._dialog?.close('leading');
203
+ this._dispatchModalCustomEvent(ON_MODAL_LEADING_ACTION_CLICK);
204
+ } else if (actionType === 'supporting') {
205
+ this._dialog?.close('supporting');
206
+ this._dispatchModalCustomEvent(ON_MODAL_SUPPORTING_ACTION_CLICK);
207
+ }
208
+ }
209
+
195
210
  /**
196
211
  * Return focus to the specified element, providing the selector is valid
197
212
  * and the chosen element can be found.
@@ -263,7 +278,7 @@ export class PieModal extends RtlMixin(LitElement) implements ModalProps {
263
278
  aria-label="${ariaLabel || nothing}"
264
279
  type="submit"
265
280
  ?isFullWidth="${this.hasStackedActions}"
266
- @click="${() => this._dialog?.close('leading')}"
281
+ @click="${() => this._handleActionClick('leading')}"
267
282
  data-test-id="modal-leading-action">
268
283
  ${text}
269
284
  </pie-button>
@@ -299,7 +314,7 @@ export class PieModal extends RtlMixin(LitElement) implements ModalProps {
299
314
  aria-label="${ariaLabel || nothing}"
300
315
  type="reset"
301
316
  ?isFullWidth="${this.hasStackedActions}"
302
- @click="${() => this._dialog?.close('supporting')}"
317
+ @click="${() => this._handleActionClick('supporting')}"
303
318
  data-test-id="modal-supporting-action">
304
319
  ${text}
305
320
  </pie-button>