Skip to content

Commit 672e2cb

Browse files
committed
feat: accessible avatars on mobile
1 parent ed52e02 commit 672e2cb

File tree

3 files changed

+65
-34
lines changed

3 files changed

+65
-34
lines changed

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

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
.item {
2-
@apply flex
2+
@apply xs:max-h-10
3+
xs:max-w-10
4+
flex
35
h-full
4-
max-h-10
6+
max-h-12
57
w-full
6-
max-w-10
8+
max-w-12
79
items-center
810
justify-center
911
rounded-full
@@ -19,18 +21,27 @@
1921
}
2022

2123
.avatar {
22-
@apply -ml-2
24+
@apply xs:-ml-2
25+
ml-0.5
2326
size-8
2427
flex-shrink-0
2528
first:ml-0;
2629

27-
&:hover {
28-
@apply z-10;
30+
.wrapper {
31+
@apply max-xs:block
32+
max-xs:py-0;
2933
}
3034
}
3135

3236
.small {
33-
@apply size-8;
37+
@apply xs:size-8
38+
size-12;
39+
40+
.clickable {
41+
@apply xs:border-white
42+
xs:dark:border-neutral-950
43+
border-green-500;
44+
}
3445
}
3546

3647
.medium {

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

+39-20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import classNames from 'classnames';
33
import type { ComponentPropsWithoutRef, ElementRef } from 'react';
44
import { forwardRef } from 'react';
55

6+
import Link from '@/components/Link';
7+
68
import styles from './index.module.css';
79

810
export type AvatarProps = {
@@ -11,30 +13,47 @@ export type AvatarProps = {
1113
nickname: string;
1214
fallback?: string;
1315
size?: 'small' | 'medium';
16+
website?: string;
1417
};
1518

1619
const Avatar = forwardRef<
1720
ElementRef<typeof RadixAvatar.Root>,
1821
ComponentPropsWithoutRef<typeof RadixAvatar.Root> & AvatarProps
19-
>(({ image, name, fallback, size = 'small', ...props }, ref) => (
20-
<RadixAvatar.Root
21-
{...props}
22-
className={classNames(styles.avatar, styles[size], props.className)}
23-
ref={ref}
24-
>
25-
<RadixAvatar.Image
26-
loading="lazy"
27-
src={image}
28-
alt={name}
29-
className={styles.item}
30-
/>
31-
<RadixAvatar.Fallback
32-
delayMs={500}
33-
className={classNames(styles.item, styles[size])}
34-
>
35-
{fallback}
36-
</RadixAvatar.Fallback>
37-
</RadixAvatar.Root>
38-
));
22+
>(
23+
(
24+
{ image, nickname, name, fallback, website, size = 'small', ...props },
25+
ref
26+
) => {
27+
const Wrapper = website ? Link : 'div';
28+
29+
return (
30+
<RadixAvatar.Root
31+
{...props}
32+
className={classNames(styles.avatar, styles[size], props.className)}
33+
ref={ref}
34+
>
35+
<Wrapper
36+
{...(website ? { href: website, target: '_blank' } : {})}
37+
className={styles.wrapper}
38+
>
39+
<RadixAvatar.Image
40+
loading="lazy"
41+
src={image}
42+
alt={name || nickname}
43+
className={classNames(styles.item, {
44+
[styles.clickable]: website,
45+
})}
46+
/>
47+
<RadixAvatar.Fallback
48+
delayMs={500}
49+
className={classNames(styles.item, styles[size])}
50+
>
51+
{fallback}
52+
</RadixAvatar.Fallback>
53+
</Wrapper>
54+
</RadixAvatar.Root>
55+
);
56+
}
57+
);
3958

4059
export default Avatar;

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

+8-7
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@ const AvatarGroup: FC<AvatarGroupProps> = ({
3434

3535
return (
3636
<div className={styles.avatarGroup}>
37-
{renderAvatars.map(({ website, ...avatar }) => (
37+
{renderAvatars.map(({ ...avatar }) => (
3838
<Fragment key={avatar.nickname}>
39-
{website ? (
40-
<Tooltip
41-
content={<AvatarOverlay {...avatar} website={website} />}
42-
asChild
43-
>
39+
{avatar.website ? (
40+
<Tooltip content={<AvatarOverlay {...avatar} />} asChild>
4441
<Avatar {...avatar} size={size} className="cursor-pointer" />
4542
</Tooltip>
4643
) : (
@@ -51,7 +48,11 @@ const AvatarGroup: FC<AvatarGroupProps> = ({
5148
{avatars.length > limit && (
5249
<span
5350
onClick={isExpandable ? () => setShowMore(prev => !prev) : undefined}
54-
className={classNames(avatarstyles.avatar, 'cursor-pointer')}
51+
className={classNames(
52+
avatarstyles.avatar,
53+
avatarstyles[size],
54+
'cursor-pointer'
55+
)}
5556
>
5657
<span className={avatarstyles.item}>
5758
{`${showMore ? '-' : '+'}${avatars.length - limit}`}

0 commit comments

Comments
 (0)