Skip to content

Commit 63ea4f0

Browse files
committed
feat: enhance documentation sidebar style
1 parent 4a9fef3 commit 63ea4f0

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

src/lib/components/elements/collapsible.tsx

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type Props = {
77
defaultOpen?: boolean;
88
currentPathname: string;
99
item: any;
10+
isNestedElement?: boolean;
1011
};
1112

1213
export default function Collapsible(props: PropsWithChildren<Props>) {
@@ -19,8 +20,39 @@ export default function Collapsible(props: PropsWithChildren<Props>) {
1920
className="flex flex-col gap-2 w-full"
2021
>
2122
<CollapsiblePrimitives.CollapsibleTrigger asChild>
22-
<div className="flex items-center justify-between w-full px-2.5 gap-1.5 text-sm text-secondary-foreground font-medium cursor-pointer">
23-
<p className="truncate">{props.item.data.label}</p>
23+
<div
24+
className={clsx(
25+
"flex items-center w-full gap-1.5 text-sm font-medium cursor-pointer justify-between",
26+
isOpen
27+
? "text-muted-foreground"
28+
: "text-muted/75 dark:text-neutral-400",
29+
)}
30+
>
31+
<div className="flex items-center gap-1.5">
32+
{props.isNestedElement && (
33+
<Icon
34+
icon={props.item.data.icon}
35+
className={clsx(
36+
"shrink-0 size-4 mr-1",
37+
isOpen
38+
? "text-muted-foreground"
39+
: "text-muted/75 dark:text-neutral-400",
40+
)}
41+
/>
42+
)}
43+
<p className="truncate">{props.item.data.label}</p>
44+
</div>
45+
{props.isNestedElement && (
46+
<Icon
47+
icon="lucide:chevron-down"
48+
className={clsx(
49+
"shrink-0 size-4 mr-1",
50+
props.currentPathname.startsWith(`/docs/${props.item.id}`)
51+
? "text-primary"
52+
: "group-data-[state=open]:text-muted-foreground",
53+
)}
54+
/>
55+
)}
2456
</div>
2557
</CollapsiblePrimitives.CollapsibleTrigger>
2658
<CollapsiblePrimitives.CollapsibleContent className="flex flex-col pl-5 ml-1">
@@ -29,11 +61,12 @@ export default function Collapsible(props: PropsWithChildren<Props>) {
2961
return (
3062
<div
3163
key={item.id}
32-
className="group relative w-full px-2.5 py-1.5 flex items-center gap-1.5 text-sm after:absolute after:-left-1.5 after:inset-y-0 after:block after:w-px after:transition-colors after:bg-muted/25 dark:after:bg-neutral-700 text-muted/75 dark:text-neutral-400"
64+
className="group relative w-full px-2.5 py-1.5 flex items-center gap-1.5 text-sm after:absolute after:-left-1.5 after:inset-y-0 after:block after:w-px after:transition-colors after:bg-muted/25 dark:after:bg-secondary text-muted/75 dark:text-neutral-400"
3365
>
3466
<Collapsible
3567
item={item}
3668
currentPathname={props.currentPathname}
69+
isNestedElement={true}
3770
/>
3871
</div>
3972
);
@@ -44,17 +77,18 @@ export default function Collapsible(props: PropsWithChildren<Props>) {
4477
key={item.id}
4578
href={`/docs/${item.id}`}
4679
className={clsx(
47-
"group relative w-full px-2.5 py-1.5 flex items-center gap-1.5 text-sm after:absolute after:-left-1.5 after:inset-y-0 after:block after:w-px after:transition-colors",
80+
"group relative w-full px-2.5 py-1.5 flex items-center gap-1.5 text-sm after:absolute after:inset-y-0 after:block after:w-px after:transition-colors",
81+
props.isNestedElement ? "after:-left-4" : "after:-left-1.5",
4882
props.currentPathname.startsWith(`/docs/${item.id}`)
4983
? "text-primary after:bg-primary after:z-1 after:rounded-full"
50-
: "after:bg-muted/25 dark:after:bg-neutral-700 text-muted/75 dark:text-neutral-400",
84+
: "after:bg-muted/25 dark:after:bg-secondary text-muted/75 dark:text-neutral-400",
5185
)}
5286
>
5387
<Icon
5488
icon={item.data.icon}
5589
className={clsx(
5690
"shrink-0 size-4 mr-1",
57-
props.currentPathname.startsWith(`/docs/${item.href}`)
91+
props.currentPathname.startsWith(`/docs/${item.id}`)
5892
? "text-primary"
5993
: "group-data-[state=open]:text-muted-foreground",
6094
)}

src/lib/layouts/DocsLayout.astro

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const currentCollection = documentations.find((element) => {
2323

2424
<BaseLayout>
2525
<main class="relative flex-1">
26-
<Separator />
2726
<div class="mx-auto px-2 sm:px-0 max-w-[var(--container-width)]">
2827
<div class="flex flex-col lg:grid lg:grid-cols-10 lg:gap-8">
2928
<aside class="hidden lg:block lg:col-span-2 pr-2">
@@ -42,11 +41,11 @@ const currentCollection = documentations.find((element) => {
4241
<div
4342
class={clsx(
4443
"rounded-sm p-1 inline-flex ring-inset ring-1",
45-
// Astro.url.pathname.startsWith(
46-
// `${element.children[0].href}`,
47-
// )
48-
// ? "bg-primary ring-primary text-white"
49-
// : "bg-gray-50 dark:bg-gray-800 ring-gray-200 dark:ring-gray-700 text-muted-foreground",
44+
Astro.url.pathname.startsWith(
45+
`/docs/${currentCollection.id.replace("_default", "")}`,
46+
)
47+
? "bg-primary ring-primary text-background"
48+
: "bg-gray-50 dark:bg-gray-800 ring-gray-200 dark:ring-gray-700 text-muted-foreground",
5049
)}
5150
>
5251
{element.data.icon && (
@@ -60,11 +59,11 @@ const currentCollection = documentations.find((element) => {
6059
<span
6160
class={clsx(
6261
"text-sm relative",
63-
// Astro.url.pathname.startsWith(
64-
// `${element.children[0].href}`,
65-
// )
66-
// ? "text-primary"
67-
// : "text-muted-foreground",
62+
Astro.url.pathname.startsWith(
63+
`/docs/${currentCollection.id.replace("_default", "")}`,
64+
)
65+
? "text-primary/80"
66+
: "text-muted-foreground",
6867
)}
6968
>
7069
{element.data.label}

0 commit comments

Comments
 (0)