UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

37 lines (36 loc) 2.28 kB
import type { ReactNode } from "react"; import { type Element, type TreeElement, type TreeElementProps } from "../../util/element.js"; import { type AbsolutePath } from "../../util/path.js"; /** * Match an element that should appear in the sidebar menu. * - Directories and plain files always qualify. * - For documentation elements, only `kind: "module"` qualifies — functions, classes, methods, properties, etc. are kept off the navigation. */ export declare function matchMenuElement(element: Element): boolean; /** Extras threaded through `TreeMenuMapper` to every menu item — the parent's URL path. */ interface TreeMenuExtras { /** URL path of the parent element. Each item appends its own `name` to compute its own path. Defaults to `/`. */ readonly path: AbsolutePath; } /** * Default menu item renderer for any `tree-*` element. * - Computes its own URL path by appending its `name` to the parent's `path`. * - Passes both the label and the nested `<TreeMenuMapper>` to `<MenuItem>`; `<MenuItem>` itself decides whether to reveal the nested submenu based on the current URL. */ export declare function TreeMenuItem({ path, name, title, children }: TreeElementProps & TreeMenuExtras): ReactNode; /** Mapping + Mapper pair for the menu — wrap children in `<TreeMenuMapping>` to override. */ export declare const TreeMenuMapping: import("react").FunctionComponent<import("../misc/Mapper.js").MappingProps<TreeMenuExtras>>, TreeMenuMapper: import("react").FunctionComponent<import("../misc/Mapper.js").MapperProps<TreeMenuExtras>>; export interface TreeMenuProps { /** Root element whose children become the navigation links. */ readonly tree: TreeElement; /** URL path of the root — children get `path + their.name`. Defaults to `/`. */ readonly path?: AbsolutePath | undefined; } /** * Sidebar navigation menu built from the children of a root tree element. * - Renders each child via `<TreeMenuItem>` (the default mapping for `tree-directory` / `tree-file`). * - To customise renderers for specific types, wrap in `<TreeMenuMapping mapping={…}>`. * - Only directories and files appear — code symbols are kept off the navigation. */ export declare function TreeMenu({ path, tree }: TreeMenuProps): ReactNode; export {};