@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.
Files changed (70) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/es/AppNav/Item/index.js +21 -77
  3. package/es/AppNav/Item/props.js +79 -0
  4. package/es/AppNav/index.js +26 -80
  5. package/es/AppNav/props.js +87 -0
  6. package/es/Navigation/NavigationItem/index.js +25 -60
  7. package/{src/AppNav/types.ts → es/Navigation/NavigationItem/props.js} +37 -14
  8. package/es/Navigation/index.js +18 -57
  9. package/es/Navigation/props.js +68 -0
  10. package/lib/AppNav/Item/index.js +21 -77
  11. package/lib/AppNav/Item/props.js +90 -0
  12. package/lib/AppNav/index.js +25 -80
  13. package/lib/AppNav/props.js +101 -0
  14. package/lib/Navigation/NavigationItem/index.js +25 -60
  15. package/lib/Navigation/NavigationItem/props.js +73 -0
  16. package/lib/Navigation/index.js +19 -61
  17. package/lib/Navigation/props.js +83 -0
  18. package/package.json +24 -25
  19. package/src/AppNav/Item/index.tsx +8 -62
  20. package/src/AppNav/Item/props.ts +107 -0
  21. package/src/AppNav/Item/styles.ts +1 -1
  22. package/src/AppNav/index.tsx +13 -69
  23. package/src/AppNav/props.ts +118 -0
  24. package/src/Navigation/NavigationItem/index.tsx +10 -45
  25. package/src/Navigation/NavigationItem/props.ts +87 -0
  26. package/src/Navigation/NavigationItem/styles.ts +1 -1
  27. package/src/Navigation/index.tsx +13 -56
  28. package/src/Navigation/props.ts +108 -0
  29. package/src/Navigation/styles.ts +1 -1
  30. package/src/index.ts +4 -4
  31. package/types/AppNav/Item/index.d.ts +25 -53
  32. package/types/AppNav/Item/index.d.ts.map +1 -1
  33. package/types/AppNav/Item/props.d.ts +23 -0
  34. package/types/AppNav/Item/props.d.ts.map +1 -0
  35. package/types/AppNav/Item/styles.d.ts +1 -1
  36. package/types/AppNav/index.d.ts +25 -58
  37. package/types/AppNav/index.d.ts.map +1 -1
  38. package/types/AppNav/props.d.ts +23 -0
  39. package/types/AppNav/props.d.ts.map +1 -0
  40. package/types/Navigation/NavigationItem/index.d.ts +19 -35
  41. package/types/Navigation/NavigationItem/index.d.ts.map +1 -1
  42. package/types/Navigation/NavigationItem/props.d.ts +20 -0
  43. package/types/Navigation/NavigationItem/props.d.ts.map +1 -0
  44. package/types/Navigation/NavigationItem/styles.d.ts +1 -1
  45. package/types/Navigation/index.d.ts +26 -42
  46. package/types/Navigation/index.d.ts.map +1 -1
  47. package/types/Navigation/props.d.ts +27 -0
  48. package/types/Navigation/props.d.ts.map +1 -0
  49. package/types/Navigation/styles.d.ts +1 -1
  50. package/types/index.d.ts +4 -4
  51. package/LICENSE.md +0 -27
  52. package/es/AppNav/Item/types.js +0 -1
  53. package/es/AppNav/types.js +0 -1
  54. package/es/Navigation/NavigationItem/types.js +0 -1
  55. package/es/Navigation/types.js +0 -1
  56. package/lib/AppNav/Item/types.js +0 -1
  57. package/lib/AppNav/types.js +0 -1
  58. package/lib/Navigation/NavigationItem/types.js +0 -1
  59. package/lib/Navigation/types.js +0 -1
  60. package/src/AppNav/Item/types.ts +0 -40
  61. package/src/Navigation/NavigationItem/types.ts +0 -37
  62. package/src/Navigation/types.ts +0 -42
  63. package/types/AppNav/Item/types.d.ts +0 -17
  64. package/types/AppNav/Item/types.d.ts.map +0 -1
  65. package/types/AppNav/types.d.ts +0 -16
  66. package/types/AppNav/types.d.ts.map +0 -1
  67. package/types/Navigation/NavigationItem/types.d.ts +0 -14
  68. package/types/Navigation/NavigationItem/types.d.ts.map +0 -1
  69. package/types/Navigation/types.d.ts +0 -18
  70. package/types/Navigation/types.d.ts.map +0 -1
@@ -0,0 +1,87 @@
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 NavigationItemOwnProps = {
30
+ icon: React.ReactNode
31
+ label: React.ReactNode
32
+ as?: AsElementType
33
+ href?: string
34
+ onClick?: (...args: any[]) => any
35
+ selected?: boolean
36
+ minimized?: boolean
37
+ }
38
+
39
+ type PropKeys = keyof NavigationItemOwnProps
40
+
41
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
42
+
43
+ type NavigationItemProps = NavigationItemOwnProps & WithStyleProps
44
+
45
+ const propTypes: PropValidators<PropKeys> = {
46
+ /**
47
+ * The visual to display (ex. an Image, Logo, Avatar, or Icon)
48
+ */
49
+ icon: PropTypes.node.isRequired,
50
+ /**
51
+ * The text to display for the Navigation Link
52
+ */
53
+ label: PropTypes.node.isRequired,
54
+ /**
55
+ * The element type to render as (will default to `<a>` if href is provided)
56
+ */
57
+ as: PropTypes.elementType,
58
+ /**
59
+ * If the NavigationItem goes to a new page, pass an href
60
+ */
61
+ href: PropTypes.string,
62
+ /**
63
+ * If the NavigationItem does not go to a new page pass an onClick
64
+ */
65
+ onClick: PropTypes.func,
66
+ /**
67
+ * Denotes which NavigationItem is currently selected
68
+ */
69
+ selected: PropTypes.bool,
70
+ /**
71
+ * 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
72
+ */
73
+ minimized: PropTypes.bool
74
+ }
75
+
76
+ const allowedProps: AllowedPropKeys = [
77
+ 'icon',
78
+ 'label',
79
+ 'as',
80
+ 'href',
81
+ 'onClick',
82
+ 'selected',
83
+ 'minimized'
84
+ ]
85
+
86
+ export type { NavigationItemProps }
87
+ export { propTypes, allowedProps }
@@ -23,7 +23,7 @@
23
23
  */
24
24
 
25
25
  import { NavigationItemTheme } from '@instructure/shared-types'
26
- import { NavigationItemProps } from './types'
26
+ import { NavigationItemProps } from './props'
27
27
 
28
28
  /**
29
29
  * ---
@@ -23,13 +23,9 @@
23
23
  */
24
24
  /** @jsx jsx */
25
25
  import { Component, Children, ReactElement } from 'react'
26
- import PropTypes from 'prop-types'
27
26
 
28
27
  import { testable } from '@instructure/ui-testable'
29
- import {
30
- controllable,
31
- Children as ChildrenPropTypes
32
- } from '@instructure/ui-prop-types'
28
+
33
29
  import { omitProps, safeCloneElement } from '@instructure/ui-react-utils'
34
30
  import { IconMoveStartLine } from '@instructure/ui-icons'
35
31
  import { ScreenReaderContent } from '@instructure/ui-a11y-content'
@@ -39,7 +35,8 @@ import { NavigationItem } from './NavigationItem'
39
35
 
40
36
  import generateStyle from './styles'
41
37
  import generateComponentTheme from './theme'
42
- import { NavigationProps, NavigationState } from './types'
38
+ import type { NavigationProps, NavigationState } from './props'
39
+ import { allowedProps, propTypes } from './props'
43
40
 
44
41
  // @ts-expect-error ts-migrate(7031) FIXME: Binding element 'minimized' implicitly has an 'any... Remove this comment to see the full error message
45
42
  const navMinimized = ({ minimized }) => ({ minimized: !minimized })
@@ -54,44 +51,8 @@ category: components
54
51
  class Navigation extends Component<NavigationProps, NavigationState> {
55
52
  static readonly componentId = 'Navigation'
56
53
 
57
- static propTypes = {
58
- // eslint-disable-next-line react/require-default-props
59
- makeStyles: PropTypes.func,
60
- // eslint-disable-next-line react/require-default-props
61
- styles: PropTypes.object,
62
- /**
63
- * children of type Navigation.Item
64
- */
65
- children: ChildrenPropTypes.oneOf([NavigationItem]),
66
- /**
67
- * 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
68
- */
69
- minimized: controllable(PropTypes.bool, 'onMinimized', 'defaultMinimized'),
70
- /**
71
- * Whether the `<Navigation />` is initially minimized (uncontrolled)
72
- */
73
- defaultMinimized: PropTypes.bool,
74
- onMinimized: PropTypes.func,
75
- /**
76
- * Screen reader label for the main Navigation
77
- */
78
- label: PropTypes.string.isRequired,
79
- /**
80
- * Screen reader label for the toggle button expanded/minimized state
81
- */
82
- toggleLabel: PropTypes.shape({
83
- expandedLabel: PropTypes.string,
84
- minimizedLabel: PropTypes.string
85
- }).isRequired,
86
- /**
87
- * If the `<Navigation.Item>` goes to a new page, pass an href
88
- */
89
- href: PropTypes.string,
90
- /**
91
- * If the `<Navigation.Item>` does not go to a new page pass an onClick
92
- */
93
- onClick: PropTypes.func
94
- }
54
+ static allowedProps = allowedProps
55
+ static propTypes = propTypes
95
56
 
96
57
  static defaultProps = {
97
58
  children: null,
@@ -99,9 +60,7 @@ class Navigation extends Component<NavigationProps, NavigationState> {
99
60
  // @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
100
61
  onMinimized: function (event, minimized) {},
101
62
  // @ts-expect-error ts-migrate(6133) FIXME: 'e' is declared but its value is never read.
102
- onClick: function (e) {},
103
- href: undefined,
104
- minimized: undefined
63
+ onClick: function (e) {}
105
64
  }
106
65
 
107
66
  static Item = NavigationItem
@@ -119,13 +78,11 @@ class Navigation extends Component<NavigationProps, NavigationState> {
119
78
  }
120
79
 
121
80
  componentDidMount() {
122
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
123
- this.props.makeStyles({ minimized: this.minimized })
81
+ this.props.makeStyles?.({ minimized: this.minimized })
124
82
  }
125
83
 
126
84
  componentDidUpdate() {
127
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
128
- this.props.makeStyles({ minimized: this.minimized })
85
+ this.props.makeStyles?.({ minimized: this.minimized })
129
86
  }
130
87
 
131
88
  get minimized() {
@@ -154,7 +111,7 @@ class Navigation extends Component<NavigationProps, NavigationState> {
154
111
  const navItem = safeCloneElement(child as ReactElement, {
155
112
  minimized: this.state.minimized
156
113
  })
157
- return <li css={this.props.styles.list}>{navItem}</li>
114
+ return <li css={this.props.styles?.list}>{navItem}</li>
158
115
  })
159
116
  }
160
117
 
@@ -170,15 +127,15 @@ class Navigation extends Component<NavigationProps, NavigationState> {
170
127
  const props = omitProps(this.props, Navigation.propTypes, ['minimized'])
171
128
 
172
129
  return (
173
- <nav {...props} css={this.props.styles.navigation} aria-label={label}>
174
- <ul css={this.props.styles.content}>{this.renderChildren()}</ul>
175
- <div css={this.props.styles.toggle}>
130
+ <nav {...props} css={this.props.styles?.navigation} aria-label={label}>
131
+ <ul css={this.props.styles?.content}>{this.renderChildren()}</ul>
132
+ <div css={this.props.styles?.toggle}>
176
133
  <NavigationItem
177
134
  aria-expanded={!this.minimized}
178
135
  onClick={this.handleNavToggle}
179
136
  icon={
180
137
  <IconMoveStartLine
181
- css={this.props.styles.toggleIcon}
138
+ css={this.props.styles?.toggleIcon}
182
139
  inline={false}
183
140
  />
184
141
  }
@@ -0,0 +1,108 @@
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 {
28
+ controllable,
29
+ Children as ChildrenPropTypes
30
+ } from '@instructure/ui-prop-types'
31
+
32
+ import { NavigationItem } from './NavigationItem'
33
+
34
+ import type { PropValidators } from '@instructure/shared-types'
35
+ import type { WithStyleProps } from '@instructure/emotion'
36
+
37
+ type NavigationOwnProps = {
38
+ minimized?: any // TODO: controllable(PropTypes.bool, 'onMinimized', 'defaultMinimized')
39
+ defaultMinimized?: boolean
40
+ onMinimized?: (...args: any[]) => any
41
+ label: string
42
+ toggleLabel: {
43
+ expandedLabel?: string
44
+ minimizedLabel?: string
45
+ }
46
+ href?: string
47
+ onClick?: (...args: any[]) => any
48
+ children?: React.ReactNode
49
+ }
50
+
51
+ type NavigationState = {
52
+ minimized: boolean
53
+ }
54
+
55
+ type PropKeys = keyof NavigationOwnProps
56
+
57
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
58
+
59
+ type NavigationProps = NavigationOwnProps & WithStyleProps
60
+
61
+ const propTypes: PropValidators<PropKeys> = {
62
+ /**
63
+ * children of type Navigation.Item
64
+ */
65
+ children: ChildrenPropTypes.oneOf([NavigationItem]),
66
+ /**
67
+ * 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
68
+ */
69
+ minimized: controllable(PropTypes.bool, 'onMinimized', 'defaultMinimized'),
70
+ /**
71
+ * Whether the `<Navigation />` is initially minimized (uncontrolled)
72
+ */
73
+ defaultMinimized: PropTypes.bool,
74
+ onMinimized: PropTypes.func,
75
+ /**
76
+ * Screen reader label for the main Navigation
77
+ */
78
+ label: PropTypes.string.isRequired,
79
+ /**
80
+ * Screen reader label for the toggle button expanded/minimized state
81
+ */
82
+ toggleLabel: PropTypes.shape({
83
+ expandedLabel: PropTypes.string,
84
+ minimizedLabel: PropTypes.string
85
+ }).isRequired,
86
+ /**
87
+ * If the `<Navigation.Item>` goes to a new page, pass an href
88
+ */
89
+ href: PropTypes.string,
90
+ /**
91
+ * If the `<Navigation.Item>` does not go to a new page pass an onClick
92
+ */
93
+ onClick: PropTypes.func
94
+ }
95
+
96
+ const allowedProps: AllowedPropKeys = [
97
+ 'children',
98
+ 'minimized',
99
+ 'defaultMinimized',
100
+ 'onMinimized',
101
+ 'label',
102
+ 'toggleLabel',
103
+ 'href',
104
+ 'onClick'
105
+ ]
106
+
107
+ export type { NavigationProps, NavigationState }
108
+ export { propTypes, allowedProps }
@@ -23,7 +23,7 @@
23
23
  */
24
24
 
25
25
  import { NavigationTheme } from '@instructure/shared-types'
26
- import { NavigationProps, NavigationState } from './types'
26
+ import { NavigationProps, NavigationState } from './props'
27
27
 
28
28
  /**
29
29
  * ---
package/src/index.ts CHANGED
@@ -25,7 +25,7 @@
25
25
  export { AppNav } from './AppNav'
26
26
  export { Navigation, NavigationItem } from './Navigation'
27
27
 
28
- export type { AppNavProps } from './AppNav/types'
29
- export type { AppNavItemProps } from './AppNav/Item/types'
30
- export type { NavigationProps } from './Navigation/types'
31
- export type { NavigationItemProps } from './Navigation/NavigationItem/types'
28
+ export type { AppNavProps } from './AppNav/props'
29
+ export type { AppNavItemProps } from './AppNav/Item/props'
30
+ export type { NavigationProps } from './Navigation/props'
31
+ export type { NavigationItemProps } from './Navigation/NavigationItem/props'
@@ -1,8 +1,7 @@
1
1
  /** @jsx jsx */
2
2
  import { Component } from 'react';
3
- import PropTypes from 'prop-types';
4
3
  import { jsx } from '@instructure/emotion';
5
- import { AppNavItemProps } from './types';
4
+ import type { AppNavItemProps } from './props';
6
5
  /**
7
6
  ---
8
7
  parent: AppNav
@@ -12,61 +11,34 @@ id: AppNav.Item
12
11
  **/
13
12
  declare class Item extends Component<AppNavItemProps> {
14
13
  static readonly componentId = "AppNav.Item";
15
- static propTypes: {
16
- makeStyles: PropTypes.Requireable<(...args: any[]) => any>;
17
- styles: PropTypes.Requireable<object>;
18
- /**
19
- * The text to display. If the `icon` prop is used, label text must be wrapped
20
- * in `ScreenReaderContent`.
21
- */
22
- renderLabel: PropTypes.Validator<string | number | boolean | {} | PropTypes.ReactElementLike | PropTypes.ReactNodeArray>;
23
- /**
24
- * Content to display after the renderLabel text, such as a badge
25
- */
26
- renderAfter: PropTypes.Requireable<string | number | boolean | {} | PropTypes.ReactElementLike | PropTypes.ReactNodeArray>;
27
- /**
28
- * The visual to display (ex. an Image, Logo, Avatar, or Icon)
29
- */
30
- renderIcon: PropTypes.Requireable<string | number | boolean | {} | PropTypes.ReactElementLike | PropTypes.ReactNodeArray>;
31
- /**
32
- * If the item goes to a new page, pass an href
33
- */
34
- href: PropTypes.Requireable<string>;
35
- /**
36
- * If the item does not go to a new page, pass an onClick
37
- */
38
- onClick: PropTypes.Requireable<(...args: any[]) => any>;
39
- /**
40
- * Denotes which item is currently selected
41
- */
42
- isSelected: PropTypes.Requireable<boolean>;
43
- /**
44
- * provides a reference to the underlying focusable (`button` or `a`) element
45
- */
46
- elementRef: PropTypes.Requireable<(...args: any[]) => any>;
47
- /**
48
- * The element type to render as (will default to `<a>` if href is provided)
49
- */
50
- as: PropTypes.Requireable<PropTypes.ReactComponentLike>;
51
- /**
52
- * Specify the mouse cursor to use on :hover.
53
- * The `pointer` cursor is used by default.
54
- */
55
- cursor: PropTypes.Requireable<string>;
56
- /**
57
- * Disables the link or button visually and functionally
58
- */
59
- isDisabled: PropTypes.Requireable<boolean>;
60
- };
14
+ static allowedProps: readonly (keyof {
15
+ renderLabel: import("react").ReactNode | ((...args: any[]) => any);
16
+ renderAfter?: import("react").ReactNode | ((...args: any[]) => any);
17
+ renderIcon?: import("react").ReactNode | ((...args: any[]) => any);
18
+ href?: string | undefined;
19
+ onClick?: ((...args: any[]) => any) | undefined;
20
+ isSelected?: boolean | undefined;
21
+ elementRef?: ((...args: any[]) => any) | undefined;
22
+ as?: import("@instructure/shared-types/types/CommonProps").AsElementType | undefined;
23
+ cursor?: string | undefined;
24
+ isDisabled?: boolean | undefined;
25
+ })[];
26
+ static propTypes: import("@instructure/shared-types/types/UtilityTypes").PropValidators<keyof {
27
+ renderLabel: import("react").ReactNode | ((...args: any[]) => any);
28
+ renderAfter?: import("react").ReactNode | ((...args: any[]) => any);
29
+ renderIcon?: import("react").ReactNode | ((...args: any[]) => any);
30
+ href?: string | undefined;
31
+ onClick?: ((...args: any[]) => any) | undefined;
32
+ isSelected?: boolean | undefined;
33
+ elementRef?: ((...args: any[]) => any) | undefined;
34
+ as?: import("@instructure/shared-types/types/CommonProps").AsElementType | undefined;
35
+ cursor?: string | undefined;
36
+ isDisabled?: boolean | undefined;
37
+ }>;
61
38
  static defaultProps: {
62
39
  children: null;
63
40
  onClick: (event: any) => void;
64
41
  isSelected: boolean;
65
- href: undefined;
66
- elementRef: undefined;
67
- renderIcon: undefined;
68
- renderAfter: undefined;
69
- as: undefined;
70
42
  cursor: string;
71
43
  isDisabled: boolean;
72
44
  };