-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introducing avatar tooltip (#7143)
* feat: tooltip component and avatar tooltip * chore: metabar story props updated * chore: self review * chore: self review * refactor: class names * refactor: horizontal margin added * feat: accessible avatars on mobile * feat: default author url * refactor: review updates * chore: self review * refactor: design and review updates * fix: Avatars in MetaBar story * refactor: review updates * fix: opening the tooltip portal within the dialog * fix: adjusting visible avatar count * refactor: review updates * Update apps/site/util/authorUtils.ts Co-authored-by: Claudio W <[email protected]> Signed-off-by: Caner Akdas <[email protected]> * refactor: enhancing code readability * refactor: review update --------- Signed-off-by: Caner Akdas <[email protected]> Co-authored-by: Claudio W <[email protected]>
- Loading branch information
1 parent
83081ef
commit bc3b2a9
Showing
32 changed files
with
845 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,53 @@ | ||
import * as RadixAvatar from '@radix-ui/react-avatar'; | ||
import type { FC } from 'react'; | ||
import classNames from 'classnames'; | ||
import type { ComponentPropsWithoutRef, ElementRef } from 'react'; | ||
import { forwardRef } from 'react'; | ||
|
||
import Link from '@/components/Link'; | ||
|
||
import styles from './index.module.css'; | ||
|
||
export type AvatarProps = { | ||
src: string; | ||
alt: string; | ||
fallback: string; | ||
image?: string; | ||
name?: string; | ||
nickname: string; | ||
fallback?: string; | ||
size?: 'small' | 'medium'; | ||
url?: string; | ||
}; | ||
|
||
const Avatar: FC<AvatarProps> = ({ src, alt, fallback }) => ( | ||
<RadixAvatar.Root className={styles.avatarRoot}> | ||
<RadixAvatar.Image | ||
loading="lazy" | ||
src={src} | ||
alt={alt} | ||
title={alt} | ||
className={styles.avatar} | ||
/> | ||
<RadixAvatar.Fallback delayMs={500} className={styles.avatar}> | ||
{fallback} | ||
</RadixAvatar.Fallback> | ||
</RadixAvatar.Root> | ||
); | ||
const Avatar = forwardRef< | ||
ElementRef<typeof RadixAvatar.Root>, | ||
ComponentPropsWithoutRef<typeof RadixAvatar.Root> & AvatarProps | ||
>(({ image, nickname, name, fallback, url, size = 'small', ...props }, ref) => { | ||
const Wrapper = url ? Link : 'div'; | ||
|
||
return ( | ||
<RadixAvatar.Root | ||
{...props} | ||
className={classNames(styles.avatar, styles[size], props.className)} | ||
ref={ref} | ||
> | ||
<Wrapper | ||
href={url || undefined} | ||
target={url ? '_blank' : undefined} | ||
className={styles.wrapper} | ||
> | ||
<RadixAvatar.Image | ||
loading="lazy" | ||
src={image} | ||
alt={name || nickname} | ||
className={styles.item} | ||
/> | ||
<RadixAvatar.Fallback | ||
delayMs={500} | ||
className={classNames(styles.item, styles[size])} | ||
> | ||
{fallback} | ||
</RadixAvatar.Fallback> | ||
</Wrapper> | ||
</RadixAvatar.Root> | ||
); | ||
}); | ||
|
||
export default Avatar; |
29 changes: 29 additions & 0 deletions
29
apps/site/components/Common/AvatarGroup/Overlay/index.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
.overlay { | ||
@apply flex | ||
min-w-56 | ||
items-center | ||
gap-2 | ||
p-3; | ||
} | ||
|
||
.user { | ||
@apply grow; | ||
} | ||
|
||
.name { | ||
@apply font-semibold | ||
text-neutral-900 | ||
dark:text-neutral-300; | ||
} | ||
|
||
.nickname { | ||
@apply font-medium | ||
text-neutral-700 | ||
dark:text-neutral-500; | ||
} | ||
|
||
.arrow { | ||
@apply w-3 | ||
fill-neutral-600 | ||
dark:fill-white; | ||
} |
21 changes: 21 additions & 0 deletions
21
apps/site/components/Common/AvatarGroup/Overlay/index.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { Meta as MetaObj, StoryObj } from '@storybook/react'; | ||
|
||
import AvatarOverlay from '@/components/Common/AvatarGroup/Overlay'; | ||
import { getAuthorWithId, getAuthorWithName } from '@/util/authorUtils'; | ||
|
||
type Story = StoryObj<typeof AvatarOverlay>; | ||
type Meta = MetaObj<typeof AvatarOverlay>; | ||
|
||
export const Default: Story = { | ||
args: getAuthorWithId(['nodejs'], true)[0], | ||
}; | ||
|
||
export const FallBack: Story = { | ||
args: getAuthorWithName(['Node.js'], true)[0], | ||
}; | ||
|
||
export const WithoutName: Story = { | ||
args: getAuthorWithId(['canerakdas'], true)[0], | ||
}; | ||
|
||
export default { component: AvatarOverlay } as Meta; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ArrowUpRightIcon } from '@heroicons/react/24/solid'; | ||
import type { ComponentProps, FC } from 'react'; | ||
|
||
import Avatar from '@/components/Common/AvatarGroup/Avatar'; | ||
import Link from '@/components/Link'; | ||
|
||
import styles from './index.module.css'; | ||
|
||
export type AvatarOverlayProps = ComponentProps<typeof Avatar> & { | ||
url?: string; | ||
}; | ||
|
||
const AvatarOverlay: FC<AvatarOverlayProps> = ({ | ||
image, | ||
name, | ||
nickname, | ||
fallback, | ||
url, | ||
}) => ( | ||
<Link className={styles.overlay} href={url} target="_blank"> | ||
<Avatar | ||
image={image} | ||
name={name} | ||
nickname={nickname} | ||
fallback={fallback} | ||
size="medium" | ||
/> | ||
<div className={styles.user}> | ||
{name && <div className={styles.name}>{name}</div>} | ||
{nickname && <div className={styles.nickname}>{nickname}</div>} | ||
</div> | ||
<ArrowUpRightIcon className={styles.arrow} /> | ||
</Link> | ||
); | ||
|
||
export default AvatarOverlay; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.