Skip to content

Commit 38a1538

Browse files
committed
refactor(ui-top-nav-bar): add submenu pages
1 parent 6dfddba commit 38a1538

File tree

2 files changed

+89
-57
lines changed

2 files changed

+89
-57
lines changed

packages/__docs__/src/App/index.tsx

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -356,19 +356,37 @@ class App extends Component<AppProps, AppState> {
356356
ltiMenuItems={[
357357
{ id: 'library', title: 'My Library' },
358358
{ id: 'share', title: 'Share with me' },
359-
{ id: 'settings', title: 'Settings' }
360-
// { id: 'SubMenu', title: 'SubMenu', options: [ {
361-
// id: 'account',
362-
// label: 'Account',
363-
// renderBeforeTitle: <IconUserLine />,
364-
// subPageId: 'account'
365-
// },
366-
// {
367-
// id: 'courses',
368-
// label: 'Courses',
369-
// renderBeforeTitle: <IconCoursesLine />,
370-
// subPageId: 'courses'
371-
// },] }
359+
{ id: 'settings', title: 'Settings' },
360+
{
361+
id: 'submenu',
362+
title: 'SubMenu',
363+
options: [
364+
{
365+
id: 'account',
366+
label: 'Account',
367+
renderBeforeTitle: <IconUserLine />,
368+
subPageId: 'accountPage',
369+
subOptions: [
370+
{
371+
id: 'profile',
372+
label: 'Profile Settings',
373+
href: '/profile'
374+
},
375+
{
376+
id: 'privacy',
377+
label: 'Privacy',
378+
href: '/privacy'
379+
}
380+
]
381+
},
382+
{
383+
id: 'courses',
384+
label: 'Courses',
385+
renderBeforeTitle: <IconCoursesLine />,
386+
href: '/courses'
387+
}
388+
]
389+
}
372390
]}
373391
currentPageId="library" // ltiCurrentPageID
374392
/>

packages/ui-top-nav-bar/src/CanvasTopNav/index.tsx

Lines changed: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -213,51 +213,65 @@ const CanvasTopNav = ({
213213
renderHiddenItemsMenuTriggerLabel={() => ''}
214214
currentPageId={currentPageId}
215215
>
216-
{ltiMenuItems?.map((item: any) => (
217-
<TopNavBarItem key={item.id} id={item.id}>
218-
{item.title}
219-
</TopNavBarItem>
220-
))}
221-
<TopNavBarItem
222-
id="submenu"
223-
renderSubmenu={
224-
<Drilldown rootPageId="root">
225-
<Drilldown.Page id="root">
226-
<Drilldown.Option
227-
id="rootOption1"
228-
subPageId="secondPage"
229-
>
230-
Link One
231-
</Drilldown.Option>
232-
<Drilldown.Option
233-
id="rootOption2"
234-
href="/#TopNavBar"
235-
>
236-
Link Two
237-
</Drilldown.Option>
238-
<Drilldown.Option
239-
id="rootOption3"
240-
href="/#TopNavBar"
241-
>
242-
Link Three
243-
</Drilldown.Option>
244-
</Drilldown.Page>
245-
<Drilldown.Page id="secondPage">
246-
<Drilldown.Option id="secondPageOption1">
247-
Level 2 Option One
248-
</Drilldown.Option>
249-
<Drilldown.Option
250-
id="secondPageOption2"
251-
href="/#TopNavBar"
252-
>
253-
Level 2 Option Two
254-
</Drilldown.Option>
255-
</Drilldown.Page>
256-
</Drilldown>
216+
{ltiMenuItems?.map((item: any) => {
217+
// Check if this item has a submenu
218+
if (item.options?.length) {
219+
return (
220+
<TopNavBarItem
221+
key={item.id}
222+
id={item.id}
223+
renderSubmenu={
224+
<Drilldown rootPageId={item.id}>
225+
{/* Root Page */}
226+
<Drilldown.Page id={item.id}>
227+
{item.options.map((option: any) => (
228+
<Drilldown.Option
229+
key={option.id}
230+
id={option.id}
231+
subPageId={option.subPageId}
232+
href={option.href}
233+
>
234+
{option.renderBeforeTitle}
235+
{option.label}
236+
</Drilldown.Option>
237+
))}
238+
</Drilldown.Page>
239+
240+
{/* Optional nested pages if subPageId is used */}
241+
{item.options
242+
.filter((opt: any) => opt.subOptions?.length)
243+
.map((opt: any) => (
244+
<Drilldown.Page
245+
key={opt.subPageId}
246+
id={opt.subPageId}
247+
>
248+
{opt.subOptions.map((subOpt: any) => (
249+
<Drilldown.Option
250+
key={subOpt.id}
251+
id={subOpt.id}
252+
href={subOpt.href}
253+
>
254+
{subOpt.renderBeforeTitle}
255+
{subOpt.label}
256+
</Drilldown.Option>
257+
))}
258+
</Drilldown.Page>
259+
))}
260+
</Drilldown>
261+
}
262+
>
263+
{item.title}
264+
</TopNavBarItem>
265+
)
257266
}
258-
>
259-
Submenu
260-
</TopNavBarItem>
267+
268+
// Top-level item with no submenu
269+
return (
270+
<TopNavBarItem key={item.id} id={item.id}>
271+
{item.title}
272+
</TopNavBarItem>
273+
)
274+
})}
261275
</TopNavBarMenuItems>
262276
</TopNavBarContext.Provider>
263277
</InstUISettingsProvider>

0 commit comments

Comments
 (0)