kamrify commited on
Commit
872c66a
·
1 Parent(s): ee23801

Active guide page highlight

Browse files
docs/src/components/DocsHeader.tsx CHANGED
@@ -3,10 +3,11 @@ import type { CollectionEntry } from "astro:content";
3
 
4
  type DocsHeaderProps = {
5
  groupedGuides: Record<string, CollectionEntry<"guides">[]>;
 
6
  };
7
 
8
  export function DocsHeader(props: DocsHeaderProps) {
9
- const { groupedGuides } = props;
10
  const [isActive, setIsActive] = useState(false);
11
 
12
  return (
@@ -29,8 +30,8 @@ export function DocsHeader(props: DocsHeaderProps) {
29
  <div key={category} className="flex flex-col gap-2">
30
  <div className="font-bold text-gray-900 text-sm uppercase">{category}</div>
31
  <div className="flex flex-col">
32
- {guides.map((guide) => (
33
- <a key={guide.slug} href={`/docs/${guide.slug}`} className="text-gray-500 hover:text-gray-900 py-1">
34
  {guide.data.title}
35
  </a>
36
  ))}
 
3
 
4
  type DocsHeaderProps = {
5
  groupedGuides: Record<string, CollectionEntry<"guides">[]>;
6
+ activeGuideTitle: string;
7
  };
8
 
9
  export function DocsHeader(props: DocsHeaderProps) {
10
+ const { groupedGuides, activeGuideTitle } = props;
11
  const [isActive, setIsActive] = useState(false);
12
 
13
  return (
 
30
  <div key={category} className="flex flex-col gap-2">
31
  <div className="font-bold text-gray-900 text-sm uppercase">{category}</div>
32
  <div className="flex flex-col">
33
+ {guides.map(guide => (
34
+ <a key={guide.slug} href={`/docs/${guide.slug}`} className={`${activeGuideTitle === guide.data.title ? 'text-black': 'text-gray-400'} hover:text-gray-900 py-1`}>
35
  {guide.data.title}
36
  </a>
37
  ))}
docs/src/components/Sidebar.astro CHANGED
@@ -7,9 +7,7 @@ export interface Props {
7
  activePath: string;
8
  }
9
 
10
- const groupedGuides = getAllGuides();
11
-
12
- const { activePath } = Astro.props;
13
  ---
14
  <div class="hidden md:block w-[200px] lg:w-[350px] border-r border-gray-200 text-right min-h-screen flex-shrink-0">
15
  <div class="relative sh:sticky top-0">
@@ -31,7 +29,7 @@ const { activePath } = Astro.props;
31
  return (
32
  <li class="mb-2">
33
  <a href={guidePath}
34
- class:list={["hover:text-black pr-5 py-2", { "text-black": activePath === guidePath }]}>{guide.data.title}</a>
35
  </li>
36
  );
37
  })}
 
7
  activePath: string;
8
  }
9
 
10
+ const { activePath, groupedGuides, activeGuideTitle } = Astro.props;
 
 
11
  ---
12
  <div class="hidden md:block w-[200px] lg:w-[350px] border-r border-gray-200 text-right min-h-screen flex-shrink-0">
13
  <div class="relative sh:sticky top-0">
 
29
  return (
30
  <li class="mb-2">
31
  <a href={guidePath}
32
+ class:list={["hover:text-black pr-5 py-2", { "text-black": activeGuideTitle === guide.data.title }]}>{guide.data.title}</a>
33
  </li>
34
  );
35
  })}
docs/src/layouts/DocsLayout.astro CHANGED
@@ -20,9 +20,11 @@ const { groupTitle, sort, title } = guide.data;
20
  ---
21
 
22
  <BaseLayout title={title}>
23
- <DocsHeader groupedGuides={groupedGuides} client:load />
 
 
24
  <div class="flex">
25
- <Sidebar />
26
  <div
27
  class="min-w-0 max-w-[800px] py-6 md:py-12 prose px-6 md:px-14 prose-base md:proxe-xl mb-24 prose-blockquote:font-normal prose-blockquote:not-italic prose-blockquote:text-gray-500 prose-p:before:content-['']">
28
  <slot />
 
20
  ---
21
 
22
  <BaseLayout title={title}>
23
+ <div class="block md:hidden">
24
+ <DocsHeader activeGuideTitle={title} groupedGuides={groupedGuides} client:load />
25
+ </div>
26
  <div class="flex">
27
+ <Sidebar activeGuideTitle={title} groupedGuides={groupedGuides} />
28
  <div
29
  class="min-w-0 max-w-[800px] py-6 md:py-12 prose px-6 md:px-14 prose-base md:proxe-xl mb-24 prose-blockquote:font-normal prose-blockquote:not-italic prose-blockquote:text-gray-500 prose-p:before:content-['']">
30
  <slot />