@instructure/ui-navigation 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.
Files changed (95) hide show
  1. package/CHANGELOG.md +36 -286
  2. package/es/AppNav/{Item → v1/Item}/index.js +2 -2
  3. package/es/AppNav/{index.js → v1/index.js} +3 -3
  4. package/es/AppNav/v2/Item/index.js +115 -0
  5. package/{src/index.ts → es/AppNav/v2/Item/props.js} +2 -5
  6. package/es/AppNav/v2/Item/styles.js +85 -0
  7. package/es/AppNav/v2/index.js +123 -0
  8. package/es/AppNav/v2/props.js +26 -0
  9. package/es/AppNav/v2/styles.js +58 -0
  10. package/es/{index.js → exports/a.js} +2 -2
  11. package/es/exports/b.js +25 -0
  12. package/lib/AppNav/v1/Item/index.js +124 -0
  13. package/lib/AppNav/{index.js → v1/index.js} +7 -7
  14. package/lib/AppNav/{Item → v2/Item}/index.js +3 -4
  15. package/lib/AppNav/v2/Item/props.js +31 -0
  16. package/lib/AppNav/v2/Item/styles.js +91 -0
  17. package/lib/AppNav/v2/index.js +128 -0
  18. package/lib/AppNav/v2/props.js +31 -0
  19. package/lib/AppNav/v2/styles.js +64 -0
  20. package/lib/{index.js → exports/a.js} +3 -3
  21. package/lib/exports/b.js +19 -0
  22. package/package.json +51 -29
  23. package/src/AppNav/{Item → v1/Item}/index.tsx +2 -2
  24. package/src/AppNav/{index.tsx → v1/index.tsx} +3 -3
  25. package/src/AppNav/v2/Item/index.tsx +144 -0
  26. package/src/AppNav/v2/Item/props.ts +103 -0
  27. package/src/AppNav/v2/Item/styles.ts +97 -0
  28. package/src/AppNav/v2/README.md +103 -0
  29. package/src/AppNav/v2/index.tsx +166 -0
  30. package/src/AppNav/v2/props.ts +113 -0
  31. package/src/AppNav/v2/styles.ts +62 -0
  32. package/src/exports/a.ts +29 -0
  33. package/src/exports/b.ts +29 -0
  34. package/tsconfig.build.tsbuildinfo +1 -1
  35. package/types/AppNav/v1/Item/index.d.ts.map +1 -0
  36. package/types/AppNav/v1/Item/props.d.ts.map +1 -0
  37. package/types/AppNav/v1/Item/styles.d.ts.map +1 -0
  38. package/types/AppNav/v1/Item/theme.d.ts.map +1 -0
  39. package/types/AppNav/v1/index.d.ts.map +1 -0
  40. package/types/AppNav/v1/props.d.ts.map +1 -0
  41. package/types/AppNav/v1/styles.d.ts.map +1 -0
  42. package/types/AppNav/v1/theme.d.ts.map +1 -0
  43. package/types/AppNav/v2/Item/index.d.ts +39 -0
  44. package/types/AppNav/v2/Item/index.d.ts.map +1 -0
  45. package/types/AppNav/v2/Item/props.d.ts +57 -0
  46. package/types/AppNav/v2/Item/props.d.ts.map +1 -0
  47. package/types/AppNav/v2/Item/styles.d.ts +15 -0
  48. package/types/AppNav/v2/Item/styles.d.ts.map +1 -0
  49. package/types/AppNav/v2/index.d.ts +46 -0
  50. package/types/AppNav/v2/index.d.ts.map +1 -0
  51. package/types/AppNav/v2/props.d.ts +66 -0
  52. package/types/AppNav/v2/props.d.ts.map +1 -0
  53. package/types/AppNav/v2/styles.d.ts +15 -0
  54. package/types/AppNav/v2/styles.d.ts.map +1 -0
  55. package/types/exports/a.d.ts +5 -0
  56. package/types/exports/a.d.ts.map +1 -0
  57. package/types/exports/b.d.ts +5 -0
  58. package/types/exports/b.d.ts.map +1 -0
  59. package/types/AppNav/Item/index.d.ts.map +0 -1
  60. package/types/AppNav/Item/props.d.ts.map +0 -1
  61. package/types/AppNav/Item/styles.d.ts.map +0 -1
  62. package/types/AppNav/Item/theme.d.ts.map +0 -1
  63. package/types/AppNav/index.d.ts.map +0 -1
  64. package/types/AppNav/props.d.ts.map +0 -1
  65. package/types/AppNav/styles.d.ts.map +0 -1
  66. package/types/AppNav/theme.d.ts.map +0 -1
  67. package/types/index.d.ts +0 -5
  68. package/types/index.d.ts.map +0 -1
  69. /package/es/AppNav/{Item → v1/Item}/props.js +0 -0
  70. /package/es/AppNav/{Item → v1/Item}/styles.js +0 -0
  71. /package/es/AppNav/{Item → v1/Item}/theme.js +0 -0
  72. /package/es/AppNav/{props.js → v1/props.js} +0 -0
  73. /package/es/AppNav/{styles.js → v1/styles.js} +0 -0
  74. /package/es/AppNav/{theme.js → v1/theme.js} +0 -0
  75. /package/lib/AppNav/{Item → v1/Item}/props.js +0 -0
  76. /package/lib/AppNav/{Item → v1/Item}/styles.js +0 -0
  77. /package/lib/AppNav/{Item → v1/Item}/theme.js +0 -0
  78. /package/lib/AppNav/{props.js → v1/props.js} +0 -0
  79. /package/lib/AppNav/{styles.js → v1/styles.js} +0 -0
  80. /package/lib/AppNav/{theme.js → v1/theme.js} +0 -0
  81. /package/src/AppNav/{Item → v1/Item}/props.ts +0 -0
  82. /package/src/AppNav/{Item → v1/Item}/styles.ts +0 -0
  83. /package/src/AppNav/{Item → v1/Item}/theme.ts +0 -0
  84. /package/src/AppNav/{README.md → v1/README.md} +0 -0
  85. /package/src/AppNav/{props.ts → v1/props.ts} +0 -0
  86. /package/src/AppNav/{styles.ts → v1/styles.ts} +0 -0
  87. /package/src/AppNav/{theme.ts → v1/theme.ts} +0 -0
  88. /package/types/AppNav/{Item → v1/Item}/index.d.ts +0 -0
  89. /package/types/AppNav/{Item → v1/Item}/props.d.ts +0 -0
  90. /package/types/AppNav/{Item → v1/Item}/styles.d.ts +0 -0
  91. /package/types/AppNav/{Item → v1/Item}/theme.d.ts +0 -0
  92. /package/types/AppNav/{index.d.ts → v1/index.d.ts} +0 -0
  93. /package/types/AppNav/{props.d.ts → v1/props.d.ts} +0 -0
  94. /package/types/AppNav/{styles.d.ts → v1/styles.d.ts} +0 -0
  95. /package/types/AppNav/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -0,0 +1,103 @@
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 {
26
+ AsElementType,
27
+ AppNavItemTheme,
28
+ OtherHTMLAttributes
29
+ } from '@instructure/shared-types'
30
+ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
31
+ import type { Cursor } from '@instructure/shared-types'
32
+ import React from 'react'
33
+ import { Renderable } from '@instructure/shared-types'
34
+
35
+ type AppNavItemOwnProps = {
36
+ /**
37
+ * The text to display. If the `icon` prop is used, label text must be wrapped
38
+ * in `ScreenReaderContent`.
39
+ */
40
+ renderLabel: Renderable
41
+ /**
42
+ * Content to display after the renderLabel text, such as a badge
43
+ */
44
+ renderAfter?: Renderable
45
+ /**
46
+ * The visual to display (ex. an Image, Logo, Avatar, or Icon)
47
+ */
48
+ renderIcon?: Renderable
49
+ /**
50
+ * If the item goes to a new page, pass an href
51
+ */
52
+ href?: string
53
+ /**
54
+ * If the item does not go to a new page, pass an onClick
55
+ */
56
+ onClick?: (event: React.MouseEvent) => void
57
+ /**
58
+ * Denotes which item is currently selected
59
+ */
60
+ isSelected?: boolean
61
+ /**
62
+ * provides a reference to the underlying focusable (`button` or `a`) element
63
+ */
64
+ elementRef?: (element: Element | null) => void
65
+ /**
66
+ * The element type to render as (will default to `<a>` if href is provided)
67
+ */
68
+ as?: AsElementType
69
+ /**
70
+ * Specify the mouse cursor to use on :hover.
71
+ * The `pointer` cursor is used by default.
72
+ */
73
+ cursor?: Cursor
74
+ /**
75
+ * Disables the link or button visually and functionally
76
+ */
77
+ isDisabled?: boolean
78
+ }
79
+
80
+ type PropKeys = keyof AppNavItemOwnProps
81
+
82
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
83
+
84
+ type AppNavItemProps = AppNavItemOwnProps &
85
+ WithStyleProps<AppNavItemTheme, AppNavItemStyle> &
86
+ OtherHTMLAttributes<AppNavItemOwnProps>
87
+
88
+ type AppNavItemStyle = ComponentStyle<'item' | 'label'>
89
+ const allowedProps: AllowedPropKeys = [
90
+ 'renderLabel',
91
+ 'renderAfter',
92
+ 'renderIcon',
93
+ 'href',
94
+ 'onClick',
95
+ 'isSelected',
96
+ 'elementRef',
97
+ 'as',
98
+ 'cursor',
99
+ 'isDisabled'
100
+ ]
101
+
102
+ export type { AppNavItemProps, AppNavItemStyle }
103
+ export { allowedProps }
@@ -0,0 +1,97 @@
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 { AppNavItemProps, AppNavItemStyle } 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} state the state of the component, the style is applied to
36
+ * @return {Object} The final style object, which will be used in the component
37
+ */
38
+ const generateStyle = (
39
+ componentTheme: NewComponentTypes['AppNavItem'],
40
+ props: AppNavItemProps
41
+ ): AppNavItemStyle => {
42
+ const { isSelected, isDisabled } = props
43
+
44
+ const itemStyles = {
45
+ appearance: 'none',
46
+ overflow: 'visible',
47
+ direction: 'inherit',
48
+ margin: '0',
49
+ textDecoration: 'none',
50
+ userSelect: 'none',
51
+ touchAction: 'manipulation',
52
+ background: 'transparent',
53
+ border: 'none',
54
+ outline: 'none',
55
+ lineHeight: componentTheme.height,
56
+ padding: `0 ${componentTheme.padding}`,
57
+ alignItems: 'flex-start',
58
+
59
+ '&:hover': {
60
+ textDecoration: 'underline',
61
+ textDecorationColor: componentTheme.textColor
62
+ },
63
+ ...(isDisabled && {
64
+ pointerEvents: 'none',
65
+ opacity: 0.5
66
+ })
67
+ }
68
+
69
+ return {
70
+ item: {
71
+ label: 'item',
72
+ ...itemStyles,
73
+
74
+ // NOTE: needs separate groups for `:is()` and `:-webkit-any()` because of css selector group validation (see https://www.w3.org/TR/selectors-3/#grouping)
75
+ '&:is(a), &:is(button)': itemStyles,
76
+ '&:-webkit-any(a), &:-webkit-any(button)': itemStyles
77
+ },
78
+
79
+ label: {
80
+ label: 'item__label',
81
+ whiteSpace: 'nowrap',
82
+ overflow: 'hidden',
83
+ textOverflow: 'ellipsis',
84
+ fontFamily: componentTheme.fontFamily,
85
+ fontSize: componentTheme.fontSize,
86
+ fontWeight: componentTheme.fontWeight,
87
+ color: componentTheme.textColor,
88
+
89
+ ...(isSelected && {
90
+ color: componentTheme.textColorSelected,
91
+ textDecoration: 'underline'
92
+ })
93
+ }
94
+ }
95
+ }
96
+
97
+ export default generateStyle
@@ -0,0 +1,103 @@
1
+ ---
2
+ describes: AppNav
3
+ ---
4
+
5
+ `AppNav` is a navigation component currently intended for use within LTI apps. AppNav
6
+ can be configured to adapt to small screen widths by truncating nav items that
7
+ don't fit within the available space.
8
+
9
+ The `onUpdate` function prop returns the number of visible nav items, while the
10
+ `renderTruncateLabel` function prop allows you to customize the trigger for the Menu
11
+ that contains the truncated items. The example below shows how you can use both of
12
+ these props to create a hamburger menu when the number of visible nav items is less
13
+ than two.
14
+
15
+ ```js
16
+ ---
17
+ type: example
18
+ ---
19
+ const totalItemsCount = 5
20
+
21
+ const AppNavExample = () => {
22
+ const [visibleItemsCount, setVisibleItemsCount] = useState(totalItemsCount)
23
+
24
+ const handleUpdate = ({ visibleItemsCount }) => {
25
+ setVisibleItemsCount(visibleItemsCount)
26
+ }
27
+
28
+ return (
29
+ <AppNav
30
+ screenReaderLabel="App navigation"
31
+ visibleItemsCount={visibleItemsCount >= 2 ? visibleItemsCount : 0}
32
+ onUpdate={handleUpdate}
33
+ renderBeforeItems={
34
+ <AppNav.Item
35
+ renderLabel={<ScreenReaderContent>Instructure</ScreenReaderContent>}
36
+ renderIcon={
37
+ <CommandInstUIIcon inline={false} size="2xl" color="baseColor" />
38
+ }
39
+ href="http://instructure.com"
40
+ />
41
+ }
42
+ renderAfterItems={
43
+ <IconButton
44
+ onClick={() => console.log('Add')}
45
+ renderIcon={<PlusInstUIIcon/>}
46
+ margin="0 0 0 x-small"
47
+ screenReaderLabel="Add something"
48
+ withBorder={false}
49
+ withBackground={false}
50
+ />
51
+ }
52
+ renderTruncateLabel={() => {
53
+ const hiddenItemsCount = totalItemsCount - visibleItemsCount
54
+ if (visibleItemsCount >= 2) {
55
+ return `${hiddenItemsCount} More`
56
+ } else {
57
+ return (
58
+ <span>
59
+ <MenuInstUIIcon size={'2xl'} inline={false} />
60
+ <ScreenReaderContent>{`${hiddenItemsCount} More`}</ScreenReaderContent>
61
+ </span>
62
+ )
63
+ }
64
+ }}
65
+ >
66
+ <AppNav.Item
67
+ renderLabel="instructure-ui"
68
+ href="http://instructure.design"
69
+ renderAfter={
70
+ <Badge
71
+ type="notification"
72
+ variant="success"
73
+ standalone
74
+ formatOutput={() => {
75
+ return (
76
+ <ScreenReaderContent>
77
+ You have notifications from instructure-ui
78
+ </ScreenReaderContent>
79
+ )
80
+ }}
81
+ />
82
+ }
83
+ />
84
+ <AppNav.Item
85
+ isSelected
86
+ renderLabel="Canvas"
87
+ href="https://www.instructure.com/canvas/"
88
+ />
89
+ <AppNav.Item renderLabel="Canvas Network" href="https://canvas.net" />
90
+ <AppNav.Item
91
+ renderLabel={() => 'Canvas Community'}
92
+ href="https://community.canvaslms.com/"
93
+ />
94
+ <AppNav.Item
95
+ renderLabel="Bridge"
96
+ href="https://www.instructure.com/bridge/"
97
+ />
98
+ </AppNav>
99
+ )
100
+ }
101
+
102
+ render(<AppNavExample />)
103
+ ```
@@ -0,0 +1,166 @@
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 { ComponentElement, Component } from 'react'
26
+
27
+ import { withStyle } from '@instructure/emotion'
28
+
29
+ import { callRenderProp, omitProps } from '@instructure/ui-react-utils'
30
+
31
+ import { View } from '@instructure/ui-view/latest'
32
+ import { Menu } from '@instructure/ui-menu/latest'
33
+ import { Item } from './Item'
34
+
35
+ import generateStyle from './styles'
36
+ import type { AppNavProps } from './props'
37
+ import { allowedProps } from './props'
38
+ import { AppNavItemProps } from './Item/props'
39
+
40
+ import { TruncateList } from '@instructure/ui-truncate-list'
41
+
42
+ /**
43
+ ---
44
+ category: components
45
+ ---
46
+ **/
47
+ @withStyle(generateStyle)
48
+ class AppNav extends Component<AppNavProps> {
49
+ static readonly componentId = 'AppNav'
50
+
51
+ static allowedProps = allowedProps
52
+
53
+ static defaultProps = {
54
+ children: null,
55
+ debounce: 300,
56
+ margin: '0',
57
+ renderTruncateLabel: () => 'More',
58
+ visibleItemsCount: 0
59
+ }
60
+
61
+ static Item = Item
62
+
63
+ state = {
64
+ isMeasuring: false
65
+ }
66
+
67
+ ref: Element | null = null
68
+
69
+ componentDidMount() {
70
+ this.props.makeStyles?.()
71
+ }
72
+
73
+ componentDidUpdate() {
74
+ this.props.makeStyles?.()
75
+ }
76
+
77
+ handleRef = (el: Element | null) => {
78
+ const { elementRef } = this.props
79
+
80
+ this.ref = el
81
+
82
+ if (typeof elementRef === 'function') {
83
+ elementRef(el)
84
+ }
85
+ }
86
+
87
+ renderMenu(items: ComponentElement<AppNavItemProps, Item>[]) {
88
+ return (
89
+ <Menu
90
+ trigger={
91
+ <AppNav.Item
92
+ renderLabel={callRenderProp(this.props.renderTruncateLabel)}
93
+ />
94
+ }
95
+ >
96
+ {(items as ComponentElement<AppNavItemProps, Item>[]).map(
97
+ (item, index) => {
98
+ return (
99
+ <Menu.Item
100
+ href={item.props.href ? item.props.href : undefined}
101
+ onClick={
102
+ item.props.onClick && !item.props.href
103
+ ? item.props.onClick
104
+ : undefined
105
+ }
106
+ key={index}
107
+ >
108
+ {callRenderProp(item.props.renderLabel)}
109
+ </Menu.Item>
110
+ )
111
+ }
112
+ )}
113
+ </Menu>
114
+ )
115
+ }
116
+
117
+ render() {
118
+ const { visibleItemsCount, screenReaderLabel, margin, debounce, styles } =
119
+ this.props
120
+
121
+ const passthroughProps = View.omitViewProps(
122
+ omitProps(this.props, AppNav.allowedProps),
123
+ AppNav
124
+ )
125
+
126
+ const renderBeforeItems = callRenderProp(this.props.renderBeforeItems)
127
+ const renderAfterItems = callRenderProp(this.props.renderAfterItems)
128
+ const hasRenderedContent = renderBeforeItems || renderAfterItems
129
+
130
+ return (
131
+ <View
132
+ {...passthroughProps}
133
+ as="nav"
134
+ css={[styles?.appNav, hasRenderedContent ? styles?.alignCenter : '']}
135
+ margin={margin}
136
+ display={hasRenderedContent ? 'flex' : 'block'}
137
+ elementRef={this.handleRef}
138
+ data-cid="AppNav"
139
+ >
140
+ {renderBeforeItems && <span>{renderBeforeItems}</span>}
141
+
142
+ <TruncateList
143
+ visibleItemsCount={visibleItemsCount}
144
+ debounce={debounce}
145
+ onUpdate={this.props.onUpdate}
146
+ renderHiddenItemMenu={(hiddenChildren) =>
147
+ this.renderMenu(
148
+ hiddenChildren as ComponentElement<AppNavItemProps, Item>[]
149
+ )
150
+ }
151
+ itemSpacing={styles?.horizontalMargin}
152
+ fixMenuTriggerWidth={styles?.menuTriggerWidth}
153
+ css={styles?.list}
154
+ aria-label={callRenderProp(screenReaderLabel)}
155
+ >
156
+ {this.props.children}
157
+ </TruncateList>
158
+
159
+ {renderAfterItems && <span>{renderAfterItems}</span>}
160
+ </View>
161
+ )
162
+ }
163
+ }
164
+
165
+ export { AppNav }
166
+ export default AppNav
@@ -0,0 +1,113 @@
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
+ Spacing,
28
+ WithStyleProps,
29
+ ComponentStyle
30
+ } from '@instructure/emotion'
31
+ import type {
32
+ AppNavTheme,
33
+ OtherHTMLAttributes
34
+ } from '@instructure/shared-types'
35
+ import { Renderable } from '@instructure/shared-types'
36
+
37
+ type AppNavOwnProps = {
38
+ /**
39
+ * Screenreader label for the overall navigation
40
+ */
41
+ screenReaderLabel: string
42
+ /**
43
+ * The rate (in ms) the component responds to container resizing or
44
+ * an update to one of its child items
45
+ */
46
+ debounce?: number
47
+ /**
48
+ * Content to display before the navigation items, such as a logo
49
+ */
50
+ renderBeforeItems?: Renderable
51
+ /**
52
+ * Content to display after the navigation items, aligned to the far end
53
+ * of the navigation
54
+ */
55
+ renderAfterItems?: Renderable
56
+ /**
57
+ * Valid values are `0`, `none`, `auto`, `xxx-small`, `xx-small`, `x-small`,
58
+ * `small`, `medium`, `large`, `x-large`, `xx-large`. Apply these values via
59
+ * familiar CSS-like shorthand. For example: `margin="small auto large"`.
60
+ */
61
+ margin?: Spacing
62
+ /**
63
+ * Provides a reference to the underlying nav element
64
+ */
65
+ elementRef?: (element: Element | null) => void
66
+ /**
67
+ * Customize the text displayed in the menu trigger when links overflow
68
+ * the overall nav width.
69
+ */
70
+ renderTruncateLabel?: Renderable
71
+ /**
72
+ * Called whenever the navigation items are updated or the size of
73
+ * the navigation changes. Passes in the `visibleItemsCount` as
74
+ * a parameter.
75
+ */
76
+ onUpdate?: (visibleItemsCount: { visibleItemsCount: number }) => void
77
+ /**
78
+ * Sets the number of navigation items that are visible.
79
+ */
80
+ visibleItemsCount?: number
81
+ /**
82
+ * Only accepts `AppNav.Item` as children
83
+ */
84
+ children?: React.ReactNode
85
+ }
86
+
87
+ type PropKeys = keyof AppNavOwnProps
88
+
89
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
90
+
91
+ type AppNavProps = AppNavOwnProps &
92
+ WithStyleProps<AppNavTheme, AppNavStyle> &
93
+ OtherHTMLAttributes<AppNavOwnProps>
94
+
95
+ type AppNavStyle = ComponentStyle<'appNav' | 'alignCenter' | 'list'> & {
96
+ horizontalMargin: string
97
+ menuTriggerWidth: string
98
+ }
99
+ const allowedProps: AllowedPropKeys = [
100
+ 'screenReaderLabel',
101
+ 'children',
102
+ 'debounce',
103
+ 'renderBeforeItems',
104
+ 'renderAfterItems',
105
+ 'margin',
106
+ 'elementRef',
107
+ 'renderTruncateLabel',
108
+ 'onUpdate',
109
+ 'visibleItemsCount'
110
+ ]
111
+
112
+ export type { AppNavProps, AppNavStyle }
113
+ export { allowedProps }
@@ -0,0 +1,62 @@
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 { AppNavStyle } 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} state the state of the component, the style is applied to
36
+ * @return {Object} The final style object, which will be used in the component
37
+ */
38
+ const generateStyle = (componentTheme: NewComponentTypes['AppNav']): AppNavStyle => {
39
+ return {
40
+ appNav: {
41
+ label: 'appNav',
42
+ fontFamily: componentTheme.fontFamily,
43
+ borderBottom: `${componentTheme.borderWidth} ${componentTheme.borderStyle} ${componentTheme.borderColor}`
44
+ },
45
+ alignCenter: {
46
+ alignItems: 'center'
47
+ },
48
+ list: {
49
+ label: 'appNav__list',
50
+ height: componentTheme.height,
51
+ flexGrow: 1,
52
+ flexShrink: 1,
53
+ flexBasis: '0',
54
+ minWidth: '0.0625rem',
55
+ paddingInlineStart: componentTheme.horizontalMargin
56
+ },
57
+ horizontalMargin: componentTheme.horizontalMargin,
58
+ menuTriggerWidth: componentTheme.menuTriggerWidth
59
+ }
60
+ }
61
+
62
+ export default generateStyle
@@ -0,0 +1,29 @@
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
+ export { AppNav } from '../AppNav/v1'
26
+ export { Item as AppNavItem } from '../AppNav/v1/Item'
27
+
28
+ export type { AppNavProps } from '../AppNav/v1/props'
29
+ export type { AppNavItemProps } from '../AppNav/v1/Item/props'