@justeattakeaway/pie-thumbnail 0.2.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.
- package/custom-elements.json +99 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +107 -34
- package/dist/react.d.ts +30 -1
- package/dist/react.js +13 -11
- package/package.json +2 -2
- package/src/defs.ts +30 -1
- package/src/index.ts +66 -5
- package/src/thumbnail.scss +29 -0
package/custom-elements.json
CHANGED
|
@@ -20,13 +20,29 @@
|
|
|
20
20
|
},
|
|
21
21
|
"default": "[\n 'default', 'outline',\n]"
|
|
22
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
|
+
},
|
|
23
39
|
{
|
|
24
40
|
"kind": "variable",
|
|
25
41
|
"name": "defaultProps",
|
|
26
42
|
"type": {
|
|
27
43
|
"text": "DefaultProps"
|
|
28
44
|
},
|
|
29
|
-
"default": "{\n variant: 'default',\n src: '',\n alt: '',\n}"
|
|
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}"
|
|
30
46
|
}
|
|
31
47
|
],
|
|
32
48
|
"exports": [
|
|
@@ -38,6 +54,22 @@
|
|
|
38
54
|
"module": "src/defs.js"
|
|
39
55
|
}
|
|
40
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
|
+
},
|
|
41
73
|
{
|
|
42
74
|
"kind": "js",
|
|
43
75
|
"name": "defaultProps",
|
|
@@ -74,6 +106,53 @@
|
|
|
74
106
|
"name": "alt",
|
|
75
107
|
"privacy": "public",
|
|
76
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."
|
|
77
156
|
}
|
|
78
157
|
],
|
|
79
158
|
"attributes": [
|
|
@@ -88,6 +167,25 @@
|
|
|
88
167
|
{
|
|
89
168
|
"name": "alt",
|
|
90
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"
|
|
91
189
|
}
|
|
92
190
|
],
|
|
93
191
|
"superclass": {
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,11 @@ import type { CSSResult } from 'lit';
|
|
|
3
3
|
import type { LitElement } from 'lit';
|
|
4
4
|
import type { TemplateResult } from 'lit-html';
|
|
5
5
|
|
|
6
|
-
export declare
|
|
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'>;
|
|
7
11
|
|
|
8
12
|
export declare const defaultProps: DefaultProps;
|
|
9
13
|
|
|
@@ -14,14 +18,39 @@ export declare class PieThumbnail extends LitElement implements ThumbnailProps {
|
|
|
14
18
|
variant: "default" | "outline";
|
|
15
19
|
src: string;
|
|
16
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;
|
|
17
37
|
render(): TemplateResult<1>;
|
|
18
38
|
static styles: CSSResult;
|
|
19
39
|
}
|
|
20
40
|
|
|
41
|
+
declare type PlaceholderProps = {
|
|
42
|
+
src?: string;
|
|
43
|
+
alt?: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
21
46
|
export declare interface ThumbnailProps {
|
|
22
47
|
variant?: typeof variants[number];
|
|
23
48
|
src?: string;
|
|
24
49
|
alt?: string;
|
|
50
|
+
disabled?: boolean;
|
|
51
|
+
hasPadding?: boolean;
|
|
52
|
+
backgroundColor?: typeof backgroundColors[number];
|
|
53
|
+
placeholder?: PlaceholderProps;
|
|
25
54
|
}
|
|
26
55
|
|
|
27
56
|
export declare const variants: readonly ["default", "outline"];
|
package/dist/index.js
CHANGED
|
@@ -1,55 +1,128 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import { validPropertyValues as
|
|
3
|
-
import { classMap as
|
|
4
|
-
import { property as n } from "lit/decorators.js";
|
|
5
|
-
const
|
|
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
6
|
"default",
|
|
7
7
|
"outline"
|
|
8
|
-
],
|
|
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 = {
|
|
9
23
|
variant: "default",
|
|
10
24
|
src: "",
|
|
11
|
-
alt: ""
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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;
|
|
17
38
|
};
|
|
18
|
-
const
|
|
39
|
+
const s = "pie-thumbnail", u = class u extends p {
|
|
19
40
|
constructor() {
|
|
20
|
-
super(...arguments), this.variant = e.variant, this.src = e.src, this.alt = e.alt;
|
|
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();
|
|
21
63
|
}
|
|
22
64
|
render() {
|
|
23
65
|
const {
|
|
24
|
-
variant:
|
|
25
|
-
src:
|
|
26
|
-
alt:
|
|
27
|
-
|
|
66
|
+
variant: r,
|
|
67
|
+
src: a,
|
|
68
|
+
alt: d,
|
|
69
|
+
disabled: o,
|
|
70
|
+
hasPadding: l,
|
|
71
|
+
backgroundColor: c,
|
|
72
|
+
_handleImageError: m
|
|
73
|
+
} = this, g = {
|
|
28
74
|
"c-thumbnail": !0,
|
|
29
|
-
[`c-thumbnail--${
|
|
75
|
+
[`c-thumbnail--${r}`]: !0,
|
|
76
|
+
[I[c]]: !0,
|
|
77
|
+
"c-thumbnail--disabled": o,
|
|
78
|
+
"c-thumbnail--padding": l
|
|
30
79
|
};
|
|
31
|
-
return
|
|
32
|
-
<div data-test-id="pie-thumbnail" class="${g
|
|
33
|
-
<img
|
|
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
|
+
/>
|
|
34
89
|
</div>
|
|
35
90
|
`;
|
|
36
91
|
}
|
|
37
92
|
};
|
|
38
|
-
|
|
39
|
-
let
|
|
40
|
-
|
|
93
|
+
u.styles = f(_);
|
|
94
|
+
let t = u;
|
|
95
|
+
i([
|
|
41
96
|
n({ type: String }),
|
|
42
|
-
|
|
43
|
-
],
|
|
44
|
-
|
|
97
|
+
h(s, S, e.variant)
|
|
98
|
+
], t.prototype, "variant");
|
|
99
|
+
i([
|
|
45
100
|
n({ type: String })
|
|
46
|
-
],
|
|
47
|
-
|
|
101
|
+
], t.prototype, "src");
|
|
102
|
+
i([
|
|
48
103
|
n({ type: String })
|
|
49
|
-
],
|
|
50
|
-
|
|
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);
|
|
51
122
|
export {
|
|
52
|
-
|
|
123
|
+
t as PieThumbnail,
|
|
124
|
+
I as backgroundColorClassNames,
|
|
125
|
+
E as backgroundColors,
|
|
53
126
|
e as defaultProps,
|
|
54
|
-
|
|
127
|
+
S as variants
|
|
55
128
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -4,7 +4,11 @@ import type { LitElement } from 'lit';
|
|
|
4
4
|
import * as React_2 from 'react';
|
|
5
5
|
import type { TemplateResult } from 'lit-html';
|
|
6
6
|
|
|
7
|
-
export declare
|
|
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'>;
|
|
8
12
|
|
|
9
13
|
export declare const defaultProps: DefaultProps;
|
|
10
14
|
|
|
@@ -17,16 +21,41 @@ declare class PieThumbnail_2 extends LitElement implements ThumbnailProps {
|
|
|
17
21
|
variant: "default" | "outline";
|
|
18
22
|
src: string;
|
|
19
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;
|
|
20
40
|
render(): TemplateResult<1>;
|
|
21
41
|
static styles: CSSResult;
|
|
22
42
|
}
|
|
23
43
|
|
|
44
|
+
declare type PlaceholderProps = {
|
|
45
|
+
src?: string;
|
|
46
|
+
alt?: string;
|
|
47
|
+
};
|
|
48
|
+
|
|
24
49
|
declare type ReactBaseType = React_2.HTMLAttributes<HTMLElement>;
|
|
25
50
|
|
|
26
51
|
export declare interface ThumbnailProps {
|
|
27
52
|
variant?: typeof variants[number];
|
|
28
53
|
src?: string;
|
|
29
54
|
alt?: string;
|
|
55
|
+
disabled?: boolean;
|
|
56
|
+
hasPadding?: boolean;
|
|
57
|
+
backgroundColor?: typeof backgroundColors[number];
|
|
58
|
+
placeholder?: PlaceholderProps;
|
|
30
59
|
}
|
|
31
60
|
|
|
32
61
|
export declare const variants: readonly ["default", "outline"];
|
package/dist/react.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { createComponent as
|
|
3
|
-
import { PieThumbnail as
|
|
4
|
-
import { defaultProps as
|
|
5
|
-
const
|
|
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({
|
|
6
6
|
displayName: "PieThumbnail",
|
|
7
|
-
elementClass:
|
|
8
|
-
react:
|
|
7
|
+
elementClass: o,
|
|
8
|
+
react: a,
|
|
9
9
|
tagName: "pie-thumbnail",
|
|
10
10
|
events: {}
|
|
11
|
-
}),
|
|
11
|
+
}), r = m;
|
|
12
12
|
export {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
p as
|
|
13
|
+
r as PieThumbnail,
|
|
14
|
+
l as backgroundColorClassNames,
|
|
15
|
+
p as backgroundColors,
|
|
16
|
+
u as defaultProps,
|
|
17
|
+
b as variants
|
|
16
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.
|
|
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.14.
|
|
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
|
@@ -4,16 +4,45 @@ export const variants = [
|
|
|
4
4
|
'default', 'outline',
|
|
5
5
|
] as const;
|
|
6
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
|
+
|
|
7
25
|
export interface ThumbnailProps {
|
|
8
26
|
variant?: typeof variants[number];
|
|
9
27
|
src?: string;
|
|
10
28
|
alt?: string;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
hasPadding?: boolean;
|
|
31
|
+
backgroundColor?: typeof backgroundColors[number];
|
|
32
|
+
placeholder?: PlaceholderProps;
|
|
11
33
|
}
|
|
12
34
|
|
|
13
|
-
export type DefaultProps = ComponentDefaultProps<ThumbnailProps, 'variant' | 'src' | 'alt'>;
|
|
35
|
+
export type DefaultProps = ComponentDefaultProps<ThumbnailProps, 'variant' | 'src' | 'alt' | 'disabled' | 'hasPadding' | 'backgroundColor' | 'placeholder'>;
|
|
14
36
|
|
|
15
37
|
export const defaultProps: DefaultProps = {
|
|
16
38
|
variant: 'default',
|
|
17
39
|
src: '',
|
|
18
40
|
alt: '',
|
|
41
|
+
disabled: false,
|
|
42
|
+
hasPadding: false,
|
|
43
|
+
backgroundColor: 'default',
|
|
44
|
+
placeholder: {
|
|
45
|
+
src: '',
|
|
46
|
+
alt: '',
|
|
47
|
+
},
|
|
19
48
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
|
-
LitElement,
|
|
2
|
+
LitElement,
|
|
3
|
+
html,
|
|
4
|
+
unsafeCSS,
|
|
3
5
|
} from 'lit';
|
|
4
|
-
|
|
5
6
|
import { defineCustomElement, validPropertyValues } from '@justeattakeaway/pie-webc-core';
|
|
6
7
|
import { classMap } from 'lit/directives/class-map.js';
|
|
7
|
-
import { property } from 'lit/decorators.js';
|
|
8
|
-
import {
|
|
8
|
+
import { property, query } from 'lit/decorators.js';
|
|
9
|
+
import {
|
|
10
|
+
type ThumbnailProps,
|
|
11
|
+
defaultProps,
|
|
12
|
+
variants,
|
|
13
|
+
backgroundColors,
|
|
14
|
+
backgroundColorClassNames,
|
|
15
|
+
} from './defs';
|
|
9
16
|
import styles from './thumbnail.scss?inline';
|
|
10
17
|
|
|
11
18
|
// Valid values available to consumers
|
|
@@ -27,21 +34,75 @@ export class PieThumbnail extends LitElement implements ThumbnailProps {
|
|
|
27
34
|
@property({ type: String })
|
|
28
35
|
public alt = defaultProps.alt;
|
|
29
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
|
+
|
|
30
78
|
render () {
|
|
31
79
|
const {
|
|
32
80
|
variant,
|
|
33
81
|
src,
|
|
34
82
|
alt,
|
|
83
|
+
disabled,
|
|
84
|
+
hasPadding,
|
|
85
|
+
backgroundColor,
|
|
86
|
+
_handleImageError,
|
|
35
87
|
} = this;
|
|
36
88
|
|
|
37
89
|
const wrapperClasses = {
|
|
38
90
|
'c-thumbnail': true,
|
|
39
91
|
[`c-thumbnail--${variant}`]: true,
|
|
92
|
+
[backgroundColorClassNames[backgroundColor]]: true,
|
|
93
|
+
'c-thumbnail--disabled': disabled,
|
|
94
|
+
'c-thumbnail--padding': hasPadding,
|
|
40
95
|
};
|
|
41
96
|
|
|
42
97
|
return html`
|
|
43
98
|
<div data-test-id="pie-thumbnail" class="${classMap(wrapperClasses)}">
|
|
44
|
-
<img
|
|
99
|
+
<img
|
|
100
|
+
data-test-id="pie-thumbnail-img"
|
|
101
|
+
src="${src}"
|
|
102
|
+
class="c-thumbnail-img"
|
|
103
|
+
alt="${alt}"
|
|
104
|
+
@error="${_handleImageError}"
|
|
105
|
+
/>
|
|
45
106
|
</div>
|
|
46
107
|
`;
|
|
47
108
|
}
|
package/src/thumbnail.scss
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
--thumbnail-border-radius: var(--dt-radius-rounded-b);
|
|
4
4
|
--thumbnail-bg-color: var(--dt-color-container-default);
|
|
5
5
|
--thumbnail-border-color: transparent;
|
|
6
|
+
--thumbnail-padding: calc(var(--dt-spacing-a) / 2);
|
|
6
7
|
|
|
7
8
|
box-sizing: border-box;
|
|
8
9
|
overflow: hidden;
|
|
@@ -16,6 +17,34 @@
|
|
|
16
17
|
--thumbnail-border-color: var(--dt-color-border-default);
|
|
17
18
|
}
|
|
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
|
+
|
|
19
48
|
.c-thumbnail-img {
|
|
20
49
|
width: 100%;
|
|
21
50
|
height: 100%;
|