@justeattakeaway/pie-modal 0.20.0 → 0.22.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/dist/react.d.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import type { CSSResult } from 'lit';
2
- import type { DependentMap } from '@justeattakeaway/pie-webc-core';
3
2
  import type { EventName } from '@lit-labs/react';
4
3
  import type { LitElement } from 'lit';
4
+ import type { PropertyValues } from 'lit';
5
5
  import type { ReactWebComponent } from '@lit-labs/react';
6
- import { RTLComponentProps } from '@justeattakeaway/pie-webc-core';
7
6
  import type { TemplateResult } from 'lit';
8
7
  import { Variant } from '@justeattakeaway/pie-button/src/defs.ts';
9
8
 
@@ -32,7 +31,7 @@ export declare const headingLevels: readonly ["h1", "h2", "h3", "h4", "h5", "h6"
32
31
 
33
32
  export declare type ModalActionType = 'leading' | 'supporting';
34
33
 
35
- export declare type ModalProps = RTLComponentProps & {
34
+ export declare type ModalProps = {
36
35
  /**
37
36
  * The ARIA labels used for the modal close and back buttons, as well as loading state.
38
37
  */
@@ -169,11 +168,10 @@ declare class PieModal_2 extends PieModal_base implements ModalProps {
169
168
  private _dialog?;
170
169
  private _backButtonClicked;
171
170
  static styles: CSSResult;
172
- constructor();
173
171
  connectedCallback(): void;
174
172
  disconnectedCallback(): void;
175
- firstUpdated(changedProperties: DependentMap<ModalProps>): void;
176
- updated(changedProperties: DependentMap<ModalProps>): void;
173
+ firstUpdated(changedProperties: PropertyValues<this>): Promise<void>;
174
+ updated(changedProperties: PropertyValues<this>): void;
177
175
  /**
178
176
  * Opens the dialog element and disables page scrolling
179
177
  */
@@ -259,7 +257,6 @@ declare class PieModal_2 extends PieModal_base implements ModalProps {
259
257
  }
260
258
 
261
259
  declare const PieModal_base: (new (...args: any[]) => {
262
- dir: "ltr" | "rtl" | "auto";
263
260
  isRTL: boolean;
264
261
  }) & typeof LitElement;
265
262
 
package/dist/react.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import * as E from "react";
2
2
  import { PieModal as C } from "./index.js";
3
- import { ON_MODAL_BACK_EVENT as b, ON_MODAL_CLOSE_EVENT as G, ON_MODAL_LEADING_ACTION_CLICK as R, ON_MODAL_OPEN_EVENT as x, ON_MODAL_SUPPORTING_ACTION_CLICK as K, headingLevels as V, positions as $, sizes as j } from "./index.js";
3
+ import { ON_MODAL_BACK_EVENT as S, ON_MODAL_CLOSE_EVENT as b, ON_MODAL_LEADING_ACTION_CLICK as G, ON_MODAL_OPEN_EVENT as R, ON_MODAL_SUPPORTING_ACTION_CLICK as x, headingLevels as K, positions as V, sizes as $ } from "./index.js";
4
4
  import "lit";
5
5
  import "lit/static-html.js";
6
6
  import "lit/decorators.js";
7
- import "lit/decorators/property.js";
8
7
  /**
9
8
  * @license
10
9
  * Copyright 2018 Google LLC
@@ -59,7 +58,7 @@ function P(c = window.React, s, p, m, h) {
59
58
  const M = i.forwardRef((d, e) => l(v, { ...d, _$Gl: e }, d == null ? void 0 : d.children));
60
59
  return M.displayName = v.displayName, M;
61
60
  }
62
- const T = P({
61
+ const w = P({
63
62
  displayName: "PieModal",
64
63
  elementClass: C,
65
64
  react: E,
@@ -78,13 +77,13 @@ const T = P({
78
77
  }
79
78
  });
80
79
  export {
81
- b as ON_MODAL_BACK_EVENT,
82
- G as ON_MODAL_CLOSE_EVENT,
83
- R as ON_MODAL_LEADING_ACTION_CLICK,
84
- x as ON_MODAL_OPEN_EVENT,
85
- K as ON_MODAL_SUPPORTING_ACTION_CLICK,
86
- T as PieModal,
87
- V as headingLevels,
88
- $ as positions,
89
- j as sizes
80
+ S as ON_MODAL_BACK_EVENT,
81
+ b as ON_MODAL_CLOSE_EVENT,
82
+ G as ON_MODAL_LEADING_ACTION_CLICK,
83
+ R as ON_MODAL_OPEN_EVENT,
84
+ x as ON_MODAL_SUPPORTING_ACTION_CLICK,
85
+ w as PieModal,
86
+ K as headingLevels,
87
+ V as positions,
88
+ $ as sizes
90
89
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-modal",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "PIE design system modal built using web components",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -37,7 +37,7 @@
37
37
  "@types/body-scroll-lock": "3.1.0"
38
38
  },
39
39
  "peerDependencies": {
40
- "body-scroll-lock": "4.0.0-beta.0"
40
+ "body-scroll-lock": "3.1.5"
41
41
  },
42
42
  "volta": {
43
43
  "extends": "../../../package.json"
package/src/defs.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { RTLComponentProps } from '@justeattakeaway/pie-webc-core';
2
1
  import { Variant } from '@justeattakeaway/pie-button/src/defs.ts';
3
2
 
4
3
  export const headingLevels = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as const;
@@ -28,7 +27,7 @@ export type ActionProps = {
28
27
  ariaLabel?: string;
29
28
  };
30
29
 
31
- export type ModalProps = RTLComponentProps & {
30
+ export type ModalProps = {
32
31
  /**
33
32
  * The ARIA labels used for the modal close and back buttons, as well as loading state.
34
33
  */
package/src/index.ts CHANGED
@@ -1,18 +1,15 @@
1
1
  import {
2
- LitElement, nothing, TemplateResult, unsafeCSS,
2
+ LitElement, nothing, TemplateResult, unsafeCSS, PropertyValues,
3
3
  } from 'lit';
4
4
  import { html, unsafeStatic } from 'lit/static-html.js';
5
5
  import { property, query } from 'lit/decorators.js';
6
6
  import {
7
7
  requiredProperty, RtlMixin, validPropertyValues,
8
8
  } from '@justeattakeaway/pie-webc-core';
9
- import type { DependentMap } from '@justeattakeaway/pie-webc-core';
10
- import { disableBodyScroll, enableBodyScroll } from 'body-scroll-lock';
11
9
  import '@justeattakeaway/pie-icons-webc/IconClose';
12
10
  import '@justeattakeaway/pie-icons-webc/IconChevronLeft';
13
11
  import '@justeattakeaway/pie-icons-webc/IconChevronRight';
14
-
15
- import dialogPolyfill from 'dialog-polyfill';
12
+ import { disableBodyScroll, enableBodyScroll } from 'body-scroll-lock';
16
13
 
17
14
  import styles from './modal.scss?inline';
18
15
  import {
@@ -100,13 +97,9 @@ export class PieModal extends RtlMixin(LitElement) implements ModalProps {
100
97
  // Renders a `CSSResult` generated from SCSS by Vite
101
98
  static styles = unsafeCSS(styles);
102
99
 
103
- constructor () {
104
- super();
105
- this.addEventListener('click', (event) => this._handleDialogLightDismiss(event));
106
- }
107
-
108
100
  connectedCallback () : void {
109
101
  super.connectedCallback();
102
+ this.addEventListener('click', (event) => this._handleDialogLightDismiss(event));
110
103
  document.addEventListener(ON_MODAL_OPEN_EVENT, this._handleModalOpened.bind(this));
111
104
  document.addEventListener(ON_MODAL_CLOSE_EVENT, this._handleModalClosed.bind(this));
112
105
  document.addEventListener(ON_MODAL_BACK_EVENT, this._handleModalClosed.bind(this));
@@ -119,8 +112,11 @@ export class PieModal extends RtlMixin(LitElement) implements ModalProps {
119
112
  super.disconnectedCallback();
120
113
  }
121
114
 
122
- firstUpdated (changedProperties: DependentMap<ModalProps>) : void {
115
+ async firstUpdated (changedProperties: PropertyValues<this>) : Promise<void> {
116
+ super.firstUpdated(changedProperties);
117
+
123
118
  if (this._dialog) {
119
+ const dialogPolyfill = await import('dialog-polyfill').then((module) => module.default);
124
120
  dialogPolyfill.registerDialog(this._dialog);
125
121
  this._dialog.addEventListener('cancel', (event) => this._handleDialogCancelEvent(event));
126
122
  this._dialog.addEventListener('close', () => {
@@ -131,7 +127,8 @@ export class PieModal extends RtlMixin(LitElement) implements ModalProps {
131
127
  this._handleModalOpenStateOnFirstRender(changedProperties);
132
128
  }
133
129
 
134
- updated (changedProperties: DependentMap<ModalProps>) : void {
130
+ updated (changedProperties: PropertyValues<this>) : void {
131
+ super.updated(changedProperties);
135
132
  this._handleModalOpenStateChanged(changedProperties);
136
133
  }
137
134
 
@@ -139,7 +136,12 @@ export class PieModal extends RtlMixin(LitElement) implements ModalProps {
139
136
  * Opens the dialog element and disables page scrolling
140
137
  */
141
138
  private _handleModalOpened () : void {
142
- disableBodyScroll(this);
139
+ const modalScrollContainer = this._dialog?.querySelector('.c-modal-scrollContainer');
140
+
141
+ if (modalScrollContainer) {
142
+ disableBodyScroll(modalScrollContainer);
143
+ }
144
+
143
145
  if (this._dialog?.hasAttribute('open') || !this._dialog?.isConnected) {
144
146
  return;
145
147
  }
@@ -151,7 +153,12 @@ export class PieModal extends RtlMixin(LitElement) implements ModalProps {
151
153
  * Closes the dialog element and re-enables page scrolling
152
154
  */
153
155
  private _handleModalClosed () : void {
154
- enableBodyScroll(this);
156
+ const modalScrollContainer = this._dialog?.querySelector('.c-modal-scrollContainer');
157
+
158
+ if (modalScrollContainer) {
159
+ enableBodyScroll(modalScrollContainer);
160
+ }
161
+
155
162
  this._dialog?.close();
156
163
  this._returnFocus();
157
164
  }
@@ -169,7 +176,7 @@ export class PieModal extends RtlMixin(LitElement) implements ModalProps {
169
176
  };
170
177
 
171
178
  // Handles the value of the isOpen property on first render of the component
172
- private _handleModalOpenStateOnFirstRender (changedProperties: DependentMap<ModalProps>) : void {
179
+ private _handleModalOpenStateOnFirstRender (changedProperties: PropertyValues<this>) : void {
173
180
  // This ensures if the modal is open on first render, the scroll lock and backdrop are applied
174
181
  const previousValue = changedProperties.get('isOpen');
175
182
 
@@ -179,7 +186,7 @@ export class PieModal extends RtlMixin(LitElement) implements ModalProps {
179
186
  }
180
187
 
181
188
  // Handles changes to the modal isOpen property by dispatching any appropriate events
182
- private _handleModalOpenStateChanged (changedProperties: DependentMap<ModalProps>) : void {
189
+ private _handleModalOpenStateChanged (changedProperties: PropertyValues<this>) : void {
183
190
  const wasPreviouslyOpen = changedProperties.get('isOpen');
184
191
 
185
192
  if (wasPreviouslyOpen !== undefined) {
@@ -327,7 +334,7 @@ export class PieModal extends RtlMixin(LitElement) implements ModalProps {
327
334
  */
328
335
  private renderModalContentAndFooter (): TemplateResult {
329
336
  return html`
330
- <article class="c-modal-content c-modal-content--scrollable">
337
+ <article class="c-modal-scrollContainer c-modal-content c-modal-content--scrollable">
331
338
  <div class="c-modal-contentInner">
332
339
  <slot></slot>
333
340
  </div>