Skip to content

Commit 88c43d4

Browse files
committed
fix styling and crash
1 parent 7f3da1f commit 88c43d4

File tree

7 files changed

+115
-59
lines changed

7 files changed

+115
-59
lines changed

apps/site/components/withSidebar.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ const WithSidebar: FC<WithSidebarProps> = ({ navKeys, context, ...props }) => {
2323
const locale = useLocale();
2424
const t = useTranslations();
2525
const { push } = useRouter();
26+
const sideNavigation = getSideNavigation(navKeys, context);
2627

27-
const mappedSidebarItems = getSideNavigation(navKeys, context).map(
28-
([, { label, items }]) => ({
29-
groupName: label,
30-
items: items.map(([, item]) => item),
31-
})
32-
);
28+
const mappedSidebarItems =
29+
// If there's only a single navigation key, use it's sub-items
30+
// as our navigation.
31+
(navKeys.length === 1 ? sideNavigation[0][1].items : sideNavigation).map(
32+
([, { label, items }]) => ({
33+
groupName: label,
34+
items: items.map(([, item]) => item),
35+
})
36+
);
3337

3438
return (
3539
<Sidebar

apps/site/layouts/Learn.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import WithBreadcrumbs from '#site/components/withBreadcrumbs';
55
import WithFooter from '#site/components/withFooter';
66
import WithMetaBar from '#site/components/withMetaBar';
77
import WithNavBar from '#site/components/withNavBar';
8-
import SideBar from '#site/components/withSidebar';
8+
import WithSideBar from '#site/components/withSidebar';
99
import WithSidebarCrossLinks from '#site/components/withSidebarCrossLinks';
1010

1111
const LearnLayout: FC<PropsWithChildren> = ({ children }) => (
1212
<>
1313
<WithNavBar />
1414

1515
<Article>
16-
<SideBar navKeys={['learn']} showProgressionIcons={true} />
16+
<WithSideBar navKeys={['learn']} showProgressionIcons={true} />
1717

1818
<div>
1919
<main>

packages/ui-components/Containers/Sidebar/SidebarGroup/index.module.css

Lines changed: 54 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,60 @@
55
w-full
66
flex-col
77
gap-2;
8-
}
98

10-
.groupName {
11-
@apply px-2
12-
py-1
13-
text-xs
14-
font-semibold
15-
text-neutral-800
16-
dark:text-neutral-600;
17-
}
9+
&:not(.progression) {
10+
.groupName {
11+
@apply px-2
12+
py-1
13+
text-xs
14+
font-semibold
15+
text-neutral-800
16+
dark:text-neutral-600;
17+
}
18+
}
1819

19-
.itemList {
20-
@apply m-0
21-
flex
22-
flex-col
23-
items-start
24-
gap-0.5
25-
p-0;
20+
&.progression {
21+
@apply flex
22+
flex-col
23+
gap-4
24+
text-sm
25+
font-medium
26+
text-neutral-800
27+
dark:text-neutral-200;
28+
29+
.itemList {
30+
@apply relative
31+
-left-1
32+
flex
33+
flex-col
34+
after:absolute
35+
after:left-[0.45rem]
36+
after:top-0
37+
after:z-10
38+
after:h-full
39+
after:w-px
40+
after:bg-neutral-200
41+
after:content-['']
42+
dark:after:bg-neutral-800;
43+
44+
a {
45+
@apply first:before:absolute
46+
first:before:bottom-[calc(50%+0.25rem)]
47+
first:before:left-0
48+
first:before:h-20
49+
first:before:w-4
50+
first:before:bg-white
51+
first:before:content-['']
52+
last:after:absolute
53+
last:after:left-0
54+
last:after:top-[calc(50%+0.25rem)]
55+
last:after:h-20
56+
last:after:w-4
57+
last:after:bg-white
58+
last:after:content-['']
59+
first:dark:before:bg-neutral-950
60+
last:dark:after:bg-neutral-950;
61+
}
62+
}
63+
}
2664
}

packages/ui-components/Containers/Sidebar/SidebarGroup/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import classNames from 'classnames';
12
import type { ComponentProps, FC } from 'react';
23

34
import SidebarItem from '#ui/Containers/Sidebar/SidebarItem';
@@ -16,18 +17,23 @@ type SidebarGroupProps = {
1617
const SidebarGroup: FC<SidebarGroupProps> = ({
1718
groupName,
1819
items,
19-
showProgressionIcons = false,
20+
showProgressionIcons,
2021
...props
2122
}) => (
22-
<section className={styles.group}>
23+
<section
24+
className={classNames({
25+
[styles.group]: true,
26+
[styles.progression]: showProgressionIcons,
27+
})}
28+
>
2329
<label className={styles.groupName}>{groupName}</label>
2430
<ul className={styles.itemList}>
2531
{items.map(({ label, link }) => (
2632
<SidebarItem
2733
key={link}
2834
label={label}
2935
link={link}
30-
showProgressionIcon={showProgressionIcons}
36+
showProgressionIcons={showProgressionIcons}
3137
{...props}
3238
/>
3339
))}
Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
@reference '../../../styles/index.css';
22

33
.item {
4-
@apply flex
4+
@apply font-regular
5+
relative
6+
z-20
7+
flex
58
w-full
6-
list-none
9+
items-center
10+
overflow-hidden
11+
text-sm
712
text-neutral-800
813
dark:text-neutral-200;
914

10-
a {
11-
@apply inline-flex
12-
items-center
13-
gap-2
14-
p-2;
15-
}
16-
1715
.label {
1816
@apply font-regular
19-
w-full
17+
p-2
2018
text-sm;
2119
}
2220

23-
svg {
21+
.progressionIcon {
2422
@apply shrink-0
2523
fill-neutral-200
2624
stroke-white
@@ -35,18 +33,24 @@
3533
dark:text-neutral-200;
3634
}
3735

38-
.active {
36+
&.progression {
37+
.label {
38+
@apply p-1;
39+
}
40+
}
41+
42+
&.active {
3943
@apply text-neutral-900
4044
dark:text-white;
4145

42-
svg {
46+
.progressionIcon {
4347
@apply fill-green-500;
4448
}
45-
}
4649

47-
&:not(.progression) > .active {
48-
@apply rounded-sm
49-
bg-green-600
50-
text-white;
50+
&:not(.progression) .label {
51+
@apply rounded-sm
52+
bg-green-600
53+
text-white;
54+
}
5155
}
5256
}

packages/ui-components/Containers/Sidebar/SidebarItem/index.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ArrowUpRightIcon } from '@heroicons/react/24/solid';
22
import classNames from 'classnames';
33
import type { FC } from 'react';
44

5-
import ActiveLink from '#ui/Common/BaseActiveLink';
5+
import BaseActiveLink from '#ui/Common/BaseActiveLink';
66
import type { FormattedMessage, LinkLike } from '#ui/types';
77

88
import styles from './index.module.css';
@@ -13,28 +13,31 @@ type SidebarItemProps = {
1313
link: string;
1414
as?: LinkLike;
1515
pathname?: string;
16-
showProgressionIcon?: boolean;
16+
showProgressionIcons?: boolean;
1717
};
1818

1919
const SidebarItem: FC<SidebarItemProps> = ({
2020
label,
2121
link,
22-
showProgressionIcon = false,
22+
showProgressionIcons = false,
2323
...props
2424
}) => (
25-
<li
25+
<BaseActiveLink
2626
className={classNames({
2727
[styles.item]: true,
28-
[styles.progression]: showProgressionIcon,
28+
[styles.progression]: showProgressionIcons,
2929
})}
30+
href={link}
31+
activeClassName={styles.active}
32+
{...props}
3033
>
31-
<ActiveLink href={link} activeClassName={styles.active} {...props}>
32-
{showProgressionIcon && <ProgressionIcon />}
33-
<span className={styles.label}>{label}</span>
34+
{showProgressionIcons && (
35+
<ProgressionIcon className={styles.progressionIcon} />
36+
)}
37+
<span className={styles.label}>{label}</span>
3438

35-
{link.startsWith('http') && <ArrowUpRightIcon className={styles.icon} />}
36-
</ActiveLink>
37-
</li>
39+
{link.startsWith('http') && <ArrowUpRightIcon className={styles.icon} />}
40+
</BaseActiveLink>
3841
);
3942

4043
export default SidebarItem;

packages/ui-components/Containers/Sidebar/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import type { LinkLike } from '#ui/types';
77
import styles from './index.module.css';
88

99
type SidebarProps = {
10-
groups: Array<Omit<ComponentProps<typeof SidebarGroup>, 'as' | 'pathname'>>;
10+
groups: Array<
11+
Pick<ComponentProps<typeof SidebarGroup>, 'items' | 'groupName'>
12+
>;
1113
pathname?: string;
1214
title: string;
1315
onSelect: (value: string) => void;
@@ -29,8 +31,7 @@ const SideBar: FC<SidebarProps> = ({
2931
}));
3032

3133
const currentItem = selectItems
32-
.map(item => item.items)
33-
.flat()
34+
.flatMap(item => item.items)
3435
.find(item => pathname === item.value);
3536

3637
return (

0 commit comments

Comments
 (0)