Skip to content

Commit cff98b1

Browse files
feat(fuselage): accept objectFit css properties on Avatar (#1943)
1 parent 6797e0f commit cff98b1

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

.changeset/cruel-owls-arrive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@rocket.chat/fuselage': minor
3+
---
4+
5+
feat(fuselage): accept all `objectFit` css properties on `Avatar` component

packages/fuselage/src/components/Avatar/Avatar.styles.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ $avatar-stack-background-color: theme(
88
);
99

1010
$sizes: 16, 18, 20, 24, 28, 32, 36, 40, 48, 124, 200, 332;
11+
$object-fit-values: contain, cover, fill, none, scale-down;
1112

1213
.rcx-avatar {
1314
display: inline-flex;
@@ -47,7 +48,11 @@ $sizes: 16, 18, 20, 24, 28, 32, 36, 40, 48, 124, 200, 332;
4748
}
4849

4950
&--object-fit {
50-
object-fit: contain;
51+
@each $value in $object-fit-values {
52+
&-#{$value} {
53+
object-fit: $value;
54+
}
55+
}
5156
}
5257

5358
&--rounded {

packages/fuselage/src/components/Avatar/Avatar.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import type { AllHTMLAttributes } from 'react';
1+
import type { AllHTMLAttributes, CSSProperties } from 'react';
22

33
import AvatarContainer, { type AvatarContainerProps } from './AvatarContainer';
44

55
export type AvatarProps = AvatarContainerProps & {
66
rounded?: boolean;
7-
objectFit?: boolean;
7+
objectFit?: CSSProperties['objectFit'];
88
url: string;
99
} & Omit<AllHTMLAttributes<HTMLImageElement>, 'size'>;
1010

1111
const Avatar = ({
1212
size = 'x36',
1313
rounded = false,
14-
objectFit = false,
14+
objectFit,
1515
url,
1616
className,
1717
alt,
1818
...props
1919
}: AvatarProps) => {
2020
const innerClass = [
2121
'rcx-avatar__element',
22-
objectFit && 'rcx-avatar__element--object-fit',
2322
size && `rcx-avatar__element--${size}`,
2423
rounded && 'rcx-avatar__element--rounded',
24+
objectFit && `rcx-avatar__element--object-fit-${objectFit}`,
2525
]
2626
.filter(Boolean)
2727
.join(' ');

0 commit comments

Comments
 (0)