Skip to content

Commit 86c1810

Browse files
committed
WIP(ui-top-nav-bar): add desktop topnav
1 parent 6448624 commit 86c1810

File tree

7 files changed

+597
-224
lines changed

7 files changed

+597
-224
lines changed

packages/__docs__/src/App/index.tsx

Lines changed: 233 additions & 223 deletions
Large diffs are not rendered by default.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
describes: MobileTopNav
3+
---
4+
5+
POC mobile top nav
6+
7+
```js
8+
---
9+
type: example
10+
---
11+
const Example = () => {
12+
const lightMode = false
13+
const brandSvg = (
14+
<IconButton screenReaderLabel="Canvas Brand" href="#">
15+
<svg viewBox="0 0 1920 1920" xmlns="http://www.w3.org/2000/svg" fill="#fff">
16+
<path d="M958.568 277.97C1100.42 277.97 1216.48 171.94 1233.67 34.3881 1146.27 12.8955 1054.57 0 958.568 0 864.001 0 770.867 12.8955 683.464 34.3881 700.658 171.94 816.718 277.97 958.568 277.97ZM35.8207 682.031C173.373 699.225 279.403 815.285 279.403 957.136 279.403 1098.99 173.373 1215.05 35.8207 1232.24 12.8953 1144.84 1.43262 1051.7 1.43262 957.136 1.43262 862.569 12.8953 769.434 35.8207 682.031ZM528.713 957.142C528.713 1005.41 489.581 1044.55 441.31 1044.55 393.038 1044.55 353.907 1005.41 353.907 957.142 353.907 908.871 393.038 869.74 441.31 869.74 489.581 869.74 528.713 908.871 528.713 957.142ZM1642.03 957.136C1642.03 1098.99 1748.06 1215.05 1885.61 1232.24 1908.54 1144.84 1920 1051.7 1920 957.136 1920 862.569 1908.54 769.434 1885.61 682.031 1748.06 699.225 1642.03 815.285 1642.03 957.136ZM1567.51 957.142C1567.51 1005.41 1528.38 1044.55 1480.11 1044.55 1431.84 1044.55 1392.71 1005.41 1392.71 957.142 1392.71 908.871 1431.84 869.74 1480.11 869.74 1528.38 869.74 1567.51 908.871 1567.51 957.142ZM958.568 1640.6C816.718 1640.6 700.658 1746.63 683.464 1884.18 770.867 1907.11 864.001 1918.57 958.568 1918.57 1053.14 1918.57 1146.27 1907.11 1233.67 1884.18 1216.48 1746.63 1100.42 1640.6 958.568 1640.6ZM1045.98 1480.11C1045.98 1528.38 1006.85 1567.51 958.575 1567.51 910.304 1567.51 871.172 1528.38 871.172 1480.11 871.172 1431.84 910.304 1392.71 958.575 1392.71 1006.85 1392.71 1045.98 1431.84 1045.98 1480.11ZM1045.98 439.877C1045.98 488.148 1006.85 527.28 958.575 527.28 910.304 527.28 871.172 488.148 871.172 439.877 871.172 391.606 910.304 352.474 958.575 352.474 1006.85 352.474 1045.98 391.606 1045.98 439.877ZM1441.44 1439.99C1341.15 1540.29 1333.98 1697.91 1418.52 1806.8 1579 1712.23 1713.68 1577.55 1806.82 1418.5 1699.35 1332.53 1541.74 1339.7 1441.44 1439.99ZM1414.21 1325.37C1414.21 1373.64 1375.08 1412.77 1326.8 1412.77 1278.53 1412.77 1239.4 1373.64 1239.4 1325.37 1239.4 1277.1 1278.53 1237.97 1326.8 1237.97 1375.08 1237.97 1414.21 1277.1 1414.21 1325.37ZM478.577 477.145C578.875 376.846 586.039 219.234 501.502 110.339 341.024 204.906 206.338 339.592 113.203 498.637 220.666 584.607 378.278 576.01 478.577 477.145ZM679.155 590.32C679.155 638.591 640.024 677.723 591.752 677.723 543.481 677.723 504.349 638.591 504.349 590.32 504.349 542.048 543.481 502.917 591.752 502.917 640.024 502.917 679.155 542.048 679.155 590.32ZM1440 475.712C1540.3 576.01 1697.91 583.174 1806.8 498.637 1712.24 338.159 1577.55 203.473 1418.51 110.339 1332.54 217.801 1341.13 375.413 1440 475.712ZM1414.21 590.32C1414.21 638.591 1375.08 677.723 1326.8 677.723 1278.53 677.723 1239.4 638.591 1239.4 590.32 1239.4 542.048 1278.53 502.917 1326.8 502.917 1375.08 502.917 1414.21 542.048 1414.21 590.32ZM477.145 1438.58C376.846 1338.28 219.234 1331.12 110.339 1415.65 204.906 1576.13 339.593 1710.82 498.637 1805.39 584.607 1696.49 577.443 1538.88 477.145 1438.58ZM679.155 1325.37C679.155 1373.64 640.024 1412.77 591.752 1412.77 543.481 1412.77 504.349 1373.64 504.349 1325.37 504.349 1277.1 543.481 1237.97 591.752 1237.97 640.024 1237.97 679.155 1277.1 679.155 1325.37Z"/>
17+
</svg>
18+
</IconButton>
19+
)
20+
return (
21+
<div>
22+
<p>
23+
1
24+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
25+
</p>
26+
<p>
27+
2
28+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
29+
</p>
30+
<p>
31+
3
32+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
33+
</p>
34+
<p>
35+
4
36+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
37+
</p>
38+
<p>
39+
5
40+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
41+
</p>
42+
<p>
43+
6
44+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
45+
</p>
46+
<p>
47+
7
48+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
49+
</p>
50+
<p>
51+
8
52+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
53+
</p>
54+
<p>
55+
9
56+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
57+
</p>
58+
<p>
59+
10
60+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
61+
</p>
62+
<p>
63+
11
64+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
65+
</p>
66+
<p>
67+
12
68+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
69+
</p>
70+
<p>
71+
13
72+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
73+
</p>
74+
<p>
75+
14
76+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
77+
</p>
78+
<p>
79+
15
80+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
81+
</p>
82+
<p>
83+
16
84+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
85+
</p>
86+
<p>
87+
17
88+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
89+
</p>
90+
<p>
91+
18
92+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
93+
</p>
94+
<p>
95+
19
96+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
97+
</p>
98+
<p>
99+
20
100+
Lorem ipsum dolor sit, amet consectetur adipisicing elit. Molestias excepturi a blanditiis, aspernatur repellat repellendus dolores cum labore eligendi architecto asperiores, dolor quisquam sequi mollitia quibusdam, cumque id ab amet?
101+
</p>
102+
</div>
103+
)
104+
}
105+
106+
render(<Example />)
107+
```
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/* eslint-disable react/display-name */
2+
/*
3+
* The MIT License (MIT)
4+
*
5+
* Copyright (c) 2015 - present Instructure, Inc.
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*/
25+
26+
/** @jsx jsx */
27+
import { Children, PropsWithChildren, useEffect, useState } from 'react'
28+
import { jsx, useTheme } from '@instructure/emotion'
29+
import type { DesktopTopNavProps } from './props'
30+
31+
import { IconButton } from '@instructure/ui-buttons'
32+
import { IconHamburgerLine, IconXLine } from '@instructure/ui-icons'
33+
import { generateStyles } from './styles'
34+
35+
/**
36+
---
37+
category: components
38+
---
39+
**/
40+
const DesktopTopNav = ({
41+
lightMode = false,
42+
styles,
43+
children
44+
}: DesktopTopNavProps) => {
45+
const [open, setOpen] = useState<boolean>(false)
46+
47+
useEffect(() => {
48+
const body = document.getElementsByTagName('body')[0]
49+
body.style.overflow = open ? 'hidden' : 'visible'
50+
}, [open])
51+
52+
const getSubComponent = (displayName: any) => {
53+
return Children.map(children, (child: any) => child)?.filter(
54+
(child: any) => child?.type?.displayName === displayName
55+
)
56+
}
57+
58+
return (
59+
<div style={styles.container(open)}>
60+
<div style={styles.topBar}>
61+
<span style={styles.btnRow}>
62+
{/*{!open && getSubComponent('BtnRow')}*/}
63+
<IconButton
64+
withBackground={false}
65+
withBorder={false}
66+
screenReaderLabel="burgir"
67+
color={lightMode ? 'secondary' : 'primary-inverse'}
68+
onClick={() => setOpen((open) => !open)}
69+
>
70+
{open ? <IconXLine /> : <IconHamburgerLine />}
71+
</IconButton>
72+
</span>
73+
{getSubComponent('BreadCrumb')}
74+
</div>
75+
</div>
76+
)
77+
}
78+
79+
const BreadCrumb = ({ children }: PropsWithChildren) => {
80+
return (
81+
<div style={{ margin: '24px 0', display: 'inline-block' }}>{children}</div>
82+
)
83+
}
84+
85+
BreadCrumb.displayName = 'BreadCrumb'
86+
87+
const withStyles =
88+
<ComponentOwnProps, ComponentStyle>(
89+
generateStyles: (props: any, theme: any) => ComponentStyle
90+
) =>
91+
(WrappedComponent: any) =>
92+
(originalProps: ComponentOwnProps) => {
93+
const theme = useTheme()
94+
const styledProps = {
95+
styles: generateStyles(originalProps, theme),
96+
...originalProps
97+
}
98+
return <WrappedComponent {...styledProps} />
99+
}
100+
101+
const SC: any = withStyles(generateStyles)(DesktopTopNav)
102+
103+
SC.BreadCrumb = BreadCrumb
104+
// TODO investigate whether displayName should be added to the original component
105+
106+
export { SC as DesktopTopNav }
107+
export default SC
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2015 - present Instructure, Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
import type { ReactNode, PropsWithChildren } from 'react'
26+
27+
type DesktopTopNavOwnProps = {
28+
lightMode?: boolean
29+
brand?: ReactNode
30+
}
31+
32+
type DesktopTopNavStyle = {
33+
container: (open: boolean) => {
34+
[key: string]: string | number
35+
}
36+
content: (open: boolean) => {
37+
[key: string]: string | number
38+
}
39+
topBar: {
40+
[key: string]: string | number
41+
}
42+
btnRow: {
43+
[key: string]: string | number
44+
}
45+
}
46+
47+
type DesktopTopNavProps = DesktopTopNavOwnProps & {
48+
styles: DesktopTopNavStyle
49+
} & PropsWithChildren
50+
51+
export type { DesktopTopNavProps, DesktopTopNavOwnProps }
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2015 - present Instructure, Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
import type { DesktopTopNavProps } from './props'
25+
26+
//TODO use theme variables for spacing
27+
const generateStyles = (props: DesktopTopNavProps, theme: any) => {
28+
const { lightMode } = props
29+
return {
30+
container: (open: boolean) => {
31+
return {
32+
height: '54px',
33+
position: open ? 'fixed' : 'relative',
34+
backgroundColor: lightMode
35+
? theme.colors.ui.surfacePageSecondary
36+
: theme.colors.ui.surfaceDark,
37+
color: lightMode
38+
? theme.colors.contrasts.grey125125
39+
: theme.colors?.contrasts?.white1010,
40+
width: '100%',
41+
zIndex: '1000'
42+
}
43+
},
44+
topBar: {
45+
padding: `0 ${theme.spacing.small}`,
46+
height: '54px',
47+
display: 'flex',
48+
alignItems: 'center'
49+
// justifyContent: 'space-between'
50+
},
51+
content: (open: boolean) => {
52+
return {
53+
padding: `0 ${theme.spacing.small}`,
54+
height: open ? '100%' : '0px',
55+
top: '3.375rem',
56+
bottom: 0,
57+
left: 0,
58+
right: 0,
59+
overflow: open ? 'scroll' : 'hidden',
60+
position: 'fixed',
61+
backgroundColor: lightMode
62+
? theme.colors.ui.surfacePageSecondary
63+
: theme.colors.ui.surfaceDark,
64+
color: lightMode
65+
? theme.colors.contrasts.grey125125
66+
: theme.colors?.contrasts?.white1010
67+
}
68+
},
69+
btnRow: {
70+
display: 'flex',
71+
gap: '12px'
72+
}
73+
}
74+
}
75+
const generateItemListStyles = (_props: any, theme: any) => {
76+
return {
77+
divider: {
78+
height: '0.0625rem',
79+
overflow: 'hidden',
80+
background: theme.colors.contrasts.grey1214
81+
}
82+
}
83+
}
84+
const generateItemStyles = (_props: any, _theme: any) => {
85+
return {
86+
container: {
87+
margin: '16px 0',
88+
display: 'flex',
89+
cursor: 'pointer',
90+
alignItems: 'flex-end'
91+
},
92+
leftIcon: { paddingRight: '8px', fontSize: '18px' },
93+
rightIcon: { marginLeft: 'auto', paddingRight: '8px', fontSize: '18px' }
94+
}
95+
}
96+
97+
export { generateStyles, generateItemListStyles, generateItemStyles }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const MobileTopNav = ({
6161
}, [open])
6262

6363
const getSubComponent = (displayName: any) => {
64-
return Children.map(children, (child: any) => child).filter(
64+
return Children.map(children, (child: any) => child)?.filter(
6565
(child: any) => child?.type?.displayName === displayName
6666
)
6767
}

packages/ui-top-nav-bar/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ export type {
6262
} from './TopNavBar/TopNavBarUser/props'
6363

6464
export { MobileTopNav } from './MobileTopNav'
65+
export { DesktopTopNav } from './DesktopTopNav'

0 commit comments

Comments
 (0)