Skip to content

Commit

Permalink
WIP(ui-top-nav-bar): some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
joyenjoyer committed Nov 17, 2024
1 parent f1bb2f3 commit d4418f5
Show file tree
Hide file tree
Showing 10 changed files with 468 additions and 15 deletions.
119 changes: 108 additions & 11 deletions packages/__docs__/src/App/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable react/jsx-no-undef */
/*
* The MIT License (MIT)
*
Expand Down Expand Up @@ -29,20 +28,21 @@ import {
createContext,
LegacyRef,
ReactElement,
SyntheticEvent,
useEffect,
useState
SyntheticEvent
} from 'react'

import { Alert } from '@instructure/ui-alerts'
import { Breadcrumb } from '@instructure/ui-breadcrumb'
import { Checkbox } from '@instructure/ui-checkbox'
import { InstUISettingsProvider, withStyle, jsx } from '@instructure/emotion'
import { Flex } from '@instructure/ui-flex'
import { Text } from '@instructure/ui-text'
import { View } from '@instructure/ui-view'
import { AccessibleContent } from '@instructure/ui-a11y-content'
import { MobileTopNav, DesktopTopNav } from '@instructure/ui-top-nav-bar'
import {
MobileTopNav,
DesktopTopNav,
TopNav
} from '@instructure/ui-top-nav-bar'
import { IconButton } from '@instructure/ui-buttons'
import { Tray } from '@instructure/ui-tray'
import { Link } from '@instructure/ui-link'
Expand Down Expand Up @@ -96,7 +96,7 @@ export const AppContext = createContext<AppContextType>({
library: undefined
})

const WrapperComponent = (props) => {
/*const WrapperComponent = (props) => {
const [isSmallScreen, setIsSmallScreen] = useState(false)
const [isLightMode, setIsLightMode] = useState(false)
Expand Down Expand Up @@ -345,7 +345,7 @@ const WrapperComponent = (props) => {
}, [])
return <>{isSmallScreen ? <SmallScreen /> : <BigScreen />}</>
}
}*/

@withStyle(generateStyle, generateComponentTheme)
class App extends Component<AppProps, AppState> {
Expand Down Expand Up @@ -395,7 +395,6 @@ class App extends Component<AppProps, AppState> {
docData.componentInstance = everyComp[components[0]][components[1]]
} else {
docData.componentInstance =
// eslint-disable-next-line import-x/namespace
EveryComponent[docId as keyof typeof EveryComponent]
}
return docData
Expand Down Expand Up @@ -426,7 +425,6 @@ class App extends Component<AppProps, AppState> {
* @returns {Set<string>} the properties
*/
getAllPropNames(object: Record<string, any>) {
// eslint-disable-next-line @typescript-eslint/ban-types
let obj: object | null = object
const props: Set<string> = new Set()
// exclude some common static props for performance
Expand Down Expand Up @@ -983,6 +981,27 @@ class App extends Component<AppProps, AppState> {
const key = this.state.key
const { showMenu, layout, docsData, iconsData } = this.state

const isLightMode = false

const brandSvg = (
<IconButton
screenReaderLabel="Canvas Brand"
href="#"
withBackground={false}
withBorder={false}
>
<svg
viewBox="0 0 1920 1920"
xmlns="http://www.w3.org/2000/svg"
fill="#fff"
width="28px"
height="28px"
>
<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>
)

if (!docsData || !iconsData) {
return <LoadingScreen />
}
Expand All @@ -1003,7 +1022,85 @@ class App extends Component<AppProps, AppState> {
boxSizing: 'border-box'
}}
>
<WrapperComponent />
<TopNav>
<DesktopTopNav>
<DesktopTopNav.BreadCrumb>
<Breadcrumb label="You are here:">
<Breadcrumb.Link>Student Forecast</Breadcrumb.Link>
<Breadcrumb.Link>University of Utah</Breadcrumb.Link>
<Breadcrumb.Link>University of Colleges</Breadcrumb.Link>
</Breadcrumb>
</DesktopTopNav.BreadCrumb>
</DesktopTopNav>
<MobileTopNav brand={brandSvg} lightMode={isLightMode}>
<MobileTopNav.BtnRow>
<IconButton
withBackground={false}
withBorder={false}
screenReaderLabel="burgir"
color={isLightMode ? 'secondary' : 'primary-inverse'}
>
<IconAnalyticsLine />
</IconButton>
<IconButton
withBackground={false}
withBorder={false}
screenReaderLabel="burgir"
color={isLightMode ? 'secondary' : 'primary-inverse'}
>
<IconAlertsLine />
</IconButton>
</MobileTopNav.BtnRow>
<MobileTopNav.BreadCrumb>
<Link
href="#"
isWithinText={false}
color={isLightMode ? 'link' : 'link-inverse'}
>
<div
style={{
display: 'flex',
alignItems: 'center',
gap: '8px'
}}
>
<IconArrowOpenStartLine />
Back
</div>
</Link>
</MobileTopNav.BreadCrumb>
<MobileTopNav.Title>Courses</MobileTopNav.Title>
<MobileTopNav.ItemList>
<MobileTopNav.Item
leftIcon={<IconUserLine />}
rightIcon={<IconArrowOpenDownLine />}
onClick={() => alert('Account clicked')}
>
Account
</MobileTopNav.Item>
<MobileTopNav.Item
leftIcon={<IconAdminLine />}
rightIcon={<IconArrowOpenDownLine />}
onClick={() => alert('Admin clicked')}
>
Admin
</MobileTopNav.Item>
<MobileTopNav.Item
leftIcon={<IconDashboardLine />}
rightIcon={<IconArrowOpenDownLine />}
onClick={() => alert('Dashboard')}
>
Dashboard
</MobileTopNav.Item>
<MobileTopNav.Item
rightIcon={<IconArrowOpenDownLine />}
onClick={() => alert('Simple option with no left icon')}
>
Simple option with no left icon
</MobileTopNav.Item>
</MobileTopNav.ItemList>
</MobileTopNav>
</TopNav>
</div>
</AppContext.Provider>
)
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-top-nav-bar/src/DesktopTopNav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,7 @@ const SC: any = withStyles(generateStyles)(DesktopTopNav)
SC.BreadCrumb = BreadCrumb
// TODO investigate whether displayName should be added to the original component

SC.displayName = 'DesktopTopNav'

export { SC as DesktopTopNav }
export default SC
2 changes: 1 addition & 1 deletion packages/ui-top-nav-bar/src/DesktopTopNav/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const generateStyles = (props: DesktopTopNavProps, theme: any) => {
},
btnRow: {
display: 'flex',
gap: '12px'
marginRight: '12px'
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/ui-top-nav-bar/src/MobileTopNav/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ SC.ItemList = withStyles(generateItemListStyles)(ItemList)
SC.ItemList.displayName = 'ItemList'
SC.Item = withStyles(generateItemStyles)(Item) //withStyles(generateItemStyles)(Item)
SC.Item.displayName = 'Item'
SC.displayName = 'MobileTopNav'

export { SC as MobileTopNav }
export default SC
6 changes: 3 additions & 3 deletions packages/ui-top-nav-bar/src/MobileTopNav/styles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ import type { MobileTopNavProps } from './props'
const generateStyles = (props: MobileTopNavProps, theme: any) => {
const { lightMode } = props
return {
container: (open: boolean) => {
container: (_open: boolean) => {
return {
height: '54px',
position: open ? 'fixed' : 'relative',
// 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'
zIndex: '9999'
}
},
topBar: {
Expand Down
107 changes: 107 additions & 0 deletions packages/ui-top-nav-bar/src/TopNav/README.md
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 />)
```
Loading

0 comments on commit d4418f5

Please sign in to comment.