Skip to content

Commit 2877920

Browse files
committed
fix: add size theme and prop for the ChannelAvatar component
1 parent 6febc5b commit 2877920

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

package/src/components/ChannelPreview/ChannelAvatar.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@ import { useChannelPreviewDisplayAvatar } from './hooks/useChannelPreviewDisplay
55
import { useChannelPreviewDisplayPresence } from './hooks/useChannelPreviewDisplayPresence';
66

77
import { ChatContextValue, useChatContext } from '../../contexts/chatContext/ChatContext';
8+
import { useTheme } from '../../contexts/themeContext/ThemeContext';
89
import type { DefaultStreamChatGenerics } from '../../types/types';
910
import { Avatar } from '../Avatar/Avatar';
1011
import { GroupAvatar } from '../Avatar/GroupAvatar';
1112

1213
export type ChannelAvatarProps<
1314
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
14-
> = Pick<ChannelPreviewProps<StreamChatGenerics>, 'channel'>;
15+
> = Pick<ChannelPreviewProps<StreamChatGenerics>, 'channel'> & {
16+
/**
17+
* The size of the avatar
18+
*/
19+
size: number;
20+
};
1521

1622
/**
1723
* This UI component displays an avatar for a particular channel.
@@ -21,7 +27,15 @@ export const ChannelAvatarWithContext = <
2127
>(
2228
props: ChannelAvatarProps<StreamChatGenerics> & Pick<ChatContextValue, 'ImageComponent'>,
2329
) => {
24-
const { channel, ImageComponent } = props;
30+
const { channel, ImageComponent, size: propSize } = props;
31+
const {
32+
theme: {
33+
channelPreview: {
34+
avatar: { size: themeSize },
35+
},
36+
},
37+
} = useTheme();
38+
const size = propSize || themeSize;
2539

2640
const displayAvatar = useChannelPreviewDisplayAvatar(channel);
2741
const displayPresence = useChannelPreviewDisplayPresence(channel);
@@ -32,7 +46,7 @@ export const ChannelAvatarWithContext = <
3246
ImageComponent={ImageComponent}
3347
images={displayAvatar.images}
3448
names={displayAvatar.names}
35-
size={40}
49+
size={size}
3650
/>
3751
);
3852
}
@@ -43,7 +57,7 @@ export const ChannelAvatarWithContext = <
4357
ImageComponent={ImageComponent}
4458
name={displayAvatar.name}
4559
online={displayPresence}
46-
size={40}
60+
size={size}
4761
/>
4862
);
4963
};

package/src/contexts/themeContext/utils/theme.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ export type Theme = {
152152
maskFillColor?: ColorValue;
153153
};
154154
channelPreview: {
155+
avatar: {
156+
size: number;
157+
};
155158
checkAllIcon: IconProps;
156159
checkIcon: IconProps;
157160
container: ViewStyle;
@@ -875,6 +878,9 @@ export const defaultTheme: Theme = {
875878
height: 64,
876879
},
877880
channelPreview: {
881+
avatar: {
882+
size: 40,
883+
},
878884
checkAllIcon: {
879885
height: DEFAULT_STATUS_ICON_SIZE,
880886
width: DEFAULT_STATUS_ICON_SIZE,

0 commit comments

Comments
 (0)