Skip to content

Commit e7eaeec

Browse files
committed
Adjust non-square preview sizes
1 parent 4306604 commit e7eaeec

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/components/media-links/media-link-preview.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function FreeFeedMediaPreview({ id }) {
4949
.then((info) => {
5050
if (info?.mediaType === 'image' || info?.mediaType === 'video') {
5151
const height = 120;
52-
const width = Math.max(90, (info.width / info.height) * height);
52+
const width = Math.round((info.width / info.height) * height);
5353
setAttrs({
5454
src: attachmentPreviewUrl(id, 'image', width, height),
5555
width,
@@ -71,6 +71,7 @@ function FreeFeedMediaPreview({ id }) {
7171
alt=""
7272
width={attrs.width}
7373
height={attrs.height}
74+
style={{ '--ar': attrs.width / attrs.height }}
7475
className={styles.preview}
7576
loading="lazy"
7677
/>
@@ -83,8 +84,9 @@ function YouTubeMediaPreview({ url }) {
8384
<img
8485
src={`https://img.youtube.com/vi/${getVideoId(url)}/default.jpg`}
8586
alt=""
86-
width={60 / aspectRatio}
87+
width={Math.round(60 / aspectRatio)}
8788
height={60}
89+
style={{ '--ar': 1 / aspectRatio }}
8890
className={styles.preview}
8991
loading="lazy"
9092
/>

src/components/media-links/media-link-preview.module.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
.preview {
22
height: 4em;
33
width: auto;
4+
aspect-ratio: clamp(0.8, var(--ar, 1), 1.2);
5+
margin-right: 0.5em;
46
object-fit: cover;
57
box-shadow: 0 0 0 1px rgb(0, 0, 0, 0.2);
68

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
@use '../../../styles/shared/mixins';
22

33
.previews {
4-
display: flex;
5-
flex-wrap: wrap;
6-
gap: 0.33em;
74
margin-left: mixins.rem(19px);
85
margin-top: 0.25em;
96
}

0 commit comments

Comments
 (0)