@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,117 @@
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
+ /**
26
+ * ---
27
+ * private: true
28
+ * ---
29
+ * Generates the style object from the theme and provided additional information
30
+ * @param componentTheme The theme variable object.
31
+ * @param params Additional parameters to customize the style.
32
+ * @return The final style object, which will be used in the component
33
+ */
34
+ const generateStyle = (componentTheme, params) => {
35
+ const {
36
+ collapsed,
37
+ current,
38
+ open
39
+ } = params;
40
+ return {
41
+ item: {
42
+ label: 'mainNavItem',
43
+ display: 'flex',
44
+ alignItems: 'center',
45
+ // MainNavItem has no gap token
46
+ gap: componentTheme.horizontalPadding,
47
+ boxSizing: 'border-box',
48
+ width: collapsed ? componentTheme.minimizedItemSize : '100%',
49
+ height: collapsed ? componentTheme.minimizedItemSize : undefined,
50
+ justifyContent: collapsed ? 'center' : undefined,
51
+ margin: 0,
52
+ padding: collapsed ? 0 : `${componentTheme.verticalPadding} ${componentTheme.horizontalPadding}`,
53
+ border: 'none',
54
+ borderRadius: componentTheme.borderRadius,
55
+ backgroundColor: current ? componentTheme.currentBackgroundColor : open ? componentTheme.activeBackgroundColor : componentTheme.backgroundColor,
56
+ color: current ? componentTheme.currentTextColor : componentTheme.fontColor,
57
+ fontFamily: componentTheme.fontFamily,
58
+ fontSize: componentTheme.fontSize,
59
+ fontWeight: componentTheme.fontWeight,
60
+ lineHeight: componentTheme.lineHeight,
61
+ textAlign: 'start',
62
+ textDecoration: componentTheme.linkTextDecoration,
63
+ cursor: 'pointer',
64
+ '&:hover': {
65
+ // a page-wide a:hover rule is more specific than the base class
66
+ textDecoration: componentTheme.linkTextDecoration,
67
+ ...(!current && !open && {
68
+ backgroundColor: componentTheme.hoverBackgroundColor
69
+ })
70
+ },
71
+ ...(!current && !open && {
72
+ '&:active': {
73
+ backgroundColor: componentTheme.activeBackgroundColor
74
+ }
75
+ }),
76
+ // the other GlobalNav focus rings animate with calcFocusOutlineStyles,
77
+ // which can't take these tokens, because each theme colors a different ring
78
+ transition: 'box-shadow 0.2s',
79
+ // same focus ring as SideNavBarItem, which has the same focus tokens
80
+ '&:focus': {
81
+ outline: 'none',
82
+ boxShadow: current ? `inset 0 0 0 0.125rem ${componentTheme.selectedOuterFocusOutlineColor}, inset 0 0 0 0.25rem ${componentTheme.selectedInnerFocusOutlineColor}` : `inset 0 0 0 0.125rem ${componentTheme.outerFocusOutlineColor}, inset 0 0 0 0.25rem ${componentTheme.innerFocusOutlineColor}`
83
+ }
84
+ },
85
+ icon: {
86
+ label: 'mainNavItem__icon',
87
+ position: 'relative',
88
+ display: 'flex',
89
+ alignItems: 'center',
90
+ flexShrink: 0,
91
+ height: componentTheme.iconWrapperHeight
92
+ },
93
+ badge: {
94
+ label: 'mainNavItem__badge',
95
+ position: 'absolute',
96
+ top: 0,
97
+ // the badge starts at the icon's center, so a longer count grows away from the icon
98
+ insetInlineStart: '50%',
99
+ // flex, so the item's line height doesn't push the badge down
100
+ display: 'flex'
101
+ },
102
+ label: {
103
+ label: 'mainNavItem__label',
104
+ flex: 1
105
+ },
106
+ chevron: {
107
+ label: 'mainNavItem__chevron',
108
+ display: 'flex',
109
+ flexShrink: 0
110
+ },
111
+ tooltipTrigger: {
112
+ label: 'mainNavItem__tooltipTrigger',
113
+ display: 'block'
114
+ }
115
+ };
116
+ };
117
+ export default generateStyle;
@@ -0,0 +1,121 @@
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 { useState } from 'react';
26
+ import { useStyleNew } from '@instructure/emotion';
27
+ import { SubNavLevel } from '../SubNavLevel/index.js';
28
+ import generateStyle from './styles.js';
29
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
30
+ // the itemIDs of the levels to open so the deepest current item shows, or undefined without one
31
+ const findCurrentPath = subNav => {
32
+ const items = subNav.items ?? [];
33
+ for (const item of items) {
34
+ if (item.subNav) {
35
+ const deeperPath = findCurrentPath(item.subNav);
36
+ if (deeperPath) return [item.itemID, ...deeperPath];
37
+ }
38
+ }
39
+ return items.some(item => item.current) ? [] : undefined;
40
+ };
41
+
42
+ // stops at an itemID that the latest data no longer has, so the deepest level that still exists shows
43
+ const resolveLevels = (subNav, path) => {
44
+ const levels = [{
45
+ subNav
46
+ }];
47
+ for (const itemID of path) {
48
+ const parent = levels[levels.length - 1].subNav;
49
+ const item = parent.items?.find(i => i.itemID === itemID);
50
+ if (!item?.subNav) break;
51
+ levels.push({
52
+ subNav: item.subNav,
53
+ itemID
54
+ });
55
+ }
56
+ return levels;
57
+ };
58
+
59
+ /**
60
+ ---
61
+ private: true
62
+ id: GlobalNav.SubNav
63
+ ---
64
+ **/
65
+ const SubNav = props => {
66
+ const {
67
+ subNav,
68
+ subNavId,
69
+ titleId,
70
+ collapsible,
71
+ closeSubNavLabel,
72
+ backLabel,
73
+ onClose,
74
+ focusIntentRef
75
+ } = props;
76
+ const styles = useStyleNew({
77
+ generateStyle,
78
+ componentId: 'SubNav'
79
+ });
80
+ const [path, setPath] = useState(() => findCurrentPath(subNav) ?? []);
81
+ const levels = resolveLevels(subNav, path);
82
+ const resolvedPath = levels.slice(1).map(level => level.itemID);
83
+ const level = levels[levels.length - 1];
84
+ const parent = levels.length > 1 ? levels[levels.length - 2] : undefined;
85
+ const handleDrillIn = (_event, item) => {
86
+ focusIntentRef.current = {
87
+ target: 'first'
88
+ };
89
+ setPath([...resolvedPath, item.itemID]);
90
+ };
91
+ const handleBack = _event => {
92
+ focusIntentRef.current = {
93
+ target: 'item',
94
+ itemID: resolvedPath[resolvedPath.length - 1]
95
+ };
96
+ setPath(resolvedPath.slice(0, -1));
97
+ };
98
+ return _jsx("nav", {
99
+ id: subNavId,
100
+ "aria-labelledby": titleId,
101
+ css: styles?.subNav,
102
+ children: _jsx(SubNavLevel
103
+ // a new level remounts, which resets its refs, focus and scroll position
104
+ , {
105
+ subNav: level.subNav,
106
+ titleId: titleId,
107
+ collapsible: collapsible,
108
+ closeSubNavLabel: closeSubNavLabel,
109
+ onClose: onClose,
110
+ back: parent && {
111
+ title: parent.subNav.title,
112
+ label: backLabel(parent.subNav.title),
113
+ onClick: handleBack
114
+ },
115
+ onDrillIn: handleDrillIn,
116
+ focusIntentRef: focusIntentRef
117
+ }, JSON.stringify(resolvedPath))
118
+ });
119
+ };
120
+ export default SubNav;
121
+ export { SubNav };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,52 @@
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
+ /**
26
+ * ---
27
+ * private: true
28
+ * ---
29
+ * Generates the style object from the theme and provided additional information
30
+ * @param componentTheme The theme variable object.
31
+ * @return The final style object, which will be used in the component
32
+ */
33
+ const generateStyle = componentTheme => {
34
+ return {
35
+ subNav: {
36
+ label: 'subNav',
37
+ width: componentTheme.width,
38
+ flexShrink: 0,
39
+ boxSizing: 'border-box',
40
+ display: 'flex',
41
+ flexDirection: 'column',
42
+ minHeight: 0,
43
+ backgroundColor: componentTheme.backgroundColor,
44
+ color: componentTheme.textColor,
45
+ borderInlineStart: `0.0625rem solid ${componentTheme.borderColor}`,
46
+ // the panel is the end of the rail card, so it takes the card's end corners
47
+ borderStartEndRadius: 'inherit',
48
+ borderEndEndRadius: 'inherit'
49
+ }
50
+ };
51
+ };
52
+ export default generateStyle;
@@ -0,0 +1,78 @@
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
+ import { getItemElementProps } from '../utils/getItemElementProps.js';
28
+ import generateStyle from './styles.js';
29
+
30
+ /**
31
+ ---
32
+ private: true
33
+ id: GlobalNav.SubNavItem
34
+ ---
35
+ **/
36
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
37
+ const SubNavItem = props => {
38
+ const {
39
+ item,
40
+ elementRef,
41
+ onDrillIn
42
+ } = props;
43
+ const styles = useStyleNew({
44
+ generateStyle,
45
+ params: {
46
+ current: !!item.current
47
+ },
48
+ componentId: 'SubNavItem'
49
+ });
50
+ const {
51
+ isLink,
52
+ props: elementProps
53
+ } = getItemElementProps(item, item.subNav ? event => onDrillIn(event, item) : undefined);
54
+ const content = _jsxs(_Fragment, {
55
+ children: [_jsx("span", {
56
+ css: styles?.label,
57
+ children: item.label
58
+ }), item.subNav && _jsx("span", {
59
+ css: styles?.chevron,
60
+ children: _jsx(ChevronRightInstUIIcon, {})
61
+ })]
62
+ });
63
+ return _jsx("li", {
64
+ children: isLink ? _jsx("a", {
65
+ ...elementProps,
66
+ ref: elementRef,
67
+ css: styles?.item,
68
+ children: content
69
+ }) : _jsx("button", {
70
+ ...elementProps,
71
+ ref: elementRef,
72
+ css: styles?.item,
73
+ children: content
74
+ })
75
+ });
76
+ };
77
+ export default SubNavItem;
78
+ export { SubNavItem };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,94 @@
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
+ /**
27
+ * ---
28
+ * private: true
29
+ * ---
30
+ * Generates the style object from the theme and provided additional information
31
+ * @param componentTheme The theme variable object.
32
+ * @param params Additional parameters to customize the style.
33
+ * @param sharedTokens Shared token object that stores common values for the theme.
34
+ * @return The final style object, which will be used in the component
35
+ */
36
+ const generateStyle = (componentTheme, params, sharedTokens) => {
37
+ const {
38
+ current
39
+ } = params;
40
+ return {
41
+ item: {
42
+ label: 'subNavItem',
43
+ display: 'flex',
44
+ alignItems: 'center',
45
+ gap: componentTheme.gap,
46
+ boxSizing: 'border-box',
47
+ width: '100%',
48
+ margin: 0,
49
+ padding: componentTheme.padding,
50
+ border: 'none',
51
+ borderRadius: componentTheme.borderRadius,
52
+ backgroundColor: current ? componentTheme.selectedBackgroundColor : componentTheme.backgroundColor,
53
+ color: current ? componentTheme.selectedTextColor : componentTheme.textColor,
54
+ fontFamily: componentTheme.fontFamily,
55
+ fontSize: componentTheme.fontSize,
56
+ fontWeight: componentTheme.fontWeight,
57
+ lineHeight: componentTheme.lineHeight,
58
+ textAlign: 'start',
59
+ textDecoration: 'none',
60
+ cursor: 'pointer',
61
+ ...calcFocusOutlineStyles({
62
+ ...sharedTokens.focusOutline,
63
+ // the `inset` token is 0, so the ring would sit outside the item, where the scrolling panel body clips it
64
+ inset: `calc(-1 * ${sharedTokens.focusOutline.width})`
65
+ }, {
66
+ focusPosition: 'inset'
67
+ }),
68
+ '&:hover': {
69
+ // a page-wide a:hover rule is more specific than the base class
70
+ textDecoration: 'none',
71
+ ...(!current && {
72
+ backgroundColor: componentTheme.hoverBackgroundColor,
73
+ color: componentTheme.hoverTextColor
74
+ })
75
+ },
76
+ ...(!current && {
77
+ '&:active': {
78
+ backgroundColor: componentTheme.activeBackgroundColor,
79
+ color: componentTheme.activeTextColor
80
+ }
81
+ })
82
+ },
83
+ label: {
84
+ label: 'subNavItem__label',
85
+ flex: 1
86
+ },
87
+ chevron: {
88
+ label: 'subNavItem__chevron',
89
+ display: 'flex',
90
+ flexShrink: 0
91
+ }
92
+ };
93
+ };
94
+ export default generateStyle;
@@ -0,0 +1,160 @@
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 { useStyleNew } from '@instructure/emotion';
27
+ import { CloseButton, CondensedButton, IconButton } from '@instructure/ui-buttons/latest';
28
+ import { findTabbable } from '@instructure/ui-dom-utils';
29
+ import { ChevronLeftInstUIIcon, PanelLeftCloseInstUIIcon } from '@instructure/ui-icons';
30
+ import { callRenderProp } from '@instructure/ui-react-utils';
31
+ import { SubNavItem } from '../SubNavItem/index.js';
32
+ import generateStyle from './styles.js';
33
+
34
+ /**
35
+ ---
36
+ private: true
37
+ id: GlobalNav.SubNavLevel
38
+ ---
39
+ **/
40
+ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
41
+ const SubNavLevel = props => {
42
+ const {
43
+ subNav,
44
+ titleId,
45
+ collapsible,
46
+ closeSubNavLabel,
47
+ onClose,
48
+ back,
49
+ onDrillIn,
50
+ focusIntentRef
51
+ } = props;
52
+ const styles = useStyleNew({
53
+ generateStyle,
54
+ componentId: 'SubNav'
55
+ });
56
+ const itemRefs = useRef(new Map());
57
+ const closeRef = useRef(null);
58
+ const focusInsideRef = useRef(false);
59
+ const rootRef = useRef(null);
60
+ const bodyRef = useRef(null);
61
+ useEffect(() => {
62
+ const root = rootRef.current;
63
+ const intent = focusIntentRef.current;
64
+ const firstElement = findTabbable(bodyRef.current)[0] ?? closeRef.current;
65
+ if (intent?.target === 'rescue' || intent?.target === 'first') {
66
+ focusIntentRef.current = undefined;
67
+ firstElement?.focus();
68
+ } else if (intent?.target === 'item') {
69
+ focusIntentRef.current = undefined;
70
+ (itemRefs.current.get(intent.itemID) ?? firstElement)?.focus();
71
+ }
72
+ return () => {
73
+ // React fires no blur event for an element it removes, so the flag still says whether focus was inside
74
+ // StrictMode runs this cleanup without removing the level, and then focus is still in it
75
+ if (focusInsideRef.current && !focusIntentRef.current && !root?.contains(document.activeElement)) {
76
+ focusIntentRef.current = {
77
+ target: 'rescue'
78
+ };
79
+ }
80
+ };
81
+ }, [focusIntentRef]);
82
+ const handleBlur = event => {
83
+ focusInsideRef.current = event.currentTarget.contains(event.relatedTarget);
84
+ };
85
+ const handleCloseRef = element => {
86
+ closeRef.current = element;
87
+ };
88
+ const items = subNav.items ?? [];
89
+ return _jsxs("div", {
90
+ ref: rootRef,
91
+ css: styles?.level,
92
+ onFocus: () => {
93
+ focusInsideRef.current = true;
94
+ },
95
+ onBlur: handleBlur,
96
+ children: [_jsxs("div", {
97
+ css: styles?.header,
98
+ children: [back && _jsx("span", {
99
+ css: styles?.back,
100
+ children: _jsx(CondensedButton, {
101
+ color: "secondary",
102
+ size: "small"
103
+ // the design shows it as plain text, without a hover background
104
+ ,
105
+ themeOverride: {
106
+ secondaryGhostHoverBackground: 'transparent'
107
+ },
108
+ renderIcon: _jsx(ChevronLeftInstUIIcon, {}),
109
+ "aria-label": back.label
110
+ // the cast is safe: the click event is typed for ViewProps, but React passes the DOM button's event
111
+ ,
112
+ onClick: event => back.onClick(event),
113
+ children: back.title
114
+ })
115
+ }), collapsible ? _jsx(IconButton, {
116
+ screenReaderLabel: closeSubNavLabel,
117
+ renderIcon: PanelLeftCloseInstUIIcon,
118
+ withBackground: false,
119
+ withBorder: false,
120
+ size: "small",
121
+ elementRef: handleCloseRef
122
+ // the cast is safe: the click event is typed for ViewProps, but React passes the DOM button's event
123
+ ,
124
+ onClick: event => onClose(event)
125
+ }) : _jsx(CloseButton, {
126
+ screenReaderLabel: closeSubNavLabel,
127
+ size: "small",
128
+ elementRef: handleCloseRef
129
+ // the cast is safe: the click event is typed for ViewProps, but React passes the DOM button's event
130
+ ,
131
+ onClick: event => onClose(event)
132
+ })]
133
+ }), _jsx("h2", {
134
+ id: titleId,
135
+ css: styles?.title,
136
+ children: subNav.title
137
+ }), _jsx("div", {
138
+ css: styles?.divider
139
+ }), _jsx("div", {
140
+ ref: bodyRef,
141
+ css: styles?.body,
142
+ children: subNav.renderContent !== undefined ? callRenderProp(subNav.renderContent) : items.length > 0 && _jsx("ul", {
143
+ css: styles?.items,
144
+ children: items.map(item => _jsx(SubNavItem, {
145
+ item: item,
146
+ elementRef: element => {
147
+ if (element) {
148
+ itemRefs.current.set(item.itemID, element);
149
+ } else {
150
+ itemRefs.current.delete(item.itemID);
151
+ }
152
+ },
153
+ onDrillIn: onDrillIn
154
+ }, item.itemID))
155
+ })
156
+ })]
157
+ });
158
+ };
159
+ export default SubNavLevel;
160
+ export { SubNavLevel };
@@ -0,0 +1 @@
1
+ export {};