@instructure/ui-global-nav 0.0.0-stage → 11.7.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -0
- package/LICENSE.md +28 -0
- package/README.md +25 -2
- package/es/GlobalNav/v1/CollapseButton/index.js +80 -0
- package/es/GlobalNav/v1/CollapseButton/props.js +1 -0
- package/es/GlobalNav/v1/CollapseButton/styles.js +64 -0
- package/es/GlobalNav/v1/CollapsedSubNav/index.js +59 -0
- package/es/GlobalNav/v1/CollapsedSubNav/props.js +1 -0
- package/es/GlobalNav/v1/CollapsedSubNav/styles.js +82 -0
- package/es/GlobalNav/v1/InstitutionLogo/index.js +93 -0
- package/es/GlobalNav/v1/InstitutionLogo/props.js +1 -0
- package/es/GlobalNav/v1/InstitutionLogo/styles.js +69 -0
- package/es/GlobalNav/v1/MainNavItem/index.js +129 -0
- package/es/GlobalNav/v1/MainNavItem/props.js +1 -0
- package/es/GlobalNav/v1/MainNavItem/styles.js +117 -0
- package/es/GlobalNav/v1/SubNav/index.js +121 -0
- package/es/GlobalNav/v1/SubNav/props.js +1 -0
- package/es/GlobalNav/v1/SubNav/styles.js +52 -0
- package/es/GlobalNav/v1/SubNavItem/index.js +78 -0
- package/es/GlobalNav/v1/SubNavItem/props.js +1 -0
- package/es/GlobalNav/v1/SubNavItem/styles.js +94 -0
- package/es/GlobalNav/v1/SubNavLevel/index.js +160 -0
- package/es/GlobalNav/v1/SubNavLevel/props.js +1 -0
- package/es/GlobalNav/v1/SubNavLevel/styles.js +94 -0
- package/es/GlobalNav/v1/index.js +222 -0
- package/es/GlobalNav/v1/props.js +28 -0
- package/es/GlobalNav/v1/styles.js +110 -0
- package/es/GlobalNav/v1/utils/getItemElementProps.js +64 -0
- package/es/exports/a.js +24 -0
- package/lib/GlobalNav/v1/CollapseButton/index.js +85 -0
- package/lib/GlobalNav/v1/CollapseButton/props.js +5 -0
- package/lib/GlobalNav/v1/CollapseButton/styles.js +70 -0
- package/lib/GlobalNav/v1/CollapsedSubNav/index.js +64 -0
- package/lib/GlobalNav/v1/CollapsedSubNav/props.js +5 -0
- package/lib/GlobalNav/v1/CollapsedSubNav/styles.js +88 -0
- package/lib/GlobalNav/v1/InstitutionLogo/index.js +98 -0
- package/lib/GlobalNav/v1/InstitutionLogo/props.js +5 -0
- package/lib/GlobalNav/v1/InstitutionLogo/styles.js +75 -0
- package/lib/GlobalNav/v1/MainNavItem/index.js +134 -0
- package/lib/GlobalNav/v1/MainNavItem/props.js +5 -0
- package/lib/GlobalNav/v1/MainNavItem/styles.js +123 -0
- package/lib/GlobalNav/v1/SubNav/index.js +128 -0
- package/lib/GlobalNav/v1/SubNav/props.js +5 -0
- package/lib/GlobalNav/v1/SubNav/styles.js +58 -0
- package/lib/GlobalNav/v1/SubNavItem/index.js +83 -0
- package/lib/GlobalNav/v1/SubNavItem/props.js +5 -0
- package/lib/GlobalNav/v1/SubNavItem/styles.js +100 -0
- package/lib/GlobalNav/v1/SubNavLevel/index.js +165 -0
- package/lib/GlobalNav/v1/SubNavLevel/props.js +5 -0
- package/lib/GlobalNav/v1/SubNavLevel/styles.js +100 -0
- package/lib/GlobalNav/v1/index.js +228 -0
- package/lib/GlobalNav/v1/props.js +33 -0
- package/lib/GlobalNav/v1/styles.js +116 -0
- package/lib/GlobalNav/v1/utils/getItemElementProps.js +70 -0
- package/lib/exports/a.js +12 -0
- package/lib/package.json +1 -0
- package/package.json +77 -3
- package/src/GlobalNav/v1/CollapseButton/index.tsx +87 -0
- package/src/GlobalNav/v1/CollapseButton/props.ts +64 -0
- package/src/GlobalNav/v1/CollapseButton/styles.ts +76 -0
- package/src/GlobalNav/v1/CollapsedSubNav/index.tsx +60 -0
- package/src/GlobalNav/v1/CollapsedSubNav/props.ts +42 -0
- package/src/GlobalNav/v1/CollapsedSubNav/styles.ts +92 -0
- package/src/GlobalNav/v1/InstitutionLogo/index.tsx +86 -0
- package/src/GlobalNav/v1/InstitutionLogo/props.ts +42 -0
- package/src/GlobalNav/v1/InstitutionLogo/styles.ts +82 -0
- package/src/GlobalNav/v1/MainNavItem/index.tsx +132 -0
- package/src/GlobalNav/v1/MainNavItem/props.ts +65 -0
- package/src/GlobalNav/v1/MainNavItem/styles.ts +137 -0
- package/src/GlobalNav/v1/README.md +234 -0
- package/src/GlobalNav/v1/SubNav/index.tsx +132 -0
- package/src/GlobalNav/v1/SubNav/props.ts +81 -0
- package/src/GlobalNav/v1/SubNav/styles.ts +58 -0
- package/src/GlobalNav/v1/SubNavItem/index.tsx +79 -0
- package/src/GlobalNav/v1/SubNavItem/props.ts +48 -0
- package/src/GlobalNav/v1/SubNavItem/styles.ts +110 -0
- package/src/GlobalNav/v1/SubNavLevel/index.tsx +193 -0
- package/src/GlobalNav/v1/SubNavLevel/props.ts +75 -0
- package/src/GlobalNav/v1/SubNavLevel/styles.ts +103 -0
- package/src/GlobalNav/v1/index.tsx +256 -0
- package/src/GlobalNav/v1/props.ts +328 -0
- package/src/GlobalNav/v1/styles.ts +132 -0
- package/src/GlobalNav/v1/utils/getItemElementProps.ts +80 -0
- package/src/exports/a.ts +35 -0
- package/tsconfig.build.json +53 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +4 -0
- package/types/GlobalNav/v1/CollapseButton/index.d.ts +11 -0
- package/types/GlobalNav/v1/CollapseButton/index.d.ts.map +1 -0
- package/types/GlobalNav/v1/CollapseButton/props.d.ts +31 -0
- package/types/GlobalNav/v1/CollapseButton/props.d.ts.map +1 -0
- package/types/GlobalNav/v1/CollapseButton/styles.d.ts +22 -0
- package/types/GlobalNav/v1/CollapseButton/styles.d.ts.map +1 -0
- package/types/GlobalNav/v1/CollapsedSubNav/index.d.ts +11 -0
- package/types/GlobalNav/v1/CollapsedSubNav/index.d.ts.map +1 -0
- package/types/GlobalNav/v1/CollapsedSubNav/props.d.ts +15 -0
- package/types/GlobalNav/v1/CollapsedSubNav/props.d.ts.map +1 -0
- package/types/GlobalNav/v1/CollapsedSubNav/styles.d.ts +14 -0
- package/types/GlobalNav/v1/CollapsedSubNav/styles.d.ts.map +1 -0
- package/types/GlobalNav/v1/InstitutionLogo/index.d.ts +11 -0
- package/types/GlobalNav/v1/InstitutionLogo/index.d.ts.map +1 -0
- package/types/GlobalNav/v1/InstitutionLogo/props.d.ts +15 -0
- package/types/GlobalNav/v1/InstitutionLogo/props.d.ts.map +1 -0
- package/types/GlobalNav/v1/InstitutionLogo/styles.d.ts +20 -0
- package/types/GlobalNav/v1/InstitutionLogo/styles.d.ts.map +1 -0
- package/types/GlobalNav/v1/MainNavItem/index.d.ts +11 -0
- package/types/GlobalNav/v1/MainNavItem/index.d.ts.map +1 -0
- package/types/GlobalNav/v1/MainNavItem/props.d.ts +32 -0
- package/types/GlobalNav/v1/MainNavItem/props.d.ts.map +1 -0
- package/types/GlobalNav/v1/MainNavItem/styles.d.ts +19 -0
- package/types/GlobalNav/v1/MainNavItem/styles.d.ts.map +1 -0
- package/types/GlobalNav/v1/SubNav/index.d.ts +11 -0
- package/types/GlobalNav/v1/SubNav/index.d.ts.map +1 -0
- package/types/GlobalNav/v1/SubNav/props.d.ts +52 -0
- package/types/GlobalNav/v1/SubNav/props.d.ts.map +1 -0
- package/types/GlobalNav/v1/SubNav/styles.d.ts +13 -0
- package/types/GlobalNav/v1/SubNav/styles.d.ts.map +1 -0
- package/types/GlobalNav/v1/SubNavItem/index.d.ts +11 -0
- package/types/GlobalNav/v1/SubNavItem/index.d.ts.map +1 -0
- package/types/GlobalNav/v1/SubNavItem/props.d.ts +20 -0
- package/types/GlobalNav/v1/SubNavItem/props.d.ts.map +1 -0
- package/types/GlobalNav/v1/SubNavItem/styles.d.ts +18 -0
- package/types/GlobalNav/v1/SubNavItem/styles.d.ts.map +1 -0
- package/types/GlobalNav/v1/SubNavLevel/index.d.ts +11 -0
- package/types/GlobalNav/v1/SubNavLevel/index.d.ts.map +1 -0
- package/types/GlobalNav/v1/SubNavLevel/props.d.ts +45 -0
- package/types/GlobalNav/v1/SubNavLevel/props.d.ts.map +1 -0
- package/types/GlobalNav/v1/SubNavLevel/styles.d.ts +14 -0
- package/types/GlobalNav/v1/SubNavLevel/styles.d.ts.map +1 -0
- package/types/GlobalNav/v1/index.d.ts +59 -0
- package/types/GlobalNav/v1/index.d.ts.map +1 -0
- package/types/GlobalNav/v1/props.d.ts +247 -0
- package/types/GlobalNav/v1/props.d.ts.map +1 -0
- package/types/GlobalNav/v1/styles.d.ts +23 -0
- package/types/GlobalNav/v1/styles.d.ts.map +1 -0
- package/types/GlobalNav/v1/utils/getItemElementProps.d.ts +37 -0
- package/types/GlobalNav/v1/utils/getItemElementProps.d.ts.map +1 -0
- package/types/exports/a.d.ts +3 -0
- package/types/exports/a.d.ts.map +1 -0
|
@@ -0,0 +1,65 @@
|
|
|
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 { MouseEvent } from 'react'
|
|
26
|
+
|
|
27
|
+
import type { ComponentStyle } from '@instructure/emotion'
|
|
28
|
+
|
|
29
|
+
import type { GlobalNavMainNavItem } from '../props.js'
|
|
30
|
+
|
|
31
|
+
type MainNavItemProps = {
|
|
32
|
+
/**
|
|
33
|
+
* The data of the item.
|
|
34
|
+
*/
|
|
35
|
+
item: GlobalNavMainNavItem
|
|
36
|
+
/**
|
|
37
|
+
* Whether the rail is collapsed.
|
|
38
|
+
*/
|
|
39
|
+
collapsed: boolean
|
|
40
|
+
/**
|
|
41
|
+
* Whether the SubNav of the item is open.
|
|
42
|
+
*/
|
|
43
|
+
open: boolean
|
|
44
|
+
/**
|
|
45
|
+
* The id of the open SubNav panel, set only while the SubNav of this item is open.
|
|
46
|
+
*/
|
|
47
|
+
subNavId?: string
|
|
48
|
+
/**
|
|
49
|
+
* Called when the user activates the item, after `item.onClick`.
|
|
50
|
+
*/
|
|
51
|
+
onActivate: (
|
|
52
|
+
event: MouseEvent<HTMLElement>,
|
|
53
|
+
item: GlobalNavMainNavItem
|
|
54
|
+
) => void
|
|
55
|
+
/**
|
|
56
|
+
* Called with the link or button element of the item.
|
|
57
|
+
*/
|
|
58
|
+
elementRef: (element: HTMLElement | null) => void
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
type MainNavItemStyle = ComponentStyle<
|
|
62
|
+
'item' | 'icon' | 'badge' | 'label' | 'chevron' | 'tooltipTrigger'
|
|
63
|
+
>
|
|
64
|
+
|
|
65
|
+
export type { MainNavItemProps, MainNavItemStyle }
|
|
@@ -0,0 +1,137 @@
|
|
|
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 { NewComponentTypes } from '@instructure/ui-themes'
|
|
26
|
+
import type { MainNavItemStyle } from './props.js'
|
|
27
|
+
|
|
28
|
+
type StyleParams = {
|
|
29
|
+
collapsed: boolean
|
|
30
|
+
current: boolean
|
|
31
|
+
open: boolean
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* ---
|
|
36
|
+
* private: true
|
|
37
|
+
* ---
|
|
38
|
+
* Generates the style object from the theme and provided additional information
|
|
39
|
+
* @param componentTheme The theme variable object.
|
|
40
|
+
* @param params Additional parameters to customize the style.
|
|
41
|
+
* @return The final style object, which will be used in the component
|
|
42
|
+
*/
|
|
43
|
+
const generateStyle = (
|
|
44
|
+
componentTheme: ReturnType<NewComponentTypes['MainNavItem']>,
|
|
45
|
+
params: StyleParams
|
|
46
|
+
): MainNavItemStyle => {
|
|
47
|
+
const { collapsed, current, open } = params
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
item: {
|
|
51
|
+
label: 'mainNavItem',
|
|
52
|
+
display: 'flex',
|
|
53
|
+
alignItems: 'center',
|
|
54
|
+
// MainNavItem has no gap token
|
|
55
|
+
gap: componentTheme.horizontalPadding,
|
|
56
|
+
boxSizing: 'border-box',
|
|
57
|
+
width: collapsed ? componentTheme.minimizedItemSize : '100%',
|
|
58
|
+
height: collapsed ? componentTheme.minimizedItemSize : undefined,
|
|
59
|
+
justifyContent: collapsed ? 'center' : undefined,
|
|
60
|
+
margin: 0,
|
|
61
|
+
padding: collapsed
|
|
62
|
+
? 0
|
|
63
|
+
: `${componentTheme.verticalPadding} ${componentTheme.horizontalPadding}`,
|
|
64
|
+
border: 'none',
|
|
65
|
+
borderRadius: componentTheme.borderRadius,
|
|
66
|
+
backgroundColor: current
|
|
67
|
+
? componentTheme.currentBackgroundColor
|
|
68
|
+
: open
|
|
69
|
+
? componentTheme.activeBackgroundColor
|
|
70
|
+
: componentTheme.backgroundColor,
|
|
71
|
+
color: current
|
|
72
|
+
? componentTheme.currentTextColor
|
|
73
|
+
: componentTheme.fontColor,
|
|
74
|
+
fontFamily: componentTheme.fontFamily,
|
|
75
|
+
fontSize: componentTheme.fontSize,
|
|
76
|
+
fontWeight: componentTheme.fontWeight,
|
|
77
|
+
lineHeight: componentTheme.lineHeight,
|
|
78
|
+
textAlign: 'start',
|
|
79
|
+
textDecoration: componentTheme.linkTextDecoration,
|
|
80
|
+
cursor: 'pointer',
|
|
81
|
+
'&:hover': {
|
|
82
|
+
// a page-wide a:hover rule is more specific than the base class
|
|
83
|
+
textDecoration: componentTheme.linkTextDecoration,
|
|
84
|
+
...(!current &&
|
|
85
|
+
!open && { backgroundColor: componentTheme.hoverBackgroundColor })
|
|
86
|
+
},
|
|
87
|
+
...(!current &&
|
|
88
|
+
!open && {
|
|
89
|
+
'&:active': {
|
|
90
|
+
backgroundColor: componentTheme.activeBackgroundColor
|
|
91
|
+
}
|
|
92
|
+
}),
|
|
93
|
+
// the other GlobalNav focus rings animate with calcFocusOutlineStyles,
|
|
94
|
+
// which can't take these tokens, because each theme colors a different ring
|
|
95
|
+
transition: 'box-shadow 0.2s',
|
|
96
|
+
// same focus ring as SideNavBarItem, which has the same focus tokens
|
|
97
|
+
'&:focus': {
|
|
98
|
+
outline: 'none',
|
|
99
|
+
boxShadow: current
|
|
100
|
+
? `inset 0 0 0 0.125rem ${componentTheme.selectedOuterFocusOutlineColor}, inset 0 0 0 0.25rem ${componentTheme.selectedInnerFocusOutlineColor}`
|
|
101
|
+
: `inset 0 0 0 0.125rem ${componentTheme.outerFocusOutlineColor}, inset 0 0 0 0.25rem ${componentTheme.innerFocusOutlineColor}`
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
icon: {
|
|
105
|
+
label: 'mainNavItem__icon',
|
|
106
|
+
position: 'relative',
|
|
107
|
+
display: 'flex',
|
|
108
|
+
alignItems: 'center',
|
|
109
|
+
flexShrink: 0,
|
|
110
|
+
height: componentTheme.iconWrapperHeight
|
|
111
|
+
},
|
|
112
|
+
badge: {
|
|
113
|
+
label: 'mainNavItem__badge',
|
|
114
|
+
position: 'absolute',
|
|
115
|
+
top: 0,
|
|
116
|
+
// the badge starts at the icon's center, so a longer count grows away from the icon
|
|
117
|
+
insetInlineStart: '50%',
|
|
118
|
+
// flex, so the item's line height doesn't push the badge down
|
|
119
|
+
display: 'flex'
|
|
120
|
+
},
|
|
121
|
+
label: {
|
|
122
|
+
label: 'mainNavItem__label',
|
|
123
|
+
flex: 1
|
|
124
|
+
},
|
|
125
|
+
chevron: {
|
|
126
|
+
label: 'mainNavItem__chevron',
|
|
127
|
+
display: 'flex',
|
|
128
|
+
flexShrink: 0
|
|
129
|
+
},
|
|
130
|
+
tooltipTrigger: {
|
|
131
|
+
label: 'mainNavItem__tooltipTrigger',
|
|
132
|
+
display: 'block'
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export default generateStyle
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
---
|
|
2
|
+
describes: GlobalNav
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
The main navigation of an app. Work in progress: the API will change, don't use it in production yet.
|
|
6
|
+
|
|
7
|
+
The app passes the navigation as data (`items` and `logo`). `GlobalNav` is controlled: the app keeps `collapsed` and `openSubNav` in its state and updates them in `onCollapse` and `onSubNavChange`.
|
|
8
|
+
|
|
9
|
+
`GlobalNav` fills the height of its container. An open SubNav makes it wider and pushes the page. While no SubNav is open, its width only depends on `collapsed`, so the strip showing or hiding doesn't move the page.
|
|
10
|
+
|
|
11
|
+
### Minimal example
|
|
12
|
+
|
|
13
|
+
A starting point to copy.
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
---
|
|
17
|
+
type: example
|
|
18
|
+
---
|
|
19
|
+
const Example = () => {
|
|
20
|
+
const [collapsed, setCollapsed] = React.useState(false)
|
|
21
|
+
const [openSubNav, setOpenSubNav] = React.useState()
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<View as="div" height="24rem">
|
|
25
|
+
<GlobalNav
|
|
26
|
+
label="Main navigation"
|
|
27
|
+
collapsed={collapsed}
|
|
28
|
+
onCollapse={(_e, isCollapsed) => setCollapsed(isCollapsed)}
|
|
29
|
+
collapseLabel="Collapse navigation"
|
|
30
|
+
expandLabel="Expand navigation"
|
|
31
|
+
backLabel={(title) => `Back to ${title}`}
|
|
32
|
+
closeSubNavLabel="Close sub navigation"
|
|
33
|
+
collapseSubNavLabel="Collapse sub navigation"
|
|
34
|
+
expandSubNavLabel="Open sub navigation"
|
|
35
|
+
openSubNav={openSubNav}
|
|
36
|
+
onSubNavChange={(_e, itemID) => setOpenSubNav(itemID)}
|
|
37
|
+
logo={{ name: 'My app', href: '#GlobalNav' }}
|
|
38
|
+
items={[
|
|
39
|
+
{
|
|
40
|
+
itemID: 'dashboard',
|
|
41
|
+
icon: <LayoutDashboardInstUIIcon />,
|
|
42
|
+
label: 'Dashboard',
|
|
43
|
+
href: '#GlobalNav',
|
|
44
|
+
current: true
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
itemID: 'courses',
|
|
48
|
+
icon: <BookOpenInstUIIcon />,
|
|
49
|
+
label: 'Courses',
|
|
50
|
+
subNav: {
|
|
51
|
+
title: 'Courses',
|
|
52
|
+
items: [
|
|
53
|
+
{
|
|
54
|
+
itemID: 'all-courses',
|
|
55
|
+
label: 'All courses',
|
|
56
|
+
href: '#GlobalNav'
|
|
57
|
+
}
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
]}
|
|
62
|
+
/>
|
|
63
|
+
</View>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
render(<Example />)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Example app
|
|
71
|
+
|
|
72
|
+
A mock app with pages. The navigation switches between them, and the current page is marked in the rail and in the SubNav. It starts on a course page with the Courses SubNav open. Close it to see the strip that opens it again. On Dashboard, closing a SubNav removes it completely. Help shows custom content.
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
---
|
|
76
|
+
type: example
|
|
77
|
+
---
|
|
78
|
+
const courses = [
|
|
79
|
+
{ id: 'biology', name: 'Biology 101' },
|
|
80
|
+
{ id: 'history', name: 'World history' },
|
|
81
|
+
{ id: 'algebra', name: 'Algebra II' }
|
|
82
|
+
]
|
|
83
|
+
const coursePages = ['Home', 'Modules', 'Grades']
|
|
84
|
+
const pageTitles = {
|
|
85
|
+
dashboard: 'Dashboard',
|
|
86
|
+
courses: 'All courses',
|
|
87
|
+
calendar: 'Calendar',
|
|
88
|
+
inbox: 'Inbox'
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const Example = () => {
|
|
92
|
+
// the current page, for example 'dashboard' or 'courses/biology/Modules'
|
|
93
|
+
const [page, setPage] = React.useState('courses/biology/Home')
|
|
94
|
+
const [collapsed, setCollapsed] = React.useState(false)
|
|
95
|
+
// a course page loads with the Courses SubNav open
|
|
96
|
+
const [openSubNav, setOpenSubNav] = React.useState('courses')
|
|
97
|
+
|
|
98
|
+
// a real app navigates with its router, this example only switches the mock page
|
|
99
|
+
const link = (path) => ({
|
|
100
|
+
href: '#GlobalNav',
|
|
101
|
+
current: page === path,
|
|
102
|
+
onClick: (event) => {
|
|
103
|
+
event.preventDefault()
|
|
104
|
+
setPage(path)
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
// the light theme has a white rail, the other themes a dark one
|
|
109
|
+
const onLightRail = useTheme().key === 'light'
|
|
110
|
+
const wordmark = onLightRail ? canvasWordmarkDark : canvasWordmarkWhite
|
|
111
|
+
const mark = onLightRail ? canvasMarkDark : canvasMarkWhite
|
|
112
|
+
|
|
113
|
+
const items = [
|
|
114
|
+
{
|
|
115
|
+
itemID: 'dashboard',
|
|
116
|
+
icon: <LayoutDashboardInstUIIcon />,
|
|
117
|
+
label: 'Dashboard',
|
|
118
|
+
...link('dashboard')
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
itemID: 'courses',
|
|
122
|
+
icon: <BookOpenInstUIIcon />,
|
|
123
|
+
label: 'Courses',
|
|
124
|
+
// the section of the current page, so its SubNav collapses to a strip
|
|
125
|
+
current: page.startsWith('courses'),
|
|
126
|
+
subNav: {
|
|
127
|
+
title: 'Courses',
|
|
128
|
+
items: [
|
|
129
|
+
{ itemID: 'all-courses', label: 'All courses', ...link('courses') },
|
|
130
|
+
...courses.map((course) => ({
|
|
131
|
+
itemID: course.id,
|
|
132
|
+
label: course.name,
|
|
133
|
+
subNav: {
|
|
134
|
+
title: course.name,
|
|
135
|
+
items: coursePages.map((coursePage) => ({
|
|
136
|
+
itemID: `${course.id}-${coursePage}`,
|
|
137
|
+
label: coursePage,
|
|
138
|
+
...link(`courses/${course.id}/${coursePage}`)
|
|
139
|
+
}))
|
|
140
|
+
}
|
|
141
|
+
}))
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
itemID: 'calendar',
|
|
147
|
+
icon: <CalendarInstUIIcon />,
|
|
148
|
+
label: 'Calendar',
|
|
149
|
+
...link('calendar')
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
itemID: 'inbox',
|
|
153
|
+
icon: <InboxInstUIIcon />,
|
|
154
|
+
label: 'Inbox',
|
|
155
|
+
badgeCount: 9,
|
|
156
|
+
badgeLabel: (count) => `${count} unread messages`,
|
|
157
|
+
...link('inbox')
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
itemID: 'help',
|
|
161
|
+
icon: <CircleHelpInstUIIcon />,
|
|
162
|
+
label: 'Help',
|
|
163
|
+
subNav: {
|
|
164
|
+
title: 'Help',
|
|
165
|
+
renderContent: () => (
|
|
166
|
+
<View as="div" padding="0 small">
|
|
167
|
+
<Text as="p" size="small">
|
|
168
|
+
Find answers to common questions.
|
|
169
|
+
</Text>
|
|
170
|
+
<List isUnstyled itemSpacing="small">
|
|
171
|
+
<List.Item>
|
|
172
|
+
<Link href="#GlobalNav">Search the guides</Link>
|
|
173
|
+
</List.Item>
|
|
174
|
+
<List.Item>
|
|
175
|
+
<Link href="#GlobalNav">Ask your instructor a question</Link>
|
|
176
|
+
</List.Item>
|
|
177
|
+
<List.Item>
|
|
178
|
+
<Link href="#GlobalNav">Report a problem</Link>
|
|
179
|
+
</List.Item>
|
|
180
|
+
</List>
|
|
181
|
+
</View>
|
|
182
|
+
)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
|
|
187
|
+
const [, courseID, coursePage] = page.split('/')
|
|
188
|
+
const course = courses.find((c) => c.id === courseID)
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<View as="div" display="flex" height="36rem">
|
|
192
|
+
<GlobalNav
|
|
193
|
+
label="Main navigation"
|
|
194
|
+
collapsed={collapsed}
|
|
195
|
+
onCollapse={(_e, isCollapsed) => setCollapsed(isCollapsed)}
|
|
196
|
+
collapseLabel="Collapse navigation"
|
|
197
|
+
expandLabel="Expand navigation"
|
|
198
|
+
backLabel={(title) => `Back to ${title}`}
|
|
199
|
+
closeSubNavLabel="Close sub navigation"
|
|
200
|
+
collapseSubNavLabel="Collapse sub navigation"
|
|
201
|
+
expandSubNavLabel="Open sub navigation"
|
|
202
|
+
openSubNav={openSubNav}
|
|
203
|
+
onSubNavChange={(_e, itemID) => setOpenSubNav(itemID)}
|
|
204
|
+
logo={{
|
|
205
|
+
src: collapsed ? mark : wordmark,
|
|
206
|
+
name: 'Canvas',
|
|
207
|
+
showName: false,
|
|
208
|
+
href: '#GlobalNav'
|
|
209
|
+
}}
|
|
210
|
+
items={items}
|
|
211
|
+
/>
|
|
212
|
+
<View as="div" width="100%" padding="medium" background="secondary">
|
|
213
|
+
{course && <Text size="small">{course.name}</Text>}
|
|
214
|
+
<Heading level="h2" margin="0 0 small">
|
|
215
|
+
{course ? coursePage : pageTitles[page]}
|
|
216
|
+
</Heading>
|
|
217
|
+
<Text>A mock page. Use the navigation to switch pages.</Text>
|
|
218
|
+
</View>
|
|
219
|
+
</View>
|
|
220
|
+
)
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
render(<Example />)
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### How it behaves
|
|
227
|
+
|
|
228
|
+
- One SubNav is open at a time. Clicking its rail item again, its close handle or a rail item without a `subNav` closes it. A click with a modifier key, for example to open a link in a new tab, keeps it open.
|
|
229
|
+
- Opening a SubNav or a deeper level moves focus to its first item, to the first focusable element of custom content, or else to the close handle. Back returns focus to the item that opened the level, and closing returns it to the rail item. Focus doesn't move when the app sets `openSubNav` itself.
|
|
230
|
+
- A SubNav opens on the level of its deepest `current` item.
|
|
231
|
+
- Set `current` on the rail item of the current page's section. Closing its SubNav then leaves a narrow strip that opens it again on click. Other SubNavs close completely.
|
|
232
|
+
- The SubNav of the current page's section has a collapse handle, named by `collapseSubNavLabel`. Other SubNavs have a close button, named by `closeSubNavLabel`.
|
|
233
|
+
- The back button shows the title of the level it returns to, and `backLabel` gets that title for the screen reader text, for example "Back to Courses".
|
|
234
|
+
- `renderContent` shows any content in place of `items`, inside the panel frame. Use it for content that can't be navigation items yet, for example while migrating an existing product.
|
|
@@ -0,0 +1,132 @@
|
|
|
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 { useState } from 'react'
|
|
26
|
+
import type { MouseEvent, SyntheticEvent } from 'react'
|
|
27
|
+
|
|
28
|
+
import { useStyleNew } from '@instructure/emotion'
|
|
29
|
+
|
|
30
|
+
import type { GlobalNavSubNav, GlobalNavSubNavItem } from '../props.js'
|
|
31
|
+
import { SubNavLevel } from '../SubNavLevel/index.js'
|
|
32
|
+
import type { SubNavProps } from './props.js'
|
|
33
|
+
import generateStyle from './styles.js'
|
|
34
|
+
|
|
35
|
+
type Level = { subNav: GlobalNavSubNav; itemID?: string }
|
|
36
|
+
|
|
37
|
+
// the itemIDs of the levels to open so the deepest current item shows, or undefined without one
|
|
38
|
+
const findCurrentPath = (subNav: GlobalNavSubNav): string[] | undefined => {
|
|
39
|
+
const items = subNav.items ?? []
|
|
40
|
+
for (const item of items) {
|
|
41
|
+
if (item.subNav) {
|
|
42
|
+
const deeperPath = findCurrentPath(item.subNav)
|
|
43
|
+
if (deeperPath) return [item.itemID, ...deeperPath]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return items.some((item) => item.current) ? [] : undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// stops at an itemID that the latest data no longer has, so the deepest level that still exists shows
|
|
50
|
+
const resolveLevels = (subNav: GlobalNavSubNav, path: string[]) => {
|
|
51
|
+
const levels: Level[] = [{ subNav }]
|
|
52
|
+
for (const itemID of path) {
|
|
53
|
+
const parent = levels[levels.length - 1].subNav
|
|
54
|
+
const item = parent.items?.find((i) => i.itemID === itemID)
|
|
55
|
+
if (!item?.subNav) break
|
|
56
|
+
levels.push({ subNav: item.subNav, itemID })
|
|
57
|
+
}
|
|
58
|
+
return levels
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
---
|
|
63
|
+
private: true
|
|
64
|
+
id: GlobalNav.SubNav
|
|
65
|
+
---
|
|
66
|
+
**/
|
|
67
|
+
const SubNav = (props: SubNavProps) => {
|
|
68
|
+
const {
|
|
69
|
+
subNav,
|
|
70
|
+
subNavId,
|
|
71
|
+
titleId,
|
|
72
|
+
collapsible,
|
|
73
|
+
closeSubNavLabel,
|
|
74
|
+
backLabel,
|
|
75
|
+
onClose,
|
|
76
|
+
focusIntentRef
|
|
77
|
+
} = props
|
|
78
|
+
|
|
79
|
+
const styles = useStyleNew({
|
|
80
|
+
generateStyle,
|
|
81
|
+
componentId: 'SubNav'
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
const [path, setPath] = useState(() => findCurrentPath(subNav) ?? [])
|
|
85
|
+
|
|
86
|
+
const levels = resolveLevels(subNav, path)
|
|
87
|
+
const resolvedPath = levels.slice(1).map((level) => level.itemID!)
|
|
88
|
+
const level = levels[levels.length - 1]
|
|
89
|
+
const parent = levels.length > 1 ? levels[levels.length - 2] : undefined
|
|
90
|
+
|
|
91
|
+
const handleDrillIn = (
|
|
92
|
+
_event: MouseEvent<HTMLElement>,
|
|
93
|
+
item: GlobalNavSubNavItem
|
|
94
|
+
) => {
|
|
95
|
+
focusIntentRef.current = { target: 'first' }
|
|
96
|
+
setPath([...resolvedPath, item.itemID])
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const handleBack = (_event: SyntheticEvent) => {
|
|
100
|
+
focusIntentRef.current = {
|
|
101
|
+
target: 'item',
|
|
102
|
+
itemID: resolvedPath[resolvedPath.length - 1]
|
|
103
|
+
}
|
|
104
|
+
setPath(resolvedPath.slice(0, -1))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<nav id={subNavId} aria-labelledby={titleId} css={styles?.subNav}>
|
|
109
|
+
<SubNavLevel
|
|
110
|
+
// a new level remounts, which resets its refs, focus and scroll position
|
|
111
|
+
key={JSON.stringify(resolvedPath)}
|
|
112
|
+
subNav={level.subNav}
|
|
113
|
+
titleId={titleId}
|
|
114
|
+
collapsible={collapsible}
|
|
115
|
+
closeSubNavLabel={closeSubNavLabel}
|
|
116
|
+
onClose={onClose}
|
|
117
|
+
back={
|
|
118
|
+
parent && {
|
|
119
|
+
title: parent.subNav.title,
|
|
120
|
+
label: backLabel(parent.subNav.title),
|
|
121
|
+
onClick: handleBack
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
onDrillIn={handleDrillIn}
|
|
125
|
+
focusIntentRef={focusIntentRef}
|
|
126
|
+
/>
|
|
127
|
+
</nav>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export default SubNav
|
|
132
|
+
export { SubNav }
|
|
@@ -0,0 +1,81 @@
|
|
|
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 { MutableRefObject, SyntheticEvent } from 'react'
|
|
26
|
+
|
|
27
|
+
import type { ComponentStyle } from '@instructure/emotion'
|
|
28
|
+
|
|
29
|
+
import type { GlobalNavSubNav } from '../props.js'
|
|
30
|
+
|
|
31
|
+
// set in event handlers and applied in effects, after the app re-renders with the new state
|
|
32
|
+
type FocusIntent =
|
|
33
|
+
// open or drill-in: the first focusable element in the level's body, else the close handle
|
|
34
|
+
| { target: 'first' }
|
|
35
|
+
// back: the item that opened the level the user left
|
|
36
|
+
| { target: 'item'; itemID: string }
|
|
37
|
+
// the user closed the SubNav: its rail item
|
|
38
|
+
| { target: 'trigger' }
|
|
39
|
+
// a rail item without a SubNav closed it: focus stays where the user clicked
|
|
40
|
+
| { target: 'none' }
|
|
41
|
+
// a level with focus went away without a user action: the rail item, or the first element of the next level
|
|
42
|
+
| { target: 'rescue' }
|
|
43
|
+
|
|
44
|
+
type SubNavProps = {
|
|
45
|
+
/**
|
|
46
|
+
* The data of the top level.
|
|
47
|
+
*/
|
|
48
|
+
subNav: GlobalNavSubNav
|
|
49
|
+
/**
|
|
50
|
+
* The id of the panel, which the rail item points to with `aria-controls`.
|
|
51
|
+
*/
|
|
52
|
+
subNavId: string
|
|
53
|
+
/**
|
|
54
|
+
* The id of the title, which names the panel.
|
|
55
|
+
*/
|
|
56
|
+
titleId: string
|
|
57
|
+
/**
|
|
58
|
+
* Whether closing the SubNav leaves the strip, which the close handle shows with its icon.
|
|
59
|
+
*/
|
|
60
|
+
collapsible: boolean
|
|
61
|
+
/**
|
|
62
|
+
* Screen reader text of the close handle.
|
|
63
|
+
*/
|
|
64
|
+
closeSubNavLabel: string
|
|
65
|
+
/**
|
|
66
|
+
* Screen reader text of the back button, from the title of the level it returns to.
|
|
67
|
+
*/
|
|
68
|
+
backLabel: (parentTitle: string) => string
|
|
69
|
+
/**
|
|
70
|
+
* Called when the user clicks the close handle.
|
|
71
|
+
*/
|
|
72
|
+
onClose: (event: SyntheticEvent) => void
|
|
73
|
+
/**
|
|
74
|
+
* The focus move that the user asked for, shared with GlobalNav.
|
|
75
|
+
*/
|
|
76
|
+
focusIntentRef: MutableRefObject<FocusIntent | undefined>
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
type SubNavStyle = ComponentStyle<'subNav'>
|
|
80
|
+
|
|
81
|
+
export type { FocusIntent, SubNavProps, SubNavStyle }
|