Skip to content

Commit 685165c

Browse files
committed
feat(docs): add provider icons to tools sidebar
1 parent 15ca66f commit 685165c

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

apps/docs/components/docs-layout/sidebar-components.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { type ReactNode, useState } from 'react'
44
import type { Folder, Item, Separator } from 'fumadocs-core/page-tree'
55
import Link from 'next/link'
66
import { usePathname } from 'next/navigation'
7+
import { blockTypeToIconMap } from '@/components/ui/icon-mapping'
78
import { i18n } from '@/lib/i18n'
89
import { cn } from '@/lib/utils'
910

@@ -41,6 +42,18 @@ function stripLangPrefix(path: string): string {
4142
return path
4243
}
4344

45+
/**
46+
* Resolves the provider icon for a tools sidebar item. Tool pages live under
47+
* `/tools/<slug>`, where the slug matches a block type in the icon map.
48+
*/
49+
function getToolIcon(url: string) {
50+
const path = stripLangPrefix(url)
51+
if (!path.startsWith('/tools/')) return null
52+
const slug = path.slice('/tools/'.length)
53+
if (!slug || slug.includes('/')) return null
54+
return blockTypeToIconMap[slug] ?? null
55+
}
56+
4457
function isActive(url: string, pathname: string, nested = true): boolean {
4558
const normalizedPathname = stripLangPrefix(pathname)
4659
const normalizedUrl = stripLangPrefix(url)
@@ -55,7 +68,7 @@ const ITEM_BASE =
5568
const ITEM_ACTIVE_MOBILE = 'bg-fd-primary/10 font-medium text-fd-primary'
5669

5770
const ITEM_DESKTOP =
58-
'lg:mb-[0.0625rem] lg:block lg:rounded-lg lg:px-2.5 lg:py-1.5 lg:font-normal lg:text-[13px] lg:leading-tight'
71+
'lg:mb-[0.0625rem] lg:rounded-lg lg:px-2.5 lg:py-1.5 lg:font-normal lg:text-[13px] lg:leading-tight'
5972
const ITEM_TEXT = 'lg:text-[#3b3b3b] lg:dark:text-[#cdcdcd]'
6073
const ITEM_HOVER = 'lg:hover:bg-[#f2f2f2] lg:dark:hover:bg-[#262626]'
6174
const ITEM_ACTIVE =
@@ -69,6 +82,7 @@ const FOLDER_ACTIVE =
6982
export function SidebarItem({ item }: { item: Item }) {
7083
const pathname = usePathname()
7184
const active = isActive(item.url, pathname, false)
85+
const ToolIcon = getToolIcon(item.url)
7286

7387
return (
7488
<Link
@@ -83,6 +97,7 @@ export function SidebarItem({ item }: { item: Item }) {
8397
active && ITEM_ACTIVE
8498
)}
8599
>
100+
{ToolIcon && <ToolIcon className='size-[14px] flex-shrink-0' />}
86101
{item.name}
87102
</Link>
88103
)

0 commit comments

Comments
 (0)