Skip to content

Commit c9d6cc5

Browse files
nusheanikiwastaken
authored andcommitted
Make items keep aspect ratio
1 parent 2b0139f commit c9d6cc5

3 files changed

Lines changed: 26 additions & 9 deletions

File tree

src/app/components/media/media.css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DefaultReset } from 'folds';
44
export const Image = style([
55
DefaultReset,
66
{
7-
objectFit: 'cover',
7+
objectFit: 'contain',
88
width: '100%',
99
height: '100%',
1010
},

src/app/components/message/MGallery.css.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,26 @@ export const GalleryHolder = style({
77
marginTop: config.space.S200,
88
});
99

10-
export const GalleryItem = style({
11-
width: toRem(300),
12-
height: toRem(200),
13-
flexShrink: 0,
14-
overflow: 'hidden',
15-
borderRadius: config.radii.R300,
10+
export const GalleryItem = recipe({
11+
base: [
12+
DefaultReset,
13+
{
14+
maxWidth: toRem(450),
15+
flexShrink: 0,
16+
overflow: 'hidden',
17+
borderRadius: config.radii.R300,
18+
},
19+
],
20+
variants: {
21+
isImage: {
22+
true: {
23+
height: toRem(300),
24+
},
25+
false: {
26+
maxHeight: toRem(300),
27+
},
28+
},
29+
},
1630
});
1731

1832
export const GalleryHolderGradient = recipe({

src/app/components/message/MGallery.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { ReactNode } from 'react';
22
import React, { useCallback, useEffect, useRef, useState } from 'react';
33
import { Box, Icon, IconButton, Icons, Scroll } from 'folds';
4-
import type { IContent } from 'matrix-js-sdk';
4+
import { MsgType, type IContent } from 'matrix-js-sdk';
55
import type { IGalleryContent, IGalleryItem } from '$types/matrix/common';
66
import {
77
getIntersectionObserverEntry,
@@ -104,7 +104,10 @@ export function MGallery({ content, renderItem, renderCaption }: MGalleryProps)
104104
)}
105105
<Box alignItems="Inherit" gap="200">
106106
{items.map((item, index) => (
107-
<div key={item.url ?? item.file?.url ?? index} className={css.GalleryItem}>
107+
<div
108+
key={item.url ?? item.file?.url ?? index}
109+
className={css.GalleryItem({ isImage: item.itemtype === MsgType.Image })}
110+
>
108111
{renderItem(galleryItemToContent(item), index)}
109112
</div>
110113
))}

0 commit comments

Comments
 (0)