@justeattakeaway/pie-modal 0.5.0 → 0.6.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.
@@ -1,8 +1,27 @@
1
1
  export interface ModalProps {
2
+ /**
3
+ * the heading of the modal .
4
+ */
5
+ heading: string;
6
+ /**
7
+ * the rendered heading tag of the modal header.
8
+ * @default h2
9
+ */
2
10
  headingLevel: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
11
+ /**
12
+ * If `true`, the modal will be opened.
13
+ * @default false
14
+ */
15
+ isOpen?: boolean;
3
16
  }
4
17
  /**
5
18
  * Modal heading levels/tags
6
19
  */
7
- export declare const headingLevels: ModalProps['headingLevel'][];
20
+ export declare const headingLevels: Array<ModalProps['headingLevel']>;
21
+ /**
22
+ * Event name for when the modal is closed.
23
+ *
24
+ * @constant
25
+ */
26
+ export declare const ON_MODAL_CLOSE_EVENT = "pie-modal-close";
8
27
  //# sourceMappingURL=defs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../../src/defs.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACvB,YAAY,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;CACzD;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,UAAU,CAAC,cAAc,CAAC,EAAyC,CAAC"}
1
+ {"version":3,"file":"defs.d.ts","sourceRoot":"","sources":["../../../src/defs.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACvB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,YAAY,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IACtD;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,CAAwC,CAAC;AAErG;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,oBAAoB,CAAC"}
@@ -10,7 +10,16 @@ export declare class PieModal extends PieModal_base {
10
10
  isOpen: boolean;
11
11
  heading: string;
12
12
  headingLevel: ModalProps['headingLevel'];
13
- render(): import("lit-html").TemplateResult<1 | 2>;
13
+ _dialog: HTMLDialogElement;
14
+ render(): import("lit-html").TemplateResult;
15
+ _handleCloseDialog: () => void;
16
+ /**
17
+ * Dispatch `ON_MODAL_CLOSE_EVENT` event.
18
+ * To be used whenever we close the modal.
19
+ *
20
+ * @event
21
+ */
22
+ _onDialogClose: () => void;
14
23
  static styles: import("lit").CSSResult;
15
24
  }
16
25
  declare global {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAM5C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAGnD,OAAO,EAAE,KAAK,UAAU,EAAE,aAAa,EAAE,CAAC;AAE1C,QAAA,MAAM,iBAAiB,cAAc,CAAC;;;;;AAEtC,qBAAa,QAAS,SAAQ,aAAoB;IAE1C,MAAM,UAAS;IAIf,OAAO,EAAG,MAAM,CAAC;IAIjB,YAAY,EAAE,UAAU,CAAC,cAAc,CAAC,CAAQ;IAEpD,MAAM;IAoBN,MAAM,CAAC,MAAM,0BAAqB;CACrC;AAID,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,qBAAqB;QAC3B,CAAC,iBAAiB,CAAC,EAAE,QAAQ,CAAC;KACjC;CACJ"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,KAAK,CAAC;AAM5C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAwB,MAAM,QAAQ,CAAC;AAGzE,OAAO,EAAE,KAAK,UAAU,EAAE,aAAa,EAAE,CAAC;AAE1C,QAAA,MAAM,iBAAiB,cAAc,CAAC;;;;;AAEtC,qBAAa,QAAS,SAAQ,aAAoB;IAE1C,MAAM,UAAS;IAIf,OAAO,EAAG,MAAM,CAAC;IAIjB,YAAY,EAAE,UAAU,CAAC,cAAc,CAAC,CAAQ;IAGhD,OAAO,EAAE,iBAAiB,CAAC;IAE/B,MAAM;IA2BN,kBAAkB,aAGhB;IAEF;;;;;OAKG;IACH,cAAc,aAGZ;IAGF,MAAM,CAAC,MAAM,0BAAqB;CACrC;AAID,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,qBAAqB;QAC3B,CAAC,iBAAiB,CAAC,EAAE,QAAQ,CAAC;KACjC;CACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-modal",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "PIE design system modal built using web components",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -8,6 +8,8 @@
8
8
  "types": "dist/types/index.d.ts",
9
9
  "scripts": {
10
10
  "build": "yarn build:wrapper pie-modal && run -T vite build",
11
+ "lint:style": "run -T stylelint ./src/**/*.{css,scss}",
12
+ "lint:style:fix": "yarn lint:style --fix",
11
13
  "watch": "run -T vite build --watch",
12
14
  "test": "echo \"Error: no test specified\" && exit 0",
13
15
  "test:ci": "yarn test",
package/src/defs.ts CHANGED
@@ -1,8 +1,28 @@
1
1
  export interface ModalProps {
2
+ /**
3
+ * the heading of the modal .
4
+ */
5
+ heading: string;
6
+ /**
7
+ * the rendered heading tag of the modal header.
8
+ * @default h2
9
+ */
2
10
  headingLevel: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
11
+ /**
12
+ * If `true`, the modal will be opened.
13
+ * @default false
14
+ */
15
+ isOpen?: boolean;
3
16
  }
4
17
 
5
18
  /**
6
19
  * Modal heading levels/tags
7
20
  */
8
- export const headingLevels: ModalProps['headingLevel'][] = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
21
+ export const headingLevels: Array<ModalProps['headingLevel']> = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
22
+
23
+ /**
24
+ * Event name for when the modal is closed.
25
+ *
26
+ * @constant
27
+ */
28
+ export const ON_MODAL_CLOSE_EVENT = 'pie-modal-close';
package/src/index.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { LitElement, unsafeCSS } from 'lit'; // eslint-disable-line import/no-extraneous-dependencies
1
+ import { LitElement, unsafeCSS } from 'lit';
2
2
  import { html, unsafeStatic } from 'lit/static-html.js';
3
- import { property } from 'lit/decorators.js'; // eslint-disable-line import/no-extraneous-dependencies
3
+ import { property, query } from 'lit/decorators.js'; // eslint-disable-line import/no-extraneous-dependencies
4
4
  import { RtlMixin, validPropertyValues, requiredProperty } from '@justeattakeaway/pie-webc-core';
5
5
 
6
6
  import styles from './modal.scss?inline';
7
- import { ModalProps, headingLevels } from './defs';
7
+ import { ModalProps, headingLevels, ON_MODAL_CLOSE_EVENT } from './defs';
8
8
 
9
9
  // Valid values available to consumers
10
10
  export { type ModalProps, headingLevels };
@@ -23,25 +23,52 @@ export class PieModal extends RtlMixin(LitElement) {
23
23
  @validPropertyValues(componentSelector, headingLevels, 'h2')
24
24
  headingLevel: ModalProps['headingLevel'] = 'h2';
25
25
 
26
+ @query('dialog')
27
+ _dialog: HTMLDialogElement;
28
+
26
29
  render () {
27
30
  const {
28
31
  isOpen,
29
32
  heading,
30
- headingLevel,
33
+ headingLevel = 'h2',
31
34
  } = this;
32
35
 
33
36
  const headingTag = unsafeStatic(headingLevel);
34
37
 
35
38
  return html`
36
- <dialog class="c-modal" ?open="${isOpen}">
37
- <${headingTag} class="c-modal-heading">${heading}</${headingTag}>
38
- <div class="c-modal-contentWrapper">
39
- <slot></slot>
40
- </div>
39
+ <dialog id="dialog" class="c-modal" ?open="${isOpen}">
40
+ <header>
41
+ <${headingTag} class="c-modal-heading">${heading}</${headingTag}>
42
+ <pie-icon-button
43
+ @click="${this._handleCloseDialog}"
44
+ variant="ghost-tertiary"
45
+ class="c-modal-closeBtn"></pie-icon-button>
46
+ </header>
47
+ <article>
48
+ <div class="c-modal-content">
49
+ <slot></slot>
50
+ </div>
51
+ </article>
41
52
  </dialog>
42
53
  `;
43
54
  }
44
55
 
56
+ _handleCloseDialog = () => {
57
+ this._dialog.close();
58
+ this._onDialogClose();
59
+ };
60
+
61
+ /**
62
+ * Dispatch `ON_MODAL_CLOSE_EVENT` event.
63
+ * To be used whenever we close the modal.
64
+ *
65
+ * @event
66
+ */
67
+ _onDialogClose = () => {
68
+ const event = new CustomEvent(ON_MODAL_CLOSE_EVENT);
69
+ this.dispatchEvent(event);
70
+ };
71
+
45
72
  // Renders a `CSSResult` generated from SCSS by Vite
46
73
  static styles = unsafeCSS(styles);
47
74
  }
package/src/modal.scss CHANGED
@@ -1,51 +1,62 @@
1
- $modal-size-l: 1080px;
2
- $modal-size-m: 600px;
3
- $modal-size-s: 450px;
4
-
5
- $modal-border-radius: var(--dt-radius-rounded-d);
6
- $modal-font: var(--dt-font-interactive-m-family);
7
- $modal-bg-color: var(--dt-color-container-default);
8
- $modal-elevation: var(--dt-elevation-04);
9
-
10
- $modal-header-font-size: calc(var(--dt-font-heading-m-size--wide) * 1px);
11
- $modal-header-font-line-height: calc(var(--dt-font-heading-m-line-height--wide) * 1px);
12
- $modal-header-font-weight: var(--dt-font-heading-m-weight);
13
- $modal-header-padding: var(--dt-spacing-e);
14
- $modal-header-padding-block-end: var(--dt-spacing-d);
15
-
16
- $modal-contentWrapper-font-size: calc(var(--dt-font-size-16) * 1px);
17
- $modal-contentWrapper-line-height: calc(var(--dt-font-size-16-line-height) * 1px);
18
- $modal-contentWrapper-font-weight: var(--dt-font-weight-regular);
19
- $modal-contentWrapper-padding: var(--dt-spacing-e);
20
- $modal-contentWrapper-padding-block-start: var(--dt-spacing-a);
21
-
22
1
  .c-modal {
23
- border-radius: $modal-border-radius;
24
- border: none;
25
- font-family: $modal-font;
26
- background-color: $modal-bg-color;
27
-
28
- padding: 0;
29
- inline-size: $modal-size-m;
30
-
31
- box-shadow: $modal-elevation;
32
-
33
- & .c-modal-heading {
34
- font-size: $modal-header-font-size;
35
- line-height: $modal-header-font-line-height;
36
- font-weight: $modal-header-font-weight;
37
-
38
- margin: 0;
39
- padding-block: $modal-header-padding $modal-header-padding-block-end;
40
- padding-inline: $modal-header-padding;
41
- }
42
-
43
- & .c-modal-contentWrapper {
44
- font-size: $modal-contentWrapper-font-size;
45
- line-height: $modal-contentWrapper-line-height;
46
- font-weight: $modal-contentWrapper-font-weight;
47
-
48
- padding-block: $modal-contentWrapper-padding-block-start $modal-contentWrapper-padding;
49
- padding-inline: $modal-contentWrapper-padding;
50
- }
2
+ // Custom Property Declarations
3
+ // These are defined here instead of :host to encapsulate them inside Shadow DOM
4
+ --modal-size-s: 450px;
5
+ --modal-size-m: 600px;
6
+ --modal-size-l: 1080px;
7
+
8
+ // The base modal defaults
9
+ --modal-border-radius: var(--dt-radius-rounded-d);
10
+ --modal-font: var(--dt-font-interactive-m-family);
11
+ --modal-bg-color: var(--dt-color-container-default);
12
+ --modal-elevation: var(--dt-elevation-04);
13
+
14
+ border-radius: var(--modal-border-radius);
15
+ border: none;
16
+ font-family: var(--modal-font);
17
+ background-color: var(--modal-bg-color);
18
+
19
+ padding: 0;
20
+ inline-size: var(--modal-size-m);
21
+
22
+ box-shadow: var(--modal-elevation);
23
+
24
+ & .c-modal-heading {
25
+ // Modal header Custom Props
26
+ --modal-header-font-size: calc(var(--dt-font-heading-m-size--wide) * 1px);
27
+ --modal-header-font-line-height: calc(var(--dt-font-heading-m-line-height--wide) * 1px);
28
+ --modal-header-font-weight: var(--dt-font-heading-m-weight);
29
+ --modal-header-padding: var(--dt-spacing-e);
30
+ --modal-header-padding-block-end: var(--dt-spacing-d);
31
+
32
+ font-size: var(--modal-header-font-size);
33
+ line-height: var(--modal-header-font-line-height);
34
+ font-weight: var(--modal-header-font-weight);
35
+
36
+ margin: 0;
37
+ padding-block: var(--modal-header-padding) var(--modal-header-padding-block-end);
38
+ padding-inline: var(--modal-header-padding);
39
+ }
40
+
41
+ & .c-modal-content {
42
+ // Modal content Custom Props
43
+ --modal-content-font-size: calc(var(--dt-font-size-16) * 1px);
44
+ --modal-content-font-weight: var(--dt-font-weight-regular);
45
+ --modal-content-line-height: calc(var(--dt-font-size-16-line-height) * 1px);
46
+ --modal-content-padding: var(--dt-spacing-e);
47
+ --modal-content-padding-block-start: var(--dt-spacing-a);
48
+
49
+ font-size: var(--modal-content-font-size);
50
+ line-height: var(--modal-content-line-height);
51
+ font-weight: var(--modal-content-font-weight);
52
+
53
+ padding-block: var(--modal-content-padding-block-start) var(--modal-content-padding);
54
+ padding-inline: var(--modal-content-padding);
55
+ }
56
+
57
+ & .c-modal-closeBtn {
58
+ position: absolute;
59
+ right: var(--dt-spacing-d);
60
+ top: var(--dt-spacing-d);
61
+ }
51
62
  }
@@ -1,4 +1,5 @@
1
1
  import { test, expect } from '@sand4rt/experimental-ct-web';
2
+ import * as events from 'events';
2
3
  import { PieModal } from '@/index';
3
4
  import { headingLevels } from '@/defs';
4
5
 
@@ -25,3 +26,28 @@ headingLevels.forEach((headingLevel) => test(`should render the correct heading
25
26
  // h2 is the default / fallback value
26
27
  await expect(component.locator('h2.c-modal-heading')).toContainText(props.heading);
27
28
  }));
29
+
30
+ test.describe('`When the Pie Modal is closed`', () => {
31
+ test.skip('should dispatch event `pie-modal-close`', async ({ mount }) => {
32
+ const messages: string[] = [];
33
+ const component = await mount(
34
+ PieModal,
35
+ {
36
+ props: {
37
+ isOpen: true,
38
+ },
39
+ },
40
+ );
41
+
42
+ await component.update({
43
+ on: {
44
+ click: (event: string) => messages.push(event),
45
+ },
46
+ });
47
+
48
+ await component.locator('.c-modal-closeBtn').click({ });
49
+
50
+ expect(messages).toHaveLength(1);
51
+ });
52
+ });
53
+
package/vite.config.js CHANGED
@@ -1,3 +1,3 @@
1
- import viteConfig from '@justeattakeaway/pie-components-config/vite.config'; // eslint-disable-line import/no-extraneous-dependencies
1
+ import viteConfig from '@justeattakeaway/pie-components-config/vite.config';
2
2
 
3
3
  export default viteConfig;