@instructure/ui-navigation 8.23.1-snapshot.9 → 8.24.1-snapshot.17

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/es/AppNav/AppNavLocator.js +2 -1
  3. package/es/AppNav/Item/AppNavItemLocator.js +2 -1
  4. package/es/AppNav/Item/index.js +1 -3
  5. package/es/AppNav/Item/props.js +1 -42
  6. package/es/AppNav/index.js +12 -10
  7. package/es/AppNav/props.js +0 -46
  8. package/es/Navigation/NavigationItem/NavigationItemLocator.js +4 -2
  9. package/es/Navigation/NavigationItem/index.js +3 -2
  10. package/es/Navigation/NavigationItem/props.js +0 -31
  11. package/es/Navigation/NavigationLocator.js +2 -1
  12. package/es/Navigation/index.js +9 -6
  13. package/es/Navigation/props.js +0 -27
  14. package/lib/AppNav/AppNavLocator.js +1 -0
  15. package/lib/AppNav/Item/AppNavItemLocator.js +1 -0
  16. package/lib/AppNav/Item/index.js +1 -3
  17. package/lib/AppNav/Item/props.js +1 -42
  18. package/lib/AppNav/index.js +11 -9
  19. package/lib/AppNav/props.js +0 -46
  20. package/lib/Navigation/NavigationItem/NavigationItemLocator.js +2 -0
  21. package/lib/Navigation/NavigationItem/index.js +3 -2
  22. package/lib/Navigation/NavigationItem/props.js +0 -31
  23. package/lib/Navigation/NavigationLocator.js +1 -0
  24. package/lib/Navigation/index.js +11 -6
  25. package/lib/Navigation/props.js +0 -27
  26. package/package.json +24 -24
  27. package/src/AppNav/Item/index.tsx +2 -8
  28. package/src/AppNav/Item/props.ts +37 -32
  29. package/src/AppNav/index.tsx +21 -35
  30. package/src/AppNav/props.ts +41 -41
  31. package/src/Navigation/NavigationItem/index.tsx +2 -4
  32. package/src/Navigation/NavigationItem/props.ts +26 -26
  33. package/src/Navigation/index.tsx +14 -17
  34. package/src/Navigation/props.ts +24 -24
  35. package/tsconfig.build.tsbuildinfo +1 -1
  36. package/types/AppNav/Item/index.d.ts +10 -10
  37. package/types/AppNav/Item/index.d.ts.map +1 -1
  38. package/types/AppNav/Item/props.d.ts +37 -5
  39. package/types/AppNav/Item/props.d.ts.map +1 -1
  40. package/types/AppNav/index.d.ts +20 -13
  41. package/types/AppNav/index.d.ts.map +1 -1
  42. package/types/AppNav/props.d.ts +43 -4
  43. package/types/AppNav/props.d.ts.map +1 -1
  44. package/types/Navigation/NavigationItem/index.d.ts +3 -3
  45. package/types/Navigation/NavigationItem/index.d.ts.map +1 -1
  46. package/types/Navigation/NavigationItem/props.d.ts +26 -2
  47. package/types/Navigation/NavigationItem/props.d.ts.map +1 -1
  48. package/types/Navigation/index.d.ts +14 -14
  49. package/types/Navigation/index.d.ts.map +1 -1
  50. package/types/Navigation/props.d.ts +24 -3
  51. package/types/Navigation/props.d.ts.map +1 -1
@@ -34,7 +34,9 @@ var _index = require("./index");
34
34
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35
35
  * SOFTWARE.
36
36
  */
37
+ // @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module '@ins... Remove this comment to see the full error message
37
38
  // eslint-disable-next-line no-restricted-imports
39
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
38
40
  const NavigationItemLocator = (0, _locator.locator)(_index.NavigationItem.selector, {
39
41
  findTooltipContent: function () {
40
42
  return _TooltipLocator.TooltipLocator.findContent(...arguments);
@@ -34,6 +34,7 @@ var _dec, _dec2, _class, _class2;
34
34
  parent: Navigation
35
35
  id: Navigation.Item
36
36
  ---
37
+ @tsProps
37
38
  **/
38
39
  let NavigationItem = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_class2 = class NavigationItem extends _react.Component {
39
40
  constructor() {
@@ -76,7 +77,8 @@ let NavigationItem = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
76
77
  icon = _this$props3.icon,
77
78
  label = _this$props3.label;
78
79
  const props = (0, _omitProps.omitProps)(this.props, NavigationItem.allowedProps);
79
- return (0, _emotion.jsx)(ElementType, Object.assign({}, props, {
80
+ return (0, _emotion.jsx)(ElementType // @ts-expect-error TODO: fix TS2590: Expression produces a union type that is too complex to represent.
81
+ , Object.assign({}, props, {
80
82
  href: href,
81
83
  onClick: onClick,
82
84
  ref: addRef ? this.handleRef : void 0,
@@ -105,7 +107,6 @@ let NavigationItem = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.def
105
107
 
106
108
  }, _class2.displayName = "NavigationItem", _class2.componentId = 'Navigation.Item', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
107
109
  as: 'a',
108
- onClick: function (e, selected) {},
109
110
  selected: false,
110
111
  minimized: false
111
112
  }, _class2)) || _class) || _class);
@@ -33,44 +33,13 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
33
33
  * SOFTWARE.
34
34
  */
35
35
  const propTypes = {
36
- /**
37
- * The reference to the underlying HTML element
38
- */
39
36
  elementRef: _propTypes.default.func,
40
-
41
- /**
42
- * The visual to display (ex. an Image, Logo, Avatar, or Icon)
43
- */
44
37
  icon: _propTypes.default.node.isRequired,
45
-
46
- /**
47
- * The text to display for the Navigation Link
48
- */
49
38
  label: _propTypes.default.node.isRequired,
50
-
51
- /**
52
- * The element type to render as (will default to `<a>` if href is provided)
53
- */
54
39
  as: _propTypes.default.elementType,
55
-
56
- /**
57
- * If the NavigationItem goes to a new page, pass an href
58
- */
59
40
  href: _propTypes.default.string,
60
-
61
- /**
62
- * If the NavigationItem does not go to a new page pass an onClick
63
- */
64
41
  onClick: _propTypes.default.func,
65
-
66
- /**
67
- * Denotes which NavigationItem is currently selected
68
- */
69
42
  selected: _propTypes.default.bool,
70
-
71
- /**
72
- * 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
73
- */
74
43
  minimized: _propTypes.default.bool
75
44
  };
76
45
  exports.propTypes = propTypes;
@@ -40,6 +40,7 @@ var _NavigationItemLocator = require("./NavigationItem/NavigationItemLocator");
40
40
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
41
41
  * SOFTWARE.
42
42
  */
43
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'selector' does not exist on type 'typeof... Remove this comment to see the full error message
43
44
  const NavigationLocator = (0, _locator.locator)(_index.Navigation.selector, {
44
45
  findAllItems: function () {
45
46
  return _NavigationItemLocator.NavigationItemLocator.findAll(...arguments);
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+
3
5
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
6
 
5
7
  Object.defineProperty(exports, "__esModule", {
@@ -14,7 +16,7 @@ Object.defineProperty(exports, "NavigationItem", {
14
16
  });
15
17
  exports.default = void 0;
16
18
 
17
- var _react = require("react");
19
+ var _react = _interopRequireWildcard(require("react"));
18
20
 
19
21
  var _testable = require("@instructure/ui-testable/lib/testable.js");
20
22
 
@@ -50,12 +52,13 @@ const navMinimized = _ref => {
50
52
  ---
51
53
  category: components/deprecated
52
54
  ---
55
+ @tsProps
53
56
  **/
54
57
 
55
58
 
56
59
  let Navigation = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec3 = (0, _deprecated.deprecated)('9.0.0', null, 'No one uses <Navigation>, so we will deprecate it.'), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = class Navigation extends _react.Component {
57
60
  constructor(props) {
58
- super();
61
+ super(props);
59
62
  this.ref = null;
60
63
 
61
64
  this.handleNavToggle = event => {
@@ -63,11 +66,13 @@ let Navigation = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default
63
66
  this.setState(navMinimized);
64
67
  }
65
68
 
66
- this.props.onMinimized(event, !this.minimized);
69
+ if (typeof this.props.onMinimized === 'function') {
70
+ this.props.onMinimized(event, !this.minimized);
71
+ }
67
72
  };
68
73
 
69
74
  this.state = {
70
- minimized: this.isControlled(props) ? props.minimized : !!props.defaultMinimized
75
+ minimized: this.isControlled(props) ? !!props.minimized : !!props.defaultMinimized
71
76
  };
72
77
  }
73
78
 
@@ -146,8 +151,8 @@ let Navigation = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default
146
151
  }, _class2.displayName = "Navigation", _class2.componentId = 'Navigation', _class2.allowedProps = _props.allowedProps, _class2.propTypes = _props.propTypes, _class2.defaultProps = {
147
152
  children: null,
148
153
  defaultMinimized: false,
149
- onMinimized: function (event, minimized) {},
150
- onClick: function (e) {}
154
+ // TODO we should investigate later if it used or not
155
+ onClick: function (_e) {}
151
156
  }, _class2.Item = _NavigationItem.NavigationItem, _class2)) || _class) || _class) || _class);
152
157
  exports.Navigation = Navigation;
153
158
  var _default = Navigation;
@@ -39,43 +39,16 @@ var _NavigationItem = require("./NavigationItem");
39
39
  * SOFTWARE.
40
40
  */
41
41
  const propTypes = {
42
- /**
43
- * children of type Navigation.Item
44
- */
45
42
  children: _Children.Children.oneOf([_NavigationItem.NavigationItem]),
46
-
47
- /**
48
- * 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
49
- */
50
43
  minimized: (0, _controllable.controllable)(_propTypes.default.bool, 'onMinimized', 'defaultMinimized'),
51
-
52
- /**
53
- * Whether the `<Navigation />` is initially minimized (uncontrolled)
54
- */
55
44
  defaultMinimized: _propTypes.default.bool,
56
45
  onMinimized: _propTypes.default.func,
57
-
58
- /**
59
- * Screen reader label for the main Navigation
60
- */
61
46
  label: _propTypes.default.string.isRequired,
62
-
63
- /**
64
- * Screen reader label for the toggle button expanded/minimized state
65
- */
66
47
  toggleLabel: _propTypes.default.shape({
67
48
  expandedLabel: _propTypes.default.string,
68
49
  minimizedLabel: _propTypes.default.string
69
50
  }).isRequired,
70
-
71
- /**
72
- * If the `<Navigation.Item>` goes to a new page, pass an href
73
- */
74
51
  href: _propTypes.default.string,
75
-
76
- /**
77
- * If the `<Navigation.Item>` does not go to a new page pass an onClick
78
- */
79
52
  onClick: _propTypes.default.func
80
53
  };
81
54
  exports.propTypes = propTypes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-navigation",
3
- "version": "8.23.1-snapshot.9+11828d0b3",
3
+ "version": "8.24.1-snapshot.17+0604ec59c",
4
4
  "description": "Main and application level navigational components",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,31 +23,31 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-babel-preset": "8.23.1-snapshot.9+11828d0b3",
27
- "@instructure/ui-color-utils": "8.23.1-snapshot.9+11828d0b3",
28
- "@instructure/ui-test-locator": "8.23.1-snapshot.9+11828d0b3",
29
- "@instructure/ui-test-utils": "8.23.1-snapshot.9+11828d0b3",
30
- "@instructure/ui-themes": "8.23.1-snapshot.9+11828d0b3"
26
+ "@instructure/ui-babel-preset": "8.24.1-snapshot.17+0604ec59c",
27
+ "@instructure/ui-color-utils": "8.24.1-snapshot.17+0604ec59c",
28
+ "@instructure/ui-test-locator": "8.24.1-snapshot.17+0604ec59c",
29
+ "@instructure/ui-test-utils": "8.24.1-snapshot.17+0604ec59c",
30
+ "@instructure/ui-themes": "8.24.1-snapshot.17+0604ec59c"
31
31
  },
32
32
  "dependencies": {
33
33
  "@babel/runtime": "^7.13.10",
34
- "@instructure/console": "8.23.1-snapshot.9+11828d0b3",
35
- "@instructure/debounce": "8.23.1-snapshot.9+11828d0b3",
36
- "@instructure/emotion": "8.23.1-snapshot.9+11828d0b3",
37
- "@instructure/shared-types": "8.23.1-snapshot.9+11828d0b3",
38
- "@instructure/ui-a11y-content": "8.23.1-snapshot.9+11828d0b3",
39
- "@instructure/ui-a11y-utils": "8.23.1-snapshot.9+11828d0b3",
40
- "@instructure/ui-badge": "8.23.1-snapshot.9+11828d0b3",
41
- "@instructure/ui-dom-utils": "8.23.1-snapshot.9+11828d0b3",
42
- "@instructure/ui-focusable": "8.23.1-snapshot.9+11828d0b3",
43
- "@instructure/ui-icons": "8.23.1-snapshot.9+11828d0b3",
44
- "@instructure/ui-menu": "8.23.1-snapshot.9+11828d0b3",
45
- "@instructure/ui-prop-types": "8.23.1-snapshot.9+11828d0b3",
46
- "@instructure/ui-react-utils": "8.23.1-snapshot.9+11828d0b3",
47
- "@instructure/ui-testable": "8.23.1-snapshot.9+11828d0b3",
48
- "@instructure/ui-tooltip": "8.23.1-snapshot.9+11828d0b3",
49
- "@instructure/ui-utils": "8.23.1-snapshot.9+11828d0b3",
50
- "@instructure/ui-view": "8.23.1-snapshot.9+11828d0b3",
34
+ "@instructure/console": "8.24.1-snapshot.17+0604ec59c",
35
+ "@instructure/debounce": "8.24.1-snapshot.17+0604ec59c",
36
+ "@instructure/emotion": "8.24.1-snapshot.17+0604ec59c",
37
+ "@instructure/shared-types": "8.24.1-snapshot.17+0604ec59c",
38
+ "@instructure/ui-a11y-content": "8.24.1-snapshot.17+0604ec59c",
39
+ "@instructure/ui-a11y-utils": "8.24.1-snapshot.17+0604ec59c",
40
+ "@instructure/ui-badge": "8.24.1-snapshot.17+0604ec59c",
41
+ "@instructure/ui-dom-utils": "8.24.1-snapshot.17+0604ec59c",
42
+ "@instructure/ui-focusable": "8.24.1-snapshot.17+0604ec59c",
43
+ "@instructure/ui-icons": "8.24.1-snapshot.17+0604ec59c",
44
+ "@instructure/ui-menu": "8.24.1-snapshot.17+0604ec59c",
45
+ "@instructure/ui-prop-types": "8.24.1-snapshot.17+0604ec59c",
46
+ "@instructure/ui-react-utils": "8.24.1-snapshot.17+0604ec59c",
47
+ "@instructure/ui-testable": "8.24.1-snapshot.17+0604ec59c",
48
+ "@instructure/ui-tooltip": "8.24.1-snapshot.17+0604ec59c",
49
+ "@instructure/ui-utils": "8.24.1-snapshot.17+0604ec59c",
50
+ "@instructure/ui-view": "8.24.1-snapshot.17+0604ec59c",
51
51
  "prop-types": "^15"
52
52
  },
53
53
  "peerDependencies": {
@@ -57,5 +57,5 @@
57
57
  "access": "public"
58
58
  },
59
59
  "sideEffects": false,
60
- "gitHead": "11828d0b32844a522d267e189c8bc52aa928843a"
60
+ "gitHead": "0604ec59c560ca2868fdac84d6f4948f92d38d5b"
61
61
  }
@@ -50,6 +50,7 @@ import { allowedProps, propTypes } from './props'
50
50
  parent: AppNav
51
51
  id: AppNav.Item
52
52
  ---
53
+ @tsProps
53
54
  @module Item
54
55
  **/
55
56
  @withStyle(generateStyle, generateComponentTheme)
@@ -62,8 +63,6 @@ class Item extends Component<AppNavItemProps> {
62
63
 
63
64
  static defaultProps = {
64
65
  children: null,
65
- // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
66
- onClick: function (event) {},
67
66
  isSelected: false,
68
67
  cursor: 'pointer',
69
68
  isDisabled: false
@@ -89,8 +88,7 @@ class Item extends Component<AppNavItemProps> {
89
88
  }
90
89
  }
91
90
 
92
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'e' implicitly has an 'any' type.
93
- handleClick = (e) => {
91
+ handleClick = (e: React.MouseEvent<Element>) => {
94
92
  const { isDisabled, onClick } = this.props
95
93
 
96
94
  if (isDisabled) {
@@ -132,10 +130,6 @@ class Item extends Component<AppNavItemProps> {
132
130
  display="flex"
133
131
  position="relative"
134
132
  borderRadius="medium"
135
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'handleFocus' does not exist on type 'Ite... Remove this comment to see the full error message
136
- onFocus={this.handleFocus}
137
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'handleBlur' does not exist on type 'Item... Remove this comment to see the full error message
138
- onBlur={this.handleBlur}
139
133
  cursor={isDisabled ? 'not-allowed' : cursor}
140
134
  css={this.props.styles?.item}
141
135
  >
@@ -31,72 +31,77 @@ import type {
31
31
  } from '@instructure/shared-types'
32
32
  import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
33
33
  import type { Cursor } from '@instructure/ui-prop-types'
34
+ import React from 'react'
34
35
 
35
36
  type AppNavItemOwnProps = {
36
- renderLabel: React.ReactNode | ((...args: any[]) => any)
37
- renderAfter?: React.ReactNode | ((...args: any[]) => any)
38
- renderIcon?: React.ReactNode | ((...args: any[]) => any)
39
- href?: string
40
- onClick?: (...args: any[]) => any
41
- isSelected?: boolean
42
- elementRef?: (element: Element | null) => void
43
- as?: AsElementType
44
- cursor?: Cursor
45
- isDisabled?: boolean
46
- }
47
-
48
- type PropKeys = keyof AppNavItemOwnProps
49
-
50
- type AllowedPropKeys = Readonly<Array<PropKeys>>
51
-
52
- type AppNavItemProps = AppNavItemOwnProps &
53
- WithStyleProps<AppNavItemTheme, AppNavItemStyle> &
54
- OtherHTMLAttributes<AppNavItemOwnProps>
55
-
56
- type AppNavItemStyle = ComponentStyle<'item' | 'label'>
57
-
58
- const propTypes: PropValidators<PropKeys> = {
59
37
  /**
60
38
  * The text to display. If the `icon` prop is used, label text must be wrapped
61
39
  * in `ScreenReaderContent`.
62
40
  */
63
- renderLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
41
+ renderLabel: React.ReactNode | (() => React.ReactNode)
64
42
  /**
65
43
  * Content to display after the renderLabel text, such as a badge
66
44
  */
67
- renderAfter: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
45
+ renderAfter?: React.ReactNode | (() => React.ReactNode)
68
46
  /**
69
47
  * The visual to display (ex. an Image, Logo, Avatar, or Icon)
70
48
  */
71
- renderIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
49
+ renderIcon?: React.ReactNode | (() => React.ReactNode)
72
50
  /**
73
51
  * If the item goes to a new page, pass an href
74
52
  */
75
- href: PropTypes.string,
53
+ href?: string
76
54
  /**
77
55
  * If the item does not go to a new page, pass an onClick
78
56
  */
79
- onClick: PropTypes.func,
57
+ onClick?: (event: React.MouseEvent<Element>) => void
80
58
  /**
81
59
  * Denotes which item is currently selected
82
60
  */
83
- isSelected: PropTypes.bool,
61
+ isSelected?: boolean
84
62
  /**
85
63
  * provides a reference to the underlying focusable (`button` or `a`) element
86
64
  */
87
- elementRef: PropTypes.func,
65
+ elementRef?: (element: Element | null) => void
88
66
  /**
89
67
  * The element type to render as (will default to `<a>` if href is provided)
90
68
  */
91
- as: PropTypes.elementType,
69
+ as?: AsElementType
92
70
  /**
93
71
  * Specify the mouse cursor to use on :hover.
94
72
  * The `pointer` cursor is used by default.
95
73
  */
96
- cursor: PropTypes.string,
74
+ cursor?: Cursor
97
75
  /**
98
76
  * Disables the link or button visually and functionally
99
77
  */
78
+ isDisabled?: boolean
79
+ }
80
+
81
+ type PropKeys = keyof AppNavItemOwnProps
82
+
83
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
84
+
85
+ type AppNavItemProps = AppNavItemOwnProps &
86
+ WithStyleProps<AppNavItemTheme, AppNavItemStyle> &
87
+ OtherHTMLAttributes<AppNavItemOwnProps>
88
+
89
+ type AppNavItemStyle = ComponentStyle<'item' | 'label'>
90
+
91
+ const propTypes: PropValidators<PropKeys> = {
92
+ renderLabel: PropTypes.oneOfType([
93
+ PropTypes.node,
94
+ PropTypes.string,
95
+ PropTypes.func
96
+ ]).isRequired,
97
+ renderAfter: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
98
+ renderIcon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
99
+ href: PropTypes.string,
100
+ onClick: PropTypes.func,
101
+ isSelected: PropTypes.bool,
102
+ elementRef: PropTypes.func,
103
+ as: PropTypes.elementType,
104
+ cursor: PropTypes.string,
100
105
  isDisabled: PropTypes.bool
101
106
  }
102
107
 
@@ -31,6 +31,7 @@ import { getBoundingClientRect } from '@instructure/ui-dom-utils'
31
31
  import { callRenderProp, omitProps } from '@instructure/ui-react-utils'
32
32
  import { px } from '@instructure/ui-utils'
33
33
  import { debounce } from '@instructure/debounce'
34
+ import type { Debounced } from '@instructure/debounce'
34
35
  import { testable } from '@instructure/ui-testable'
35
36
 
36
37
  import { View } from '@instructure/ui-view'
@@ -41,11 +42,13 @@ import generateStyle from './styles'
41
42
  import generateComponentTheme from './theme'
42
43
  import type { AppNavProps } from './props'
43
44
  import { allowedProps, propTypes } from './props'
45
+ import { AppNavItemProps } from './Item/props'
44
46
 
45
47
  /**
46
48
  ---
47
49
  category: components
48
50
  ---
51
+ @tsProps
49
52
  **/
50
53
  @withStyle(generateStyle, generateComponentTheme)
51
54
  @testable()
@@ -59,10 +62,7 @@ class AppNav extends Component<AppNavProps> {
59
62
  children: null,
60
63
  debounce: 300,
61
64
  margin: '0',
62
- // @ts-expect-error ts-migrate(6133) FIXME: 'el' is declared but its value is never read.
63
- elementRef: (el) => {},
64
65
  renderTruncateLabel: () => 'More',
65
- onUpdate: () => {},
66
66
  visibleItemsCount: 0
67
67
  }
68
68
 
@@ -73,31 +73,29 @@ class AppNav extends Component<AppNavProps> {
73
73
  }
74
74
 
75
75
  ref: Element | null = null
76
- _list = null
76
+ _list: HTMLUListElement | null = null
77
+ _debounced?: Debounced
78
+ _resizeListener?: ResizeObserver
77
79
 
78
80
  componentDidMount() {
79
81
  this.props.makeStyles?.()
80
82
  const { width: origWidth } = getBoundingClientRect(this._list)
81
83
 
82
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_debounced' does not exist on type 'AppN... Remove this comment to see the full error message
83
84
  this._debounced = debounce(this.handleResize, this.props.debounce, {
84
85
  leading: true,
85
86
  trailing: true
86
87
  })
87
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_resizeListener' does not exist on type ... Remove this comment to see the full error message
88
88
  this._resizeListener = new ResizeObserver((entries) => {
89
89
  for (const entry of entries) {
90
90
  const { width } = entry.contentRect
91
91
 
92
92
  if (origWidth !== width) {
93
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_debounced' does not exist on type 'AppN... Remove this comment to see the full error message
94
- this._debounced()
93
+ this._debounced!()
95
94
  }
96
95
  }
97
96
  })
98
97
 
99
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_resizeListener' does not exist on type ... Remove this comment to see the full error message
100
- this._resizeListener.observe(this._list)
98
+ this._resizeListener.observe(this._list!)
101
99
 
102
100
  this.handleResize()
103
101
  }
@@ -107,15 +105,11 @@ class AppNav extends Component<AppNavProps> {
107
105
  }
108
106
 
109
107
  componentWillUnmount() {
110
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_resizeListener' does not exist on type ... Remove this comment to see the full error message
111
108
  if (this._resizeListener) {
112
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_resizeListener' does not exist on type ... Remove this comment to see the full error message
113
109
  this._resizeListener.disconnect()
114
110
  }
115
111
 
116
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_debounced' does not exist on type 'AppN... Remove this comment to see the full error message
117
112
  if (this._debounced) {
118
- // @ts-expect-error ts-migrate(2339) FIXME: Property '_debounced' does not exist on type 'AppN... Remove this comment to see the full error message
119
113
  this._debounced.cancel()
120
114
  }
121
115
  }
@@ -127,7 +121,6 @@ class AppNav extends Component<AppNavProps> {
127
121
  if (this._list) {
128
122
  const { width: navWidth } = getBoundingClientRect(this._list)
129
123
 
130
- // @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
131
124
  const itemWidths = Array.from(this._list.getElementsByTagName('li')).map(
132
125
  (item) => {
133
126
  // Todo: if item's type isn't `unknown`, can remove `Element`
@@ -156,8 +149,9 @@ class AppNav extends Component<AppNavProps> {
156
149
  this.setState({ isMeasuring: true }, () => {
157
150
  const { visibleItemsCount } = this.measureItems()
158
151
 
159
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
160
- this.props.onUpdate({ visibleItemsCount })
152
+ if (typeof this.props.onUpdate === 'function') {
153
+ this.props.onUpdate({ visibleItemsCount })
154
+ }
161
155
  this.setState({ isMeasuring: false })
162
156
  })
163
157
  }
@@ -172,8 +166,7 @@ class AppNav extends Component<AppNavProps> {
172
166
  }
173
167
  }
174
168
 
175
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'item' implicitly has an 'any' type.
176
- renderListItem(item, isMenuTrigger, key) {
169
+ renderListItem(item: React.ReactNode, isMenuTrigger: boolean, key?: number) {
177
170
  return (
178
171
  <li
179
172
  key={key}
@@ -187,20 +180,15 @@ class AppNav extends Component<AppNavProps> {
187
180
  </li>
188
181
  )
189
182
  }
190
-
191
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'items' implicitly has an 'any' type.
192
- renderMenu(items) {
183
+ renderMenu(items: React.ComponentElement<AppNavItemProps, Item>[]) {
193
184
  const menu = (
194
185
  <Menu
195
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'handleMenuDismiss' does not exist on typ... Remove this comment to see the full error message
196
- onDismiss={this.handleMenuDismiss} // TODO: remove when INSTUI-2262 is resolved
197
186
  trigger={
198
187
  <AppNav.Item
199
188
  renderLabel={callRenderProp(this.props.renderTruncateLabel)}
200
189
  />
201
190
  }
202
191
  >
203
- {/* @ts-expect-error ts-migrate(7006) FIXME: Parameter 'item' implicitly has an 'any' type. */}
204
192
  {items.map((item, index) => {
205
193
  return (
206
194
  <Menu.Item
@@ -208,7 +196,7 @@ class AppNav extends Component<AppNavProps> {
208
196
  onClick={
209
197
  item.props.onClick && !item.props.href
210
198
  ? item.props.onClick
211
- : null
199
+ : undefined
212
200
  }
213
201
  key={index}
214
202
  >
@@ -219,16 +207,12 @@ class AppNav extends Component<AppNavProps> {
219
207
  </Menu>
220
208
  )
221
209
 
222
- return this.renderListItem(menu, true, null)
210
+ return this.renderListItem(menu, true)
223
211
  }
224
212
 
225
213
  render() {
226
- const {
227
- children,
228
- visibleItemsCount,
229
- screenReaderLabel,
230
- margin
231
- } = this.props
214
+ const { children, visibleItemsCount, screenReaderLabel, margin } =
215
+ this.props
232
216
 
233
217
  const passthroughProps = View.omitViewProps(
234
218
  omitProps(this.props, AppNav.allowedProps),
@@ -236,7 +220,10 @@ class AppNav extends Component<AppNavProps> {
236
220
  )
237
221
 
238
222
  const { isMeasuring } = this.state
239
- const childrenArray = Children.toArray(children)
223
+ const childrenArray = Children.toArray(children) as React.ComponentElement<
224
+ AppNavItemProps,
225
+ Item
226
+ >[]
240
227
  const visibleChildren = isMeasuring
241
228
  ? childrenArray
242
229
  : childrenArray.splice(0, visibleItemsCount)
@@ -259,7 +246,6 @@ class AppNav extends Component<AppNavProps> {
259
246
  >
260
247
  {renderBeforeItems && <span>{renderBeforeItems}</span>}
261
248
  <ul
262
- // @ts-expect-error ts-migrate(2322) FIXME: Type 'HTMLUListElement | null' is not assignable t... Remove this comment to see the full error message
263
249
  ref={(el) => (this._list = el)}
264
250
  css={this.props.styles?.list}
265
251
  aria-label={callRenderProp(screenReaderLabel)}