docs: added file module docs (#7278)
This commit is contained in:
@@ -1,15 +1,59 @@
|
||||
"use client"
|
||||
|
||||
import React from "react"
|
||||
import React, { useMemo } from "react"
|
||||
import { Card, CardList, MDXComponents, useSidebar } from "../.."
|
||||
import { SidebarItemType } from "types"
|
||||
|
||||
type ChildDocsProps = {
|
||||
onlyTopLevel?: boolean
|
||||
type?: "sidebar" | "item"
|
||||
filters?: string[]
|
||||
}
|
||||
|
||||
export const ChildDocs = ({ onlyTopLevel = false }: ChildDocsProps) => {
|
||||
const { currentItems } = useSidebar()
|
||||
export const ChildDocs = ({
|
||||
onlyTopLevel = false,
|
||||
filters = [],
|
||||
type = "sidebar",
|
||||
}: ChildDocsProps) => {
|
||||
const { currentItems, getActiveItem } = useSidebar()
|
||||
|
||||
const filterItems = (items: SidebarItemType[]): SidebarItemType[] => {
|
||||
return items
|
||||
.filter(
|
||||
(item) =>
|
||||
(!item.path || !filters.includes(item.path)) &&
|
||||
!filters.includes(item.title)
|
||||
)
|
||||
.map((item) => Object.assign({}, item))
|
||||
.map((item) => {
|
||||
if (item.children) {
|
||||
item.children = filterItems(item.children)
|
||||
}
|
||||
|
||||
return item
|
||||
})
|
||||
}
|
||||
|
||||
const filteredItems = useMemo(() => {
|
||||
const targetItems =
|
||||
type === "sidebar"
|
||||
? currentItems
|
||||
? Object.assign({}, currentItems)
|
||||
: undefined
|
||||
: {
|
||||
top: [...(getActiveItem()?.children || [])],
|
||||
bottom: [],
|
||||
}
|
||||
if (!filters.length || !targetItems) {
|
||||
return targetItems
|
||||
}
|
||||
|
||||
return {
|
||||
...targetItems,
|
||||
top: filterItems(targetItems.top),
|
||||
bottom: filterItems(targetItems.bottom),
|
||||
}
|
||||
}, [currentItems, type, getActiveItem])
|
||||
|
||||
const getTopLevelElms = (items?: SidebarItemType[]) => (
|
||||
<CardList
|
||||
@@ -58,8 +102,8 @@ export const ChildDocs = ({ onlyTopLevel = false }: ChildDocsProps) => {
|
||||
|
||||
return (
|
||||
<>
|
||||
{getElms(currentItems?.top)}
|
||||
{getElms(currentItems?.bottom)}
|
||||
{getElms(filteredItems?.top)}
|
||||
{getElms(filteredItems?.bottom)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user