@justeattakeaway/pie-thumbnail 0.2.0 → 0.4.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 +132 -1
- package/dist/index.d.ts +59 -1
- package/dist/index.js +129 -38
- package/dist/react.d.ts +59 -1
- package/dist/react.js +14 -11
- package/package.json +2 -2
- package/src/defs.ts +65 -1
- package/src/index.ts +90 -6
- package/src/thumbnail.scss +34 -4
package/custom-elements.json
CHANGED
|
@@ -20,13 +20,34 @@
|
|
|
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
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"kind": "variable",
|
|
41
|
+
"name": "sizes",
|
|
42
|
+
"default": "Object.freeze(Array.from(\n { length: (SIZE_MAX - SIZE_MIN) / SIZE_INCREMENT_BY + 1 },\n (_, i) => SIZE_MIN + i * SIZE_INCREMENT_BY,\n))"
|
|
43
|
+
},
|
|
23
44
|
{
|
|
24
45
|
"kind": "variable",
|
|
25
46
|
"name": "defaultProps",
|
|
26
47
|
"type": {
|
|
27
48
|
"text": "DefaultProps"
|
|
28
49
|
},
|
|
29
|
-
"default": "{\n variant: 'default',\n src: '',\n alt: '',\n}"
|
|
50
|
+
"default": "{\n variant: 'default',\n size: 48,\n src: '',\n alt: '',\n disabled: false,\n hasPadding: false,\n backgroundColor: 'default',\n placeholder: {\n src: '',\n alt: '',\n },\n}"
|
|
30
51
|
}
|
|
31
52
|
],
|
|
32
53
|
"exports": [
|
|
@@ -38,6 +59,30 @@
|
|
|
38
59
|
"module": "src/defs.js"
|
|
39
60
|
}
|
|
40
61
|
},
|
|
62
|
+
{
|
|
63
|
+
"kind": "js",
|
|
64
|
+
"name": "backgroundColors",
|
|
65
|
+
"declaration": {
|
|
66
|
+
"name": "backgroundColors",
|
|
67
|
+
"module": "src/defs.js"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"kind": "js",
|
|
72
|
+
"name": "backgroundColorClassNames",
|
|
73
|
+
"declaration": {
|
|
74
|
+
"name": "backgroundColorClassNames",
|
|
75
|
+
"module": "src/defs.js"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
"kind": "js",
|
|
80
|
+
"name": "sizes",
|
|
81
|
+
"declaration": {
|
|
82
|
+
"name": "sizes",
|
|
83
|
+
"module": "src/defs.js"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
41
86
|
{
|
|
42
87
|
"kind": "js",
|
|
43
88
|
"name": "defaultProps",
|
|
@@ -63,6 +108,12 @@
|
|
|
63
108
|
"privacy": "public",
|
|
64
109
|
"attribute": "variant"
|
|
65
110
|
},
|
|
111
|
+
{
|
|
112
|
+
"kind": "field",
|
|
113
|
+
"name": "size",
|
|
114
|
+
"privacy": "public",
|
|
115
|
+
"attribute": "size"
|
|
116
|
+
},
|
|
66
117
|
{
|
|
67
118
|
"kind": "field",
|
|
68
119
|
"name": "src",
|
|
@@ -74,6 +125,63 @@
|
|
|
74
125
|
"name": "alt",
|
|
75
126
|
"privacy": "public",
|
|
76
127
|
"attribute": "alt"
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
"kind": "field",
|
|
131
|
+
"name": "disabled",
|
|
132
|
+
"privacy": "public",
|
|
133
|
+
"attribute": "disabled"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"kind": "field",
|
|
137
|
+
"name": "hasPadding",
|
|
138
|
+
"privacy": "public",
|
|
139
|
+
"attribute": "hasPadding"
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
"kind": "field",
|
|
143
|
+
"name": "backgroundColor",
|
|
144
|
+
"privacy": "public",
|
|
145
|
+
"attribute": "backgroundColor"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"kind": "field",
|
|
149
|
+
"name": "placeholder",
|
|
150
|
+
"type": {
|
|
151
|
+
"text": "ThumbnailProps['placeholder']"
|
|
152
|
+
},
|
|
153
|
+
"privacy": "public",
|
|
154
|
+
"attribute": "placeholder"
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
"kind": "field",
|
|
158
|
+
"name": "img",
|
|
159
|
+
"type": {
|
|
160
|
+
"text": "HTMLImageElement"
|
|
161
|
+
},
|
|
162
|
+
"privacy": "private"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"kind": "method",
|
|
166
|
+
"name": "_generateSizeStyles",
|
|
167
|
+
"privacy": "private",
|
|
168
|
+
"return": {
|
|
169
|
+
"type": {
|
|
170
|
+
"text": "string"
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"kind": "method",
|
|
176
|
+
"name": "_handleImageError",
|
|
177
|
+
"privacy": "private",
|
|
178
|
+
"description": "Handles image load errors by replacing the src and alt props\nwith the placeholder props."
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
"kind": "method",
|
|
182
|
+
"name": "_checkImageError",
|
|
183
|
+
"privacy": "private",
|
|
184
|
+
"description": "Detects image load status and applies the placeholder on failure.\nThis is needed as the `onerror` event is not triggered in SSR."
|
|
77
185
|
}
|
|
78
186
|
],
|
|
79
187
|
"attributes": [
|
|
@@ -81,6 +189,10 @@
|
|
|
81
189
|
"name": "variant",
|
|
82
190
|
"fieldName": "variant"
|
|
83
191
|
},
|
|
192
|
+
{
|
|
193
|
+
"name": "size",
|
|
194
|
+
"fieldName": "size"
|
|
195
|
+
},
|
|
84
196
|
{
|
|
85
197
|
"name": "src",
|
|
86
198
|
"fieldName": "src"
|
|
@@ -88,6 +200,25 @@
|
|
|
88
200
|
{
|
|
89
201
|
"name": "alt",
|
|
90
202
|
"fieldName": "alt"
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"name": "disabled",
|
|
206
|
+
"fieldName": "disabled"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"name": "hasPadding",
|
|
210
|
+
"fieldName": "hasPadding"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"name": "backgroundColor",
|
|
214
|
+
"fieldName": "backgroundColor"
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"name": "placeholder",
|
|
218
|
+
"type": {
|
|
219
|
+
"text": "ThumbnailProps['placeholder']"
|
|
220
|
+
},
|
|
221
|
+
"fieldName": "placeholder"
|
|
91
222
|
}
|
|
92
223
|
],
|
|
93
224
|
"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>;
|
|
7
11
|
|
|
8
12
|
export declare const defaultProps: DefaultProps;
|
|
9
13
|
|
|
@@ -12,16 +16,70 @@ export declare const defaultProps: DefaultProps;
|
|
|
12
16
|
*/
|
|
13
17
|
export declare class PieThumbnail extends LitElement implements ThumbnailProps {
|
|
14
18
|
variant: "default" | "outline";
|
|
19
|
+
size: number;
|
|
15
20
|
src: string;
|
|
16
21
|
alt: string;
|
|
22
|
+
disabled: boolean;
|
|
23
|
+
hasPadding: boolean;
|
|
24
|
+
backgroundColor: "default" | "subtle" | "strong" | "dark" | "inverse" | "inverse-alternative";
|
|
25
|
+
placeholder: ThumbnailProps['placeholder'];
|
|
26
|
+
private img;
|
|
27
|
+
private _generateSizeStyles;
|
|
28
|
+
/**
|
|
29
|
+
* Handles image load errors by replacing the src and alt props
|
|
30
|
+
* with the placeholder props.
|
|
31
|
+
*/
|
|
32
|
+
private _handleImageError;
|
|
33
|
+
/**
|
|
34
|
+
* Detects image load status and applies the placeholder on failure.
|
|
35
|
+
* This is needed as the `onerror` event is not triggered in SSR.
|
|
36
|
+
*/
|
|
37
|
+
private _checkImageError;
|
|
38
|
+
protected firstUpdated(): void;
|
|
17
39
|
render(): TemplateResult<1>;
|
|
18
40
|
static styles: CSSResult;
|
|
19
41
|
}
|
|
20
42
|
|
|
43
|
+
declare type PlaceholderProps = {
|
|
44
|
+
src?: string;
|
|
45
|
+
alt?: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export declare const sizes: readonly number[];
|
|
49
|
+
|
|
21
50
|
export declare interface ThumbnailProps {
|
|
51
|
+
/**
|
|
52
|
+
* What style variant the thumbnail should be such as default or outline.
|
|
53
|
+
*/
|
|
22
54
|
variant?: typeof variants[number];
|
|
55
|
+
/**
|
|
56
|
+
* Specify the size as a number between 24 and 128 (inclusive) and a multiple of 8.
|
|
57
|
+
*/
|
|
58
|
+
size?: typeof sizes[number];
|
|
59
|
+
/**
|
|
60
|
+
* The src attribute for the underlying image tag.
|
|
61
|
+
*/
|
|
23
62
|
src?: string;
|
|
63
|
+
/**
|
|
64
|
+
* The alt attribute for the underlying image tag.
|
|
65
|
+
*/
|
|
24
66
|
alt?: string;
|
|
67
|
+
/**
|
|
68
|
+
* When true, the disabled styles are applied.
|
|
69
|
+
*/
|
|
70
|
+
disabled?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* When true, an extra spacing around the thumbnail container is applied.
|
|
73
|
+
*/
|
|
74
|
+
hasPadding?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* What background color the thumbnail should be.
|
|
77
|
+
*/
|
|
78
|
+
backgroundColor?: typeof backgroundColors[number];
|
|
79
|
+
/**
|
|
80
|
+
* What placeholder should be used when the image fails to load.
|
|
81
|
+
*/
|
|
82
|
+
placeholder?: PlaceholderProps;
|
|
25
83
|
}
|
|
26
84
|
|
|
27
85
|
export declare const variants: readonly ["default", "outline"];
|
package/dist/index.js
CHANGED
|
@@ -1,55 +1,146 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import { validPropertyValues as
|
|
3
|
-
import { classMap as
|
|
4
|
-
import { property as
|
|
5
|
-
const
|
|
1
|
+
import { LitElement as f, html as y, unsafeCSS as k } from "lit";
|
|
2
|
+
import { validPropertyValues as b, defineCustomElement as S } from "@justeattakeaway/pie-webc-core";
|
|
3
|
+
import { classMap as z } from "lit/directives/class-map.js";
|
|
4
|
+
import { property as o, query as _ } from "lit/decorators.js";
|
|
5
|
+
const C = [
|
|
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
|
+
}, m = 8, g = 24, x = 128, $ = Object.freeze(Array.from(
|
|
23
|
+
{ length: (x - g) / m + 1 },
|
|
24
|
+
(c, t) => g + t * m
|
|
25
|
+
)), e = {
|
|
9
26
|
variant: "default",
|
|
27
|
+
size: 48,
|
|
10
28
|
src: "",
|
|
11
|
-
alt: ""
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
29
|
+
alt: "",
|
|
30
|
+
disabled: !1,
|
|
31
|
+
hasPadding: !1,
|
|
32
|
+
backgroundColor: "default",
|
|
33
|
+
placeholder: {
|
|
34
|
+
src: "",
|
|
35
|
+
alt: ""
|
|
36
|
+
}
|
|
37
|
+
}, P = ".c-thumbnail{--thumbnail-size: 48px;--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);display:flex;justify-content:center;align-items:center;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:auto}";
|
|
38
|
+
var A = Object.defineProperty, i = (c, t, r, u) => {
|
|
39
|
+
for (var n = void 0, l = c.length - 1, s; l >= 0; l--)
|
|
40
|
+
(s = c[l]) && (n = s(t, r, n) || n);
|
|
41
|
+
return n && A(t, r, n), n;
|
|
17
42
|
};
|
|
18
|
-
const
|
|
43
|
+
const d = "pie-thumbnail", h = class h extends f {
|
|
19
44
|
constructor() {
|
|
20
|
-
super(...arguments), this.variant = e.variant, this.src = e.src, this.alt = e.alt;
|
|
45
|
+
super(...arguments), this.variant = e.variant, this.size = e.size, this.src = e.src, this.alt = e.alt, this.disabled = e.disabled, this.hasPadding = e.hasPadding, this.backgroundColor = e.backgroundColor, this.placeholder = e.placeholder;
|
|
46
|
+
}
|
|
47
|
+
_generateSizeStyles() {
|
|
48
|
+
const { size: t } = this;
|
|
49
|
+
let r = "--dt-radius-rounded-c";
|
|
50
|
+
return t <= 40 ? r = "--dt-radius-rounded-a" : t <= 56 && (r = "--dt-radius-rounded-b"), `
|
|
51
|
+
--thumbnail-size: ${t}px;
|
|
52
|
+
--thumbnail-border-radius: var(${r});
|
|
53
|
+
`;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Handles image load errors by replacing the src and alt props
|
|
57
|
+
* with the placeholder props.
|
|
58
|
+
*/
|
|
59
|
+
_handleImageError() {
|
|
60
|
+
var t, r;
|
|
61
|
+
(t = this.placeholder) != null && t.src && this.setAttribute("src", this.placeholder.src), (r = this.placeholder) != null && r.alt && this.setAttribute("alt", this.placeholder.alt);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Detects image load status and applies the placeholder on failure.
|
|
65
|
+
* This is needed as the `onerror` event is not triggered in SSR.
|
|
66
|
+
*/
|
|
67
|
+
_checkImageError() {
|
|
68
|
+
if (this.img) {
|
|
69
|
+
const { complete: t, naturalHeight: r } = this.img;
|
|
70
|
+
t && r === 0 && this._handleImageError.call(this);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
firstUpdated() {
|
|
74
|
+
this._checkImageError();
|
|
21
75
|
}
|
|
22
76
|
render() {
|
|
23
77
|
const {
|
|
24
|
-
variant:
|
|
25
|
-
src:
|
|
26
|
-
alt: u
|
|
27
|
-
|
|
78
|
+
variant: t,
|
|
79
|
+
src: r,
|
|
80
|
+
alt: u,
|
|
81
|
+
disabled: n,
|
|
82
|
+
hasPadding: l,
|
|
83
|
+
backgroundColor: s
|
|
84
|
+
} = this, p = {
|
|
28
85
|
"c-thumbnail": !0,
|
|
29
|
-
[`c-thumbnail--${
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
86
|
+
[`c-thumbnail--${t}`]: !0,
|
|
87
|
+
[I[s]]: !0,
|
|
88
|
+
"c-thumbnail--disabled": n,
|
|
89
|
+
"c-thumbnail--padding": l
|
|
90
|
+
}, v = this._generateSizeStyles();
|
|
91
|
+
return y`
|
|
92
|
+
<div data-test-id="pie-thumbnail"
|
|
93
|
+
class="${z(p)}"
|
|
94
|
+
style="${v}">
|
|
95
|
+
<img
|
|
96
|
+
data-test-id="pie-thumbnail-img"
|
|
97
|
+
src="${r}"
|
|
98
|
+
class="c-thumbnail-img"
|
|
99
|
+
alt="${u}"
|
|
100
|
+
@error="${this._handleImageError}"
|
|
101
|
+
/>
|
|
34
102
|
</div>
|
|
35
103
|
`;
|
|
36
104
|
}
|
|
37
105
|
};
|
|
38
|
-
|
|
39
|
-
let
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
],
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
106
|
+
h.styles = k(P);
|
|
107
|
+
let a = h;
|
|
108
|
+
i([
|
|
109
|
+
o({ type: String }),
|
|
110
|
+
b(d, C, e.variant)
|
|
111
|
+
], a.prototype, "variant");
|
|
112
|
+
i([
|
|
113
|
+
o({ type: Number }),
|
|
114
|
+
b(d, $, e.size)
|
|
115
|
+
], a.prototype, "size");
|
|
116
|
+
i([
|
|
117
|
+
o({ type: String })
|
|
118
|
+
], a.prototype, "src");
|
|
119
|
+
i([
|
|
120
|
+
o({ type: String })
|
|
121
|
+
], a.prototype, "alt");
|
|
122
|
+
i([
|
|
123
|
+
o({ type: Boolean })
|
|
124
|
+
], a.prototype, "disabled");
|
|
125
|
+
i([
|
|
126
|
+
o({ type: Boolean })
|
|
127
|
+
], a.prototype, "hasPadding");
|
|
128
|
+
i([
|
|
129
|
+
o({ type: String }),
|
|
130
|
+
b(d, E, e.backgroundColor)
|
|
131
|
+
], a.prototype, "backgroundColor");
|
|
132
|
+
i([
|
|
133
|
+
o({ type: Object })
|
|
134
|
+
], a.prototype, "placeholder");
|
|
135
|
+
i([
|
|
136
|
+
_("img")
|
|
137
|
+
], a.prototype, "img");
|
|
138
|
+
S(d, a);
|
|
51
139
|
export {
|
|
52
|
-
|
|
140
|
+
a as PieThumbnail,
|
|
141
|
+
I as backgroundColorClassNames,
|
|
142
|
+
E as backgroundColors,
|
|
53
143
|
e as defaultProps,
|
|
54
|
-
|
|
144
|
+
$ as sizes,
|
|
145
|
+
C as variants
|
|
55
146
|
};
|
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>;
|
|
8
12
|
|
|
9
13
|
export declare const defaultProps: DefaultProps;
|
|
10
14
|
|
|
@@ -15,18 +19,72 @@ export declare const PieThumbnail: React_2.ForwardRefExoticComponent<ThumbnailPr
|
|
|
15
19
|
*/
|
|
16
20
|
declare class PieThumbnail_2 extends LitElement implements ThumbnailProps {
|
|
17
21
|
variant: "default" | "outline";
|
|
22
|
+
size: number;
|
|
18
23
|
src: string;
|
|
19
24
|
alt: string;
|
|
25
|
+
disabled: boolean;
|
|
26
|
+
hasPadding: boolean;
|
|
27
|
+
backgroundColor: "default" | "subtle" | "strong" | "dark" | "inverse" | "inverse-alternative";
|
|
28
|
+
placeholder: ThumbnailProps['placeholder'];
|
|
29
|
+
private img;
|
|
30
|
+
private _generateSizeStyles;
|
|
31
|
+
/**
|
|
32
|
+
* Handles image load errors by replacing the src and alt props
|
|
33
|
+
* with the placeholder props.
|
|
34
|
+
*/
|
|
35
|
+
private _handleImageError;
|
|
36
|
+
/**
|
|
37
|
+
* Detects image load status and applies the placeholder on failure.
|
|
38
|
+
* This is needed as the `onerror` event is not triggered in SSR.
|
|
39
|
+
*/
|
|
40
|
+
private _checkImageError;
|
|
41
|
+
protected firstUpdated(): void;
|
|
20
42
|
render(): TemplateResult<1>;
|
|
21
43
|
static styles: CSSResult;
|
|
22
44
|
}
|
|
23
45
|
|
|
46
|
+
declare type PlaceholderProps = {
|
|
47
|
+
src?: string;
|
|
48
|
+
alt?: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
24
51
|
declare type ReactBaseType = React_2.HTMLAttributes<HTMLElement>;
|
|
25
52
|
|
|
53
|
+
export declare const sizes: readonly number[];
|
|
54
|
+
|
|
26
55
|
export declare interface ThumbnailProps {
|
|
56
|
+
/**
|
|
57
|
+
* What style variant the thumbnail should be such as default or outline.
|
|
58
|
+
*/
|
|
27
59
|
variant?: typeof variants[number];
|
|
60
|
+
/**
|
|
61
|
+
* Specify the size as a number between 24 and 128 (inclusive) and a multiple of 8.
|
|
62
|
+
*/
|
|
63
|
+
size?: typeof sizes[number];
|
|
64
|
+
/**
|
|
65
|
+
* The src attribute for the underlying image tag.
|
|
66
|
+
*/
|
|
28
67
|
src?: string;
|
|
68
|
+
/**
|
|
69
|
+
* The alt attribute for the underlying image tag.
|
|
70
|
+
*/
|
|
29
71
|
alt?: string;
|
|
72
|
+
/**
|
|
73
|
+
* When true, the disabled styles are applied.
|
|
74
|
+
*/
|
|
75
|
+
disabled?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* When true, an extra spacing around the thumbnail container is applied.
|
|
78
|
+
*/
|
|
79
|
+
hasPadding?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* What background color the thumbnail should be.
|
|
82
|
+
*/
|
|
83
|
+
backgroundColor?: typeof backgroundColors[number];
|
|
84
|
+
/**
|
|
85
|
+
* What placeholder should be used when the image fails to load.
|
|
86
|
+
*/
|
|
87
|
+
placeholder?: PlaceholderProps;
|
|
30
88
|
}
|
|
31
89
|
|
|
32
90
|
export declare const variants: readonly ["default", "outline"];
|
package/dist/react.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { createComponent as
|
|
3
|
-
import { PieThumbnail as
|
|
4
|
-
import { defaultProps as
|
|
5
|
-
const i =
|
|
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, sizes as b, variants as c } from "./index.js";
|
|
5
|
+
const i = 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 = i;
|
|
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 sizes,
|
|
18
|
+
c as variants
|
|
16
19
|
};
|
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.4.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,80 @@ 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
|
+
const SIZE_INCREMENT_BY = 8;
|
|
21
|
+
const SIZE_MIN = 24;
|
|
22
|
+
const SIZE_MAX = 128;
|
|
23
|
+
|
|
24
|
+
export const sizes = Object.freeze(Array.from(
|
|
25
|
+
{ length: (SIZE_MAX - SIZE_MIN) / SIZE_INCREMENT_BY + 1 },
|
|
26
|
+
(_, i) => SIZE_MIN + i * SIZE_INCREMENT_BY,
|
|
27
|
+
)) as readonly number[];
|
|
28
|
+
|
|
29
|
+
type PlaceholderProps = {
|
|
30
|
+
src?: string;
|
|
31
|
+
alt?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
7
34
|
export interface ThumbnailProps {
|
|
35
|
+
/**
|
|
36
|
+
* What style variant the thumbnail should be such as default or outline.
|
|
37
|
+
*/
|
|
8
38
|
variant?: typeof variants[number];
|
|
39
|
+
/**
|
|
40
|
+
* Specify the size as a number between 24 and 128 (inclusive) and a multiple of 8.
|
|
41
|
+
*/
|
|
42
|
+
size?: typeof sizes[number];
|
|
43
|
+
/**
|
|
44
|
+
* The src attribute for the underlying image tag.
|
|
45
|
+
*/
|
|
9
46
|
src?: string;
|
|
47
|
+
/**
|
|
48
|
+
* The alt attribute for the underlying image tag.
|
|
49
|
+
*/
|
|
10
50
|
alt?: string;
|
|
51
|
+
/**
|
|
52
|
+
* When true, the disabled styles are applied.
|
|
53
|
+
*/
|
|
54
|
+
disabled?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* When true, an extra spacing around the thumbnail container is applied.
|
|
57
|
+
*/
|
|
58
|
+
hasPadding?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* What background color the thumbnail should be.
|
|
61
|
+
*/
|
|
62
|
+
backgroundColor?: typeof backgroundColors[number];
|
|
63
|
+
/**
|
|
64
|
+
* What placeholder should be used when the image fails to load.
|
|
65
|
+
*/
|
|
66
|
+
placeholder?: PlaceholderProps;
|
|
11
67
|
}
|
|
12
68
|
|
|
13
|
-
export type DefaultProps = ComponentDefaultProps<ThumbnailProps
|
|
69
|
+
export type DefaultProps = ComponentDefaultProps<ThumbnailProps>;
|
|
14
70
|
|
|
15
71
|
export const defaultProps: DefaultProps = {
|
|
16
72
|
variant: 'default',
|
|
73
|
+
size: 48,
|
|
17
74
|
src: '',
|
|
18
75
|
alt: '',
|
|
76
|
+
disabled: false,
|
|
77
|
+
hasPadding: false,
|
|
78
|
+
backgroundColor: 'default',
|
|
79
|
+
placeholder: {
|
|
80
|
+
src: '',
|
|
81
|
+
alt: '',
|
|
82
|
+
},
|
|
19
83
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
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
|
+
sizes,
|
|
16
|
+
} from './defs';
|
|
9
17
|
import styles from './thumbnail.scss?inline';
|
|
10
18
|
|
|
11
19
|
// Valid values available to consumers
|
|
@@ -21,27 +29,103 @@ export class PieThumbnail extends LitElement implements ThumbnailProps {
|
|
|
21
29
|
@validPropertyValues(componentSelector, variants, defaultProps.variant)
|
|
22
30
|
public variant = defaultProps.variant;
|
|
23
31
|
|
|
32
|
+
@property({ type: Number })
|
|
33
|
+
@validPropertyValues(componentSelector, sizes, defaultProps.size)
|
|
34
|
+
public size = defaultProps.size;
|
|
35
|
+
|
|
24
36
|
@property({ type: String })
|
|
25
37
|
public src = defaultProps.src;
|
|
26
38
|
|
|
27
39
|
@property({ type: String })
|
|
28
40
|
public alt = defaultProps.alt;
|
|
29
41
|
|
|
42
|
+
@property({ type: Boolean })
|
|
43
|
+
public disabled = defaultProps.disabled;
|
|
44
|
+
|
|
45
|
+
@property({ type: Boolean })
|
|
46
|
+
public hasPadding = defaultProps.hasPadding;
|
|
47
|
+
|
|
48
|
+
@property({ type: String })
|
|
49
|
+
@validPropertyValues(componentSelector, backgroundColors, defaultProps.backgroundColor)
|
|
50
|
+
public backgroundColor = defaultProps.backgroundColor;
|
|
51
|
+
|
|
52
|
+
@property({ type: Object })
|
|
53
|
+
public placeholder: ThumbnailProps['placeholder'] = defaultProps.placeholder;
|
|
54
|
+
|
|
55
|
+
@query('img')
|
|
56
|
+
private img!: HTMLImageElement;
|
|
57
|
+
|
|
58
|
+
private _generateSizeStyles (): string {
|
|
59
|
+
const { size } = this;
|
|
60
|
+
let borderRadius = '--dt-radius-rounded-c';
|
|
61
|
+
if (size <= 40) {
|
|
62
|
+
borderRadius = '--dt-radius-rounded-a';
|
|
63
|
+
} else if (size <= 56) {
|
|
64
|
+
borderRadius = '--dt-radius-rounded-b';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return `
|
|
68
|
+
--thumbnail-size: ${size}px;
|
|
69
|
+
--thumbnail-border-radius: var(${borderRadius});
|
|
70
|
+
`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Handles image load errors by replacing the src and alt props
|
|
75
|
+
* with the placeholder props.
|
|
76
|
+
*/
|
|
77
|
+
private _handleImageError () {
|
|
78
|
+
if (this.placeholder?.src) this.setAttribute('src', this.placeholder.src);
|
|
79
|
+
if (this.placeholder?.alt) this.setAttribute('alt', this.placeholder.alt);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Detects image load status and applies the placeholder on failure.
|
|
84
|
+
* This is needed as the `onerror` event is not triggered in SSR.
|
|
85
|
+
*/
|
|
86
|
+
private _checkImageError () {
|
|
87
|
+
if (this.img) {
|
|
88
|
+
const { complete, naturalHeight } = this.img;
|
|
89
|
+
const hasError = complete && naturalHeight === 0;
|
|
90
|
+
if (hasError) this._handleImageError.call(this);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
protected firstUpdated (): void {
|
|
95
|
+
this._checkImageError();
|
|
96
|
+
}
|
|
97
|
+
|
|
30
98
|
render () {
|
|
31
99
|
const {
|
|
32
100
|
variant,
|
|
33
101
|
src,
|
|
34
102
|
alt,
|
|
103
|
+
disabled,
|
|
104
|
+
hasPadding,
|
|
105
|
+
backgroundColor,
|
|
35
106
|
} = this;
|
|
36
107
|
|
|
37
108
|
const wrapperClasses = {
|
|
38
109
|
'c-thumbnail': true,
|
|
39
110
|
[`c-thumbnail--${variant}`]: true,
|
|
111
|
+
[backgroundColorClassNames[backgroundColor]]: true,
|
|
112
|
+
'c-thumbnail--disabled': disabled,
|
|
113
|
+
'c-thumbnail--padding': hasPadding,
|
|
40
114
|
};
|
|
41
115
|
|
|
116
|
+
const sizeStyles = this._generateSizeStyles();
|
|
117
|
+
|
|
42
118
|
return html`
|
|
43
|
-
<div data-test-id="pie-thumbnail"
|
|
44
|
-
|
|
119
|
+
<div data-test-id="pie-thumbnail"
|
|
120
|
+
class="${classMap(wrapperClasses)}"
|
|
121
|
+
style="${sizeStyles}">
|
|
122
|
+
<img
|
|
123
|
+
data-test-id="pie-thumbnail-img"
|
|
124
|
+
src="${src}"
|
|
125
|
+
class="c-thumbnail-img"
|
|
126
|
+
alt="${alt}"
|
|
127
|
+
@error="${this._handleImageError}"
|
|
128
|
+
/>
|
|
45
129
|
</div>
|
|
46
130
|
`;
|
|
47
131
|
}
|
package/src/thumbnail.scss
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
.c-thumbnail {
|
|
2
|
-
--thumbnail-size:
|
|
2
|
+
--thumbnail-size: 48px;
|
|
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
|
|
|
8
|
+
display: flex;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
align-items: center;
|
|
7
11
|
box-sizing: border-box;
|
|
8
12
|
overflow: hidden;
|
|
9
13
|
width: var(--thumbnail-size);
|
|
@@ -16,10 +20,36 @@
|
|
|
16
20
|
--thumbnail-border-color: var(--dt-color-border-default);
|
|
17
21
|
}
|
|
18
22
|
|
|
23
|
+
&.c-thumbnail--disabled {
|
|
24
|
+
opacity: 0.5;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&.c-thumbnail--backgroundSubtle {
|
|
28
|
+
--thumbnail-bg-color: var(--dt-color-container-subtle);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
&.c-thumbnail--backgroundStrong {
|
|
32
|
+
--thumbnail-bg-color: var(--dt-color-container-strong);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
&.c-thumbnail--backgroundDark {
|
|
36
|
+
--thumbnail-bg-color: var(--dt-color-container-dark);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&.c-thumbnail--backgroundInverse {
|
|
40
|
+
--thumbnail-bg-color: var(--dt-color-container-inverse);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
&.c-thumbnail--backgroundInverseAlternative {
|
|
44
|
+
--thumbnail-bg-color: var(--dt-color-container-inverse-alternative);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&.c-thumbnail--padding {
|
|
48
|
+
padding: var(--thumbnail-padding);
|
|
49
|
+
}
|
|
50
|
+
|
|
19
51
|
.c-thumbnail-img {
|
|
20
52
|
width: 100%;
|
|
21
|
-
height:
|
|
22
|
-
object-fit: contain;
|
|
23
|
-
display: block;
|
|
53
|
+
height: auto;
|
|
24
54
|
}
|
|
25
55
|
}
|