@justeattakeaway/pie-thumbnail 0.1.0 → 0.3.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.
@@ -11,8 +11,74 @@
11
11
  {
12
12
  "kind": "javascript-module",
13
13
  "path": "src/defs.js",
14
- "declarations": [],
15
- "exports": []
14
+ "declarations": [
15
+ {
16
+ "kind": "variable",
17
+ "name": "variants",
18
+ "type": {
19
+ "text": "[\n 'default', 'outline',\n]"
20
+ },
21
+ "default": "[\n 'default', 'outline',\n]"
22
+ },
23
+ {
24
+ "kind": "variable",
25
+ "name": "backgroundColors",
26
+ "type": {
27
+ "text": "[\n 'default', 'subtle', 'strong', 'dark', 'inverse', 'inverse-alternative'\n]"
28
+ },
29
+ "default": "[\n 'default', 'subtle', 'strong', 'dark', 'inverse', 'inverse-alternative'\n]"
30
+ },
31
+ {
32
+ "kind": "variable",
33
+ "name": "backgroundColorClassNames",
34
+ "type": {
35
+ "text": "Record<typeof backgroundColors[number], string>"
36
+ },
37
+ "default": "{\n default: 'c-thumbnail--backgroundDefault',\n subtle: 'c-thumbnail--backgroundSubtle',\n strong: 'c-thumbnail--backgroundStrong',\n dark: 'c-thumbnail--backgroundDark',\n inverse: 'c-thumbnail--backgroundInverse',\n 'inverse-alternative': 'c-thumbnail--backgroundInverseAlternative',\n}"
38
+ },
39
+ {
40
+ "kind": "variable",
41
+ "name": "defaultProps",
42
+ "type": {
43
+ "text": "DefaultProps"
44
+ },
45
+ "default": "{\n variant: 'default',\n src: '',\n alt: '',\n disabled: false,\n hasPadding: false,\n backgroundColor: 'default',\n placeholder: {\n src: '',\n alt: '',\n },\n}"
46
+ }
47
+ ],
48
+ "exports": [
49
+ {
50
+ "kind": "js",
51
+ "name": "variants",
52
+ "declaration": {
53
+ "name": "variants",
54
+ "module": "src/defs.js"
55
+ }
56
+ },
57
+ {
58
+ "kind": "js",
59
+ "name": "backgroundColors",
60
+ "declaration": {
61
+ "name": "backgroundColors",
62
+ "module": "src/defs.js"
63
+ }
64
+ },
65
+ {
66
+ "kind": "js",
67
+ "name": "backgroundColorClassNames",
68
+ "declaration": {
69
+ "name": "backgroundColorClassNames",
70
+ "module": "src/defs.js"
71
+ }
72
+ },
73
+ {
74
+ "kind": "js",
75
+ "name": "defaultProps",
76
+ "declaration": {
77
+ "name": "defaultProps",
78
+ "module": "src/defs.js"
79
+ }
80
+ }
81
+ ]
16
82
  },
17
83
  {
18
84
  "kind": "javascript-module",
@@ -22,7 +88,106 @@
22
88
  "kind": "class",
23
89
  "description": "",
24
90
  "name": "PieThumbnail",
25
- "members": [],
91
+ "members": [
92
+ {
93
+ "kind": "field",
94
+ "name": "variant",
95
+ "privacy": "public",
96
+ "attribute": "variant"
97
+ },
98
+ {
99
+ "kind": "field",
100
+ "name": "src",
101
+ "privacy": "public",
102
+ "attribute": "src"
103
+ },
104
+ {
105
+ "kind": "field",
106
+ "name": "alt",
107
+ "privacy": "public",
108
+ "attribute": "alt"
109
+ },
110
+ {
111
+ "kind": "field",
112
+ "name": "disabled",
113
+ "privacy": "public",
114
+ "attribute": "disabled"
115
+ },
116
+ {
117
+ "kind": "field",
118
+ "name": "hasPadding",
119
+ "privacy": "public",
120
+ "attribute": "hasPadding"
121
+ },
122
+ {
123
+ "kind": "field",
124
+ "name": "backgroundColor",
125
+ "privacy": "public",
126
+ "attribute": "backgroundColor"
127
+ },
128
+ {
129
+ "kind": "field",
130
+ "name": "placeholder",
131
+ "type": {
132
+ "text": "ThumbnailProps['placeholder']"
133
+ },
134
+ "privacy": "public",
135
+ "attribute": "placeholder"
136
+ },
137
+ {
138
+ "kind": "field",
139
+ "name": "img",
140
+ "type": {
141
+ "text": "HTMLImageElement"
142
+ },
143
+ "privacy": "private"
144
+ },
145
+ {
146
+ "kind": "method",
147
+ "name": "_handleImageError",
148
+ "privacy": "private",
149
+ "description": "Handles image load errors by replacing the src and alt props\nwith the placeholder props."
150
+ },
151
+ {
152
+ "kind": "method",
153
+ "name": "_checkImageError",
154
+ "privacy": "private",
155
+ "description": "Detects image load status and applies the placeholder on failure.\nThis is needed as the `onerror` event is not triggered in SSR."
156
+ }
157
+ ],
158
+ "attributes": [
159
+ {
160
+ "name": "variant",
161
+ "fieldName": "variant"
162
+ },
163
+ {
164
+ "name": "src",
165
+ "fieldName": "src"
166
+ },
167
+ {
168
+ "name": "alt",
169
+ "fieldName": "alt"
170
+ },
171
+ {
172
+ "name": "disabled",
173
+ "fieldName": "disabled"
174
+ },
175
+ {
176
+ "name": "hasPadding",
177
+ "fieldName": "hasPadding"
178
+ },
179
+ {
180
+ "name": "backgroundColor",
181
+ "fieldName": "backgroundColor"
182
+ },
183
+ {
184
+ "name": "placeholder",
185
+ "type": {
186
+ "text": "ThumbnailProps['placeholder']"
187
+ },
188
+ "fieldName": "placeholder"
189
+ }
190
+ ],
26
191
  "superclass": {
27
192
  "name": "LitElement",
28
193
  "package": "lit"
package/dist/index.d.ts CHANGED
@@ -1,16 +1,58 @@
1
+ import type { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
1
2
  import type { CSSResult } from 'lit';
2
3
  import type { LitElement } from 'lit';
3
4
  import type { TemplateResult } from 'lit-html';
4
5
 
6
+ export declare const backgroundColorClassNames: Record<typeof backgroundColors[number], string>;
7
+
8
+ export declare const backgroundColors: readonly ["default", "subtle", "strong", "dark", "inverse", "inverse-alternative"];
9
+
10
+ export declare type DefaultProps = ComponentDefaultProps<ThumbnailProps, 'variant' | 'src' | 'alt' | 'disabled' | 'hasPadding' | 'backgroundColor' | 'placeholder'>;
11
+
12
+ export declare const defaultProps: DefaultProps;
13
+
5
14
  /**
6
15
  * @tagname pie-thumbnail
7
16
  */
8
17
  export declare class PieThumbnail extends LitElement implements ThumbnailProps {
18
+ variant: "default" | "outline";
19
+ src: string;
20
+ alt: string;
21
+ disabled: boolean;
22
+ hasPadding: boolean;
23
+ backgroundColor: "default" | "subtle" | "strong" | "dark" | "inverse" | "inverse-alternative";
24
+ placeholder: ThumbnailProps['placeholder'];
25
+ private img;
26
+ /**
27
+ * Handles image load errors by replacing the src and alt props
28
+ * with the placeholder props.
29
+ */
30
+ private _handleImageError;
31
+ /**
32
+ * Detects image load status and applies the placeholder on failure.
33
+ * This is needed as the `onerror` event is not triggered in SSR.
34
+ */
35
+ private _checkImageError;
36
+ protected firstUpdated(): void;
9
37
  render(): TemplateResult<1>;
10
38
  static styles: CSSResult;
11
39
  }
12
40
 
41
+ declare type PlaceholderProps = {
42
+ src?: string;
43
+ alt?: string;
44
+ };
45
+
13
46
  export declare interface ThumbnailProps {
47
+ variant?: typeof variants[number];
48
+ src?: string;
49
+ alt?: string;
50
+ disabled?: boolean;
51
+ hasPadding?: boolean;
52
+ backgroundColor?: typeof backgroundColors[number];
53
+ placeholder?: PlaceholderProps;
14
54
  }
15
55
 
56
+ export declare const variants: readonly ["default", "outline"];
57
+
16
58
  export { }
package/dist/index.js CHANGED
@@ -1,13 +1,128 @@
1
- import { LitElement as o, html as s, unsafeCSS as r } from "lit";
2
- import { defineCustomElement as n } from "@justeattakeaway/pie-webc-core";
3
- const i = "*,*:after,*:before{box-sizing:inherit}", l = "pie-thumbnail", e = class e extends o {
1
+ import { LitElement as p, html as v, unsafeCSS as f } from "lit";
2
+ import { validPropertyValues as h, defineCustomElement as k } from "@justeattakeaway/pie-webc-core";
3
+ import { classMap as y } from "lit/directives/class-map.js";
4
+ import { property as n, query as C } from "lit/decorators.js";
5
+ const S = [
6
+ "default",
7
+ "outline"
8
+ ], E = [
9
+ "default",
10
+ "subtle",
11
+ "strong",
12
+ "dark",
13
+ "inverse",
14
+ "inverse-alternative"
15
+ ], I = {
16
+ default: "c-thumbnail--backgroundDefault",
17
+ subtle: "c-thumbnail--backgroundSubtle",
18
+ strong: "c-thumbnail--backgroundStrong",
19
+ dark: "c-thumbnail--backgroundDark",
20
+ inverse: "c-thumbnail--backgroundInverse",
21
+ "inverse-alternative": "c-thumbnail--backgroundInverseAlternative"
22
+ }, e = {
23
+ variant: "default",
24
+ src: "",
25
+ alt: "",
26
+ disabled: !1,
27
+ hasPadding: !1,
28
+ backgroundColor: "default",
29
+ placeholder: {
30
+ src: "",
31
+ alt: ""
32
+ }
33
+ }, _ = ".c-thumbnail{--thumbnail-size: var(--dt-spacing-g);--thumbnail-border-radius: var(--dt-radius-rounded-b);--thumbnail-bg-color: var(--dt-color-container-default);--thumbnail-border-color: transparent;--thumbnail-padding: calc(var(--dt-spacing-a) / 2);box-sizing:border-box;overflow:hidden;width:var(--thumbnail-size);height:var(--thumbnail-size);border-radius:var(--thumbnail-border-radius);border:1px solid var(--thumbnail-border-color);background-color:var(--thumbnail-bg-color)}.c-thumbnail.c-thumbnail--outline{--thumbnail-border-color: var(--dt-color-border-default)}.c-thumbnail.c-thumbnail--disabled{opacity:.5}.c-thumbnail.c-thumbnail--backgroundSubtle{--thumbnail-bg-color: var(--dt-color-container-subtle)}.c-thumbnail.c-thumbnail--backgroundStrong{--thumbnail-bg-color: var(--dt-color-container-strong)}.c-thumbnail.c-thumbnail--backgroundDark{--thumbnail-bg-color: var(--dt-color-container-dark)}.c-thumbnail.c-thumbnail--backgroundInverse{--thumbnail-bg-color: var(--dt-color-container-inverse)}.c-thumbnail.c-thumbnail--backgroundInverseAlternative{--thumbnail-bg-color: var(--dt-color-container-inverse-alternative)}.c-thumbnail.c-thumbnail--padding{padding:var(--thumbnail-padding)}.c-thumbnail .c-thumbnail-img{width:100%;height:100%;object-fit:contain;display:block}";
34
+ var P = Object.defineProperty, i = (b, r, a, d) => {
35
+ for (var o = void 0, l = b.length - 1, c; l >= 0; l--)
36
+ (c = b[l]) && (o = c(r, a, o) || o);
37
+ return o && P(r, a, o), o;
38
+ };
39
+ const s = "pie-thumbnail", u = class u extends p {
40
+ constructor() {
41
+ super(...arguments), this.variant = e.variant, this.src = e.src, this.alt = e.alt, this.disabled = e.disabled, this.hasPadding = e.hasPadding, this.backgroundColor = e.backgroundColor, this.placeholder = e.placeholder;
42
+ }
43
+ /**
44
+ * Handles image load errors by replacing the src and alt props
45
+ * with the placeholder props.
46
+ */
47
+ _handleImageError() {
48
+ var r, a;
49
+ (r = this.placeholder) != null && r.src && this.setAttribute("src", this.placeholder.src), (a = this.placeholder) != null && a.alt && this.setAttribute("alt", this.placeholder.alt);
50
+ }
51
+ /**
52
+ * Detects image load status and applies the placeholder on failure.
53
+ * This is needed as the `onerror` event is not triggered in SSR.
54
+ */
55
+ _checkImageError() {
56
+ if (this.img) {
57
+ const { complete: r, naturalHeight: a } = this.img;
58
+ r && a === 0 && this._handleImageError.call(this);
59
+ }
60
+ }
61
+ firstUpdated() {
62
+ this._checkImageError();
63
+ }
4
64
  render() {
5
- return s`<h1 data-test-id="pie-thumbnail">Hello world!</h1>`;
65
+ const {
66
+ variant: r,
67
+ src: a,
68
+ alt: d,
69
+ disabled: o,
70
+ hasPadding: l,
71
+ backgroundColor: c,
72
+ _handleImageError: m
73
+ } = this, g = {
74
+ "c-thumbnail": !0,
75
+ [`c-thumbnail--${r}`]: !0,
76
+ [I[c]]: !0,
77
+ "c-thumbnail--disabled": o,
78
+ "c-thumbnail--padding": l
79
+ };
80
+ return v`
81
+ <div data-test-id="pie-thumbnail" class="${y(g)}">
82
+ <img
83
+ data-test-id="pie-thumbnail-img"
84
+ src="${a}"
85
+ class="c-thumbnail-img"
86
+ alt="${d}"
87
+ @error="${m}"
88
+ />
89
+ </div>
90
+ `;
6
91
  }
7
92
  };
8
- e.styles = r(i);
9
- let t = e;
10
- n(l, t);
93
+ u.styles = f(_);
94
+ let t = u;
95
+ i([
96
+ n({ type: String }),
97
+ h(s, S, e.variant)
98
+ ], t.prototype, "variant");
99
+ i([
100
+ n({ type: String })
101
+ ], t.prototype, "src");
102
+ i([
103
+ n({ type: String })
104
+ ], t.prototype, "alt");
105
+ i([
106
+ n({ type: Boolean })
107
+ ], t.prototype, "disabled");
108
+ i([
109
+ n({ type: Boolean })
110
+ ], t.prototype, "hasPadding");
111
+ i([
112
+ n({ type: String }),
113
+ h(s, E, e.backgroundColor)
114
+ ], t.prototype, "backgroundColor");
115
+ i([
116
+ n({ type: Object })
117
+ ], t.prototype, "placeholder");
118
+ i([
119
+ C("img")
120
+ ], t.prototype, "img");
121
+ k(s, t);
11
122
  export {
12
- t as PieThumbnail
123
+ t as PieThumbnail,
124
+ I as backgroundColorClassNames,
125
+ E as backgroundColors,
126
+ e as defaultProps,
127
+ S as variants
13
128
  };
package/dist/react.d.ts CHANGED
@@ -1,21 +1,63 @@
1
+ import type { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
1
2
  import type { CSSResult } from 'lit';
2
3
  import type { LitElement } from 'lit';
3
4
  import * as React_2 from 'react';
4
5
  import type { TemplateResult } from 'lit-html';
5
6
 
7
+ export declare const backgroundColorClassNames: Record<typeof backgroundColors[number], string>;
8
+
9
+ export declare const backgroundColors: readonly ["default", "subtle", "strong", "dark", "inverse", "inverse-alternative"];
10
+
11
+ export declare type DefaultProps = ComponentDefaultProps<ThumbnailProps, 'variant' | 'src' | 'alt' | 'disabled' | 'hasPadding' | 'backgroundColor' | 'placeholder'>;
12
+
13
+ export declare const defaultProps: DefaultProps;
14
+
6
15
  export declare const PieThumbnail: React_2.ForwardRefExoticComponent<ThumbnailProps & React_2.RefAttributes<PieThumbnail_2> & ReactBaseType>;
7
16
 
8
17
  /**
9
18
  * @tagname pie-thumbnail
10
19
  */
11
20
  declare class PieThumbnail_2 extends LitElement implements ThumbnailProps {
21
+ variant: "default" | "outline";
22
+ src: string;
23
+ alt: string;
24
+ disabled: boolean;
25
+ hasPadding: boolean;
26
+ backgroundColor: "default" | "subtle" | "strong" | "dark" | "inverse" | "inverse-alternative";
27
+ placeholder: ThumbnailProps['placeholder'];
28
+ private img;
29
+ /**
30
+ * Handles image load errors by replacing the src and alt props
31
+ * with the placeholder props.
32
+ */
33
+ private _handleImageError;
34
+ /**
35
+ * Detects image load status and applies the placeholder on failure.
36
+ * This is needed as the `onerror` event is not triggered in SSR.
37
+ */
38
+ private _checkImageError;
39
+ protected firstUpdated(): void;
12
40
  render(): TemplateResult<1>;
13
41
  static styles: CSSResult;
14
42
  }
15
43
 
44
+ declare type PlaceholderProps = {
45
+ src?: string;
46
+ alt?: string;
47
+ };
48
+
16
49
  declare type ReactBaseType = React_2.HTMLAttributes<HTMLElement>;
17
50
 
18
51
  export declare interface ThumbnailProps {
52
+ variant?: typeof variants[number];
53
+ src?: string;
54
+ alt?: string;
55
+ disabled?: boolean;
56
+ hasPadding?: boolean;
57
+ backgroundColor?: typeof backgroundColors[number];
58
+ placeholder?: PlaceholderProps;
19
59
  }
20
60
 
61
+ export declare const variants: readonly ["default", "outline"];
62
+
21
63
  export { }
package/dist/react.js CHANGED
@@ -1,13 +1,18 @@
1
- import * as e from "react";
2
- import { createComponent as a } from "@lit/react";
3
- import { PieThumbnail as i } from "./index.js";
4
- const m = a({
1
+ import * as a from "react";
2
+ import { createComponent as e } from "@lit/react";
3
+ import { PieThumbnail as o } from "./index.js";
4
+ import { backgroundColorClassNames as l, backgroundColors as p, defaultProps as u, variants as b } from "./index.js";
5
+ const m = e({
5
6
  displayName: "PieThumbnail",
6
- elementClass: i,
7
- react: e,
7
+ elementClass: o,
8
+ react: a,
8
9
  tagName: "pie-thumbnail",
9
10
  events: {}
10
- }), o = m;
11
+ }), r = m;
11
12
  export {
12
- o as PieThumbnail
13
+ r as PieThumbnail,
14
+ l as backgroundColorClassNames,
15
+ p as backgroundColors,
16
+ u as defaultProps,
17
+ b as variants
13
18
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-thumbnail",
3
3
  "description": "PIE Design System Thumbnail built using Web Components",
4
- "version": "0.1.0",
4
+ "version": "0.3.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -36,7 +36,7 @@
36
36
  "devDependencies": {
37
37
  "@custom-elements-manifest/analyzer": "0.9.0",
38
38
  "@justeattakeaway/pie-components-config": "0.18.0",
39
- "@justeattakeaway/pie-css": "0.13.1",
39
+ "@justeattakeaway/pie-css": "0.14.1",
40
40
  "cem-plugin-module-file-extensions": "0.0.5"
41
41
  },
42
42
  "dependencies": {
package/src/defs.ts CHANGED
@@ -1,3 +1,48 @@
1
- // TODO - please remove the eslint disable comment below when you add props to this interface
2
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
3
- export interface ThumbnailProps {}
1
+ import type { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
2
+
3
+ export const variants = [
4
+ 'default', 'outline',
5
+ ] as const;
6
+
7
+ export const backgroundColors = [
8
+ 'default', 'subtle', 'strong', 'dark', 'inverse', 'inverse-alternative'
9
+ ] as const;
10
+
11
+ export const backgroundColorClassNames: Record<typeof backgroundColors[number], string> = {
12
+ default: 'c-thumbnail--backgroundDefault',
13
+ subtle: 'c-thumbnail--backgroundSubtle',
14
+ strong: 'c-thumbnail--backgroundStrong',
15
+ dark: 'c-thumbnail--backgroundDark',
16
+ inverse: 'c-thumbnail--backgroundInverse',
17
+ 'inverse-alternative': 'c-thumbnail--backgroundInverseAlternative',
18
+ };
19
+
20
+ type PlaceholderProps = {
21
+ src?: string;
22
+ alt?: string;
23
+ }
24
+
25
+ export interface ThumbnailProps {
26
+ variant?: typeof variants[number];
27
+ src?: string;
28
+ alt?: string;
29
+ disabled?: boolean;
30
+ hasPadding?: boolean;
31
+ backgroundColor?: typeof backgroundColors[number];
32
+ placeholder?: PlaceholderProps;
33
+ }
34
+
35
+ export type DefaultProps = ComponentDefaultProps<ThumbnailProps, 'variant' | 'src' | 'alt' | 'disabled' | 'hasPadding' | 'backgroundColor' | 'placeholder'>;
36
+
37
+ export const defaultProps: DefaultProps = {
38
+ variant: 'default',
39
+ src: '',
40
+ alt: '',
41
+ disabled: false,
42
+ hasPadding: false,
43
+ backgroundColor: 'default',
44
+ placeholder: {
45
+ src: '',
46
+ alt: '',
47
+ },
48
+ };
package/src/index.ts CHANGED
@@ -1,8 +1,19 @@
1
- import { LitElement, html, unsafeCSS } from 'lit';
2
-
3
- import { defineCustomElement } from '@justeattakeaway/pie-webc-core';
1
+ import {
2
+ LitElement,
3
+ html,
4
+ unsafeCSS,
5
+ } from 'lit';
6
+ import { defineCustomElement, validPropertyValues } from '@justeattakeaway/pie-webc-core';
7
+ import { classMap } from 'lit/directives/class-map.js';
8
+ import { property, query } from 'lit/decorators.js';
9
+ import {
10
+ type ThumbnailProps,
11
+ defaultProps,
12
+ variants,
13
+ backgroundColors,
14
+ backgroundColorClassNames,
15
+ } from './defs';
4
16
  import styles from './thumbnail.scss?inline';
5
- import { type ThumbnailProps } from './defs';
6
17
 
7
18
  // Valid values available to consumers
8
19
  export * from './defs';
@@ -13,8 +24,87 @@ const componentSelector = 'pie-thumbnail';
13
24
  * @tagname pie-thumbnail
14
25
  */
15
26
  export class PieThumbnail extends LitElement implements ThumbnailProps {
27
+ @property({ type: String })
28
+ @validPropertyValues(componentSelector, variants, defaultProps.variant)
29
+ public variant = defaultProps.variant;
30
+
31
+ @property({ type: String })
32
+ public src = defaultProps.src;
33
+
34
+ @property({ type: String })
35
+ public alt = defaultProps.alt;
36
+
37
+ @property({ type: Boolean })
38
+ public disabled = defaultProps.disabled;
39
+
40
+ @property({ type: Boolean })
41
+ public hasPadding = defaultProps.hasPadding;
42
+
43
+ @property({ type: String })
44
+ @validPropertyValues(componentSelector, backgroundColors, defaultProps.backgroundColor)
45
+ public backgroundColor = defaultProps.backgroundColor;
46
+
47
+ @property({ type: Object })
48
+ public placeholder: ThumbnailProps['placeholder'] = defaultProps.placeholder;
49
+
50
+ @query('img')
51
+ private img!: HTMLImageElement;
52
+
53
+ /**
54
+ * Handles image load errors by replacing the src and alt props
55
+ * with the placeholder props.
56
+ */
57
+ private _handleImageError () {
58
+ if (this.placeholder?.src) this.setAttribute('src', this.placeholder.src);
59
+ if (this.placeholder?.alt) this.setAttribute('alt', this.placeholder.alt);
60
+ }
61
+
62
+ /**
63
+ * Detects image load status and applies the placeholder on failure.
64
+ * This is needed as the `onerror` event is not triggered in SSR.
65
+ */
66
+ private _checkImageError () {
67
+ if (this.img) {
68
+ const { complete, naturalHeight } = this.img;
69
+ const hasError = complete && naturalHeight === 0;
70
+ if (hasError) this._handleImageError.call(this);
71
+ }
72
+ }
73
+
74
+ protected firstUpdated (): void {
75
+ this._checkImageError();
76
+ }
77
+
16
78
  render () {
17
- return html`<h1 data-test-id="pie-thumbnail">Hello world!</h1>`;
79
+ const {
80
+ variant,
81
+ src,
82
+ alt,
83
+ disabled,
84
+ hasPadding,
85
+ backgroundColor,
86
+ _handleImageError,
87
+ } = this;
88
+
89
+ const wrapperClasses = {
90
+ 'c-thumbnail': true,
91
+ [`c-thumbnail--${variant}`]: true,
92
+ [backgroundColorClassNames[backgroundColor]]: true,
93
+ 'c-thumbnail--disabled': disabled,
94
+ 'c-thumbnail--padding': hasPadding,
95
+ };
96
+
97
+ return html`
98
+ <div data-test-id="pie-thumbnail" class="${classMap(wrapperClasses)}">
99
+ <img
100
+ data-test-id="pie-thumbnail-img"
101
+ src="${src}"
102
+ class="c-thumbnail-img"
103
+ alt="${alt}"
104
+ @error="${_handleImageError}"
105
+ />
106
+ </div>
107
+ `;
18
108
  }
19
109
 
20
110
  // Renders a `CSSResult` generated from SCSS by Vite
@@ -1 +1,54 @@
1
- @use '@justeattakeaway/pie-css/scss' as p;
1
+ .c-thumbnail {
2
+ --thumbnail-size: var(--dt-spacing-g);
3
+ --thumbnail-border-radius: var(--dt-radius-rounded-b);
4
+ --thumbnail-bg-color: var(--dt-color-container-default);
5
+ --thumbnail-border-color: transparent;
6
+ --thumbnail-padding: calc(var(--dt-spacing-a) / 2);
7
+
8
+ box-sizing: border-box;
9
+ overflow: hidden;
10
+ width: var(--thumbnail-size);
11
+ height: var(--thumbnail-size);
12
+ border-radius: var(--thumbnail-border-radius);
13
+ border: 1px solid var(--thumbnail-border-color);
14
+ background-color: var(--thumbnail-bg-color);
15
+
16
+ &.c-thumbnail--outline {
17
+ --thumbnail-border-color: var(--dt-color-border-default);
18
+ }
19
+
20
+ &.c-thumbnail--disabled {
21
+ opacity: 0.5;
22
+ }
23
+
24
+ &.c-thumbnail--backgroundSubtle {
25
+ --thumbnail-bg-color: var(--dt-color-container-subtle);
26
+ }
27
+
28
+ &.c-thumbnail--backgroundStrong {
29
+ --thumbnail-bg-color: var(--dt-color-container-strong);
30
+ }
31
+
32
+ &.c-thumbnail--backgroundDark {
33
+ --thumbnail-bg-color: var(--dt-color-container-dark);
34
+ }
35
+
36
+ &.c-thumbnail--backgroundInverse {
37
+ --thumbnail-bg-color: var(--dt-color-container-inverse);
38
+ }
39
+
40
+ &.c-thumbnail--backgroundInverseAlternative {
41
+ --thumbnail-bg-color: var(--dt-color-container-inverse-alternative);
42
+ }
43
+
44
+ &.c-thumbnail--padding {
45
+ padding: var(--thumbnail-padding);
46
+ }
47
+
48
+ .c-thumbnail-img {
49
+ width: 100%;
50
+ height: 100%;
51
+ object-fit: contain;
52
+ display: block;
53
+ }
54
+ }