UNPKG

fumadocs-ui

Version:

The Radix UI version of Fumadocs UI

178 lines (177 loc) 4.58 kB
import { FullSearchTriggerProps, SearchTriggerProps } from "./slots/search-trigger.js"; import { ThemeSwitchProps } from "./slots/theme-switch.js"; import { BaseSlots, BaseSlotsProps, LinkItem, baseSlots } from "./client.js"; import { ComponentProps, FC, ReactNode } from "react"; import * as PageTree from "fumadocs-core/page-tree"; import { I18nConfig } from "fumadocs-core/i18n"; //#region src/layouts/shared/index.d.ts interface NavOptions { enabled?: boolean; children?: ReactNode; title?: ReactNode | FC<ComponentProps<'a'>>; /** * Redirect url of title * @defaultValue '/' */ url?: string; /** * Use transparent background * * @defaultValue none */ transparentMode?: 'always' | 'top' | 'none'; /** * @deprecated use `slots.header` instead. */ component?: ReactNode; } interface BaseLayoutProps { /** * GitHub url */ githubUrl?: string; links?: LinkItemType[]; /** * navigation config */ nav?: NavOptions; slots?: Partial<BaseSlots>; children?: ReactNode; themeSwitch?: ThemeSwitchOptions; searchToggle?: SearchToggleOptions; /** * @deprecated this is now optional for i18n setups, you can still customize language switch from `slots`. */ i18n?: boolean | I18nConfig; } interface SearchToggleOptions { enabled?: boolean; sm?: SearchTriggerProps; full?: FullSearchTriggerProps; /** @deprecated use `slots.searchTrigger` instead */ components?: { sm?: ReactNode; lg?: ReactNode; }; } interface ThemeSwitchOptions extends ThemeSwitchProps { enabled?: boolean; /** @deprecated use `slots.themeSwitch` instead */ component?: ReactNode; } interface LayoutTab { /** * Redirect URL of the folder, usually the index page */ url: string; icon?: ReactNode; title: ReactNode; description?: ReactNode; unlisted?: boolean; props?: ComponentProps<'a'>; /** * bind to a page tree node. */ $folder?: PageTree.Folder; /** * Detect from a list of urls (when not binded to page tree). */ urls?: Set<string>; } interface GetLayoutTabsOptions { transform?: (option: LayoutTab, node: PageTree.Folder) => LayoutTab | null; } declare function getLayoutTabs(tree: PageTree.Root, { transform }?: GetLayoutTabsOptions): LayoutTab[]; declare function isLayoutTabActive(tab: LayoutTab, pathname: string): boolean; interface Filterable { /** * Restrict where the item is displayed * * @defaultValue 'all' */ on?: 'menu' | 'nav' | 'all'; } interface WithHref { url: string; /** * When the item is marked as active * * @defaultValue 'url' */ active?: 'url' | 'nested-url' | 'none'; external?: boolean; } interface MainItemType extends WithHref, Filterable { type?: 'main'; icon?: ReactNode; text: ReactNode; description?: ReactNode; } interface IconItemType extends WithHref, Filterable { type: 'icon'; /** * `aria-label` of icon button */ label?: string; icon: ReactNode; text: ReactNode; /** * @defaultValue true */ secondary?: boolean; } interface ButtonItemType extends WithHref, Filterable { type: 'button'; icon?: ReactNode; text: ReactNode; /** * @defaultValue false */ secondary?: boolean; } interface MenuItemType extends Partial<WithHref>, Filterable { type: 'menu'; icon?: ReactNode; text: ReactNode; items: ((MainItemType & { /** * Options when displayed on navigation menu */ menu?: ComponentProps<'a'> & { banner?: ReactNode; }; }) | CustomItemType)[]; /** * @defaultValue false */ secondary?: boolean; } interface CustomItemType extends Filterable { type: 'custom'; /** * @defaultValue false */ secondary?: boolean; children: ReactNode; } type LinkItemType = MainItemType | IconItemType | ButtonItemType | MenuItemType | CustomItemType; /** * Get link items with shortcuts */ declare function resolveLinkItems({ links, githubUrl }: Pick<BaseLayoutProps, 'links' | 'githubUrl'>): LinkItemType[]; declare function useLinkItems({ githubUrl, links }: Pick<BaseLayoutProps, 'links' | 'githubUrl'>): { navItems: LinkItemType[]; menuItems: LinkItemType[]; all: LinkItemType[]; }; declare function isLinkItemActive(link: LinkItemType, pathname: string): boolean; //#endregion export { BaseLayoutProps, type BaseSlots, type BaseSlotsProps, ButtonItemType, CustomItemType, GetLayoutTabsOptions, IconItemType, LayoutTab, LinkItem, LinkItemType, MainItemType, MenuItemType, NavOptions, baseSlots, getLayoutTabs, isLayoutTabActive, isLinkItemActive, resolveLinkItems, useLinkItems };