Skip to content

Commit ce1739f

Browse files
feat(metabar): Add avatarGroup on learn section (nodejs#6467)
* feat(metabar): allow Avatar * fix(styles): overflow * story: add more avatar on MetaBar * fix: scrollbar on avatar * update/clean logic * update style * feat(metabar): use breakpoint for limit of avatar --------- Co-authored-by: Claudio W <[email protected]>
1 parent b4f21da commit ce1739f

File tree

6 files changed

+57
-21
lines changed

6 files changed

+57
-21
lines changed

components/Common/AvatarGroup/Avatar/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { FC } from 'react';
33

44
import styles from './index.module.css';
55

6-
type AvatarProps = {
6+
export type AvatarProps = {
77
src: string;
88
alt: string;
99
};
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.avatarGroup {
2-
@apply flex
3-
h-8
4-
items-center;
2+
@apply -mb-4
3+
flex
4+
items-center
5+
overflow-x-auto
6+
pb-4;
57
}

components/Containers/MetaBar/index.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
xs:border-t-neutral-200
2020
xs:dark:border-t-neutral-900;
2121

22+
dl {
23+
@apply w-full;
24+
}
25+
2226
dt {
2327
@apply mb-2
2428
text-sm

components/Containers/MetaBar/index.stories.tsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,28 @@ import AvatarGroup from '@/components/Common/AvatarGroup';
55
import MetaBar from '@/components/Containers/MetaBar';
66
import GitHub from '@/components/Icons/Social/GitHub';
77
import Link from '@/components/Link';
8+
import { getGitHubAvatarUrl } from '@/util/gitHubUtils';
89

910
type Story = StoryObj<typeof MetaBar>;
1011
type Meta = MetaObj<typeof MetaBar>;
1112

13+
const names = [
14+
'ovflowd',
15+
'bmuenzenmeyer',
16+
'AugustinMauroy',
17+
'HinataKah0',
18+
'Harkunwar',
19+
'rodion-arr',
20+
'mikeesto',
21+
'bnb',
22+
'benhalverson',
23+
'aymen94',
24+
'shanpriyan',
25+
'Wai-Dung',
26+
'manishprivet',
27+
'araujogui',
28+
];
29+
1230
export const Default: Story = {
1331
args: {
1432
items: {
@@ -20,20 +38,11 @@ export const Default: Story = {
2038
'components.metabar.author': 'The Node.js Project',
2139
'components.metabar.authors': (
2240
<AvatarGroup
23-
avatars={[
24-
{
25-
src: 'https://avatars.githubusercontent.com/canerakdas',
26-
alt: 'Caner Akdas',
27-
},
28-
{
29-
src: 'https://avatars.githubusercontent.com/bmuenzenmeyer',
30-
alt: 'Brian Muenzenmeyer',
31-
},
32-
{
33-
src: 'https://avatars.githubusercontent.com/ovflowd',
34-
alt: 'Claudio W',
35-
},
36-
]}
41+
avatars={names.map(name => ({
42+
src: getGitHubAvatarUrl(name),
43+
alt: name,
44+
}))}
45+
limit={8}
3746
/>
3847
),
3948
'components.metabar.contribute': (

components/withMetaBar.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,46 @@
1+
'use client';
12
import { useFormatter } from 'next-intl';
23
import type { FC } from 'react';
34

5+
import AvatarGroup from '@/components/Common/AvatarGroup';
46
import MetaBar from '@/components/Containers/MetaBar';
57
import GitHub from '@/components/Icons/Social/GitHub';
68
import Link from '@/components/Link';
7-
import { useClientContext } from '@/hooks/server';
9+
import { useClientContext } from '@/hooks/react-client';
10+
import useMediaQuery from '@/hooks/react-client/useMediaQuery';
811
import { DEFAULT_DATE_FORMAT } from '@/next.calendar.constants.mjs';
9-
import { getGitHubBlobUrl } from '@/util/gitHubUtils';
12+
import { getGitHubBlobUrl, getGitHubAvatarUrl } from '@/util/gitHubUtils';
13+
import { getAcronymFromString } from '@/util/stringUtils';
1014

1115
const WithMetaBar: FC = () => {
1216
const { headings, readingTime, frontmatter, filename } = useClientContext();
1317
const formatter = useFormatter();
14-
1518
const lastUpdated = frontmatter.date
1619
? formatter.dateTime(new Date(frontmatter.date), DEFAULT_DATE_FORMAT)
1720
: undefined;
1821

22+
const usernames =
23+
frontmatter.authors?.split(',').map(author => author.trim()) ?? [];
24+
const avatars = usernames.map(username => ({
25+
src: getGitHubAvatarUrl(username),
26+
alt: getAcronymFromString(username),
27+
}));
28+
29+
// Doing that because on mobile list on top of page and on desktop list on the right side
30+
const shortAvatarList = useMediaQuery(
31+
'(min-width: 670px) and (max-width: 1280px)'
32+
);
33+
1934
return (
2035
<MetaBar
2136
items={{
2237
'components.metabar.lastUpdated': lastUpdated,
2338
'components.metabar.readingTime': readingTime.text,
39+
...(avatars.length && {
40+
[`components.metabar.${avatars.length > 1 ? 'authors' : 'author'}`]: (
41+
<AvatarGroup avatars={avatars} limit={shortAvatarList ? 4 : 8} />
42+
),
43+
}),
2444
'components.metabar.contribute': (
2545
<>
2646
<GitHub className="fill-neutral-700 dark:fill-neutral-100" />

types/frontmatter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface LegacyFrontMatter extends Record<string, any> {
66
layout?: Layouts;
77
title?: string;
88
labels?: Record<string, string>;
9+
authors?: string;
910
}
1011

1112
// @TODO: Extra data from Frontmatter should not be a thing in the future

0 commit comments

Comments
 (0)