@instructure/ui-side-nav-bar 11.6.0 → 11.6.1-snapshot-129
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 +34 -290
- package/es/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/index.js +2 -2
- package/es/SideNavBar/{index.js → v1/index.js} +1 -1
- package/es/SideNavBar/v2/SideNavBarItem/index.js +109 -0
- package/{src/index.ts → es/SideNavBar/v2/SideNavBarItem/props.js} +2 -4
- package/es/SideNavBar/v2/SideNavBarItem/styles.js +101 -0
- package/es/SideNavBar/v2/index.js +135 -0
- package/es/SideNavBar/v2/props.js +26 -0
- package/es/SideNavBar/v2/styles.js +95 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/es/exports/b.js +24 -0
- package/lib/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/index.js +3 -3
- package/lib/SideNavBar/{index.js → v1/index.js} +2 -2
- package/lib/SideNavBar/v2/SideNavBarItem/index.js +115 -0
- package/lib/SideNavBar/v2/SideNavBarItem/props.js +31 -0
- package/lib/SideNavBar/v2/SideNavBarItem/styles.js +107 -0
- package/lib/SideNavBar/v2/index.js +149 -0
- package/lib/SideNavBar/v2/props.js +31 -0
- package/lib/SideNavBar/v2/styles.js +100 -0
- package/lib/{index.js → exports/a.js} +3 -3
- package/lib/exports/b.js +18 -0
- package/package.json +43 -21
- package/src/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/index.tsx +2 -2
- package/src/SideNavBar/{index.tsx → v1/index.tsx} +1 -1
- package/src/SideNavBar/v2/README.md +108 -0
- package/src/SideNavBar/v2/SideNavBarItem/index.tsx +112 -0
- package/src/SideNavBar/v2/SideNavBarItem/props.ts +89 -0
- package/src/SideNavBar/v2/SideNavBarItem/styles.ts +111 -0
- package/src/SideNavBar/v2/index.tsx +162 -0
- package/src/SideNavBar/v2/props.ts +94 -0
- package/src/SideNavBar/v2/styles.ts +105 -0
- package/src/exports/a.ts +28 -0
- package/src/exports/b.ts +28 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/SideNavBar/v1/SideNavBarItem/index.d.ts.map +1 -0
- package/types/SideNavBar/v1/SideNavBarItem/props.d.ts.map +1 -0
- package/types/SideNavBar/v1/SideNavBarItem/styles.d.ts.map +1 -0
- package/types/SideNavBar/v1/SideNavBarItem/theme.d.ts.map +1 -0
- package/types/SideNavBar/v1/index.d.ts.map +1 -0
- package/types/SideNavBar/v1/props.d.ts.map +1 -0
- package/types/SideNavBar/v1/styles.d.ts.map +1 -0
- package/types/SideNavBar/v1/theme.d.ts.map +1 -0
- package/types/SideNavBar/v2/SideNavBarItem/index.d.ts +35 -0
- package/types/SideNavBar/v2/SideNavBarItem/index.d.ts.map +1 -0
- package/types/SideNavBar/v2/SideNavBarItem/props.d.ts +45 -0
- package/types/SideNavBar/v2/SideNavBarItem/props.d.ts.map +1 -0
- package/types/SideNavBar/v2/SideNavBarItem/styles.d.ts +16 -0
- package/types/SideNavBar/v2/SideNavBarItem/styles.d.ts.map +1 -0
- package/types/SideNavBar/v2/index.d.ts +44 -0
- package/types/SideNavBar/v2/index.d.ts.map +1 -0
- package/types/SideNavBar/v2/props.d.ts +48 -0
- package/types/SideNavBar/v2/props.d.ts.map +1 -0
- package/types/SideNavBar/v2/styles.d.ts +16 -0
- package/types/SideNavBar/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +4 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +4 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/SideNavBar/SideNavBarItem/index.d.ts.map +0 -1
- package/types/SideNavBar/SideNavBarItem/props.d.ts.map +0 -1
- package/types/SideNavBar/SideNavBarItem/styles.d.ts.map +0 -1
- package/types/SideNavBar/SideNavBarItem/theme.d.ts.map +0 -1
- package/types/SideNavBar/index.d.ts.map +0 -1
- package/types/SideNavBar/props.d.ts.map +0 -1
- package/types/SideNavBar/styles.d.ts.map +0 -1
- package/types/SideNavBar/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -4
- package/types/index.d.ts.map +0 -1
- /package/es/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/props.js +0 -0
- /package/es/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/styles.js +0 -0
- /package/es/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/theme.js +0 -0
- /package/es/SideNavBar/{props.js → v1/props.js} +0 -0
- /package/es/SideNavBar/{styles.js → v1/styles.js} +0 -0
- /package/es/SideNavBar/{theme.js → v1/theme.js} +0 -0
- /package/lib/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/props.js +0 -0
- /package/lib/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/styles.js +0 -0
- /package/lib/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/theme.js +0 -0
- /package/lib/SideNavBar/{props.js → v1/props.js} +0 -0
- /package/lib/SideNavBar/{styles.js → v1/styles.js} +0 -0
- /package/lib/SideNavBar/{theme.js → v1/theme.js} +0 -0
- /package/src/SideNavBar/{README.md → v1/README.md} +0 -0
- /package/src/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/props.ts +0 -0
- /package/src/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/styles.ts +0 -0
- /package/src/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/theme.ts +0 -0
- /package/src/SideNavBar/{props.ts → v1/props.ts} +0 -0
- /package/src/SideNavBar/{styles.ts → v1/styles.ts} +0 -0
- /package/src/SideNavBar/{theme.ts → v1/theme.ts} +0 -0
- /package/types/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/index.d.ts +0 -0
- /package/types/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/props.d.ts +0 -0
- /package/types/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/styles.d.ts +0 -0
- /package/types/SideNavBar/{SideNavBarItem → v1/SideNavBarItem}/theme.d.ts +0 -0
- /package/types/SideNavBar/{index.d.ts → v1/index.d.ts} +0 -0
- /package/types/SideNavBar/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/SideNavBar/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/SideNavBar/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
---
|
|
2
|
+
describes: SideNavBar
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
A top-level `SideNavBar` component.
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
---
|
|
9
|
+
type: example
|
|
10
|
+
---
|
|
11
|
+
const Example = () => {
|
|
12
|
+
const [minimized, setMinimized] = React.useState(false)
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<div style={{height: '47rem', width: '10rem'}}>
|
|
16
|
+
<SideNavBar
|
|
17
|
+
label="Main navigation"
|
|
18
|
+
toggleLabel={{
|
|
19
|
+
expandedLabel: 'Minimize SideNavBar',
|
|
20
|
+
minimizedLabel: 'Expand SideNavBar'
|
|
21
|
+
}}
|
|
22
|
+
onMinimized={(_e, isMinimized) => setMinimized(isMinimized)}
|
|
23
|
+
>
|
|
24
|
+
<SideNavBar.Item
|
|
25
|
+
icon={<GlobeInstUIIcon size={minimized ? "small" : "medium"}/>}
|
|
26
|
+
label={<ScreenReaderContent>Home</ScreenReaderContent>}
|
|
27
|
+
href="#"
|
|
28
|
+
themeOverride={{
|
|
29
|
+
contentPadding: '1em 0.375rem 1em 0.375rem'
|
|
30
|
+
}}
|
|
31
|
+
/>
|
|
32
|
+
<SideNavBar.Item
|
|
33
|
+
icon={<Avatar name="Ziggy Marley" size="x-small" src={avatarSquare} showBorder="always"/>}
|
|
34
|
+
label="Account"
|
|
35
|
+
onClick={() => { this.loadSubNav('account') }}
|
|
36
|
+
/>
|
|
37
|
+
<SideNavBar.Item
|
|
38
|
+
icon={<ShieldUserInstUIIcon />}
|
|
39
|
+
label="Admin"
|
|
40
|
+
href="#"
|
|
41
|
+
/>
|
|
42
|
+
<SideNavBar.Item selected
|
|
43
|
+
icon={<LayoutDashboardInstUIIcon />}
|
|
44
|
+
label="Dashboard"
|
|
45
|
+
href="#"
|
|
46
|
+
/>
|
|
47
|
+
<SideNavBar.Item
|
|
48
|
+
icon={<BookTextInstUIIcon />}
|
|
49
|
+
label="Courses"
|
|
50
|
+
href="#"
|
|
51
|
+
/>
|
|
52
|
+
<SideNavBar.Item
|
|
53
|
+
icon={<CalendarDaysInstUIIcon />}
|
|
54
|
+
label="Calendar"
|
|
55
|
+
href="#"
|
|
56
|
+
/>
|
|
57
|
+
<SideNavBar.Item
|
|
58
|
+
icon={
|
|
59
|
+
<Badge count={99}
|
|
60
|
+
formatOutput={function (formattedCount) {
|
|
61
|
+
return (
|
|
62
|
+
<AccessibleContent alt={`You have ${formattedCount} unread messages.`}>
|
|
63
|
+
{formattedCount}
|
|
64
|
+
</AccessibleContent>
|
|
65
|
+
)
|
|
66
|
+
}}
|
|
67
|
+
>
|
|
68
|
+
<InboxInstUIIcon />
|
|
69
|
+
</Badge>
|
|
70
|
+
}
|
|
71
|
+
label="Inbox"
|
|
72
|
+
href="#"
|
|
73
|
+
/>
|
|
74
|
+
<SideNavBar.Item
|
|
75
|
+
icon={<Clock4InstUIIcon />}
|
|
76
|
+
label="History"
|
|
77
|
+
href="#"
|
|
78
|
+
/>
|
|
79
|
+
<SideNavBar.Item
|
|
80
|
+
icon={<HelpCircleInstUIIcon />}
|
|
81
|
+
label="Help"
|
|
82
|
+
href="#"
|
|
83
|
+
/>
|
|
84
|
+
</SideNavBar>
|
|
85
|
+
</div>
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
render(<Example />)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Guidelines
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
---
|
|
96
|
+
type: embed
|
|
97
|
+
---
|
|
98
|
+
<Guidelines>
|
|
99
|
+
<Figure recommendation="yes" title="Do">
|
|
100
|
+
<Figure.Item>Use for top-level SideNavBar</Figure.Item>
|
|
101
|
+
<Figure.Item>Remember that SideNavBar can be themed by the institution</Figure.Item>
|
|
102
|
+
<Figure.Item>When using an <Link href="/#Avatar">Avatar</Link> in the SideNavBar it should have the <code>showBorder="always"</code> prop</Figure.Item>
|
|
103
|
+
</Figure>
|
|
104
|
+
<Figure recommendation="no" title="Don't">
|
|
105
|
+
<Figure.Item>Add LTI links to the main area</Figure.Item>
|
|
106
|
+
</Figure>
|
|
107
|
+
</Guidelines>
|
|
108
|
+
```
|
|
@@ -0,0 +1,112 @@
|
|
|
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 { Component } from 'react'
|
|
26
|
+
|
|
27
|
+
import { omitProps, getElementType } from '@instructure/ui-react-utils'
|
|
28
|
+
import { Tooltip } from '@instructure/ui-tooltip/latest'
|
|
29
|
+
import { hasVisibleChildren } from '@instructure/ui-a11y-utils'
|
|
30
|
+
import { withStyle } from '@instructure/emotion'
|
|
31
|
+
|
|
32
|
+
import generateStyle from './styles'
|
|
33
|
+
import type { SideNavBarItemProps } from './props'
|
|
34
|
+
import { allowedProps } from './props'
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
---
|
|
38
|
+
parent: SideNavBar
|
|
39
|
+
id: SideNavBar.Item
|
|
40
|
+
---
|
|
41
|
+
**/
|
|
42
|
+
@withStyle(generateStyle, 'SideNavBarItem')
|
|
43
|
+
class SideNavBarItem extends Component<SideNavBarItemProps> {
|
|
44
|
+
static readonly componentId = 'SideNavBar.Item'
|
|
45
|
+
|
|
46
|
+
static allowedProps = allowedProps
|
|
47
|
+
|
|
48
|
+
static defaultProps = {
|
|
49
|
+
as: 'a',
|
|
50
|
+
selected: false,
|
|
51
|
+
minimized: false
|
|
52
|
+
} as const
|
|
53
|
+
|
|
54
|
+
ref: Element | null = null
|
|
55
|
+
|
|
56
|
+
handleRef = (el: Element | null) => {
|
|
57
|
+
const { elementRef } = this.props
|
|
58
|
+
this.ref = el
|
|
59
|
+
if (typeof elementRef === 'function') {
|
|
60
|
+
elementRef(el)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
componentDidMount() {
|
|
65
|
+
this.props.makeStyles?.({ minimized: this.props.minimized })
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
componentDidUpdate() {
|
|
69
|
+
this.props.makeStyles?.({ minimized: this.props.minimized })
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
renderLink(addRef: boolean) {
|
|
73
|
+
const ElementType = getElementType(SideNavBarItem, this.props)
|
|
74
|
+
|
|
75
|
+
const { href, onClick, icon, label } = this.props
|
|
76
|
+
|
|
77
|
+
const props = omitProps(this.props, SideNavBarItem.allowedProps)
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<ElementType
|
|
81
|
+
{...props}
|
|
82
|
+
href={href}
|
|
83
|
+
onClick={onClick}
|
|
84
|
+
ref={addRef ? this.handleRef : undefined}
|
|
85
|
+
css={this.props.styles?.navigationItem}
|
|
86
|
+
aria-label={this.props.minimized ? (label as string) : undefined}
|
|
87
|
+
data-cid="SideNavBarItem"
|
|
88
|
+
>
|
|
89
|
+
<div css={this.props.styles?.icon}>{icon}</div>
|
|
90
|
+
{!this.props.minimized ? (
|
|
91
|
+
<div css={this.props.styles?.label}>{label}</div>
|
|
92
|
+
) : null}
|
|
93
|
+
</ElementType>
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
render() {
|
|
98
|
+
const { minimized, label } = this.props
|
|
99
|
+
const hasTooltip: boolean = minimized! && hasVisibleChildren(label)
|
|
100
|
+
const link = this.renderLink(!hasTooltip)
|
|
101
|
+
return hasTooltip ? (
|
|
102
|
+
<Tooltip renderTip={label} placement="end" elementRef={this.handleRef}>
|
|
103
|
+
{link}
|
|
104
|
+
</Tooltip>
|
|
105
|
+
) : (
|
|
106
|
+
link
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export default SideNavBarItem
|
|
112
|
+
export { SideNavBarItem }
|
|
@@ -0,0 +1,89 @@
|
|
|
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 React from 'react'
|
|
26
|
+
import type {
|
|
27
|
+
AsElementType,
|
|
28
|
+
SideNavBarItemTheme,
|
|
29
|
+
OtherHTMLAttributes
|
|
30
|
+
} from '@instructure/shared-types'
|
|
31
|
+
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
32
|
+
|
|
33
|
+
type SideNavBarItemOwnProps = {
|
|
34
|
+
/**
|
|
35
|
+
* The reference to the underlying HTML element
|
|
36
|
+
*/
|
|
37
|
+
elementRef?: (el: Element | null) => void
|
|
38
|
+
/**
|
|
39
|
+
* The visual to display (ex. an Image, Logo, Avatar, or Icon)
|
|
40
|
+
*/
|
|
41
|
+
icon: React.ReactNode
|
|
42
|
+
/**
|
|
43
|
+
* The text to display for the SideNavBar Link
|
|
44
|
+
*/
|
|
45
|
+
label: React.ReactNode
|
|
46
|
+
/**
|
|
47
|
+
* The element type to render as (will default to `<a>` if href is provided)
|
|
48
|
+
*/
|
|
49
|
+
as?: AsElementType
|
|
50
|
+
/**
|
|
51
|
+
* If the SideNavBarItem goes to a new page, pass an href
|
|
52
|
+
*/
|
|
53
|
+
href?: string
|
|
54
|
+
/**
|
|
55
|
+
* If the SideNavBarItem does not go to a new page pass an onClick
|
|
56
|
+
*/
|
|
57
|
+
onClick?: (event: React.MouseEvent) => void
|
|
58
|
+
/**
|
|
59
|
+
* Denotes which SideNavBarItem is currently selected
|
|
60
|
+
*/
|
|
61
|
+
selected?: boolean
|
|
62
|
+
/**
|
|
63
|
+
* When minimized is set to true, the `<SideNavBar />` shows icons only while the text becomes a tooltip. When it is set to false, the `<SideNavBar />` shows text in addition to the icons
|
|
64
|
+
*/
|
|
65
|
+
minimized?: boolean
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
type PropKeys = keyof SideNavBarItemOwnProps
|
|
69
|
+
|
|
70
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
71
|
+
|
|
72
|
+
type SideNavBarItemProps = SideNavBarItemOwnProps &
|
|
73
|
+
WithStyleProps<SideNavBarItemTheme, SideNavBarItemStyle> &
|
|
74
|
+
OtherHTMLAttributes<SideNavBarItemOwnProps>
|
|
75
|
+
|
|
76
|
+
type SideNavBarItemStyle = ComponentStyle<'navigationItem' | 'icon' | 'label'>
|
|
77
|
+
const allowedProps: AllowedPropKeys = [
|
|
78
|
+
'elementRef',
|
|
79
|
+
'icon',
|
|
80
|
+
'label',
|
|
81
|
+
'as',
|
|
82
|
+
'href',
|
|
83
|
+
'onClick',
|
|
84
|
+
'selected',
|
|
85
|
+
'minimized'
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
export type { SideNavBarItemProps, SideNavBarItemStyle }
|
|
89
|
+
export { allowedProps }
|
|
@@ -0,0 +1,111 @@
|
|
|
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 { SideNavBarItemProps, SideNavBarItemStyle } from './props'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* ---
|
|
30
|
+
* private: true
|
|
31
|
+
* ---
|
|
32
|
+
* Generates the style object from the theme and provided additional information
|
|
33
|
+
* @param {Object} componentTheme The theme variable object.
|
|
34
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
35
|
+
* @param {Object} sharedTokens Shared theme token object
|
|
36
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
37
|
+
* @return {Object} The final style object, which will be used in the component
|
|
38
|
+
*/
|
|
39
|
+
const generateStyle = (
|
|
40
|
+
componentTheme: NewComponentTypes['SideNavBarItem'],
|
|
41
|
+
props: SideNavBarItemProps
|
|
42
|
+
): SideNavBarItemStyle => {
|
|
43
|
+
const { selected } = props
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
navigationItem: {
|
|
47
|
+
borderRadius: componentTheme.borderRadius,
|
|
48
|
+
label: 'navigationItem',
|
|
49
|
+
fontFamily: componentTheme.fontFamily,
|
|
50
|
+
fontWeight: componentTheme.fontWeight,
|
|
51
|
+
display: 'block',
|
|
52
|
+
width: '100%',
|
|
53
|
+
textAlign: 'center',
|
|
54
|
+
padding: componentTheme.contentPadding,
|
|
55
|
+
cursor: 'pointer',
|
|
56
|
+
border: 'none',
|
|
57
|
+
boxSizing: 'border-box',
|
|
58
|
+
textDecoration: componentTheme.linkTextDecoration,
|
|
59
|
+
overflowWrap: 'break-word',
|
|
60
|
+
wordWrap: 'break-word',
|
|
61
|
+
hyphens: 'auto',
|
|
62
|
+
...(selected
|
|
63
|
+
? {
|
|
64
|
+
backgroundColor: componentTheme.selectedBackgroundColor,
|
|
65
|
+
color: componentTheme.selectedFontColor,
|
|
66
|
+
'&:active, &:hover': {
|
|
67
|
+
backgroundColor: componentTheme.selectedBackgroundColor,
|
|
68
|
+
color: componentTheme.selectedFontColor,
|
|
69
|
+
textDecoration: componentTheme.linkTextDecoration
|
|
70
|
+
},
|
|
71
|
+
'&:focus': {
|
|
72
|
+
backgroundColor: componentTheme.selectedBackgroundColor,
|
|
73
|
+
boxShadow: `${componentTheme.selectedOuterFocusOutlineColor}, ${componentTheme.selectedInnerFocusOutlineColor}`,
|
|
74
|
+
outline: 'none'
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
: {
|
|
78
|
+
backgroundColor: componentTheme.backgroundColor,
|
|
79
|
+
color: componentTheme.fontColor,
|
|
80
|
+
'&:active': {
|
|
81
|
+
backgroundColor: componentTheme.hoverBackgroundColor
|
|
82
|
+
},
|
|
83
|
+
'&:hover': {
|
|
84
|
+
transition: 'background-color .3s',
|
|
85
|
+
backgroundColor: componentTheme.hoverBackgroundColor,
|
|
86
|
+
color: componentTheme.fontColor,
|
|
87
|
+
textDecoration: componentTheme.linkTextDecoration
|
|
88
|
+
},
|
|
89
|
+
'&:focus': {
|
|
90
|
+
backgroundColor: componentTheme.hoverBackgroundColor,
|
|
91
|
+
boxShadow: `inset 0 0 0 0.125rem ${componentTheme.outerFocusOutlineColor}, inset 0 0 0 0.25rem ${componentTheme.innerFocusOutlineColor}`,
|
|
92
|
+
outline: 'none'
|
|
93
|
+
}
|
|
94
|
+
})
|
|
95
|
+
},
|
|
96
|
+
icon: {
|
|
97
|
+
label: 'navigationItem__icon',
|
|
98
|
+
height: componentTheme.iconWrapperHeight,
|
|
99
|
+
display: 'flex',
|
|
100
|
+
alignItems: 'center',
|
|
101
|
+
justifyContent: 'center'
|
|
102
|
+
},
|
|
103
|
+
label: {
|
|
104
|
+
label: 'navigationItem__label',
|
|
105
|
+
fontSize: componentTheme.fontSize,
|
|
106
|
+
lineHeight: componentTheme.lineHeight
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export default generateStyle
|
|
@@ -0,0 +1,162 @@
|
|
|
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 { Component, Children, ReactElement, isValidElement } from 'react'
|
|
25
|
+
|
|
26
|
+
import { omitProps, safeCloneElement } from '@instructure/ui-react-utils'
|
|
27
|
+
import {
|
|
28
|
+
PanelLeftCloseInstUIIcon,
|
|
29
|
+
PanelLeftOpenInstUIIcon,
|
|
30
|
+
renderIconWithProps
|
|
31
|
+
} from '@instructure/ui-icons'
|
|
32
|
+
import { ScreenReaderContent } from '@instructure/ui-a11y-content'
|
|
33
|
+
import { withStyle } from '@instructure/emotion'
|
|
34
|
+
|
|
35
|
+
import { SideNavBarItem } from './SideNavBarItem'
|
|
36
|
+
|
|
37
|
+
import generateStyle from './styles'
|
|
38
|
+
import type { SideNavBarProps, SideNavBarState } from './props'
|
|
39
|
+
import { allowedProps } from './props'
|
|
40
|
+
|
|
41
|
+
const navMinimized = ({ minimized }: { minimized: boolean }) => ({
|
|
42
|
+
minimized: !minimized
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
---
|
|
47
|
+
category: components
|
|
48
|
+
---
|
|
49
|
+
**/
|
|
50
|
+
@withStyle(generateStyle)
|
|
51
|
+
class SideNavBar extends Component<SideNavBarProps, SideNavBarState> {
|
|
52
|
+
static readonly componentId = 'SideNavBar'
|
|
53
|
+
|
|
54
|
+
static allowedProps = allowedProps
|
|
55
|
+
|
|
56
|
+
static defaultProps = {
|
|
57
|
+
children: null,
|
|
58
|
+
defaultMinimized: false,
|
|
59
|
+
// TODO we should investigate later if it used or not
|
|
60
|
+
onClick: function (_e: React.MouseEvent) {}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static Item = SideNavBarItem
|
|
64
|
+
|
|
65
|
+
ref: Element | null = null
|
|
66
|
+
|
|
67
|
+
constructor(props: SideNavBarProps) {
|
|
68
|
+
super(props)
|
|
69
|
+
|
|
70
|
+
this.state = {
|
|
71
|
+
minimized: this.isControlled(props)
|
|
72
|
+
? !!props.minimized
|
|
73
|
+
: !!props.defaultMinimized
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
componentDidMount() {
|
|
78
|
+
this.props.makeStyles?.({ minimized: this.minimized })
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
componentDidUpdate() {
|
|
82
|
+
this.props.makeStyles?.({ minimized: this.minimized })
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get minimized() {
|
|
86
|
+
if (this.isControlled()) {
|
|
87
|
+
return !!this.props.minimized
|
|
88
|
+
}
|
|
89
|
+
return !!this.state.minimized
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
isControlled(props = this.props) {
|
|
93
|
+
return typeof props.minimized === 'boolean'
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
handleNavToggle = (event: React.SyntheticEvent) => {
|
|
97
|
+
if (!this.isControlled()) {
|
|
98
|
+
this.setState(navMinimized)
|
|
99
|
+
}
|
|
100
|
+
if (typeof this.props.onMinimized === 'function') {
|
|
101
|
+
this.props.onMinimized(event, !this.minimized)
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
renderChildren() {
|
|
106
|
+
return Children.map(this.props.children, (child) => {
|
|
107
|
+
if (!isValidElement(child)) return null
|
|
108
|
+
const navItem = safeCloneElement(child as ReactElement, {
|
|
109
|
+
minimized: this.state.minimized
|
|
110
|
+
})
|
|
111
|
+
return <li css={this.props.styles?.list}>{navItem}</li>
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
renderIcon() {
|
|
116
|
+
const icon = this.minimized
|
|
117
|
+
? PanelLeftOpenInstUIIcon
|
|
118
|
+
: PanelLeftCloseInstUIIcon
|
|
119
|
+
const iconColor = this.props.selected
|
|
120
|
+
? 'sideNavActiveColor'
|
|
121
|
+
: 'sideNavColor'
|
|
122
|
+
|
|
123
|
+
return renderIconWithProps(icon, 'lg', iconColor as any) //TODO-rework remove after merging into v12
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
toggleMessage() {
|
|
127
|
+
return this.state.minimized
|
|
128
|
+
? this.props.toggleLabel.minimizedLabel
|
|
129
|
+
: this.props.toggleLabel.expandedLabel
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
render() {
|
|
133
|
+
const { label } = this.props
|
|
134
|
+
|
|
135
|
+
const props = omitProps(this.props, SideNavBar.allowedProps, ['minimized'])
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<nav
|
|
139
|
+
{...props}
|
|
140
|
+
css={this.props.styles?.navigation}
|
|
141
|
+
data-cid="SideNavBar"
|
|
142
|
+
aria-label={label}
|
|
143
|
+
ref={(element) => {
|
|
144
|
+
this.ref = element
|
|
145
|
+
}}
|
|
146
|
+
>
|
|
147
|
+
<ul css={this.props.styles?.content}>{this.renderChildren()}</ul>
|
|
148
|
+
<SideNavBarItem
|
|
149
|
+
aria-expanded={!this.minimized}
|
|
150
|
+
onClick={this.handleNavToggle}
|
|
151
|
+
icon={this.renderIcon()}
|
|
152
|
+
label={
|
|
153
|
+
<ScreenReaderContent>{this.toggleMessage()}</ScreenReaderContent>
|
|
154
|
+
}
|
|
155
|
+
></SideNavBarItem>
|
|
156
|
+
</nav>
|
|
157
|
+
)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export default SideNavBar
|
|
162
|
+
export { SideNavBar, SideNavBarItem }
|
|
@@ -0,0 +1,94 @@
|
|
|
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 React from 'react'
|
|
25
|
+
|
|
26
|
+
import type {
|
|
27
|
+
SideNavBarTheme,
|
|
28
|
+
OtherHTMLAttributes
|
|
29
|
+
} from '@instructure/shared-types'
|
|
30
|
+
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
31
|
+
|
|
32
|
+
type SideNavBarOwnProps = {
|
|
33
|
+
/**
|
|
34
|
+
* When minimized is set to true, the `<SideNavBar />` shows icons only while the text becomes a tooltip. When it is set to false, the `<SideNavBar />` shows text in addition to the icons
|
|
35
|
+
*/
|
|
36
|
+
minimized?: boolean
|
|
37
|
+
/**
|
|
38
|
+
* Whether the `<SideNavBar />` is initially minimized (uncontrolled)
|
|
39
|
+
*/
|
|
40
|
+
defaultMinimized?: boolean
|
|
41
|
+
onMinimized?: (event: React.SyntheticEvent, minimized: boolean) => void
|
|
42
|
+
/**
|
|
43
|
+
* Screen reader label for the main SideNavBar
|
|
44
|
+
*/
|
|
45
|
+
label: string
|
|
46
|
+
/**
|
|
47
|
+
* Screen reader label for the toggle button expanded/minimized state
|
|
48
|
+
*/
|
|
49
|
+
toggleLabel: {
|
|
50
|
+
expandedLabel?: string
|
|
51
|
+
minimizedLabel?: string
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* If the `<SideNavBar.Item>` goes to a new page, pass an href
|
|
55
|
+
*/
|
|
56
|
+
href?: string
|
|
57
|
+
/**
|
|
58
|
+
* If the `<SideNavBar.Item>` does not go to a new page pass an onClick
|
|
59
|
+
*/
|
|
60
|
+
onClick?: (event: React.MouseEvent) => void
|
|
61
|
+
/**
|
|
62
|
+
* children of type SideNavBar.Item
|
|
63
|
+
*/
|
|
64
|
+
children?: React.ReactNode
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type SideNavBarState = {
|
|
68
|
+
minimized: boolean
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type PropKeys = keyof SideNavBarOwnProps
|
|
72
|
+
|
|
73
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
74
|
+
|
|
75
|
+
type SideNavBarProps = SideNavBarOwnProps &
|
|
76
|
+
WithStyleProps<SideNavBarTheme, SideNavBarStyle> &
|
|
77
|
+
OtherHTMLAttributes<SideNavBarOwnProps>
|
|
78
|
+
|
|
79
|
+
type SideNavBarStyle = ComponentStyle<
|
|
80
|
+
'navigation' | 'list' | 'content' | 'toggleIcon'
|
|
81
|
+
>
|
|
82
|
+
const allowedProps: AllowedPropKeys = [
|
|
83
|
+
'children',
|
|
84
|
+
'minimized',
|
|
85
|
+
'defaultMinimized',
|
|
86
|
+
'onMinimized',
|
|
87
|
+
'label',
|
|
88
|
+
'toggleLabel',
|
|
89
|
+
'href',
|
|
90
|
+
'onClick'
|
|
91
|
+
]
|
|
92
|
+
|
|
93
|
+
export type { SideNavBarProps, SideNavBarState, SideNavBarStyle }
|
|
94
|
+
export { allowedProps }
|