@@ -7,6 +7,7 @@ import { Filename } from "./filename";
7
7
import { Image } from "./image" ;
8
8
import brokenImage from "~/shared/images/broken-image-placeholder.svg" ;
9
9
import { theme } from "@webstudio-is/design-system" ;
10
+ import { isVideoFormat } from "../assets/asset-utils" ;
10
11
11
12
const StyledWebstudioImage = styled ( Image , {
12
13
position : "absolute" ,
@@ -34,6 +35,32 @@ const StyledWebstudioImage = styled(Image, {
34
35
} ,
35
36
} ) ;
36
37
38
+ const StyledWebstudioVideo = styled ( "video" , {
39
+ position : "absolute" ,
40
+ width : "100%" ,
41
+ height : "100%" ,
42
+ objectFit : "contain" ,
43
+
44
+ // This is shown only if an image was not loaded and broken
45
+ // From the spec:
46
+ // - The pseudo-elements generated by ::before and ::after are contained by the element's formatting box,
47
+ // and thus don't apply to "replaced" elements such as <img>, or to <br> elements
48
+ // Not in spec but supported by all browsers:
49
+ // - broken image is not a "replaced" element so this style is applied
50
+ "&::after" : {
51
+ content : "' '" ,
52
+ position : "absolute" ,
53
+ width : "100%" ,
54
+ height : "100%" ,
55
+ left : 0 ,
56
+ top : 0 ,
57
+ backgroundSize : "contain" ,
58
+ backgroundRepeat : "no-repeat" ,
59
+ backgroundPosition : "center" ,
60
+ backgroundImage : `url(${ brokenImage } )` ,
61
+ } ,
62
+ } ) ;
63
+
37
64
const ThumbnailContainer = styled ( Box , {
38
65
position : "relative" ,
39
66
display : "flex" ,
@@ -120,18 +147,23 @@ export const ImageThumbnail = ({
120
147
onChange ?.( assetContainer ) ;
121
148
} }
122
149
>
123
- < StyledWebstudioImage
124
- assetId = { assetContainer . asset . id }
125
- name = { assetContainer . asset . name }
126
- objectURL = {
127
- assetContainer . status === "uploading"
128
- ? assetContainer . objectURL
129
- : undefined
130
- }
131
- alt = { description ?? name }
132
- // width={64} used for Image optimizations it should be approximately equal to the width of the picture on the screen in px
133
- width = { 64 }
134
- />
150
+ { isVideoFormat ( assetContainer . asset . format ) &&
151
+ assetContainer . status === "uploading" ? (
152
+ < StyledWebstudioVideo width = { 64 } src = { assetContainer . objectURL } />
153
+ ) : (
154
+ < StyledWebstudioImage
155
+ assetId = { assetContainer . asset . id }
156
+ name = { assetContainer . asset . name }
157
+ objectURL = {
158
+ assetContainer . status === "uploading"
159
+ ? assetContainer . objectURL
160
+ : undefined
161
+ }
162
+ alt = { description ?? name }
163
+ // width={64} used for Image optimizations it should be approximately equal to the width of the picture on the screen in px
164
+ width = { 64 }
165
+ />
166
+ ) }
135
167
</ Thumbnail >
136
168
< Box
137
169
css = { {
0 commit comments