Skip to content

Commit c353780

Browse files
authored
chore: resolve some todos (nodejs#7751)
1 parent fd87584 commit c353780

File tree

10 files changed

+154
-128
lines changed

10 files changed

+154
-128
lines changed

apps/site/components/MDX/Image/index.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import type { ImageProps } from 'next/image';
22
import Image from 'next/image';
33
import type { FC } from 'react';
44

5-
import { isSvgImage } from '#site/util/imageUtils';
6-
75
const MDXImage: FC<ImageProps> = ({ width, height, alt, src, ...props }) => {
8-
const isUnoptimizedImage = isSvgImage(src.toString());
9-
106
if (!width || !height) {
117
// Since `width` and `height` are not provided in the Markdown image format,
128
// we provide the height and width automatically.
@@ -15,7 +11,6 @@ const MDXImage: FC<ImageProps> = ({ width, height, alt, src, ...props }) => {
1511
<Image
1612
{...props}
1713
src={src}
18-
unoptimized={isUnoptimizedImage}
1914
alt={alt}
2015
width={0}
2116
height={0}
@@ -25,16 +20,7 @@ const MDXImage: FC<ImageProps> = ({ width, height, alt, src, ...props }) => {
2520
);
2621
}
2722

28-
return (
29-
<Image
30-
{...props}
31-
alt={alt}
32-
width={width}
33-
height={height}
34-
src={src}
35-
unoptimized={isUnoptimizedImage}
36-
/>
37-
);
23+
return <Image {...props} alt={alt} width={width} height={height} src={src} />;
3824
};
3925

4026
export default MDXImage;

apps/site/components/withAvatarGroup.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use client';
22

33
import AvatarGroup from '@node-core/ui-components/Common/AvatarGroup';
4-
import Image from 'next/image';
54
import type { ComponentProps, FC } from 'react';
65

76
import Link from '#site/components/Link';
@@ -27,7 +26,6 @@ const WithAvatarGroup: FC<WithAvatarGroupProps> = ({
2726
clickable: clickable,
2827
})}
2928
as={Link}
30-
img={Image}
3129
{...props}
3230
/>
3331
);

apps/site/next.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const nextConfig = {
8888
'@radix-ui/react-tabs',
8989
'@radix-ui/react-toast',
9090
'@radix-ui/react-tooltip',
91+
'@radix-ui/react-avatar',
9192
'@orama/highlight',
9293
'@orama/react-components',
9394
'@heroicons/react',

apps/site/util/__tests__/imageUtils.test.mjs

Lines changed: 0 additions & 56 deletions
This file was deleted.

apps/site/util/imageUtils.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

packages/ui-components/Common/AvatarGroup/Avatar/index.tsx

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import * as RadixAvatar from '@radix-ui/react-avatar';
12
import classNames from 'classnames';
2-
import type { HTMLAttributes, ElementType } from 'react';
3+
import type { HTMLAttributes } from 'react';
34
import { forwardRef } from 'react';
45

56
import type { LinkLike } from '#ui/types';
@@ -14,12 +15,8 @@ export type AvatarProps = {
1415
size?: 'small' | 'medium';
1516
url?: string;
1617
as?: LinkLike | 'div';
17-
img?: ElementType | 'img';
1818
};
1919

20-
// @TODO: We temporarily removed the Avatar Radix UI primitive, since it was causing flashing
21-
// during initial load and not being able to render nicely when images are already cached.
22-
// @see https://github.com/radix-ui/primitives/pull/3008
2320
const Avatar = forwardRef<
2421
HTMLSpanElement,
2522
HTMLAttributes<HTMLSpanElement> & AvatarProps
@@ -33,14 +30,13 @@ const Avatar = forwardRef<
3330
url,
3431
size = 'small',
3532
as: Component = 'a',
36-
img: Image = 'img',
3733
...props
3834
},
3935
ref
4036
) => {
4137
if (!url) Component = 'div';
4238
return (
43-
<span
39+
<RadixAvatar.Root
4440
{...props}
4541
ref={ref}
4642
className={classNames(styles.avatar, styles[size], props.className)}
@@ -50,25 +46,20 @@ const Avatar = forwardRef<
5046
target={url ? '_blank' : undefined}
5147
className={styles.wrapper}
5248
>
53-
{image && (
54-
<Image
55-
width={40}
56-
height={40}
57-
loading="lazy"
58-
decoding="async"
59-
src={image}
60-
alt={name || nickname}
61-
className={styles.item}
62-
/>
63-
)}
64-
65-
{!image && (
66-
<span className={classNames(styles.item, styles[size])}>
67-
{fallback}
68-
</span>
69-
)}
49+
<RadixAvatar.Image
50+
loading="lazy"
51+
decoding="async"
52+
src={image}
53+
alt={name || nickname}
54+
className={styles.item}
55+
/>
56+
<RadixAvatar.Fallback
57+
className={classNames(styles.item, styles[size])}
58+
>
59+
{fallback}
60+
</RadixAvatar.Fallback>
7061
</Component>
71-
</span>
62+
</RadixAvatar.Root>
7263
);
7364
}
7465
);

packages/ui-components/Common/AvatarGroup/Overlay/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const AvatarOverlay: FC<AvatarOverlayProps> = ({
1616
fallback,
1717
url,
1818
as: Component = 'a',
19-
img,
2019
}) => (
2120
<Component className={styles.overlay} href={url} target="_blank">
2221
<Avatar
@@ -25,7 +24,6 @@ const AvatarOverlay: FC<AvatarOverlayProps> = ({
2524
nickname={nickname}
2625
fallback={fallback}
2726
size="medium"
28-
img={img}
2927
/>
3028

3129
<div className={styles.user}>

packages/ui-components/Common/AvatarGroup/index.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use client';
22

33
import classNames from 'classnames';
4-
import type { FC, ElementType } from 'react';
4+
import type { FC } from 'react';
55
import { useState, useMemo } from 'react';
66

77
import type { AvatarProps } from '#ui/Common/AvatarGroup/Avatar';
@@ -20,7 +20,6 @@ type AvatarGroupProps = {
2020
size?: AvatarProps['size'];
2121
container?: HTMLElement;
2222
as?: LinkLike;
23-
img?: ElementType | 'img';
2423
};
2524

2625
const AvatarGroup: FC<AvatarGroupProps> = ({
@@ -30,7 +29,6 @@ const AvatarGroup: FC<AvatarGroupProps> = ({
3029
size = 'small',
3130
container,
3231
as,
33-
img,
3432
}) => {
3533
const [showMore, setShowMore] = useState(false);
3634

@@ -54,7 +52,7 @@ const AvatarGroup: FC<AvatarGroupProps> = ({
5452
key={avatar.nickname}
5553
asChild
5654
container={container}
57-
content={<AvatarOverlay {...avatar} as={as} img={img} />}
55+
content={<AvatarOverlay {...avatar} as={as} />}
5856
>
5957
<Avatar
6058
{...avatar}
@@ -64,7 +62,6 @@ const AvatarGroup: FC<AvatarGroupProps> = ({
6462
'pointer-events-none': !avatar.url,
6563
})}
6664
as={as}
67-
img={img}
6865
/>
6966
</Tooltip>
7067
))}

packages/ui-components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"dependencies": {
3434
"@heroicons/react": "^2.2.0",
35+
"@radix-ui/react-avatar": "^1.1.9",
3536
"@radix-ui/react-dialog": "^1.1.7",
3637
"@radix-ui/react-dropdown-menu": "~2.1.6",
3738
"@radix-ui/react-label": "~2.1.2",

0 commit comments

Comments
 (0)