Skip to content

Commit fe7c163

Browse files
committed
fix: avatar rendering and avatar group margins
1 parent 5247e87 commit fe7c163

11 files changed

Lines changed: 60 additions & 61 deletions

File tree

apps/site/components/Common/AvatarGroup/Avatar/index.module.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
justify-center
1111
rounded-full
1212
border-2
13-
border-white
13+
border-transparent
1414
bg-neutral-100
1515
object-cover
1616
text-xs
1717
text-neutral-800
18-
dark:border-neutral-950
1918
dark:bg-neutral-900
2019
dark:text-neutral-300;
2120
}
Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import * as RadixAvatar from '@radix-ui/react-avatar';
21
import classNames from 'classnames';
3-
import type { ComponentPropsWithoutRef, ElementRef } from 'react';
4-
import { forwardRef } from 'react';
2+
import Image from 'next/image';
3+
import type { FC, HTMLAttributes } from 'react';
54

65
import Link from '@/components/Link';
76

@@ -16,38 +15,47 @@ export type AvatarProps = {
1615
url?: string;
1716
};
1817

19-
const Avatar = forwardRef<
20-
ElementRef<typeof RadixAvatar.Root>,
21-
ComponentPropsWithoutRef<typeof RadixAvatar.Root> & AvatarProps
22-
>(({ image, nickname, name, fallback, url, size = 'small', ...props }, ref) => {
18+
const Avatar: FC<HTMLAttributes<HTMLSpanElement> & AvatarProps> = ({
19+
image,
20+
nickname,
21+
name,
22+
fallback,
23+
url,
24+
size = 'small',
25+
...props
26+
}) => {
2327
const Wrapper = url ? Link : 'div';
2428

2529
return (
26-
<RadixAvatar.Root
30+
<span
2731
{...props}
2832
className={classNames(styles.avatar, styles[size], props.className)}
29-
ref={ref}
3033
>
3134
<Wrapper
3235
href={url || undefined}
3336
target={url ? '_blank' : undefined}
3437
className={styles.wrapper}
3538
>
36-
<RadixAvatar.Image
37-
loading="lazy"
38-
src={image}
39-
alt={name || nickname}
40-
className={styles.item}
41-
/>
42-
<RadixAvatar.Fallback
43-
delayMs={500}
44-
className={classNames(styles.item, styles[size])}
45-
>
46-
{fallback}
47-
</RadixAvatar.Fallback>
39+
{image && (
40+
<Image
41+
width={40}
42+
height={40}
43+
loading="lazy"
44+
decoding="async"
45+
src={image}
46+
alt={name || nickname}
47+
className={styles.item}
48+
/>
49+
)}
50+
51+
{!image && (
52+
<span className={classNames(styles.item, styles[size])}>
53+
{fallback}
54+
</span>
55+
)}
4856
</Wrapper>
49-
</RadixAvatar.Root>
57+
</span>
5058
);
51-
});
59+
};
5260

5361
export default Avatar;

apps/site/components/Common/AvatarGroup/Overlay/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const AvatarOverlay: FC<AvatarOverlayProps> = ({
2525
fallback={fallback}
2626
size="medium"
2727
/>
28+
2829
<div className={styles.user}>
2930
{name && <div className={styles.name}>{name}</div>}
3031
{nickname && <div className={styles.nickname}>{nickname}</div>}

apps/site/components/Common/AvatarGroup/index.module.css

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22
@apply flex
33
flex-wrap
44
items-center;
5+
6+
&:not(.expandable) {
7+
> span {
8+
@apply ml-0;
9+
}
10+
}
511
}
612

713
.small {
8-
@apply xs:-space-x-2
9-
space-x-0.5;
14+
> span {
15+
@apply -ml-2;
16+
}
1017
}
1118

1219
.medium {
13-
@apply -space-x-2.5;
20+
> span {
21+
@apply -ml-2.5;
22+
}
1423
}

apps/site/components/Common/AvatarGroup/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ const AvatarGroup: FC<AvatarGroupProps> = ({
3535
);
3636

3737
return (
38-
<div className={classNames(styles.avatarGroup, styles[size])}>
38+
<div
39+
className={classNames(styles.avatarGroup, styles[size], {
40+
[styles.expandable]: avatars.length > limit,
41+
})}
42+
>
3943
{renderAvatars.map(({ ...avatar }) => (
4044
<Fragment key={avatar.nickname}>
4145
<Tooltip
@@ -54,6 +58,7 @@ const AvatarGroup: FC<AvatarGroupProps> = ({
5458
</Tooltip>
5559
</Fragment>
5660
))}
61+
5762
{avatars.length > limit && (
5863
<span
5964
onClick={isExpandable ? () => setShowMore(prev => !prev) : undefined}

apps/site/components/withAvatarGroup.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use client';
2-
31
import type { ComponentProps, FC } from 'react';
42

53
import AvatarGroup from '@/components/Common/AvatarGroup';

apps/site/components/withMetaBar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use client';
2+
23
import { useFormatter } from 'next-intl';
34
import type { FC } from 'react';
45

apps/site/layouts/Post.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const PostLayout: FC<PropsWithChildren> = ({ children }) => {
2929
<h1>{frontmatter.title}</h1>
3030

3131
<section>
32-
<WithAvatarGroup names={authors} />
32+
<WithAvatarGroup names={authors} size="medium" />
3333

3434
<p>{authors.join(', ')}</p>
3535
</section>

apps/site/next.config.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ const nextConfig = {
2121
// We add it to the remote pattern for the static images we use from multiple sources
2222
// to be marked as safe sources (these come from Markdown files)
2323
remotePatterns: [
24+
{
25+
protocol: 'https',
26+
hostname: 'avatars.githubusercontent.com',
27+
port: '',
28+
pathname: '/**',
29+
},
2430
{
2531
protocol: 'https',
2632
hostname: 'bestpractices.coreinfrastructure.org',
@@ -76,7 +82,6 @@ const nextConfig = {
7682
// @see https://vercel.com/blog/how-we-optimized-package-imports-in-next-js
7783
optimizePackageImports: [
7884
'@radix-ui/react-accessible-icon',
79-
'@radix-ui/react-avatar',
8085
'@radix-ui/react-dropdown-menu',
8186
'@radix-ui/react-label',
8287
'@radix-ui/react-scroll-area',
@@ -86,6 +91,7 @@ const nextConfig = {
8691
'@radix-ui/react-toast',
8792
'@radix-ui/react-tooltip',
8893
'@orama/highlight',
94+
'@orama/react-components',
8995
'@heroicons/react',
9096
'tailwindcss',
9197
'shiki',

apps/site/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"@orama/react-components": "^0.1.23",
3131
"@oramacloud/client": "^2.1.4",
3232
"@radix-ui/react-accessible-icon": "^1.1.0",
33-
"@radix-ui/react-avatar": "^1.1.1",
3433
"@radix-ui/react-dropdown-menu": "^2.1.2",
3534
"@radix-ui/react-label": "^2.1.0",
3635
"@radix-ui/react-scroll-area": "^1.2.1",

0 commit comments

Comments
 (0)