@justeattakeaway/pie-thumbnail 0.3.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 +34 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +74 -56
- package/dist/react.d.ts +30 -1
- package/dist/react.js +5 -4
- package/package.json +1 -1
- package/src/defs.ts +36 -1
- package/src/index.ts +26 -3
- package/src/thumbnail.scss +5 -4
package/custom-elements.json
CHANGED
|
@@ -36,13 +36,18 @@
|
|
|
36
36
|
},
|
|
37
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
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
|
+
},
|
|
39
44
|
{
|
|
40
45
|
"kind": "variable",
|
|
41
46
|
"name": "defaultProps",
|
|
42
47
|
"type": {
|
|
43
48
|
"text": "DefaultProps"
|
|
44
49
|
},
|
|
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}"
|
|
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}"
|
|
46
51
|
}
|
|
47
52
|
],
|
|
48
53
|
"exports": [
|
|
@@ -70,6 +75,14 @@
|
|
|
70
75
|
"module": "src/defs.js"
|
|
71
76
|
}
|
|
72
77
|
},
|
|
78
|
+
{
|
|
79
|
+
"kind": "js",
|
|
80
|
+
"name": "sizes",
|
|
81
|
+
"declaration": {
|
|
82
|
+
"name": "sizes",
|
|
83
|
+
"module": "src/defs.js"
|
|
84
|
+
}
|
|
85
|
+
},
|
|
73
86
|
{
|
|
74
87
|
"kind": "js",
|
|
75
88
|
"name": "defaultProps",
|
|
@@ -95,6 +108,12 @@
|
|
|
95
108
|
"privacy": "public",
|
|
96
109
|
"attribute": "variant"
|
|
97
110
|
},
|
|
111
|
+
{
|
|
112
|
+
"kind": "field",
|
|
113
|
+
"name": "size",
|
|
114
|
+
"privacy": "public",
|
|
115
|
+
"attribute": "size"
|
|
116
|
+
},
|
|
98
117
|
{
|
|
99
118
|
"kind": "field",
|
|
100
119
|
"name": "src",
|
|
@@ -142,6 +161,16 @@
|
|
|
142
161
|
},
|
|
143
162
|
"privacy": "private"
|
|
144
163
|
},
|
|
164
|
+
{
|
|
165
|
+
"kind": "method",
|
|
166
|
+
"name": "_generateSizeStyles",
|
|
167
|
+
"privacy": "private",
|
|
168
|
+
"return": {
|
|
169
|
+
"type": {
|
|
170
|
+
"text": "string"
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
},
|
|
145
174
|
{
|
|
146
175
|
"kind": "method",
|
|
147
176
|
"name": "_handleImageError",
|
|
@@ -160,6 +189,10 @@
|
|
|
160
189
|
"name": "variant",
|
|
161
190
|
"fieldName": "variant"
|
|
162
191
|
},
|
|
192
|
+
{
|
|
193
|
+
"name": "size",
|
|
194
|
+
"fieldName": "size"
|
|
195
|
+
},
|
|
163
196
|
{
|
|
164
197
|
"name": "src",
|
|
165
198
|
"fieldName": "src"
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare const backgroundColorClassNames: Record<typeof backgroundColors[n
|
|
|
7
7
|
|
|
8
8
|
export declare const backgroundColors: readonly ["default", "subtle", "strong", "dark", "inverse", "inverse-alternative"];
|
|
9
9
|
|
|
10
|
-
export declare type DefaultProps = ComponentDefaultProps<ThumbnailProps
|
|
10
|
+
export declare type DefaultProps = ComponentDefaultProps<ThumbnailProps>;
|
|
11
11
|
|
|
12
12
|
export declare const defaultProps: DefaultProps;
|
|
13
13
|
|
|
@@ -16,6 +16,7 @@ export declare const defaultProps: DefaultProps;
|
|
|
16
16
|
*/
|
|
17
17
|
export declare class PieThumbnail extends LitElement implements ThumbnailProps {
|
|
18
18
|
variant: "default" | "outline";
|
|
19
|
+
size: number;
|
|
19
20
|
src: string;
|
|
20
21
|
alt: string;
|
|
21
22
|
disabled: boolean;
|
|
@@ -23,6 +24,7 @@ export declare class PieThumbnail extends LitElement implements ThumbnailProps {
|
|
|
23
24
|
backgroundColor: "default" | "subtle" | "strong" | "dark" | "inverse" | "inverse-alternative";
|
|
24
25
|
placeholder: ThumbnailProps['placeholder'];
|
|
25
26
|
private img;
|
|
27
|
+
private _generateSizeStyles;
|
|
26
28
|
/**
|
|
27
29
|
* Handles image load errors by replacing the src and alt props
|
|
28
30
|
* with the placeholder props.
|
|
@@ -43,13 +45,40 @@ declare type PlaceholderProps = {
|
|
|
43
45
|
alt?: string;
|
|
44
46
|
};
|
|
45
47
|
|
|
48
|
+
export declare const sizes: readonly number[];
|
|
49
|
+
|
|
46
50
|
export declare interface ThumbnailProps {
|
|
51
|
+
/**
|
|
52
|
+
* What style variant the thumbnail should be such as default or outline.
|
|
53
|
+
*/
|
|
47
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
|
+
*/
|
|
48
62
|
src?: string;
|
|
63
|
+
/**
|
|
64
|
+
* The alt attribute for the underlying image tag.
|
|
65
|
+
*/
|
|
49
66
|
alt?: string;
|
|
67
|
+
/**
|
|
68
|
+
* When true, the disabled styles are applied.
|
|
69
|
+
*/
|
|
50
70
|
disabled?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* When true, an extra spacing around the thumbnail container is applied.
|
|
73
|
+
*/
|
|
51
74
|
hasPadding?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* What background color the thumbnail should be.
|
|
77
|
+
*/
|
|
52
78
|
backgroundColor?: typeof backgroundColors[number];
|
|
79
|
+
/**
|
|
80
|
+
* What placeholder should be used when the image fails to load.
|
|
81
|
+
*/
|
|
53
82
|
placeholder?: PlaceholderProps;
|
|
54
83
|
}
|
|
55
84
|
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
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 = [
|
|
@@ -19,8 +19,12 @@ const S = [
|
|
|
19
19
|
dark: "c-thumbnail--backgroundDark",
|
|
20
20
|
inverse: "c-thumbnail--backgroundInverse",
|
|
21
21
|
"inverse-alternative": "c-thumbnail--backgroundInverseAlternative"
|
|
22
|
-
},
|
|
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 = {
|
|
23
26
|
variant: "default",
|
|
27
|
+
size: 48,
|
|
24
28
|
src: "",
|
|
25
29
|
alt: "",
|
|
26
30
|
disabled: !1,
|
|
@@ -30,23 +34,31 @@ const S = [
|
|
|
30
34
|
src: "",
|
|
31
35
|
alt: ""
|
|
32
36
|
}
|
|
33
|
-
},
|
|
34
|
-
var
|
|
35
|
-
for (var
|
|
36
|
-
(
|
|
37
|
-
return
|
|
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;
|
|
38
42
|
};
|
|
39
|
-
const
|
|
43
|
+
const d = "pie-thumbnail", h = class h extends f {
|
|
40
44
|
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;
|
|
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
|
+
`;
|
|
42
54
|
}
|
|
43
55
|
/**
|
|
44
56
|
* Handles image load errors by replacing the src and alt props
|
|
45
57
|
* with the placeholder props.
|
|
46
58
|
*/
|
|
47
59
|
_handleImageError() {
|
|
48
|
-
var
|
|
49
|
-
(
|
|
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);
|
|
50
62
|
}
|
|
51
63
|
/**
|
|
52
64
|
* Detects image load status and applies the placeholder on failure.
|
|
@@ -54,8 +66,8 @@ const s = "pie-thumbnail", u = class u extends p {
|
|
|
54
66
|
*/
|
|
55
67
|
_checkImageError() {
|
|
56
68
|
if (this.img) {
|
|
57
|
-
const { complete:
|
|
58
|
-
|
|
69
|
+
const { complete: t, naturalHeight: r } = this.img;
|
|
70
|
+
t && r === 0 && this._handleImageError.call(this);
|
|
59
71
|
}
|
|
60
72
|
}
|
|
61
73
|
firstUpdated() {
|
|
@@ -63,66 +75,72 @@ const s = "pie-thumbnail", u = class u extends p {
|
|
|
63
75
|
}
|
|
64
76
|
render() {
|
|
65
77
|
const {
|
|
66
|
-
variant:
|
|
67
|
-
src:
|
|
68
|
-
alt:
|
|
69
|
-
disabled:
|
|
78
|
+
variant: t,
|
|
79
|
+
src: r,
|
|
80
|
+
alt: u,
|
|
81
|
+
disabled: n,
|
|
70
82
|
hasPadding: l,
|
|
71
|
-
backgroundColor:
|
|
72
|
-
|
|
73
|
-
} = this, g = {
|
|
83
|
+
backgroundColor: s
|
|
84
|
+
} = this, p = {
|
|
74
85
|
"c-thumbnail": !0,
|
|
75
|
-
[`c-thumbnail--${
|
|
76
|
-
[I[
|
|
77
|
-
"c-thumbnail--disabled":
|
|
86
|
+
[`c-thumbnail--${t}`]: !0,
|
|
87
|
+
[I[s]]: !0,
|
|
88
|
+
"c-thumbnail--disabled": n,
|
|
78
89
|
"c-thumbnail--padding": l
|
|
79
|
-
};
|
|
80
|
-
return
|
|
81
|
-
<div data-test-id="pie-thumbnail"
|
|
90
|
+
}, v = this._generateSizeStyles();
|
|
91
|
+
return y`
|
|
92
|
+
<div data-test-id="pie-thumbnail"
|
|
93
|
+
class="${z(p)}"
|
|
94
|
+
style="${v}">
|
|
82
95
|
<img
|
|
83
96
|
data-test-id="pie-thumbnail-img"
|
|
84
|
-
src="${
|
|
97
|
+
src="${r}"
|
|
85
98
|
class="c-thumbnail-img"
|
|
86
|
-
alt="${
|
|
87
|
-
@error="${
|
|
99
|
+
alt="${u}"
|
|
100
|
+
@error="${this._handleImageError}"
|
|
88
101
|
/>
|
|
89
102
|
</div>
|
|
90
103
|
`;
|
|
91
104
|
}
|
|
92
105
|
};
|
|
93
|
-
|
|
94
|
-
let
|
|
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");
|
|
95
112
|
i([
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
],
|
|
113
|
+
o({ type: Number }),
|
|
114
|
+
b(d, $, e.size)
|
|
115
|
+
], a.prototype, "size");
|
|
99
116
|
i([
|
|
100
|
-
|
|
101
|
-
],
|
|
117
|
+
o({ type: String })
|
|
118
|
+
], a.prototype, "src");
|
|
102
119
|
i([
|
|
103
|
-
|
|
104
|
-
],
|
|
120
|
+
o({ type: String })
|
|
121
|
+
], a.prototype, "alt");
|
|
105
122
|
i([
|
|
106
|
-
|
|
107
|
-
],
|
|
123
|
+
o({ type: Boolean })
|
|
124
|
+
], a.prototype, "disabled");
|
|
108
125
|
i([
|
|
109
|
-
|
|
110
|
-
],
|
|
126
|
+
o({ type: Boolean })
|
|
127
|
+
], a.prototype, "hasPadding");
|
|
111
128
|
i([
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
],
|
|
129
|
+
o({ type: String }),
|
|
130
|
+
b(d, E, e.backgroundColor)
|
|
131
|
+
], a.prototype, "backgroundColor");
|
|
115
132
|
i([
|
|
116
|
-
|
|
117
|
-
],
|
|
133
|
+
o({ type: Object })
|
|
134
|
+
], a.prototype, "placeholder");
|
|
118
135
|
i([
|
|
119
|
-
|
|
120
|
-
],
|
|
121
|
-
|
|
136
|
+
_("img")
|
|
137
|
+
], a.prototype, "img");
|
|
138
|
+
S(d, a);
|
|
122
139
|
export {
|
|
123
|
-
|
|
140
|
+
a as PieThumbnail,
|
|
124
141
|
I as backgroundColorClassNames,
|
|
125
142
|
E as backgroundColors,
|
|
126
143
|
e as defaultProps,
|
|
127
|
-
|
|
144
|
+
$ as sizes,
|
|
145
|
+
C as variants
|
|
128
146
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare const backgroundColorClassNames: Record<typeof backgroundColors[n
|
|
|
8
8
|
|
|
9
9
|
export declare const backgroundColors: readonly ["default", "subtle", "strong", "dark", "inverse", "inverse-alternative"];
|
|
10
10
|
|
|
11
|
-
export declare type DefaultProps = ComponentDefaultProps<ThumbnailProps
|
|
11
|
+
export declare type DefaultProps = ComponentDefaultProps<ThumbnailProps>;
|
|
12
12
|
|
|
13
13
|
export declare const defaultProps: DefaultProps;
|
|
14
14
|
|
|
@@ -19,6 +19,7 @@ export declare const PieThumbnail: React_2.ForwardRefExoticComponent<ThumbnailPr
|
|
|
19
19
|
*/
|
|
20
20
|
declare class PieThumbnail_2 extends LitElement implements ThumbnailProps {
|
|
21
21
|
variant: "default" | "outline";
|
|
22
|
+
size: number;
|
|
22
23
|
src: string;
|
|
23
24
|
alt: string;
|
|
24
25
|
disabled: boolean;
|
|
@@ -26,6 +27,7 @@ declare class PieThumbnail_2 extends LitElement implements ThumbnailProps {
|
|
|
26
27
|
backgroundColor: "default" | "subtle" | "strong" | "dark" | "inverse" | "inverse-alternative";
|
|
27
28
|
placeholder: ThumbnailProps['placeholder'];
|
|
28
29
|
private img;
|
|
30
|
+
private _generateSizeStyles;
|
|
29
31
|
/**
|
|
30
32
|
* Handles image load errors by replacing the src and alt props
|
|
31
33
|
* with the placeholder props.
|
|
@@ -48,13 +50,40 @@ declare type PlaceholderProps = {
|
|
|
48
50
|
|
|
49
51
|
declare type ReactBaseType = React_2.HTMLAttributes<HTMLElement>;
|
|
50
52
|
|
|
53
|
+
export declare const sizes: readonly number[];
|
|
54
|
+
|
|
51
55
|
export declare interface ThumbnailProps {
|
|
56
|
+
/**
|
|
57
|
+
* What style variant the thumbnail should be such as default or outline.
|
|
58
|
+
*/
|
|
52
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
|
+
*/
|
|
53
67
|
src?: string;
|
|
68
|
+
/**
|
|
69
|
+
* The alt attribute for the underlying image tag.
|
|
70
|
+
*/
|
|
54
71
|
alt?: string;
|
|
72
|
+
/**
|
|
73
|
+
* When true, the disabled styles are applied.
|
|
74
|
+
*/
|
|
55
75
|
disabled?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* When true, an extra spacing around the thumbnail container is applied.
|
|
78
|
+
*/
|
|
56
79
|
hasPadding?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* What background color the thumbnail should be.
|
|
82
|
+
*/
|
|
57
83
|
backgroundColor?: typeof backgroundColors[number];
|
|
84
|
+
/**
|
|
85
|
+
* What placeholder should be used when the image fails to load.
|
|
86
|
+
*/
|
|
58
87
|
placeholder?: PlaceholderProps;
|
|
59
88
|
}
|
|
60
89
|
|
package/dist/react.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import * as a from "react";
|
|
2
2
|
import { createComponent as e } from "@lit/react";
|
|
3
3
|
import { PieThumbnail as o } from "./index.js";
|
|
4
|
-
import { backgroundColorClassNames as l, backgroundColors as p, defaultProps as u,
|
|
5
|
-
const
|
|
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
7
|
elementClass: o,
|
|
8
8
|
react: a,
|
|
9
9
|
tagName: "pie-thumbnail",
|
|
10
10
|
events: {}
|
|
11
|
-
}), r =
|
|
11
|
+
}), r = i;
|
|
12
12
|
export {
|
|
13
13
|
r as PieThumbnail,
|
|
14
14
|
l as backgroundColorClassNames,
|
|
15
15
|
p as backgroundColors,
|
|
16
16
|
u as defaultProps,
|
|
17
|
-
b as
|
|
17
|
+
b as sizes,
|
|
18
|
+
c as variants
|
|
18
19
|
};
|
package/package.json
CHANGED
package/src/defs.ts
CHANGED
|
@@ -17,25 +17,60 @@ export const backgroundColorClassNames: Record<typeof backgroundColors[number],
|
|
|
17
17
|
'inverse-alternative': 'c-thumbnail--backgroundInverseAlternative',
|
|
18
18
|
};
|
|
19
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
|
+
|
|
20
29
|
type PlaceholderProps = {
|
|
21
30
|
src?: string;
|
|
22
31
|
alt?: string;
|
|
23
32
|
}
|
|
24
33
|
|
|
25
34
|
export interface ThumbnailProps {
|
|
35
|
+
/**
|
|
36
|
+
* What style variant the thumbnail should be such as default or outline.
|
|
37
|
+
*/
|
|
26
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
|
+
*/
|
|
27
46
|
src?: string;
|
|
47
|
+
/**
|
|
48
|
+
* The alt attribute for the underlying image tag.
|
|
49
|
+
*/
|
|
28
50
|
alt?: string;
|
|
51
|
+
/**
|
|
52
|
+
* When true, the disabled styles are applied.
|
|
53
|
+
*/
|
|
29
54
|
disabled?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* When true, an extra spacing around the thumbnail container is applied.
|
|
57
|
+
*/
|
|
30
58
|
hasPadding?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* What background color the thumbnail should be.
|
|
61
|
+
*/
|
|
31
62
|
backgroundColor?: typeof backgroundColors[number];
|
|
63
|
+
/**
|
|
64
|
+
* What placeholder should be used when the image fails to load.
|
|
65
|
+
*/
|
|
32
66
|
placeholder?: PlaceholderProps;
|
|
33
67
|
}
|
|
34
68
|
|
|
35
|
-
export type DefaultProps = ComponentDefaultProps<ThumbnailProps
|
|
69
|
+
export type DefaultProps = ComponentDefaultProps<ThumbnailProps>;
|
|
36
70
|
|
|
37
71
|
export const defaultProps: DefaultProps = {
|
|
38
72
|
variant: 'default',
|
|
73
|
+
size: 48,
|
|
39
74
|
src: '',
|
|
40
75
|
alt: '',
|
|
41
76
|
disabled: false,
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
variants,
|
|
13
13
|
backgroundColors,
|
|
14
14
|
backgroundColorClassNames,
|
|
15
|
+
sizes,
|
|
15
16
|
} from './defs';
|
|
16
17
|
import styles from './thumbnail.scss?inline';
|
|
17
18
|
|
|
@@ -28,6 +29,10 @@ export class PieThumbnail extends LitElement implements ThumbnailProps {
|
|
|
28
29
|
@validPropertyValues(componentSelector, variants, defaultProps.variant)
|
|
29
30
|
public variant = defaultProps.variant;
|
|
30
31
|
|
|
32
|
+
@property({ type: Number })
|
|
33
|
+
@validPropertyValues(componentSelector, sizes, defaultProps.size)
|
|
34
|
+
public size = defaultProps.size;
|
|
35
|
+
|
|
31
36
|
@property({ type: String })
|
|
32
37
|
public src = defaultProps.src;
|
|
33
38
|
|
|
@@ -50,6 +55,21 @@ export class PieThumbnail extends LitElement implements ThumbnailProps {
|
|
|
50
55
|
@query('img')
|
|
51
56
|
private img!: HTMLImageElement;
|
|
52
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
|
+
|
|
53
73
|
/**
|
|
54
74
|
* Handles image load errors by replacing the src and alt props
|
|
55
75
|
* with the placeholder props.
|
|
@@ -83,7 +103,6 @@ export class PieThumbnail extends LitElement implements ThumbnailProps {
|
|
|
83
103
|
disabled,
|
|
84
104
|
hasPadding,
|
|
85
105
|
backgroundColor,
|
|
86
|
-
_handleImageError,
|
|
87
106
|
} = this;
|
|
88
107
|
|
|
89
108
|
const wrapperClasses = {
|
|
@@ -94,14 +113,18 @@ export class PieThumbnail extends LitElement implements ThumbnailProps {
|
|
|
94
113
|
'c-thumbnail--padding': hasPadding,
|
|
95
114
|
};
|
|
96
115
|
|
|
116
|
+
const sizeStyles = this._generateSizeStyles();
|
|
117
|
+
|
|
97
118
|
return html`
|
|
98
|
-
<div data-test-id="pie-thumbnail"
|
|
119
|
+
<div data-test-id="pie-thumbnail"
|
|
120
|
+
class="${classMap(wrapperClasses)}"
|
|
121
|
+
style="${sizeStyles}">
|
|
99
122
|
<img
|
|
100
123
|
data-test-id="pie-thumbnail-img"
|
|
101
124
|
src="${src}"
|
|
102
125
|
class="c-thumbnail-img"
|
|
103
126
|
alt="${alt}"
|
|
104
|
-
@error="${_handleImageError}"
|
|
127
|
+
@error="${this._handleImageError}"
|
|
105
128
|
/>
|
|
106
129
|
</div>
|
|
107
130
|
`;
|
package/src/thumbnail.scss
CHANGED
|
@@ -1,10 +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
6
|
--thumbnail-padding: calc(var(--dt-spacing-a) / 2);
|
|
7
7
|
|
|
8
|
+
display: flex;
|
|
9
|
+
justify-content: center;
|
|
10
|
+
align-items: center;
|
|
8
11
|
box-sizing: border-box;
|
|
9
12
|
overflow: hidden;
|
|
10
13
|
width: var(--thumbnail-size);
|
|
@@ -47,8 +50,6 @@
|
|
|
47
50
|
|
|
48
51
|
.c-thumbnail-img {
|
|
49
52
|
width: 100%;
|
|
50
|
-
height:
|
|
51
|
-
object-fit: contain;
|
|
52
|
-
display: block;
|
|
53
|
+
height: auto;
|
|
53
54
|
}
|
|
54
55
|
}
|