@instructure/ui-navigation 8.8.1-snapshot.8 → 8.9.1
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 +10 -0
- package/es/AppNav/Item/index.js +21 -77
- package/es/AppNav/Item/props.js +79 -0
- package/es/AppNav/index.js +26 -80
- package/es/AppNav/props.js +87 -0
- package/es/Navigation/NavigationItem/index.js +25 -60
- package/{src/AppNav/types.ts → es/Navigation/NavigationItem/props.js} +37 -14
- package/es/Navigation/index.js +18 -57
- package/es/Navigation/props.js +68 -0
- package/lib/AppNav/Item/index.js +21 -77
- package/lib/AppNav/Item/props.js +90 -0
- package/lib/AppNav/index.js +25 -80
- package/lib/AppNav/props.js +101 -0
- package/lib/Navigation/NavigationItem/index.js +25 -60
- package/lib/Navigation/NavigationItem/props.js +73 -0
- package/lib/Navigation/index.js +19 -61
- package/lib/Navigation/props.js +83 -0
- package/package.json +24 -25
- package/src/AppNav/Item/index.tsx +8 -62
- package/src/AppNav/Item/props.ts +107 -0
- package/src/AppNav/Item/styles.ts +1 -1
- package/src/AppNav/index.tsx +13 -69
- package/src/AppNav/props.ts +118 -0
- package/src/Navigation/NavigationItem/index.tsx +10 -45
- package/src/Navigation/NavigationItem/props.ts +87 -0
- package/src/Navigation/NavigationItem/styles.ts +1 -1
- package/src/Navigation/index.tsx +13 -56
- package/src/Navigation/props.ts +108 -0
- package/src/Navigation/styles.ts +1 -1
- package/src/index.ts +4 -4
- package/types/AppNav/Item/index.d.ts +25 -53
- package/types/AppNav/Item/index.d.ts.map +1 -1
- package/types/AppNav/Item/props.d.ts +23 -0
- package/types/AppNav/Item/props.d.ts.map +1 -0
- package/types/AppNav/Item/styles.d.ts +1 -1
- package/types/AppNav/index.d.ts +25 -58
- package/types/AppNav/index.d.ts.map +1 -1
- package/types/AppNav/props.d.ts +23 -0
- package/types/AppNav/props.d.ts.map +1 -0
- package/types/Navigation/NavigationItem/index.d.ts +19 -35
- package/types/Navigation/NavigationItem/index.d.ts.map +1 -1
- package/types/Navigation/NavigationItem/props.d.ts +20 -0
- package/types/Navigation/NavigationItem/props.d.ts.map +1 -0
- package/types/Navigation/NavigationItem/styles.d.ts +1 -1
- package/types/Navigation/index.d.ts +26 -42
- package/types/Navigation/index.d.ts.map +1 -1
- package/types/Navigation/props.d.ts +27 -0
- package/types/Navigation/props.d.ts.map +1 -0
- package/types/Navigation/styles.d.ts +1 -1
- package/types/index.d.ts +4 -4
- package/LICENSE.md +0 -27
- package/es/AppNav/Item/types.js +0 -1
- package/es/AppNav/types.js +0 -1
- package/es/Navigation/NavigationItem/types.js +0 -1
- package/es/Navigation/types.js +0 -1
- package/lib/AppNav/Item/types.js +0 -1
- package/lib/AppNav/types.js +0 -1
- package/lib/Navigation/NavigationItem/types.js +0 -1
- package/lib/Navigation/types.js +0 -1
- package/src/AppNav/Item/types.ts +0 -40
- package/src/Navigation/NavigationItem/types.ts +0 -37
- package/src/Navigation/types.ts +0 -42
- package/types/AppNav/Item/types.d.ts +0 -17
- package/types/AppNav/Item/types.d.ts.map +0 -1
- package/types/AppNav/types.d.ts +0 -16
- package/types/AppNav/types.d.ts.map +0 -1
- package/types/Navigation/NavigationItem/types.d.ts +0 -14
- package/types/Navigation/NavigationItem/types.d.ts.map +0 -1
- package/types/Navigation/types.d.ts +0 -18
- package/types/Navigation/types.d.ts.map +0 -1
|
@@ -0,0 +1,107 @@
|
|
|
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 PropTypes from 'prop-types'
|
|
25
|
+
|
|
26
|
+
import type { AsElementType, PropValidators } from '@instructure/shared-types'
|
|
27
|
+
import type { WithStyleProps } from '@instructure/emotion'
|
|
28
|
+
|
|
29
|
+
type AppNavItemOwnProps = {
|
|
30
|
+
renderLabel: React.ReactNode | ((...args: any[]) => any)
|
|
31
|
+
renderAfter?: React.ReactNode | ((...args: any[]) => any)
|
|
32
|
+
renderIcon?: React.ReactNode | ((...args: any[]) => any)
|
|
33
|
+
href?: string
|
|
34
|
+
onClick?: (...args: any[]) => any
|
|
35
|
+
isSelected?: boolean
|
|
36
|
+
elementRef?: (...args: any[]) => any
|
|
37
|
+
as?: AsElementType
|
|
38
|
+
cursor?: string
|
|
39
|
+
isDisabled?: boolean
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type PropKeys = keyof AppNavItemOwnProps
|
|
43
|
+
|
|
44
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
45
|
+
|
|
46
|
+
type AppNavItemProps = AppNavItemOwnProps & WithStyleProps
|
|
47
|
+
|
|
48
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
49
|
+
/**
|
|
50
|
+
* The text to display. If the `icon` prop is used, label text must be wrapped
|
|
51
|
+
* in `ScreenReaderContent`.
|
|
52
|
+
*/
|
|
53
|
+
renderLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
|
|
54
|
+
/**
|
|
55
|
+
* Content to display after the renderLabel text, such as a badge
|
|
56
|
+
*/
|
|
57
|
+
renderAfter: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
58
|
+
/**
|
|
59
|
+
* The visual to display (ex. an Image, Logo, Avatar, or Icon)
|
|
60
|
+
*/
|
|
61
|
+
renderIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
62
|
+
/**
|
|
63
|
+
* If the item goes to a new page, pass an href
|
|
64
|
+
*/
|
|
65
|
+
href: PropTypes.string,
|
|
66
|
+
/**
|
|
67
|
+
* If the item does not go to a new page, pass an onClick
|
|
68
|
+
*/
|
|
69
|
+
onClick: PropTypes.func,
|
|
70
|
+
/**
|
|
71
|
+
* Denotes which item is currently selected
|
|
72
|
+
*/
|
|
73
|
+
isSelected: PropTypes.bool,
|
|
74
|
+
/**
|
|
75
|
+
* provides a reference to the underlying focusable (`button` or `a`) element
|
|
76
|
+
*/
|
|
77
|
+
elementRef: PropTypes.func,
|
|
78
|
+
/**
|
|
79
|
+
* The element type to render as (will default to `<a>` if href is provided)
|
|
80
|
+
*/
|
|
81
|
+
as: PropTypes.elementType,
|
|
82
|
+
/**
|
|
83
|
+
* Specify the mouse cursor to use on :hover.
|
|
84
|
+
* The `pointer` cursor is used by default.
|
|
85
|
+
*/
|
|
86
|
+
cursor: PropTypes.string,
|
|
87
|
+
/**
|
|
88
|
+
* Disables the link or button visually and functionally
|
|
89
|
+
*/
|
|
90
|
+
isDisabled: PropTypes.bool
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const allowedProps: AllowedPropKeys = [
|
|
94
|
+
'renderLabel',
|
|
95
|
+
'renderAfter',
|
|
96
|
+
'renderIcon',
|
|
97
|
+
'href',
|
|
98
|
+
'onClick',
|
|
99
|
+
'isSelected',
|
|
100
|
+
'elementRef',
|
|
101
|
+
'as',
|
|
102
|
+
'cursor',
|
|
103
|
+
'isDisabled'
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
export type { AppNavItemProps }
|
|
107
|
+
export { propTypes, allowedProps }
|
package/src/AppNav/index.tsx
CHANGED
|
@@ -24,10 +24,8 @@
|
|
|
24
24
|
|
|
25
25
|
/** @jsx jsx */
|
|
26
26
|
import { Children, Component } from 'react'
|
|
27
|
-
import PropTypes from 'prop-types'
|
|
28
27
|
|
|
29
|
-
import { withStyle, jsx
|
|
30
|
-
import { Children as ChildrenPropTypes } from '@instructure/ui-prop-types'
|
|
28
|
+
import { withStyle, jsx } from '@instructure/emotion'
|
|
31
29
|
|
|
32
30
|
import { getBoundingClientRect } from '@instructure/ui-dom-utils'
|
|
33
31
|
import { callRenderProp, omitProps } from '@instructure/ui-react-utils'
|
|
@@ -41,7 +39,8 @@ import { Item } from './Item'
|
|
|
41
39
|
|
|
42
40
|
import generateStyle from './styles'
|
|
43
41
|
import generateComponentTheme from './theme'
|
|
44
|
-
import { AppNavProps } from './
|
|
42
|
+
import type { AppNavProps } from './props'
|
|
43
|
+
import { allowedProps, propTypes } from './props'
|
|
45
44
|
|
|
46
45
|
/**
|
|
47
46
|
---
|
|
@@ -53,66 +52,13 @@ category: components
|
|
|
53
52
|
class AppNav extends Component<AppNavProps> {
|
|
54
53
|
static readonly componentId = 'AppNav'
|
|
55
54
|
|
|
56
|
-
static
|
|
57
|
-
|
|
58
|
-
* Screenreader label for the overall navigation
|
|
59
|
-
*/
|
|
60
|
-
screenReaderLabel: PropTypes.string.isRequired,
|
|
61
|
-
/**
|
|
62
|
-
* Only accepts `AppNav.Item` as children
|
|
63
|
-
*/
|
|
64
|
-
children: ChildrenPropTypes.oneOf([Item]),
|
|
65
|
-
/**
|
|
66
|
-
* The rate (in ms) the component responds to container resizing or
|
|
67
|
-
* an update to one of its child items
|
|
68
|
-
*/
|
|
69
|
-
debounce: PropTypes.number,
|
|
70
|
-
/**
|
|
71
|
-
* Content to display before the navigation items, such as a logo
|
|
72
|
-
*/
|
|
73
|
-
renderBeforeItems: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
74
|
-
/**
|
|
75
|
-
* Content to display after the navigation items, aligned to the far end
|
|
76
|
-
* of the navigation
|
|
77
|
-
*/
|
|
78
|
-
renderAfterItems: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
79
|
-
/**
|
|
80
|
-
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
81
|
-
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
82
|
-
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
83
|
-
*/
|
|
84
|
-
margin: ThemeablePropTypes.spacing,
|
|
85
|
-
/**
|
|
86
|
-
* Provides a reference to the underlying nav element
|
|
87
|
-
*/
|
|
88
|
-
elementRef: PropTypes.func,
|
|
89
|
-
/**
|
|
90
|
-
* Customize the text displayed in the menu trigger when links overflow
|
|
91
|
-
* the overall nav width.
|
|
92
|
-
*/
|
|
93
|
-
renderTruncateLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
94
|
-
/**
|
|
95
|
-
* Called whenever the navigation items are updated or the size of
|
|
96
|
-
* the navigation changes. Passes in the `visibleItemsCount` as
|
|
97
|
-
* a parameter.
|
|
98
|
-
*/
|
|
99
|
-
onUpdate: PropTypes.func,
|
|
100
|
-
/**
|
|
101
|
-
* Sets the number of navigation items that are visible.
|
|
102
|
-
*/
|
|
103
|
-
visibleItemsCount: PropTypes.number,
|
|
104
|
-
// eslint-disable-next-line react/require-default-props
|
|
105
|
-
makeStyles: PropTypes.func,
|
|
106
|
-
// eslint-disable-next-line react/require-default-props
|
|
107
|
-
styles: PropTypes.object
|
|
108
|
-
}
|
|
55
|
+
static allowedProps = allowedProps
|
|
56
|
+
static propTypes = propTypes
|
|
109
57
|
|
|
110
58
|
static defaultProps = {
|
|
111
59
|
children: null,
|
|
112
60
|
debounce: 300,
|
|
113
61
|
margin: '0',
|
|
114
|
-
renderBeforeItems: undefined,
|
|
115
|
-
renderAfterItems: undefined,
|
|
116
62
|
// @ts-expect-error ts-migrate(6133) FIXME: 'el' is declared but its value is never read.
|
|
117
63
|
elementRef: (el) => {},
|
|
118
64
|
renderTruncateLabel: () => 'More',
|
|
@@ -129,8 +75,7 @@ class AppNav extends Component<AppNavProps> {
|
|
|
129
75
|
_list = null
|
|
130
76
|
|
|
131
77
|
componentDidMount() {
|
|
132
|
-
|
|
133
|
-
this.props.makeStyles()
|
|
78
|
+
this.props.makeStyles?.()
|
|
134
79
|
const { width: origWidth } = getBoundingClientRect(this._list)
|
|
135
80
|
|
|
136
81
|
// @ts-expect-error ts-migrate(2339) FIXME: Property '_debounced' does not exist on type 'AppN... Remove this comment to see the full error message
|
|
@@ -157,8 +102,7 @@ class AppNav extends Component<AppNavProps> {
|
|
|
157
102
|
}
|
|
158
103
|
|
|
159
104
|
componentDidUpdate() {
|
|
160
|
-
|
|
161
|
-
this.props.makeStyles()
|
|
105
|
+
this.props.makeStyles?.()
|
|
162
106
|
}
|
|
163
107
|
|
|
164
108
|
componentWillUnmount() {
|
|
@@ -176,7 +120,7 @@ class AppNav extends Component<AppNavProps> {
|
|
|
176
120
|
}
|
|
177
121
|
|
|
178
122
|
measureItems = () => {
|
|
179
|
-
const menuTriggerWidth = px(this.props.styles
|
|
123
|
+
const menuTriggerWidth = px(this.props.styles?.menuTriggerWidth as number)
|
|
180
124
|
let visibleItemsCount = 0
|
|
181
125
|
|
|
182
126
|
if (this._list) {
|
|
@@ -224,8 +168,8 @@ class AppNav extends Component<AppNavProps> {
|
|
|
224
168
|
key={key}
|
|
225
169
|
css={
|
|
226
170
|
isMenuTrigger
|
|
227
|
-
? this.props.styles
|
|
228
|
-
: this.props.styles
|
|
171
|
+
? this.props.styles?.listItemWithMenuTrigger
|
|
172
|
+
: this.props.styles?.listItem
|
|
229
173
|
}
|
|
230
174
|
>
|
|
231
175
|
{item}
|
|
@@ -296,8 +240,8 @@ class AppNav extends Component<AppNavProps> {
|
|
|
296
240
|
{...passthroughProps}
|
|
297
241
|
as="nav"
|
|
298
242
|
css={[
|
|
299
|
-
this.props.styles
|
|
300
|
-
hasRenderedContent ? this.props.styles
|
|
243
|
+
this.props.styles?.appNav,
|
|
244
|
+
hasRenderedContent ? this.props.styles?.alignCenter : ''
|
|
301
245
|
]}
|
|
302
246
|
margin={margin}
|
|
303
247
|
display={hasRenderedContent ? 'flex' : 'block'}
|
|
@@ -307,7 +251,7 @@ class AppNav extends Component<AppNavProps> {
|
|
|
307
251
|
<ul
|
|
308
252
|
// @ts-expect-error ts-migrate(2322) FIXME: Type 'HTMLUListElement | null' is not assignable t... Remove this comment to see the full error message
|
|
309
253
|
ref={(el) => (this._list = el)}
|
|
310
|
-
css={this.props.styles
|
|
254
|
+
css={this.props.styles?.list}
|
|
311
255
|
aria-label={callRenderProp(screenReaderLabel)}
|
|
312
256
|
>
|
|
313
257
|
{visibleChildren.map((child, index) => {
|
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
import PropTypes from 'prop-types'
|
|
26
|
+
|
|
27
|
+
import { Children as ChildrenPropTypes } from '@instructure/ui-prop-types'
|
|
28
|
+
import { ThemeablePropTypes } from '@instructure/emotion'
|
|
29
|
+
|
|
30
|
+
import { Item } from './Item'
|
|
31
|
+
|
|
32
|
+
import type { Spacing, WithStyleProps } from '@instructure/emotion'
|
|
33
|
+
import type { PropValidators } from '@instructure/shared-types'
|
|
34
|
+
|
|
35
|
+
type AppNavOwnProps = {
|
|
36
|
+
screenReaderLabel: string
|
|
37
|
+
debounce?: number
|
|
38
|
+
renderBeforeItems?: React.ReactNode | ((...args: any[]) => any)
|
|
39
|
+
renderAfterItems?: React.ReactNode | ((...args: any[]) => any)
|
|
40
|
+
margin?: Spacing
|
|
41
|
+
elementRef?: (...args: any[]) => any
|
|
42
|
+
renderTruncateLabel?: React.ReactNode | ((...args: any[]) => any)
|
|
43
|
+
onUpdate?: (...args: any[]) => any
|
|
44
|
+
visibleItemsCount?: number
|
|
45
|
+
children?: React.ReactNode
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type PropKeys = keyof AppNavOwnProps
|
|
49
|
+
|
|
50
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
51
|
+
|
|
52
|
+
type AppNavProps = AppNavOwnProps & WithStyleProps
|
|
53
|
+
|
|
54
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
55
|
+
/**
|
|
56
|
+
* Screenreader label for the overall navigation
|
|
57
|
+
*/
|
|
58
|
+
screenReaderLabel: PropTypes.string.isRequired,
|
|
59
|
+
/**
|
|
60
|
+
* Only accepts `AppNav.Item` as children
|
|
61
|
+
*/
|
|
62
|
+
children: ChildrenPropTypes.oneOf([Item]),
|
|
63
|
+
/**
|
|
64
|
+
* The rate (in ms) the component responds to container resizing or
|
|
65
|
+
* an update to one of its child items
|
|
66
|
+
*/
|
|
67
|
+
debounce: PropTypes.number,
|
|
68
|
+
/**
|
|
69
|
+
* Content to display before the navigation items, such as a logo
|
|
70
|
+
*/
|
|
71
|
+
renderBeforeItems: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
72
|
+
/**
|
|
73
|
+
* Content to display after the navigation items, aligned to the far end
|
|
74
|
+
* of the navigation
|
|
75
|
+
*/
|
|
76
|
+
renderAfterItems: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
77
|
+
/**
|
|
78
|
+
* Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
|
|
79
|
+
* `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
|
|
80
|
+
* familiar CSS-like shorthand. For example: `margin="small auto large"`.
|
|
81
|
+
*/
|
|
82
|
+
margin: ThemeablePropTypes.spacing,
|
|
83
|
+
/**
|
|
84
|
+
* Provides a reference to the underlying nav element
|
|
85
|
+
*/
|
|
86
|
+
elementRef: PropTypes.func,
|
|
87
|
+
/**
|
|
88
|
+
* Customize the text displayed in the menu trigger when links overflow
|
|
89
|
+
* the overall nav width.
|
|
90
|
+
*/
|
|
91
|
+
renderTruncateLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
92
|
+
/**
|
|
93
|
+
* Called whenever the navigation items are updated or the size of
|
|
94
|
+
* the navigation changes. Passes in the `visibleItemsCount` as
|
|
95
|
+
* a parameter.
|
|
96
|
+
*/
|
|
97
|
+
onUpdate: PropTypes.func,
|
|
98
|
+
/**
|
|
99
|
+
* Sets the number of navigation items that are visible.
|
|
100
|
+
*/
|
|
101
|
+
visibleItemsCount: PropTypes.number
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const allowedProps: AllowedPropKeys = [
|
|
105
|
+
'screenReaderLabel',
|
|
106
|
+
'children',
|
|
107
|
+
'debounce',
|
|
108
|
+
'renderBeforeItems',
|
|
109
|
+
'renderAfterItems',
|
|
110
|
+
'margin',
|
|
111
|
+
'elementRef',
|
|
112
|
+
'renderTruncateLabel',
|
|
113
|
+
'onUpdate',
|
|
114
|
+
'visibleItemsCount'
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
export type { AppNavProps }
|
|
118
|
+
export { propTypes, allowedProps }
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
*/
|
|
24
24
|
/** @jsx jsx */
|
|
25
25
|
import { Component } from 'react'
|
|
26
|
-
import PropTypes from 'prop-types'
|
|
27
26
|
|
|
28
27
|
import { testable } from '@instructure/ui-testable'
|
|
29
28
|
import { omitProps, getElementType } from '@instructure/ui-react-utils'
|
|
@@ -33,7 +32,8 @@ import { withStyle, jsx } from '@instructure/emotion'
|
|
|
33
32
|
|
|
34
33
|
import generateStyle from './styles'
|
|
35
34
|
import generateComponentTheme from './theme'
|
|
36
|
-
import { NavigationItemProps } from './
|
|
35
|
+
import type { NavigationItemProps } from './props'
|
|
36
|
+
import { allowedProps, propTypes } from './props'
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
---
|
|
@@ -46,58 +46,23 @@ id: Navigation.Item
|
|
|
46
46
|
class NavigationItem extends Component<NavigationItemProps> {
|
|
47
47
|
static readonly componentId = 'Navigation.Item'
|
|
48
48
|
|
|
49
|
-
static
|
|
50
|
-
|
|
51
|
-
makeStyles: PropTypes.func,
|
|
52
|
-
// eslint-disable-next-line react/require-default-props
|
|
53
|
-
styles: PropTypes.object,
|
|
54
|
-
/**
|
|
55
|
-
* The visual to display (ex. an Image, Logo, Avatar, or Icon)
|
|
56
|
-
*/
|
|
57
|
-
icon: PropTypes.node.isRequired,
|
|
58
|
-
/**
|
|
59
|
-
* The text to display for the Navigation Link
|
|
60
|
-
*/
|
|
61
|
-
label: PropTypes.node.isRequired,
|
|
62
|
-
/**
|
|
63
|
-
* The element type to render as (will default to `<a>` if href is provided)
|
|
64
|
-
*/
|
|
65
|
-
as: PropTypes.elementType,
|
|
66
|
-
/**
|
|
67
|
-
* If the NavigationItem goes to a new page, pass an href
|
|
68
|
-
*/
|
|
69
|
-
href: PropTypes.string,
|
|
70
|
-
/**
|
|
71
|
-
* If the NavigationItem does not go to a new page pass an onClick
|
|
72
|
-
*/
|
|
73
|
-
onClick: PropTypes.func,
|
|
74
|
-
/**
|
|
75
|
-
* Denotes which NavigationItem is currently selected
|
|
76
|
-
*/
|
|
77
|
-
selected: PropTypes.bool,
|
|
78
|
-
/**
|
|
79
|
-
* When minimized is set to true, the `<Navigation />` shows icons only while the text becomes a tooltip. When it is set to false, the `<Navigation />` shows text in addition to the icons
|
|
80
|
-
*/
|
|
81
|
-
minimized: PropTypes.bool
|
|
82
|
-
} as const
|
|
49
|
+
static allowedProps = allowedProps
|
|
50
|
+
static propTypes = propTypes
|
|
83
51
|
|
|
84
52
|
static defaultProps = {
|
|
85
53
|
as: 'a',
|
|
86
54
|
// @ts-expect-error ts-migrate(6133) FIXME: 'e' is declared but its value is never read.
|
|
87
55
|
onClick: function (e, selected) {},
|
|
88
56
|
selected: false,
|
|
89
|
-
minimized: false
|
|
90
|
-
href: undefined
|
|
57
|
+
minimized: false
|
|
91
58
|
} as const
|
|
92
59
|
|
|
93
60
|
componentDidMount() {
|
|
94
|
-
|
|
95
|
-
this.props.makeStyles({ minimized: this.minimized })
|
|
61
|
+
this.props.makeStyles?.({ minimized: this.props.minimized })
|
|
96
62
|
}
|
|
97
63
|
|
|
98
64
|
componentDidUpdate() {
|
|
99
|
-
|
|
100
|
-
this.props.makeStyles({ minimized: this.minimized })
|
|
65
|
+
this.props.makeStyles?.({ minimized: this.props.minimized })
|
|
101
66
|
}
|
|
102
67
|
|
|
103
68
|
renderLink() {
|
|
@@ -112,15 +77,15 @@ class NavigationItem extends Component<NavigationItemProps> {
|
|
|
112
77
|
{...props}
|
|
113
78
|
href={href}
|
|
114
79
|
onClick={onClick}
|
|
115
|
-
css={this.props.styles
|
|
80
|
+
css={this.props.styles?.navigationItem}
|
|
116
81
|
//@ts-expect-error TODO: INSTUI-3245
|
|
117
82
|
aria-label={this.props.minimized ? label : undefined}
|
|
118
83
|
>
|
|
119
|
-
<div css={this.props.styles
|
|
84
|
+
<div css={this.props.styles?.icon} aria-hidden="true">
|
|
120
85
|
{icon}
|
|
121
86
|
</div>
|
|
122
87
|
{!this.props.minimized ? (
|
|
123
|
-
<div css={this.props.styles
|
|
88
|
+
<div css={this.props.styles?.label}>{label}</div>
|
|
124
89
|
) : null}
|
|
125
90
|
</ElementType>
|
|
126
91
|
)
|