Skip to content

Commit

Permalink
fix: add size theme and prop for the ChannelAvatar component
Browse files Browse the repository at this point in the history
  • Loading branch information
khushal87 committed Jan 8, 2025
1 parent 6febc5b commit 2877920
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
22 changes: 18 additions & 4 deletions package/src/components/ChannelPreview/ChannelAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import { useChannelPreviewDisplayAvatar } from './hooks/useChannelPreviewDisplay
import { useChannelPreviewDisplayPresence } from './hooks/useChannelPreviewDisplayPresence';

import { ChatContextValue, useChatContext } from '../../contexts/chatContext/ChatContext';
import { useTheme } from '../../contexts/themeContext/ThemeContext';
import type { DefaultStreamChatGenerics } from '../../types/types';
import { Avatar } from '../Avatar/Avatar';
import { GroupAvatar } from '../Avatar/GroupAvatar';

export type ChannelAvatarProps<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
> = Pick<ChannelPreviewProps<StreamChatGenerics>, 'channel'>;
> = Pick<ChannelPreviewProps<StreamChatGenerics>, 'channel'> & {
/**
* The size of the avatar
*/
size: number;
};

/**
* This UI component displays an avatar for a particular channel.
Expand All @@ -21,7 +27,15 @@ export const ChannelAvatarWithContext = <
>(
props: ChannelAvatarProps<StreamChatGenerics> & Pick<ChatContextValue, 'ImageComponent'>,
) => {
const { channel, ImageComponent } = props;
const { channel, ImageComponent, size: propSize } = props;
const {
theme: {
channelPreview: {
avatar: { size: themeSize },
},
},
} = useTheme();
const size = propSize || themeSize;

const displayAvatar = useChannelPreviewDisplayAvatar(channel);
const displayPresence = useChannelPreviewDisplayPresence(channel);
Expand All @@ -32,7 +46,7 @@ export const ChannelAvatarWithContext = <
ImageComponent={ImageComponent}
images={displayAvatar.images}
names={displayAvatar.names}
size={40}
size={size}
/>
);
}
Expand All @@ -43,7 +57,7 @@ export const ChannelAvatarWithContext = <
ImageComponent={ImageComponent}
name={displayAvatar.name}
online={displayPresence}
size={40}
size={size}
/>
);
};
Expand Down
6 changes: 6 additions & 0 deletions package/src/contexts/themeContext/utils/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ export type Theme = {
maskFillColor?: ColorValue;
};
channelPreview: {
avatar: {
size: number;
};
checkAllIcon: IconProps;
checkIcon: IconProps;
container: ViewStyle;
Expand Down Expand Up @@ -875,6 +878,9 @@ export const defaultTheme: Theme = {
height: 64,
},
channelPreview: {
avatar: {
size: 40,
},
checkAllIcon: {
height: DEFAULT_STATUS_ICON_SIZE,
width: DEFAULT_STATUS_ICON_SIZE,
Expand Down

0 comments on commit 2877920

Please sign in to comment.