@instructure/ui-global-nav 0.0.0-stage → 11.7.10

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 (139) hide show
  1. package/CHANGELOG.md +0 -0
  2. package/LICENSE.md +28 -0
  3. package/README.md +25 -2
  4. package/es/GlobalNav/v1/CollapseButton/index.js +80 -0
  5. package/es/GlobalNav/v1/CollapseButton/props.js +1 -0
  6. package/es/GlobalNav/v1/CollapseButton/styles.js +64 -0
  7. package/es/GlobalNav/v1/CollapsedSubNav/index.js +59 -0
  8. package/es/GlobalNav/v1/CollapsedSubNav/props.js +1 -0
  9. package/es/GlobalNav/v1/CollapsedSubNav/styles.js +82 -0
  10. package/es/GlobalNav/v1/InstitutionLogo/index.js +93 -0
  11. package/es/GlobalNav/v1/InstitutionLogo/props.js +1 -0
  12. package/es/GlobalNav/v1/InstitutionLogo/styles.js +69 -0
  13. package/es/GlobalNav/v1/MainNavItem/index.js +129 -0
  14. package/es/GlobalNav/v1/MainNavItem/props.js +1 -0
  15. package/es/GlobalNav/v1/MainNavItem/styles.js +117 -0
  16. package/es/GlobalNav/v1/SubNav/index.js +121 -0
  17. package/es/GlobalNav/v1/SubNav/props.js +1 -0
  18. package/es/GlobalNav/v1/SubNav/styles.js +52 -0
  19. package/es/GlobalNav/v1/SubNavItem/index.js +78 -0
  20. package/es/GlobalNav/v1/SubNavItem/props.js +1 -0
  21. package/es/GlobalNav/v1/SubNavItem/styles.js +94 -0
  22. package/es/GlobalNav/v1/SubNavLevel/index.js +160 -0
  23. package/es/GlobalNav/v1/SubNavLevel/props.js +1 -0
  24. package/es/GlobalNav/v1/SubNavLevel/styles.js +94 -0
  25. package/es/GlobalNav/v1/index.js +222 -0
  26. package/es/GlobalNav/v1/props.js +28 -0
  27. package/es/GlobalNav/v1/styles.js +110 -0
  28. package/es/GlobalNav/v1/utils/getItemElementProps.js +64 -0
  29. package/es/exports/a.js +24 -0
  30. package/lib/GlobalNav/v1/CollapseButton/index.js +85 -0
  31. package/lib/GlobalNav/v1/CollapseButton/props.js +5 -0
  32. package/lib/GlobalNav/v1/CollapseButton/styles.js +70 -0
  33. package/lib/GlobalNav/v1/CollapsedSubNav/index.js +64 -0
  34. package/lib/GlobalNav/v1/CollapsedSubNav/props.js +5 -0
  35. package/lib/GlobalNav/v1/CollapsedSubNav/styles.js +88 -0
  36. package/lib/GlobalNav/v1/InstitutionLogo/index.js +98 -0
  37. package/lib/GlobalNav/v1/InstitutionLogo/props.js +5 -0
  38. package/lib/GlobalNav/v1/InstitutionLogo/styles.js +75 -0
  39. package/lib/GlobalNav/v1/MainNavItem/index.js +134 -0
  40. package/lib/GlobalNav/v1/MainNavItem/props.js +5 -0
  41. package/lib/GlobalNav/v1/MainNavItem/styles.js +123 -0
  42. package/lib/GlobalNav/v1/SubNav/index.js +128 -0
  43. package/lib/GlobalNav/v1/SubNav/props.js +5 -0
  44. package/lib/GlobalNav/v1/SubNav/styles.js +58 -0
  45. package/lib/GlobalNav/v1/SubNavItem/index.js +83 -0
  46. package/lib/GlobalNav/v1/SubNavItem/props.js +5 -0
  47. package/lib/GlobalNav/v1/SubNavItem/styles.js +100 -0
  48. package/lib/GlobalNav/v1/SubNavLevel/index.js +165 -0
  49. package/lib/GlobalNav/v1/SubNavLevel/props.js +5 -0
  50. package/lib/GlobalNav/v1/SubNavLevel/styles.js +100 -0
  51. package/lib/GlobalNav/v1/index.js +228 -0
  52. package/lib/GlobalNav/v1/props.js +33 -0
  53. package/lib/GlobalNav/v1/styles.js +116 -0
  54. package/lib/GlobalNav/v1/utils/getItemElementProps.js +70 -0
  55. package/lib/exports/a.js +12 -0
  56. package/lib/package.json +1 -0
  57. package/package.json +77 -3
  58. package/src/GlobalNav/v1/CollapseButton/index.tsx +87 -0
  59. package/src/GlobalNav/v1/CollapseButton/props.ts +64 -0
  60. package/src/GlobalNav/v1/CollapseButton/styles.ts +76 -0
  61. package/src/GlobalNav/v1/CollapsedSubNav/index.tsx +60 -0
  62. package/src/GlobalNav/v1/CollapsedSubNav/props.ts +42 -0
  63. package/src/GlobalNav/v1/CollapsedSubNav/styles.ts +92 -0
  64. package/src/GlobalNav/v1/InstitutionLogo/index.tsx +86 -0
  65. package/src/GlobalNav/v1/InstitutionLogo/props.ts +42 -0
  66. package/src/GlobalNav/v1/InstitutionLogo/styles.ts +82 -0
  67. package/src/GlobalNav/v1/MainNavItem/index.tsx +132 -0
  68. package/src/GlobalNav/v1/MainNavItem/props.ts +65 -0
  69. package/src/GlobalNav/v1/MainNavItem/styles.ts +137 -0
  70. package/src/GlobalNav/v1/README.md +234 -0
  71. package/src/GlobalNav/v1/SubNav/index.tsx +132 -0
  72. package/src/GlobalNav/v1/SubNav/props.ts +81 -0
  73. package/src/GlobalNav/v1/SubNav/styles.ts +58 -0
  74. package/src/GlobalNav/v1/SubNavItem/index.tsx +79 -0
  75. package/src/GlobalNav/v1/SubNavItem/props.ts +48 -0
  76. package/src/GlobalNav/v1/SubNavItem/styles.ts +110 -0
  77. package/src/GlobalNav/v1/SubNavLevel/index.tsx +193 -0
  78. package/src/GlobalNav/v1/SubNavLevel/props.ts +75 -0
  79. package/src/GlobalNav/v1/SubNavLevel/styles.ts +103 -0
  80. package/src/GlobalNav/v1/index.tsx +256 -0
  81. package/src/GlobalNav/v1/props.ts +328 -0
  82. package/src/GlobalNav/v1/styles.ts +132 -0
  83. package/src/GlobalNav/v1/utils/getItemElementProps.ts +80 -0
  84. package/src/exports/a.ts +35 -0
  85. package/tsconfig.build.json +53 -0
  86. package/tsconfig.build.tsbuildinfo +1 -0
  87. package/tsconfig.json +4 -0
  88. package/types/GlobalNav/v1/CollapseButton/index.d.ts +11 -0
  89. package/types/GlobalNav/v1/CollapseButton/index.d.ts.map +1 -0
  90. package/types/GlobalNav/v1/CollapseButton/props.d.ts +31 -0
  91. package/types/GlobalNav/v1/CollapseButton/props.d.ts.map +1 -0
  92. package/types/GlobalNav/v1/CollapseButton/styles.d.ts +22 -0
  93. package/types/GlobalNav/v1/CollapseButton/styles.d.ts.map +1 -0
  94. package/types/GlobalNav/v1/CollapsedSubNav/index.d.ts +11 -0
  95. package/types/GlobalNav/v1/CollapsedSubNav/index.d.ts.map +1 -0
  96. package/types/GlobalNav/v1/CollapsedSubNav/props.d.ts +15 -0
  97. package/types/GlobalNav/v1/CollapsedSubNav/props.d.ts.map +1 -0
  98. package/types/GlobalNav/v1/CollapsedSubNav/styles.d.ts +14 -0
  99. package/types/GlobalNav/v1/CollapsedSubNav/styles.d.ts.map +1 -0
  100. package/types/GlobalNav/v1/InstitutionLogo/index.d.ts +11 -0
  101. package/types/GlobalNav/v1/InstitutionLogo/index.d.ts.map +1 -0
  102. package/types/GlobalNav/v1/InstitutionLogo/props.d.ts +15 -0
  103. package/types/GlobalNav/v1/InstitutionLogo/props.d.ts.map +1 -0
  104. package/types/GlobalNav/v1/InstitutionLogo/styles.d.ts +20 -0
  105. package/types/GlobalNav/v1/InstitutionLogo/styles.d.ts.map +1 -0
  106. package/types/GlobalNav/v1/MainNavItem/index.d.ts +11 -0
  107. package/types/GlobalNav/v1/MainNavItem/index.d.ts.map +1 -0
  108. package/types/GlobalNav/v1/MainNavItem/props.d.ts +32 -0
  109. package/types/GlobalNav/v1/MainNavItem/props.d.ts.map +1 -0
  110. package/types/GlobalNav/v1/MainNavItem/styles.d.ts +19 -0
  111. package/types/GlobalNav/v1/MainNavItem/styles.d.ts.map +1 -0
  112. package/types/GlobalNav/v1/SubNav/index.d.ts +11 -0
  113. package/types/GlobalNav/v1/SubNav/index.d.ts.map +1 -0
  114. package/types/GlobalNav/v1/SubNav/props.d.ts +52 -0
  115. package/types/GlobalNav/v1/SubNav/props.d.ts.map +1 -0
  116. package/types/GlobalNav/v1/SubNav/styles.d.ts +13 -0
  117. package/types/GlobalNav/v1/SubNav/styles.d.ts.map +1 -0
  118. package/types/GlobalNav/v1/SubNavItem/index.d.ts +11 -0
  119. package/types/GlobalNav/v1/SubNavItem/index.d.ts.map +1 -0
  120. package/types/GlobalNav/v1/SubNavItem/props.d.ts +20 -0
  121. package/types/GlobalNav/v1/SubNavItem/props.d.ts.map +1 -0
  122. package/types/GlobalNav/v1/SubNavItem/styles.d.ts +18 -0
  123. package/types/GlobalNav/v1/SubNavItem/styles.d.ts.map +1 -0
  124. package/types/GlobalNav/v1/SubNavLevel/index.d.ts +11 -0
  125. package/types/GlobalNav/v1/SubNavLevel/index.d.ts.map +1 -0
  126. package/types/GlobalNav/v1/SubNavLevel/props.d.ts +45 -0
  127. package/types/GlobalNav/v1/SubNavLevel/props.d.ts.map +1 -0
  128. package/types/GlobalNav/v1/SubNavLevel/styles.d.ts +14 -0
  129. package/types/GlobalNav/v1/SubNavLevel/styles.d.ts.map +1 -0
  130. package/types/GlobalNav/v1/index.d.ts +59 -0
  131. package/types/GlobalNav/v1/index.d.ts.map +1 -0
  132. package/types/GlobalNav/v1/props.d.ts +247 -0
  133. package/types/GlobalNav/v1/props.d.ts.map +1 -0
  134. package/types/GlobalNav/v1/styles.d.ts +23 -0
  135. package/types/GlobalNav/v1/styles.d.ts.map +1 -0
  136. package/types/GlobalNav/v1/utils/getItemElementProps.d.ts +37 -0
  137. package/types/GlobalNav/v1/utils/getItemElementProps.d.ts.map +1 -0
  138. package/types/exports/a.d.ts +3 -0
  139. package/types/exports/a.d.ts.map +1 -0
@@ -0,0 +1,58 @@
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 { SubNavStyle } from './props.js'
27
+
28
+ /**
29
+ * ---
30
+ * private: true
31
+ * ---
32
+ * Generates the style object from the theme and provided additional information
33
+ * @param componentTheme The theme variable object.
34
+ * @return The final style object, which will be used in the component
35
+ */
36
+ const generateStyle = (
37
+ componentTheme: ReturnType<NewComponentTypes['SubNav']>
38
+ ): SubNavStyle => {
39
+ return {
40
+ subNav: {
41
+ label: 'subNav',
42
+ width: componentTheme.width,
43
+ flexShrink: 0,
44
+ boxSizing: 'border-box',
45
+ display: 'flex',
46
+ flexDirection: 'column',
47
+ minHeight: 0,
48
+ backgroundColor: componentTheme.backgroundColor,
49
+ color: componentTheme.textColor,
50
+ borderInlineStart: `0.0625rem solid ${componentTheme.borderColor}`,
51
+ // the panel is the end of the rail card, so it takes the card's end corners
52
+ borderStartEndRadius: 'inherit',
53
+ borderEndEndRadius: 'inherit'
54
+ }
55
+ }
56
+ }
57
+
58
+ export default generateStyle
@@ -0,0 +1,79 @@
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 { useStyleNew } from '@instructure/emotion'
26
+ import { ChevronRightInstUIIcon } from '@instructure/ui-icons'
27
+
28
+ import { getItemElementProps } from '../utils/getItemElementProps.js'
29
+ import type { SubNavItemProps } from './props.js'
30
+ import generateStyle from './styles.js'
31
+
32
+ /**
33
+ ---
34
+ private: true
35
+ id: GlobalNav.SubNavItem
36
+ ---
37
+ **/
38
+ const SubNavItem = (props: SubNavItemProps) => {
39
+ const { item, elementRef, onDrillIn } = props
40
+
41
+ const styles = useStyleNew({
42
+ generateStyle,
43
+ params: { current: !!item.current },
44
+ componentId: 'SubNavItem'
45
+ })
46
+
47
+ const { isLink, props: elementProps } = getItemElementProps(
48
+ item,
49
+ item.subNav ? (event) => onDrillIn(event, item) : undefined
50
+ )
51
+
52
+ const content = (
53
+ <>
54
+ <span css={styles?.label}>{item.label}</span>
55
+ {item.subNav && (
56
+ <span css={styles?.chevron}>
57
+ <ChevronRightInstUIIcon />
58
+ </span>
59
+ )}
60
+ </>
61
+ )
62
+
63
+ return (
64
+ <li>
65
+ {isLink ? (
66
+ <a {...elementProps} ref={elementRef} css={styles?.item}>
67
+ {content}
68
+ </a>
69
+ ) : (
70
+ <button {...elementProps} ref={elementRef} css={styles?.item}>
71
+ {content}
72
+ </button>
73
+ )}
74
+ </li>
75
+ )
76
+ }
77
+
78
+ export default SubNavItem
79
+ export { SubNavItem }
@@ -0,0 +1,48 @@
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 { MouseEvent } from 'react'
26
+
27
+ import type { ComponentStyle } from '@instructure/emotion'
28
+
29
+ import type { GlobalNavSubNavItem } from '../props.js'
30
+
31
+ type SubNavItemProps = {
32
+ /**
33
+ * The data of the item.
34
+ */
35
+ item: GlobalNavSubNavItem
36
+ /**
37
+ * Called with the link or button element of the item.
38
+ */
39
+ elementRef: (element: HTMLElement | null) => void
40
+ /**
41
+ * Called when the user activates an item with a `subNav`, after `item.onClick`.
42
+ */
43
+ onDrillIn: (event: MouseEvent<HTMLElement>, item: GlobalNavSubNavItem) => void
44
+ }
45
+
46
+ type SubNavItemStyle = ComponentStyle<'item' | 'label' | 'chevron'>
47
+
48
+ export type { SubNavItemProps, SubNavItemStyle }
@@ -0,0 +1,110 @@
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 { calcFocusOutlineStyles } from '@instructure/emotion'
26
+ import type { NewComponentTypes, SharedTokens } from '@instructure/ui-themes'
27
+ import type { SubNavItemStyle } from './props.js'
28
+
29
+ type StyleParams = {
30
+ current: boolean
31
+ }
32
+
33
+ /**
34
+ * ---
35
+ * private: true
36
+ * ---
37
+ * Generates the style object from the theme and provided additional information
38
+ * @param componentTheme The theme variable object.
39
+ * @param params Additional parameters to customize the style.
40
+ * @param sharedTokens Shared token object that stores common values for the theme.
41
+ * @return The final style object, which will be used in the component
42
+ */
43
+ const generateStyle = (
44
+ componentTheme: ReturnType<NewComponentTypes['SubNavItem']>,
45
+ params: StyleParams,
46
+ sharedTokens: SharedTokens
47
+ ): SubNavItemStyle => {
48
+ const { current } = params
49
+
50
+ return {
51
+ item: {
52
+ label: 'subNavItem',
53
+ display: 'flex',
54
+ alignItems: 'center',
55
+ gap: componentTheme.gap,
56
+ boxSizing: 'border-box',
57
+ width: '100%',
58
+ margin: 0,
59
+ padding: componentTheme.padding,
60
+ border: 'none',
61
+ borderRadius: componentTheme.borderRadius,
62
+ backgroundColor: current
63
+ ? componentTheme.selectedBackgroundColor
64
+ : componentTheme.backgroundColor,
65
+ color: current
66
+ ? componentTheme.selectedTextColor
67
+ : componentTheme.textColor,
68
+ fontFamily: componentTheme.fontFamily,
69
+ fontSize: componentTheme.fontSize,
70
+ fontWeight: componentTheme.fontWeight,
71
+ lineHeight: componentTheme.lineHeight,
72
+ textAlign: 'start',
73
+ textDecoration: 'none',
74
+ cursor: 'pointer',
75
+ ...calcFocusOutlineStyles(
76
+ {
77
+ ...sharedTokens.focusOutline,
78
+ // the `inset` token is 0, so the ring would sit outside the item, where the scrolling panel body clips it
79
+ inset: `calc(-1 * ${sharedTokens.focusOutline.width})`
80
+ },
81
+ { focusPosition: 'inset' }
82
+ ),
83
+ '&:hover': {
84
+ // a page-wide a:hover rule is more specific than the base class
85
+ textDecoration: 'none',
86
+ ...(!current && {
87
+ backgroundColor: componentTheme.hoverBackgroundColor,
88
+ color: componentTheme.hoverTextColor
89
+ })
90
+ },
91
+ ...(!current && {
92
+ '&:active': {
93
+ backgroundColor: componentTheme.activeBackgroundColor,
94
+ color: componentTheme.activeTextColor
95
+ }
96
+ })
97
+ },
98
+ label: {
99
+ label: 'subNavItem__label',
100
+ flex: 1
101
+ },
102
+ chevron: {
103
+ label: 'subNavItem__chevron',
104
+ display: 'flex',
105
+ flexShrink: 0
106
+ }
107
+ }
108
+ }
109
+
110
+ export default generateStyle
@@ -0,0 +1,193 @@
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 { useEffect, useRef } from 'react'
26
+ import type { FocusEvent, SyntheticEvent } from 'react'
27
+
28
+ import { useStyleNew } from '@instructure/emotion'
29
+ import {
30
+ CloseButton,
31
+ CondensedButton,
32
+ IconButton
33
+ } from '@instructure/ui-buttons/latest'
34
+ import { findTabbable } from '@instructure/ui-dom-utils'
35
+ import {
36
+ ChevronLeftInstUIIcon,
37
+ PanelLeftCloseInstUIIcon
38
+ } from '@instructure/ui-icons'
39
+ import { callRenderProp } from '@instructure/ui-react-utils'
40
+
41
+ import { SubNavItem } from '../SubNavItem/index.js'
42
+ import type { SubNavLevelProps } from './props.js'
43
+ import generateStyle from './styles.js'
44
+
45
+ /**
46
+ ---
47
+ private: true
48
+ id: GlobalNav.SubNavLevel
49
+ ---
50
+ **/
51
+ const SubNavLevel = (props: SubNavLevelProps) => {
52
+ const {
53
+ subNav,
54
+ titleId,
55
+ collapsible,
56
+ closeSubNavLabel,
57
+ onClose,
58
+ back,
59
+ onDrillIn,
60
+ focusIntentRef
61
+ } = props
62
+
63
+ const styles = useStyleNew({
64
+ generateStyle,
65
+ componentId: 'SubNav'
66
+ })
67
+
68
+ const itemRefs = useRef(new Map<string, HTMLElement>())
69
+ const closeRef = useRef<HTMLElement | null>(null)
70
+ const focusInsideRef = useRef(false)
71
+ const rootRef = useRef<HTMLDivElement>(null)
72
+ const bodyRef = useRef<HTMLDivElement>(null)
73
+
74
+ useEffect(() => {
75
+ const root = rootRef.current
76
+ const intent = focusIntentRef.current
77
+ const firstElement =
78
+ (findTabbable(bodyRef.current)[0] as HTMLElement | undefined) ??
79
+ closeRef.current
80
+ if (intent?.target === 'rescue' || intent?.target === 'first') {
81
+ focusIntentRef.current = undefined
82
+ firstElement?.focus()
83
+ } else if (intent?.target === 'item') {
84
+ focusIntentRef.current = undefined
85
+ ;(itemRefs.current.get(intent.itemID) ?? firstElement)?.focus()
86
+ }
87
+
88
+ return () => {
89
+ // React fires no blur event for an element it removes, so the flag still says whether focus was inside
90
+ // StrictMode runs this cleanup without removing the level, and then focus is still in it
91
+ if (
92
+ focusInsideRef.current &&
93
+ !focusIntentRef.current &&
94
+ !root?.contains(document.activeElement)
95
+ ) {
96
+ focusIntentRef.current = { target: 'rescue' }
97
+ }
98
+ }
99
+ }, [focusIntentRef])
100
+
101
+ const handleBlur = (event: FocusEvent<HTMLDivElement>) => {
102
+ focusInsideRef.current = event.currentTarget.contains(
103
+ event.relatedTarget as Node | null
104
+ )
105
+ }
106
+
107
+ const handleCloseRef = (element: Element | null) => {
108
+ closeRef.current = element as HTMLElement | null
109
+ }
110
+
111
+ const items = subNav.items ?? []
112
+
113
+ return (
114
+ <div
115
+ ref={rootRef}
116
+ css={styles?.level}
117
+ onFocus={() => {
118
+ focusInsideRef.current = true
119
+ }}
120
+ onBlur={handleBlur}
121
+ >
122
+ <div css={styles?.header}>
123
+ {back && (
124
+ <span css={styles?.back}>
125
+ <CondensedButton
126
+ color="secondary"
127
+ size="small"
128
+ // the design shows it as plain text, without a hover background
129
+ themeOverride={{ secondaryGhostHoverBackground: 'transparent' }}
130
+ renderIcon={<ChevronLeftInstUIIcon />}
131
+ aria-label={back.label}
132
+ // the cast is safe: the click event is typed for ViewProps, but React passes the DOM button's event
133
+ onClick={(event) =>
134
+ back.onClick(event as unknown as SyntheticEvent)
135
+ }
136
+ >
137
+ {back.title}
138
+ </CondensedButton>
139
+ </span>
140
+ )}
141
+ {collapsible ? (
142
+ <IconButton
143
+ screenReaderLabel={closeSubNavLabel}
144
+ renderIcon={PanelLeftCloseInstUIIcon}
145
+ withBackground={false}
146
+ withBorder={false}
147
+ size="small"
148
+ elementRef={handleCloseRef}
149
+ // the cast is safe: the click event is typed for ViewProps, but React passes the DOM button's event
150
+ onClick={(event) => onClose(event as unknown as SyntheticEvent)}
151
+ />
152
+ ) : (
153
+ <CloseButton
154
+ screenReaderLabel={closeSubNavLabel}
155
+ size="small"
156
+ elementRef={handleCloseRef}
157
+ // the cast is safe: the click event is typed for ViewProps, but React passes the DOM button's event
158
+ onClick={(event) => onClose(event as unknown as SyntheticEvent)}
159
+ />
160
+ )}
161
+ </div>
162
+ <h2 id={titleId} css={styles?.title}>
163
+ {subNav.title}
164
+ </h2>
165
+ <div css={styles?.divider} />
166
+ <div ref={bodyRef} css={styles?.body}>
167
+ {subNav.renderContent !== undefined
168
+ ? callRenderProp(subNav.renderContent)
169
+ : items.length > 0 && (
170
+ <ul css={styles?.items}>
171
+ {items.map((item) => (
172
+ <SubNavItem
173
+ key={item.itemID}
174
+ item={item}
175
+ elementRef={(element) => {
176
+ if (element) {
177
+ itemRefs.current.set(item.itemID, element)
178
+ } else {
179
+ itemRefs.current.delete(item.itemID)
180
+ }
181
+ }}
182
+ onDrillIn={onDrillIn}
183
+ />
184
+ ))}
185
+ </ul>
186
+ )}
187
+ </div>
188
+ </div>
189
+ )
190
+ }
191
+
192
+ export default SubNavLevel
193
+ export { SubNavLevel }
@@ -0,0 +1,75 @@
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 { MouseEvent, MutableRefObject, SyntheticEvent } from 'react'
26
+
27
+ import type { ComponentStyle } from '@instructure/emotion'
28
+
29
+ import type { GlobalNavSubNav, GlobalNavSubNavItem } from '../props.js'
30
+ import type { FocusIntent } from '../SubNav/props.js'
31
+
32
+ type SubNavLevelProps = {
33
+ /**
34
+ * The data of the level.
35
+ */
36
+ subNav: GlobalNavSubNav
37
+ /**
38
+ * The id of the title.
39
+ */
40
+ titleId: string
41
+ /**
42
+ * Whether closing the SubNav leaves the strip, which the close handle shows with its icon.
43
+ */
44
+ collapsible: boolean
45
+ /**
46
+ * Screen reader text of the close handle.
47
+ */
48
+ closeSubNavLabel: string
49
+ /**
50
+ * Called when the user clicks the close handle.
51
+ */
52
+ onClose: (event: SyntheticEvent) => void
53
+ /**
54
+ * The back button of a deeper level: the title of the level it returns to, its screen reader text and its click handler.
55
+ */
56
+ back?: {
57
+ title: string
58
+ label: string
59
+ onClick: (event: SyntheticEvent) => void
60
+ }
61
+ /**
62
+ * Called when the user activates an item with a `subNav`.
63
+ */
64
+ onDrillIn: (event: MouseEvent<HTMLElement>, item: GlobalNavSubNavItem) => void
65
+ /**
66
+ * The focus move that the user asked for, shared with GlobalNav.
67
+ */
68
+ focusIntentRef: MutableRefObject<FocusIntent | undefined>
69
+ }
70
+
71
+ type SubNavLevelStyle = ComponentStyle<
72
+ 'level' | 'header' | 'back' | 'title' | 'divider' | 'body' | 'items'
73
+ >
74
+
75
+ export type { SubNavLevelProps, SubNavLevelStyle }
@@ -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 { NewComponentTypes, SharedTokens } from '@instructure/ui-themes'
26
+ import type { SubNavLevelStyle } from './props.js'
27
+
28
+ /**
29
+ * ---
30
+ * private: true
31
+ * ---
32
+ * Generates the style object from the theme and provided additional information
33
+ * @param componentTheme The theme variable object.
34
+ * @param sharedTokens Shared token object that stores common values for the theme.
35
+ * @return The final style object, which will be used in the component
36
+ */
37
+ const generateStyle = (
38
+ componentTheme: ReturnType<NewComponentTypes['SubNav']>,
39
+ _params: undefined,
40
+ sharedTokens: SharedTokens
41
+ ): SubNavLevelStyle => {
42
+ const focusRingSize = `calc(${sharedTokens.focusOutline.width} + ${sharedTokens.focusOutline.offset})`
43
+
44
+ return {
45
+ level: {
46
+ label: 'subNavLevel',
47
+ display: 'flex',
48
+ flexDirection: 'column',
49
+ flex: 1,
50
+ minHeight: 0,
51
+ boxSizing: 'border-box',
52
+ gap: componentTheme.gap,
53
+ padding: componentTheme.padding,
54
+ // GlobalNav sets the variable, so the close handle lines up with the rail's collapse button
55
+ paddingTop: `var(--globalNav-collapseButtonTop, ${componentTheme.padding})`
56
+ },
57
+ header: {
58
+ label: 'subNavLevel__header',
59
+ display: 'flex',
60
+ alignItems: 'center',
61
+ justifyContent: 'flex-end'
62
+ },
63
+ back: {
64
+ label: 'subNavLevel__back',
65
+ // pushes the close handle to the end, and lets a long parent title shrink
66
+ marginInlineEnd: 'auto',
67
+ minWidth: 0
68
+ },
69
+ title: {
70
+ label: 'subNavLevel__title',
71
+ margin: 0,
72
+ fontFamily: componentTheme.titleFontFamily,
73
+ fontSize: componentTheme.titleFontSize,
74
+ fontWeight: componentTheme.titleFontWeight,
75
+ lineHeight: componentTheme.titleLineHeight
76
+ },
77
+ divider: {
78
+ label: 'subNavLevel__divider',
79
+ // SubNav has no divider width token
80
+ borderTop: `0.0625rem solid ${componentTheme.strokeColor}`
81
+ },
82
+ body: {
83
+ label: 'subNavLevel__body',
84
+ flex: 1,
85
+ minHeight: 0,
86
+ overflowY: 'auto',
87
+ // the scroll container clips focus rings that reach past its edges
88
+ padding: focusRingSize,
89
+ margin: `calc(-1 * ${focusRingSize})`
90
+ },
91
+ items: {
92
+ label: 'subNavLevel__items',
93
+ display: 'flex',
94
+ flexDirection: 'column',
95
+ gap: componentTheme.navItemsGap,
96
+ listStyle: 'none',
97
+ margin: 0,
98
+ padding: 0
99
+ }
100
+ }
101
+ }
102
+
103
+ export default generateStyle