Skip to content

Commit 25a385b

Browse files
committed
WIP(ui-top-nav-bar): refactor
1 parent b514597 commit 25a385b

File tree

2 files changed

+79
-30
lines changed

2 files changed

+79
-30
lines changed

packages/__docs__/src/App/index.tsx

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
} from '@instructure/ui-icons'
4040
import generateStyle from './styles'
4141
import generateComponentTheme from './theme'
42+
import { Img } from '@instructure/ui-img'
4243

4344
type AppProps = {
4445
navigate: (path: string, options?: { replace: boolean }) => void
@@ -63,6 +64,8 @@ type Menu = {
6364
onClick?: () => void
6465
}
6566
title: string
67+
renderBeforeMobileMenuItems?: JSX.Element
68+
renderAfterMobileMenuItems?: JSX.Element
6669
}
6770

6871
type MenuCollection = {
@@ -75,7 +78,12 @@ class App extends Component<AppProps, AppState> {
7578
super(props)
7679

7780
this.state = {
78-
menuStack: ['default']
81+
menuStack: [
82+
'default',
83+
...(window.location.pathname.substring(1)
84+
? [window.location.pathname.substring(1)]
85+
: [])
86+
]
7987
}
8088
}
8189

@@ -142,9 +150,8 @@ class App extends Component<AppProps, AppState> {
142150
label: 'Dashboard',
143151
renderBeforeLabel: <IconDashboardLine />,
144152
onClick: () => {
145-
// Navigate and reload logic
146153
this.props.navigate('/dashboard', { replace: true })
147-
window.location.reload() // Forces a reload
154+
window.location.reload()
148155
}
149156
},
150157
{
@@ -153,12 +160,19 @@ class App extends Component<AppProps, AppState> {
153160
}
154161
],
155162
backNavigation: {
156-
href: '#',
157-
label: 'Back'
163+
href: undefined,
164+
label: '',
165+
onClick: undefined
158166
},
159-
title: 'Main Menu'
167+
title: ''
160168
},
161169
account: {
170+
renderBeforeMobileMenuItems: (
171+
<div style={{ display: 'flex', justifyContent: 'center' }}>
172+
<Img src="https://sbcf.fr/wp-content/uploads/2018/03/sbcf-default-avatar.png" />
173+
</div>
174+
),
175+
renderAfterMobileMenuItems: <h3>Additional account info</h3>,
162176
items: [
163177
{
164178
label: 'AccountInfo1'
@@ -182,6 +196,18 @@ class App extends Component<AppProps, AppState> {
182196
}
183197
},
184198
title: 'Courses'
199+
},
200+
dashboard: {
201+
title: 'Dashboard',
202+
items: [{ label: 'Courses1' }, { label: 'Courses2' }],
203+
backNavigation: {
204+
label: 'Back',
205+
onClick: () => {
206+
this.popMenu()
207+
this.props.navigate('/', { replace: true })
208+
window.location.reload()
209+
}
210+
}
185211
}
186212
}
187213

@@ -219,15 +245,18 @@ class App extends Component<AppProps, AppState> {
219245
onClick: () => alert('Alerts clicked')
220246
}
221247
]}
222-
mobileMenuBackNavigation={menu[this.getCurrentMenu()].backNavigation}
248+
mobileMenuBackNavigation={menu[this.getCurrentMenu()]?.backNavigation}
223249
mobileMenu={menu[this.getCurrentMenu()].items}
224-
beforeMobileMenuItems={<div>Before Mobile Menu</div>}
225-
afterMobileMenuItems={<div>After Mobile Menu</div>}
250+
beforeMobileMenuItems={
251+
menu[this.getCurrentMenu()]?.renderBeforeMobileMenuItems
252+
}
253+
afterMobileMenuItems={
254+
menu[this.getCurrentMenu()]?.renderAfterMobileMenuItems
255+
}
226256
/>
227257
<Routes>
228258
<Route path="/" element={<h1>This is home</h1>} />
229259
<Route path="/dashboard" element={<h1>This is dashboard</h1>} />
230-
{/*<Route path="/profile" element={<Profile />} />*/}
231260
</Routes>
232261
</div>
233262
)

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

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,42 @@ const CanvasTopNav = ({
8888
))}
8989
</MobileTopNav.End>
9090
<MobileTopNav.Menu>
91-
<div style={{ marginTop: 16 }}>
92-
<Breadcrumb label={mobileMenuBackNavigation.label}>
93-
<BreadcrumbLink
94-
href={mobileMenuBackNavigation.href}
95-
onClick={mobileMenuBackNavigation.onClick}
91+
{mobileMenuBackNavigation.label && (
92+
<div style={{ marginTop: 16 }}>
93+
<InstUISettingsProvider
94+
theme={{
95+
componentOverrides: {
96+
Link: {
97+
color: styles.breadcrumbOverride.color
98+
}
99+
}
100+
}}
96101
>
97-
<div
98-
style={{
99-
display: 'flex',
100-
alignItems: 'center',
101-
gap: '8px'
102-
}}
103-
>
104-
<IconArrowOpenStartLine />
105-
{mobileMenuBackNavigation.label}
106-
</div>
107-
</BreadcrumbLink>
108-
</Breadcrumb>
109-
</div>
110-
{beforeMobileMenuItems && beforeMobileMenuItems}
102+
<Breadcrumb label={mobileMenuBackNavigation.label}>
103+
<BreadcrumbLink
104+
href={mobileMenuBackNavigation.href}
105+
onClick={mobileMenuBackNavigation.onClick}
106+
>
107+
<div
108+
style={{
109+
display: 'flex',
110+
alignItems: 'center',
111+
gap: '8px'
112+
}}
113+
>
114+
<IconArrowOpenStartLine />
115+
{mobileMenuBackNavigation.label}
116+
</div>
117+
</BreadcrumbLink>
118+
</Breadcrumb>
119+
</InstUISettingsProvider>
120+
</div>
121+
)}
122+
{beforeMobileMenuItems && (
123+
<div style={{ marginTop: '24px', marginBottom: '16px' }}>
124+
{beforeMobileMenuItems}
125+
</div>
126+
)}
111127
<MobileTopNav.ItemList title={mobileMenuTitle}>
112128
{mobileMenu.map((item: any, index: any) => (
113129
<MobileTopNav.Item
@@ -120,7 +136,11 @@ const CanvasTopNav = ({
120136
</MobileTopNav.Item>
121137
))}
122138
</MobileTopNav.ItemList>
123-
{afterMobileMenuItems && afterMobileMenuItems}
139+
{afterMobileMenuItems && (
140+
<div style={{ marginTop: '24px', marginBottom: '16px' }}>
141+
{afterMobileMenuItems}
142+
</div>
143+
)}
124144
</MobileTopNav.Menu>
125145
</MobileTopNav>
126146
) : (

0 commit comments

Comments
 (0)