@justeattakeaway/pie-modal 0.3.0 → 0.5.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,14 +1,14 @@
1
- [11:03:18 AM] @custom-elements-manifest/analyzer: Created new manifest.
1
+ [3:48:32 PM] @custom-elements-manifest/analyzer: Created new manifest.
2
2
  react wrapper has been added!
3
- vite v4.2.1 building for production...
3
+ vite v4.2.3 building for production...
4
4
  transforming...
5
- ✓ 17 modules transformed.
5
+ ✓ 28 modules transformed.
6
6
  rendering chunks...
7
7
  computing gzip size...
8
- dist/index.js  1.46 kB │ gzip: 0.76 kB
9
- dist/react.js 59.09 kB │ gzip: 15.93 kB
8
+ dist/index.js  5.83 kB │ gzip: 2.00 kB
9
+ dist/react.js 59.15 kB │ gzip: 15.94 kB
10
10
  
11
11
  [vite:dts] Start generate declaration files...
12
- ✓ built in 35.44s
13
- [vite:dts] Declaration files built in 33629ms.
12
+ ✓ built in 30.45s
13
+ [vite:dts] Declaration files built in 28192ms.
14
14
  
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @justeattakeaway/pie-modal
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [Updated] - enum types to string union types to string union types ([#508](https://github.com/justeattakeaway/pie/pull/508)) by [@FayeCarter](https://github.com/FayeCarter)
8
+
9
+ ## 0.4.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [Added] - `heading` and `headingLevel` props to the modal component ([#530](https://github.com/justeattakeaway/pie/pull/530)) by [@raoufswe](https://github.com/raoufswe)
14
+
15
+ - [Added] - Modal heading added to component ([#513](https://github.com/justeattakeaway/pie/pull/513)) by [@fernandofranca](https://github.com/fernandofranca)
16
+
17
+ [Added] - Basic styling for modal default state
18
+
19
+ - [Changed] - moved pie-webc-core dependency to devDependencies in each component ([#499](https://github.com/justeattakeaway/pie/pull/499)) by [@jamieomaguire](https://github.com/jamieomaguire)
20
+
21
+ - [Added] - Additional notes on visual tests and environment variables ([#525](https://github.com/justeattakeaway/pie/pull/525)) by [@jamieomaguire](https://github.com/jamieomaguire)
22
+
23
+ - [Added] prop to control modal open & close state ([#527](https://github.com/justeattakeaway/pie/pull/527)) by [@kevinrodrigues](https://github.com/kevinrodrigues)
24
+
25
+ - [Added] Read me percy config examples ([#529](https://github.com/justeattakeaway/pie/pull/529)) by [@kevinrodrigues](https://github.com/kevinrodrigues)
26
+
27
+ ### Patch Changes
28
+
29
+ - [Fixed] - PieModal CSS by adding logical property ([#521](https://github.com/justeattakeaway/pie/pull/521)) by [@fernandofranca](https://github.com/fernandofranca)
30
+
3
31
  ## 0.3.0
4
32
 
5
33
  ### Minor Changes
package/README.md CHANGED
@@ -8,6 +8,13 @@
8
8
  </a>
9
9
  </p>
10
10
 
11
+ # Table of Contents
12
+
13
+ 1. [Introduction](#pie-modal)
14
+ 2. [Local Development](#local-development)
15
+ 3. [Importing the component](#importing-the-component)
16
+ 4. [Props](#props)
17
+
11
18
  # pie-modal
12
19
 
13
20
  This modal is a Web Component built using Lit.
@@ -39,3 +46,36 @@ import { PieModal } from '@justeattakeaway/pie-button';
39
46
  // react
40
47
  import { PieModal } from '@justeattakeaway/pie-button/dist/react';
41
48
  ```
49
+
50
+ ## Props
51
+
52
+ | Property | Type | Default | Description |
53
+ |----------|-----------|---------|-------------------------------------------------|
54
+ | isOpen | `Boolean` | `false` | Controls if the modal element is open or closed |
55
+ | heading* | `String` | - | Sets the heading of the modal |
56
+ | headingLevel | `String` | `h2` | Allows you to set the heading tag (from `h1` to `h6`) |
57
+
58
+
59
+ ## Testing
60
+
61
+ ### Visual tests
62
+
63
+ Run at the root of the monorepo:
64
+ ```
65
+ yarn test:visual --filter=pie-modal
66
+ ```
67
+
68
+ Note: To run these locally, you will need to ensure that any environment variables required are set up on your machine to mirror those on CI (such as Percy tokens). How you achieve this will differ between operating systems.
69
+
70
+ ### Setup via bash:
71
+
72
+ ```
73
+ export PERCY_TOKEN_PIE_MODAL=abcde
74
+ ```
75
+
76
+ ### Setup via package.json:
77
+
78
+ Under scripts `test:visual` replace the environment variable with the below:
79
+
80
+ ```
81
+ PERCY_TOKEN_PIE_MODAL=abcde
package/dist/index.js CHANGED
@@ -1,12 +1,14 @@
1
- import { html as n, LitElement as p } from "lit";
2
- import { property as d } from "lit/decorators/property.js";
3
- var u = Object.defineProperty, f = Object.getOwnPropertyDescriptor, m = (i, e, s, t) => {
4
- for (var r = t > 1 ? void 0 : t ? f(e, s) : e, o = i.length - 1, l; o >= 0; o--)
5
- (l = i[o]) && (r = (t ? l(e, s, r) : l(r)) || r);
6
- return t && r && u(e, s, r), r;
1
+ import { unsafeCSS as h, LitElement as v, html as g } from "lit";
2
+ import { unsafeStatic as u, html as b } from "lit/static-html.js";
3
+ import { property as d } from "lit/decorators.js";
4
+ import { property as $ } from "lit/decorators/property.js";
5
+ var y = Object.defineProperty, w = Object.getOwnPropertyDescriptor, P = (s, r, n, t) => {
6
+ for (var e = t > 1 ? void 0 : t ? w(r, n) : r, o = s.length - 1, i; o >= 0; o--)
7
+ (i = s[o]) && (e = (t ? i(r, n, e) : i(e)) || e);
8
+ return t && e && y(r, n, e), e;
7
9
  };
8
- const a = (i) => {
9
- class e extends i {
10
+ const _ = (s) => {
11
+ class r extends s {
10
12
  constructor() {
11
13
  super(...arguments), this.dir = "";
12
14
  }
@@ -24,20 +26,115 @@ const a = (i) => {
24
26
  return this.dir === "ltr" ? !1 : this.dir === "rtl" || ((t = window == null ? void 0 : window.getComputedStyle(this)) == null ? void 0 : t.direction) === "rtl";
25
27
  }
26
28
  }
27
- return m([
28
- d({ type: String })
29
- ], e.prototype, "dir", 2), e;
29
+ return P([
30
+ $({ type: String })
31
+ ], r.prototype, "dir", 2), r;
32
+ }, O = (s, r, n) => function(t, e) {
33
+ const o = `#${e}`;
34
+ Object.defineProperty(t, e, {
35
+ get() {
36
+ return this[o];
37
+ },
38
+ set(i) {
39
+ const m = this[o];
40
+ r.includes(i) ? this[o] = i : (console.error(
41
+ `<${s}> Invalid value "${i}" provided for property "${e}".`,
42
+ `Must be one of: ${r.join(" | ")}.`,
43
+ `Falling back to default value: "${n}"`
44
+ ), this[o] = n), this.requestUpdate(e, m);
45
+ }
46
+ });
47
+ }, x = (s) => function(r, n) {
48
+ const t = `#${n}`;
49
+ Object.defineProperty(r, n, {
50
+ get() {
51
+ return this[t];
52
+ },
53
+ set(e) {
54
+ const o = this[t];
55
+ (e == null || e === "") && console.error(`<${s}> Missing required attribute "${n}"`), this[t] = e, this.requestUpdate(n, o);
56
+ }
57
+ });
58
+ }, C = `.c-webComponentTestWrapper{padding-block:var(--dt-spacing-c);padding-inline:var(--dt-spacing-e);font-family:var(--dt-font-interactive-m-family);font-size:calc(var(--dt-font-size-20) * 1px);border:1px solid var(--dt-color-background-dark);display:grid;grid-template-columns:1fr 1fr}.c-webComponentTestWrapper-label{margin-block:var(--dt-spacing-c)}.c-webComponentTestWrapper-slot{padding:var(--dt-spacing-c);border:1px dashed var(--dt-color-background-dark);grid-column:1/3;margin-block-start:var(--dt-spacing-c)}
59
+ `;
60
+ var T = Object.defineProperty, W = Object.getOwnPropertyDescriptor, j = (s, r, n, t) => {
61
+ for (var e = t > 1 ? void 0 : t ? W(r, n) : r, o = s.length - 1, i; o >= 0; o--)
62
+ (i = s[o]) && (e = (t ? i(r, n, e) : i(e)) || e);
63
+ return t && e && T(r, n, e), e;
30
64
  };
31
- class c extends a(p) {
65
+ class p extends v {
66
+ constructor() {
67
+ super(...arguments), this.propKeyValues = "";
68
+ }
69
+ // Renders a string such as 'size: small, isFullWidth: true'
70
+ // as HTML such as:
71
+ // <p class="c-webComponentTestWrapper-label"><b>size</b>: <code>small</code></p>
72
+ // <p class="c-webComponentTestWrapper-label"><b>isFullWidth</b>: <code>true</code></p>
73
+ _renderPropKeyValues() {
74
+ return this.propKeyValues.split(",").map((r) => {
75
+ const [n, t] = r.split(":");
76
+ return g`<p class="c-webComponentTestWrapper-label"><b>${n}</b>: <code>${t}</code></p>`;
77
+ });
78
+ }
32
79
  // eslint-disable-next-line class-methods-use-this
33
80
  render() {
34
- return n`
35
- <div>This is the Pie Modal
36
- <slot></slot>
81
+ return g`
82
+ <div class="c-webComponentTestWrapper">
83
+ ${this._renderPropKeyValues()}
84
+ <div class="c-webComponentTestWrapper-slot">
85
+ <slot></slot>
86
+ </div>
37
87
  </div>`;
38
88
  }
39
89
  }
40
- customElements.define("pie-modal", c);
90
+ p.styles = h(C);
91
+ j([
92
+ d({ type: String })
93
+ ], p.prototype, "propKeyValues", 2);
94
+ const f = "web-component-test-wrapper";
95
+ customElements.get(f) || customElements.define(f, p);
96
+ const S = `.c-modal{border-radius:var(--dt-radius-rounded-d);border:none;font-family:var(--dt-font-interactive-m-family);background-color:var(--dt-color-container-default);padding:0;inline-size:600px;box-shadow:var(--dt-elevation-04)}.c-modal .c-modal-heading{font-size:calc(var(--dt-font-heading-m-size--wide) * 1px);line-height:calc(var(--dt-font-heading-m-line-height--wide) * 1px);font-weight:var(--dt-font-heading-m-weight);margin:0;padding-block:var(--dt-spacing-e) var(--dt-spacing-d);padding-inline:var(--dt-spacing-e)}.c-modal .c-modal-contentWrapper{font-size:calc(var(--dt-font-size-16) * 1px);line-height:calc(var(--dt-font-size-16-line-height) * 1px);font-weight:var(--dt-font-weight-regular);padding-block:var(--dt-spacing-a) var(--dt-spacing-e);padding-inline:var(--dt-spacing-e)}
97
+ `, z = ["h1", "h2", "h3", "h4", "h5", "h6"];
98
+ var L = Object.defineProperty, D = Object.getOwnPropertyDescriptor, l = (s, r, n, t) => {
99
+ for (var e = t > 1 ? void 0 : t ? D(r, n) : r, o = s.length - 1, i; o >= 0; o--)
100
+ (i = s[o]) && (e = (t ? i(r, n, e) : i(e)) || e);
101
+ return t && e && L(r, n, e), e;
102
+ };
103
+ const c = "pie-modal";
104
+ class a extends _(v) {
105
+ constructor() {
106
+ super(...arguments), this.isOpen = !1, this.headingLevel = "h2";
107
+ }
108
+ render() {
109
+ const {
110
+ isOpen: r,
111
+ heading: n,
112
+ headingLevel: t
113
+ } = this, e = u(t);
114
+ return b`
115
+ <dialog class="c-modal" ?open="${r}">
116
+ <${e} class="c-modal-heading">${n}</${e}>
117
+ <div class="c-modal-contentWrapper">
118
+ <slot></slot>
119
+ </div>
120
+ </dialog>
121
+ `;
122
+ }
123
+ }
124
+ a.styles = h(S);
125
+ l([
126
+ d({ type: Boolean })
127
+ ], a.prototype, "isOpen", 2);
128
+ l([
129
+ d({ type: String }),
130
+ x(c)
131
+ ], a.prototype, "heading", 2);
132
+ l([
133
+ d(),
134
+ O(c, z, "h2")
135
+ ], a.prototype, "headingLevel", 2);
136
+ customElements.define(c, a);
41
137
  export {
42
- c as PieModal
138
+ a as PieModal,
139
+ z as headingLevels
43
140
  };
package/dist/react.js CHANGED
@@ -1,5 +1,7 @@
1
1
  import { PieModal as Ir } from "./index.js";
2
2
  import "lit";
3
+ import "lit/static-html.js";
4
+ import "lit/decorators.js";
3
5
  import "lit/decorators/property.js";
4
6
  function Nr(h, c) {
5
7
  for (var U = 0; U < c.length; U++) {
@@ -1592,7 +1594,7 @@ function Br(h = window.React, c, U, T, A) {
1592
1594
  const J = k.forwardRef((D, P) => F(H, { ...D, _$Gl: P }, D == null ? void 0 : D.children));
1593
1595
  return J.displayName = H.displayName, J;
1594
1596
  }
1595
- const Kr = Br({
1597
+ const Jr = Br({
1596
1598
  displayName: "PieModal",
1597
1599
  elementClass: Ir,
1598
1600
  react: Wr,
@@ -1600,5 +1602,5 @@ const Kr = Br({
1600
1602
  events: {}
1601
1603
  });
1602
1604
  export {
1603
- Kr as PieModal
1605
+ Jr as PieModal
1604
1606
  };
@@ -0,0 +1,8 @@
1
+ export interface ModalProps {
2
+ headingLevel: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
3
+ }
4
+ /**
5
+ * Modal heading levels/tags
6
+ */
7
+ export declare const headingLevels: ModalProps['headingLevel'][];
8
+ //# sourceMappingURL=defs.d.ts.map
@@ -0,0 +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,15 +1,21 @@
1
1
  import { LitElement } from 'lit';
2
+ import { ModalProps, headingLevels } from './defs';
3
+ export { type ModalProps, headingLevels };
4
+ declare const componentSelector = "pie-modal";
2
5
  declare const PieModal_base: (new (...args: any[]) => {
3
6
  dir: string;
4
7
  isRTL: boolean;
5
8
  }) & typeof LitElement;
6
9
  export declare class PieModal extends PieModal_base {
7
- render(): import("lit-html").TemplateResult<1>;
10
+ isOpen: boolean;
11
+ heading: string;
12
+ headingLevel: ModalProps['headingLevel'];
13
+ render(): import("lit-html").TemplateResult<1 | 2>;
14
+ static styles: import("lit").CSSResult;
8
15
  }
9
16
  declare global {
10
17
  interface HTMLElementTagNameMap {
11
- 'pie-modal': PieModal;
18
+ [componentSelector]: PieModal;
12
19
  }
13
20
  }
14
- export {};
15
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAQ,MAAM,KAAK,CAAC;;;;;AAGvC,qBAAa,QAAS,SAAQ,aAAoB;IAE9C,MAAM;CAMT;AAID,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,qBAAqB;QAC3B,WAAW,EAAE,QAAQ,CAAC;KACzB;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,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"}
package/package.json CHANGED
@@ -1,24 +1,26 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-modal",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "PIE design system modal built using web components",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
8
8
  "types": "dist/types/index.d.ts",
9
9
  "scripts": {
10
- "build": "yarn build:wrapper pie-modal && run -T vite build --config ../../../configs/pie-components-config/vite.config.js",
11
- "watch": "run -T vite build --config ../../../configs/pie-components-config/vite.config.js --watch",
10
+ "build": "yarn build:wrapper pie-modal && run -T vite build",
11
+ "watch": "run -T vite build --watch",
12
12
  "test": "echo \"Error: no test specified\" && exit 0",
13
- "test:ci": "yarn test"
13
+ "test:ci": "yarn test",
14
+ "test:browsers": "npx playwright test -c ./playwright-lit.config.ts",
15
+ "test:browsers:ci": "yarn test:browsers",
16
+ "test:visual": "run -T cross-env-shell PERCY_TOKEN=${PERCY_TOKEN_PIE_MODAL} percy exec --allowed-hostname cloudfront.net -- npx playwright test -c ./playwright-lit-visual.config.ts",
17
+ "test:visual:ci": "yarn test:visual"
14
18
  },
15
19
  "author": "JustEatTakeaway - Design System Web Team",
16
20
  "license": "Apache-2.0",
17
- "dependencies": {
18
- "@justeattakeaway/pie-webc-core": "workspace:*"
19
- },
20
21
  "devDependencies": {
21
- "@justeattakeaway/pie-components-config": "workspace:*"
22
+ "@justeattakeaway/pie-components-config": "workspace:*",
23
+ "@justeattakeaway/pie-webc-core": "workspace:*"
22
24
  },
23
25
  "volta": {
24
26
  "extends": "../../../package.json"
@@ -0,0 +1,56 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <link rel="preload" href="https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-Regular-optimised.woff2" as="font" type="font/woff2" crossorigin>
7
+ <link rel="preload" href="https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-Bold-optimised.woff2" as="font" type="font/woff2" crossorigin>
8
+ <link rel="preload" href="https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-ExtraBold-optimised.woff2" as="font" type="font/woff2" crossorigin>
9
+ <style>
10
+ @font-face {
11
+ font-family: JETSansDigital;
12
+ src: url('https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-Regular-optimised.woff2') format("woff2"),
13
+ url('https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-Regular-optimised.woff') format("woff");
14
+ font-weight: 400;
15
+ font-display: swap;
16
+ }
17
+ @font-face {
18
+ font-family: JETSansDigital;
19
+ src: url('https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-Bold-optimised.woff2') format("woff2"),
20
+ url('https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-Bold-optimised.woff') format("woff");
21
+ font-weight: 700;
22
+ font-display: swap;
23
+ }
24
+ @font-face {
25
+ font-family: JETSansDigital;
26
+ src: url('https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-ExtraBold-optimised.woff2') format("woff2"),
27
+ url('https://d30v2pzvrfyzpo.cloudfront.net/fonts/JETSansDigital-ExtraBold-optimised.woff') format("woff");
28
+ font-weight: 800;
29
+ font-display: swap;
30
+ }
31
+ body {
32
+ font-feature-settings: "tnum"; /* Enable tabular numbers */
33
+ }
34
+ /* basic styles to center align components and give them some spacing */
35
+ #root {
36
+ padding: 1em;
37
+ }
38
+
39
+ #root > * {
40
+ display: block;
41
+ margin-inline: auto;
42
+ }
43
+
44
+ #root > * + * {
45
+ margin-top: 1em;
46
+ }
47
+ </style>
48
+ <title>Testing Page</title>
49
+ <link rel="stylesheet" type="text/css" href="https://unpkg.com/@justeat/pie-design-tokens/dist/jet.css" />
50
+ <link rel="stylesheet" type="text/css" href="https://unpkg.com/@justeat/pie-design-tokens/dist/jet-hsl-colors.css" />
51
+ </head>
52
+ <body>
53
+ <div id="root"></div>
54
+ <script type="module" src="./index.ts"></script>
55
+ </body>
56
+ </html>
@@ -0,0 +1 @@
1
+ //Import common styles here
@@ -0,0 +1,5 @@
1
+ import { defineConfig } from '@sand4rt/experimental-ct-web';
2
+ import { getPlaywrightVisualConfig } from '@justeattakeaway/pie-components-config';
3
+
4
+ // @ts-ignore
5
+ export default defineConfig(getPlaywrightVisualConfig());
@@ -0,0 +1,5 @@
1
+ import { defineConfig } from '@sand4rt/experimental-ct-web';
2
+ import { getPlaywrightConfig } from '@justeattakeaway/pie-components-config'
3
+
4
+ // @ts-ignore
5
+ export default defineConfig(getPlaywrightConfig());
package/src/defs.ts ADDED
@@ -0,0 +1,8 @@
1
+ export interface ModalProps {
2
+ headingLevel: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
3
+ }
4
+
5
+ /**
6
+ * Modal heading levels/tags
7
+ */
8
+ export const headingLevels: ModalProps['headingLevel'][] = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
package/src/index.ts CHANGED
@@ -1,20 +1,55 @@
1
- import { LitElement, html } from 'lit'; // eslint-disable-line import/no-extraneous-dependencies
2
- import { RtlMixin } from '@justeattakeaway/pie-webc-core';
1
+ import { LitElement, unsafeCSS } from 'lit'; // eslint-disable-line import/no-extraneous-dependencies
2
+ import { html, unsafeStatic } from 'lit/static-html.js';
3
+ import { property } from 'lit/decorators.js'; // eslint-disable-line import/no-extraneous-dependencies
4
+ import { RtlMixin, validPropertyValues, requiredProperty } from '@justeattakeaway/pie-webc-core';
5
+
6
+ import styles from './modal.scss?inline';
7
+ import { ModalProps, headingLevels } from './defs';
8
+
9
+ // Valid values available to consumers
10
+ export { type ModalProps, headingLevels };
11
+
12
+ const componentSelector = 'pie-modal';
3
13
 
4
14
  export class PieModal extends RtlMixin(LitElement) {
5
- // eslint-disable-next-line class-methods-use-this
15
+ @property({ type: Boolean })
16
+ isOpen = false;
17
+
18
+ @property({ type: String })
19
+ @requiredProperty(componentSelector)
20
+ heading!: string;
21
+
22
+ @property()
23
+ @validPropertyValues(componentSelector, headingLevels, 'h2')
24
+ headingLevel: ModalProps['headingLevel'] = 'h2';
25
+
6
26
  render () {
27
+ const {
28
+ isOpen,
29
+ heading,
30
+ headingLevel,
31
+ } = this;
32
+
33
+ const headingTag = unsafeStatic(headingLevel);
34
+
7
35
  return html`
8
- <div>This is the Pie Modal
9
- <slot></slot>
10
- </div>`;
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>
41
+ </dialog>
42
+ `;
11
43
  }
44
+
45
+ // Renders a `CSSResult` generated from SCSS by Vite
46
+ static styles = unsafeCSS(styles);
12
47
  }
13
48
 
14
- customElements.define('pie-modal', PieModal);
49
+ customElements.define(componentSelector, PieModal);
15
50
 
16
51
  declare global {
17
52
  interface HTMLElementTagNameMap {
18
- 'pie-modal': PieModal;
53
+ [componentSelector]: PieModal;
19
54
  }
20
55
  }
package/src/modal.scss ADDED
@@ -0,0 +1,51 @@
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
+ .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
+ }
51
+ }
@@ -0,0 +1,27 @@
1
+ import { test, expect } from '@sand4rt/experimental-ct-web';
2
+ import { PieModal } from '@/index';
3
+ import { headingLevels } from '@/defs';
4
+
5
+ headingLevels.forEach((headingLevel) => test(`should render the correct heading tag based on the value of headingLevel: ${headingLevel}`, async ({ mount }) => {
6
+ const props = {
7
+ heading: 'Modal Header',
8
+ headingLevel,
9
+ };
10
+
11
+ const component = await mount(PieModal, { props });
12
+
13
+ await expect(component.locator(`${props.headingLevel}.c-modal-heading`)).toContainText(props.heading);
14
+ }));
15
+
16
+ ['span', 'section'].forEach((headingLevel) => test(`should render the fallback heading level 'h2' if invalid headingLevel: ${headingLevel} is passed`, async ({ mount }) => {
17
+ const props = {
18
+ heading: 'Modal Header',
19
+ // assert type checking as we purposely provide incorrect value
20
+ headingLevel,
21
+ };
22
+
23
+ const component = await mount(PieModal, { props });
24
+
25
+ // h2 is the default / fallback value
26
+ await expect(component.locator('h2.c-modal-heading')).toContainText(props.heading);
27
+ }));
@@ -0,0 +1,20 @@
1
+ import { test } from '@sand4rt/experimental-ct-web';
2
+ import percySnapshot from '@percy/playwright';
3
+ import { PieModal } from '@/index';
4
+ import { getLitPercyOptions } from '@justeattakeaway/pie-webc-core/src/test-helpers/percy-lit-options.ts';
5
+
6
+ const propIsOpenValues = [{ heading: 'Modal Heading', isOpen: true }, { isOpen: false }];
7
+
8
+ propIsOpenValues.forEach((props) => test(`should render Modal correctly when prop isOpen is set to ${props.isOpen}`, async ({ page, mount }) => {
9
+ await mount(
10
+ PieModal,
11
+ {
12
+ props,
13
+ slots: {
14
+ default: 'Hello, this is the Pie Modal!',
15
+ },
16
+ },
17
+ );
18
+
19
+ await percySnapshot(page, `PIE Modal when isOpen is set to ${props.isOpen}`, getLitPercyOptions());
20
+ }));
package/vite.config.js CHANGED
@@ -1,23 +1,3 @@
1
- /* eslint-disable import/no-extraneous-dependencies */
2
- import { defineConfig } from 'vite';
3
- import dts from 'vite-plugin-dts';
1
+ import viteConfig from '@justeattakeaway/pie-components-config/vite.config'; // eslint-disable-line import/no-extraneous-dependencies
4
2
 
5
- // https://vitejs.dev/config/
6
- export default defineConfig({
7
- build: {
8
- lib: {
9
- entry: {
10
- index: 'src/index.ts',
11
- react: 'src/react.ts'
12
- },
13
- formats: ['es'],
14
- },
15
- rollupOptions: {
16
- external: /^lit/,
17
- },
18
- },
19
- plugins: [dts({
20
- insertTypesEntry: true,
21
- outputDir: 'dist/types',
22
- })],
23
- });
3
+ export default viteConfig;