MCPcopy Index your code
hub / github.com/adobe/react-spectrum / Nav

Function Nav

packages/dev/s2-docs/src/Nav.tsx:18–219  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16}
17
18export function Nav() {
19 let {pages, currentPage} = useRouter();
20 let [maskSize, setMaskSize] = useState(0);
21 let displayPage = usePendingPage();
22
23 if (currentPage.exports?.hideNav) {
24 return null;
25 }
26
27 let currentLibrary = getLibraryFromPage(displayPage);
28 let sections = new Map<string, SectionValue>();
29 let sectionLibrary = new Map();
30 for (let page of pages) {
31 if (page.exports?.hideNav || page.exports?.omitFromNav) {
32 continue;
33 }
34
35 let library = getLibraryFromPage(page);
36
37 if (currentLibrary === 'react-spectrum' && library !== currentLibrary) {
38 continue;
39 }
40
41 // If the current library is React Aria, we only want to skip pages in React Spectrum so that include Internationalized pages in the side nav
42 if (currentLibrary === 'react-aria' && library === 'react-spectrum') {
43 continue;
44 }
45
46 let section = page.exports?.section ?? 'Components';
47 let group = page.exports?.group ?? undefined;
48 if (section === '' || page.exports?.isSubpage) {
49 continue;
50 }
51
52 if (group && section) {
53 let value = sections.get(group);
54 let groupMap: Map<string, Page[]>;
55 if (value instanceof Map) {
56 groupMap = value;
57 } else {
58 groupMap = new Map<string, Page[]>();
59 }
60 let groupPages = groupMap.get(section) ?? [];
61 groupPages.push(page);
62 groupMap.set(section, groupPages);
63 sections.set(group, groupMap);
64 } else if (section) {
65 let value = sections.get(section);
66 let sectionPages = Array.isArray(value) ? value : [];
67 sectionPages.push(page);
68 sections.set(section, sectionPages);
69 }
70
71 sectionLibrary.set(section, library);
72 }
73
74 let sortedSections = [...sections].sort((a, b) => {
75 if (a[0] === 'Overview') {

Callers

nothing calls this directly

Calls 11

useRouterFunction · 0.90
usePendingPageFunction · 0.90
getLibraryFromPageFunction · 0.90
spaceFunction · 0.90
isSectionMapFunction · 0.85
isIntroductionFunction · 0.85
titleFunction · 0.85
pushMethod · 0.80
sortMethod · 0.65
filterMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected