MCPcopy Create free account
hub / github.com/adobe/react-spectrum / SideNavExample

Function SideNavExample

examples/s2-next-macros/src/app/page.tsx:270–313  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

268// Wrap SideNav in a RouterProvider whose navigate only updates local state so
269// clicking a link selects the item without actually navigating the page.
270function SideNavExample() {
271 let [selectedRoute, setSelectedRoute] = useState('/notes');
272 return (
273 <RouterProvider navigate={href => setSelectedRoute(href)}>
274 <SideNav
275 aria-label="Files"
276 styles={style({height: 300, width: 210})}
277 selectedRoute={selectedRoute}
278 defaultExpandedKeys={[1, 2, 5]}
279 items={sideNavItems}>
280 {function renderItem(item: SideNavItemData) {
281 return (
282 <SideNavItem textValue={item.title} href={item.href}>
283 <SideNavItemContent>
284 {item.href ? (
285 <SideNavItemLink>
286 {item.type === 'directory' ? <Folder /> : <File />}
287 <Text>{item.title}</Text>
288 </SideNavItemLink>
289 ) : (
290 <>
291 {item.type === 'directory' ? <Folder /> : <File />}
292 <Text>{item.title}</Text>
293 </>
294 )}
295 <ActionMenu>
296 <MenuItem>
297 <Edit />
298 <Text>Edit</Text>
299 </MenuItem>
300 <MenuItem>
301 <Delete />
302 <Text>Delete</Text>
303 </MenuItem>
304 </ActionMenu>
305 </SideNavItemContent>
306 {item.children && <Collection items={item.children}>{renderItem}</Collection>}
307 </SideNavItem>
308 );
309 }}
310 </SideNav>
311 </RouterProvider>
312 );
313}
314
315function App() {
316 let [isLazyLoaded, setLazyLoaded] = useState(false);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected