-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP(ui-top-nav-bar): add desktop topnav
- Loading branch information
1 parent
6448624
commit 86c1810
Showing
7 changed files
with
597 additions
and
224 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
--- | ||
describes: MobileTopNav | ||
--- | ||
|
||
POC mobile top nav | ||
|
||
```js | ||
--- | ||
type: example | ||
--- | ||
const Example = () => { | ||
const lightMode = false | ||
const brandSvg = ( | ||
<IconButton screenReaderLabel="Canvas Brand" href="#"> | ||
<svg viewBox="0 0 1920 1920" xmlns="http://www.w3.org/2000/svg" fill="#fff"> | ||
<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"/> | ||
</svg> | ||
</IconButton> | ||
) | ||
return ( | ||
<div> | ||
<p> | ||
1 | ||
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? | ||
</p> | ||
<p> | ||
2 | ||
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? | ||
</p> | ||
<p> | ||
3 | ||
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? | ||
</p> | ||
<p> | ||
4 | ||
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? | ||
</p> | ||
<p> | ||
5 | ||
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? | ||
</p> | ||
<p> | ||
6 | ||
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? | ||
</p> | ||
<p> | ||
7 | ||
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? | ||
</p> | ||
<p> | ||
8 | ||
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? | ||
</p> | ||
<p> | ||
9 | ||
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? | ||
</p> | ||
<p> | ||
10 | ||
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? | ||
</p> | ||
<p> | ||
11 | ||
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? | ||
</p> | ||
<p> | ||
12 | ||
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? | ||
</p> | ||
<p> | ||
13 | ||
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? | ||
</p> | ||
<p> | ||
14 | ||
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? | ||
</p> | ||
<p> | ||
15 | ||
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? | ||
</p> | ||
<p> | ||
16 | ||
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? | ||
</p> | ||
<p> | ||
17 | ||
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? | ||
</p> | ||
<p> | ||
18 | ||
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? | ||
</p> | ||
<p> | ||
19 | ||
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? | ||
</p> | ||
<p> | ||
20 | ||
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? | ||
</p> | ||
</div> | ||
) | ||
} | ||
|
||
render(<Example />) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* eslint-disable react/display-name */ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 - present Instructure, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
/** @jsx jsx */ | ||
import { Children, PropsWithChildren, useEffect, useState } from 'react' | ||
import { jsx, useTheme } from '@instructure/emotion' | ||
import type { DesktopTopNavProps } from './props' | ||
|
||
import { IconButton } from '@instructure/ui-buttons' | ||
import { IconHamburgerLine, IconXLine } from '@instructure/ui-icons' | ||
import { generateStyles } from './styles' | ||
|
||
/** | ||
--- | ||
category: components | ||
--- | ||
**/ | ||
const DesktopTopNav = ({ | ||
lightMode = false, | ||
styles, | ||
children | ||
}: DesktopTopNavProps) => { | ||
const [open, setOpen] = useState<boolean>(false) | ||
|
||
useEffect(() => { | ||
const body = document.getElementsByTagName('body')[0] | ||
body.style.overflow = open ? 'hidden' : 'visible' | ||
}, [open]) | ||
|
||
const getSubComponent = (displayName: any) => { | ||
return Children.map(children, (child: any) => child)?.filter( | ||
(child: any) => child?.type?.displayName === displayName | ||
) | ||
} | ||
|
||
return ( | ||
<div style={styles.container(open)}> | ||
<div style={styles.topBar}> | ||
<span style={styles.btnRow}> | ||
{/*{!open && getSubComponent('BtnRow')}*/} | ||
<IconButton | ||
withBackground={false} | ||
withBorder={false} | ||
screenReaderLabel="burgir" | ||
color={lightMode ? 'secondary' : 'primary-inverse'} | ||
onClick={() => setOpen((open) => !open)} | ||
> | ||
{open ? <IconXLine /> : <IconHamburgerLine />} | ||
</IconButton> | ||
</span> | ||
{getSubComponent('BreadCrumb')} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
const BreadCrumb = ({ children }: PropsWithChildren) => { | ||
return ( | ||
<div style={{ margin: '24px 0', display: 'inline-block' }}>{children}</div> | ||
) | ||
} | ||
|
||
BreadCrumb.displayName = 'BreadCrumb' | ||
|
||
const withStyles = | ||
<ComponentOwnProps, ComponentStyle>( | ||
generateStyles: (props: any, theme: any) => ComponentStyle | ||
) => | ||
(WrappedComponent: any) => | ||
(originalProps: ComponentOwnProps) => { | ||
const theme = useTheme() | ||
const styledProps = { | ||
styles: generateStyles(originalProps, theme), | ||
...originalProps | ||
} | ||
return <WrappedComponent {...styledProps} /> | ||
} | ||
|
||
const SC: any = withStyles(generateStyles)(DesktopTopNav) | ||
|
||
SC.BreadCrumb = BreadCrumb | ||
// TODO investigate whether displayName should be added to the original component | ||
|
||
export { SC as DesktopTopNav } | ||
export default SC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 - present Instructure, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
import type { ReactNode, PropsWithChildren } from 'react' | ||
|
||
type DesktopTopNavOwnProps = { | ||
lightMode?: boolean | ||
brand?: ReactNode | ||
} | ||
|
||
type DesktopTopNavStyle = { | ||
container: (open: boolean) => { | ||
[key: string]: string | number | ||
} | ||
content: (open: boolean) => { | ||
[key: string]: string | number | ||
} | ||
topBar: { | ||
[key: string]: string | number | ||
} | ||
btnRow: { | ||
[key: string]: string | number | ||
} | ||
} | ||
|
||
type DesktopTopNavProps = DesktopTopNavOwnProps & { | ||
styles: DesktopTopNavStyle | ||
} & PropsWithChildren | ||
|
||
export type { DesktopTopNavProps, DesktopTopNavOwnProps } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015 - present Instructure, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
import type { DesktopTopNavProps } from './props' | ||
|
||
//TODO use theme variables for spacing | ||
const generateStyles = (props: DesktopTopNavProps, theme: any) => { | ||
const { lightMode } = props | ||
return { | ||
container: (open: boolean) => { | ||
return { | ||
height: '54px', | ||
position: open ? 'fixed' : 'relative', | ||
backgroundColor: lightMode | ||
? theme.colors.ui.surfacePageSecondary | ||
: theme.colors.ui.surfaceDark, | ||
color: lightMode | ||
? theme.colors.contrasts.grey125125 | ||
: theme.colors?.contrasts?.white1010, | ||
width: '100%', | ||
zIndex: '1000' | ||
} | ||
}, | ||
topBar: { | ||
padding: `0 ${theme.spacing.small}`, | ||
height: '54px', | ||
display: 'flex', | ||
alignItems: 'center' | ||
// justifyContent: 'space-between' | ||
}, | ||
content: (open: boolean) => { | ||
return { | ||
padding: `0 ${theme.spacing.small}`, | ||
height: open ? '100%' : '0px', | ||
top: '3.375rem', | ||
bottom: 0, | ||
left: 0, | ||
right: 0, | ||
overflow: open ? 'scroll' : 'hidden', | ||
position: 'fixed', | ||
backgroundColor: lightMode | ||
? theme.colors.ui.surfacePageSecondary | ||
: theme.colors.ui.surfaceDark, | ||
color: lightMode | ||
? theme.colors.contrasts.grey125125 | ||
: theme.colors?.contrasts?.white1010 | ||
} | ||
}, | ||
btnRow: { | ||
display: 'flex', | ||
gap: '12px' | ||
} | ||
} | ||
} | ||
const generateItemListStyles = (_props: any, theme: any) => { | ||
return { | ||
divider: { | ||
height: '0.0625rem', | ||
overflow: 'hidden', | ||
background: theme.colors.contrasts.grey1214 | ||
} | ||
} | ||
} | ||
const generateItemStyles = (_props: any, _theme: any) => { | ||
return { | ||
container: { | ||
margin: '16px 0', | ||
display: 'flex', | ||
cursor: 'pointer', | ||
alignItems: 'flex-end' | ||
}, | ||
leftIcon: { paddingRight: '8px', fontSize: '18px' }, | ||
rightIcon: { marginLeft: 'auto', paddingRight: '8px', fontSize: '18px' } | ||
} | ||
} | ||
|
||
export { generateStyles, generateItemListStyles, generateItemStyles } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters