@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,228 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = exports.GlobalNav = void 0;
8
+ var _react = require("react");
9
+ var _emotion = require("@instructure/emotion");
10
+ var _uiReactUtils = require("@instructure/ui-react-utils");
11
+ var _props = require("./props.js");
12
+ var _styles = _interopRequireWildcard(require("./styles.js"));
13
+ var _index = require("./CollapseButton/index.js");
14
+ var _index2 = require("./CollapsedSubNav/index.js");
15
+ var _index3 = require("./InstitutionLogo/index.js");
16
+ var _index4 = require("./MainNavItem/index.js");
17
+ var _index5 = require("./SubNav/index.js");
18
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
19
+ /*
20
+ * The MIT License (MIT)
21
+ *
22
+ * Copyright (c) 2015 - present Instructure, Inc.
23
+ *
24
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
25
+ * of this software and associated documentation files (the "Software"), to deal
26
+ * in the Software without restriction, including without limitation the rights
27
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
28
+ * copies of the Software, and to permit persons to whom the Software is
29
+ * furnished to do so, subject to the following conditions:
30
+ *
31
+ * The above copyright notice and this permission notice shall be included in all
32
+ * copies or substantial portions of the Software.
33
+ *
34
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40
+ * SOFTWARE.
41
+ */
42
+
43
+ // React 18 warns about useLayoutEffect on the server, where there is no layout to measure
44
+ const useClientLayoutEffect = typeof window === 'undefined' ? _react.useEffect : _react.useLayoutEffect;
45
+
46
+ /**
47
+ ---
48
+ category: components
49
+ isWIP: true
50
+ ---
51
+ **/
52
+ const GlobalNav = exports.GlobalNav = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
53
+ const {
54
+ label,
55
+ collapsed,
56
+ onCollapse,
57
+ collapseLabel,
58
+ expandLabel,
59
+ backLabel,
60
+ closeSubNavLabel,
61
+ collapseSubNavLabel,
62
+ expandSubNavLabel,
63
+ openSubNav,
64
+ onSubNavChange,
65
+ items,
66
+ logo,
67
+ themeOverride
68
+ } = props;
69
+ const openItem = items.find(item => item.itemID === openSubNav && item.subNav);
70
+ const styles = (0, _emotion.useStyleNew)({
71
+ generateStyle: _styles.default,
72
+ themeOverride,
73
+ params: {
74
+ collapsed,
75
+ subNavOpen: !!openItem
76
+ },
77
+ componentId: 'GlobalNav',
78
+ displayName: 'GlobalNav'
79
+ });
80
+
81
+ // MainNav is a separate token set, and useStyleNew reads one set per call
82
+ const mainNavStyles = (0, _emotion.useStyleNew)({
83
+ generateStyle: _styles.generateMainNavStyle,
84
+ params: {
85
+ collapsed
86
+ },
87
+ componentId: 'MainNav'
88
+ });
89
+ const getId = (0, _uiReactUtils.useDeterministicId)('GlobalNav');
90
+ const subNavId = getId('GlobalNav-subNav');
91
+ const titleId = getId('GlobalNav-subNavTitle');
92
+ const focusIntentRef = (0, _react.useRef)();
93
+ const triggerRefs = (0, _react.useRef)(new Map());
94
+ const renderedSubNavRef = (0, _react.useRef)();
95
+ const railRef = (0, _react.useRef)(null);
96
+ const headerRef = (0, _react.useRef)(null);
97
+ const collapseButtonRef = (0, _react.useRef)(null);
98
+
99
+ // the SubNav buttons line up with the rail's collapse button, whose position depends on the logo
100
+ const updateCollapseButtonTop = () => {
101
+ const rail = railRef.current;
102
+ const button = collapseButtonRef.current;
103
+ if (!rail || !button) return;
104
+ const buttonRect = button.getBoundingClientRect();
105
+ const top = buttonRect.top - rail.getBoundingClientRect().top - rail.clientTop;
106
+ rail.style.setProperty('--globalNav-collapseButtonTop', `${top}px`);
107
+ rail.style.setProperty('--globalNav-collapseButtonHeight', `${buttonRect.height}px`);
108
+ };
109
+
110
+ // after every render, because the theme and the collapsed state move the button,
111
+ // and before paint, so a SubNav that is open on page load doesn't jump
112
+ useClientLayoutEffect(updateCollapseButtonTop);
113
+
114
+ // the header also resizes without a render, for example when the logo image loads
115
+ (0, _react.useEffect)(() => {
116
+ const header = headerRef.current;
117
+ if (!header || typeof ResizeObserver === 'undefined') return;
118
+ const observer = new ResizeObserver(updateCollapseButtonTop);
119
+ observer.observe(header);
120
+ return () => observer.disconnect();
121
+ }, []);
122
+
123
+ // the SubNav of the current page collapses to a strip, other SubNavs close completely
124
+ const currentSectionItem = items.find(item => item.current && item.subNav);
125
+ const collapsible = !!openItem && openItem.itemID === currentSectionItem?.itemID;
126
+ (0, _react.useEffect)(() => {
127
+ const intent = focusIntentRef.current;
128
+ // an intent lives for one commit, so a change that the app ignores doesn't move focus later
129
+ focusIntentRef.current = undefined;
130
+ const closedID = renderedSubNavRef.current;
131
+ renderedSubNavRef.current = openItem?.itemID;
132
+ if (!openItem && closedID !== undefined && (intent?.target === 'trigger' || intent?.target === 'rescue')) {
133
+ triggerRefs.current.get(closedID)?.focus();
134
+ }
135
+ });
136
+ const handleItemActivate = (event, item) => {
137
+ if (item.subNav) {
138
+ const next = openSubNav === item.itemID ? undefined : item.itemID;
139
+ focusIntentRef.current = next ? {
140
+ target: 'first'
141
+ } : {
142
+ target: 'trigger'
143
+ };
144
+ onSubNavChange?.(event, next);
145
+ } else if (openItem &&
146
+ // a link opened in a new tab or window keeps the SubNav open
147
+ !(event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)) {
148
+ focusIntentRef.current = {
149
+ target: 'none'
150
+ };
151
+ onSubNavChange?.(event, undefined);
152
+ }
153
+ };
154
+ const handleSubNavClose = event => {
155
+ focusIntentRef.current = {
156
+ target: 'trigger'
157
+ };
158
+ onSubNavChange?.(event, undefined);
159
+ };
160
+ const handleSubNavExpand = event => {
161
+ if (!currentSectionItem) return;
162
+ focusIntentRef.current = {
163
+ target: 'first'
164
+ };
165
+ onSubNavChange?.(event, currentSectionItem.itemID);
166
+ };
167
+ return (0, _jsxRuntime.jsx)("nav", {
168
+ ...(0, _uiReactUtils.omitProps)(props, _props.allowedProps),
169
+ ref: ref,
170
+ "aria-label": label,
171
+ css: styles?.globalNav,
172
+ children: (0, _jsxRuntime.jsxs)("div", {
173
+ ref: railRef,
174
+ css: styles?.rail,
175
+ children: [(0, _jsxRuntime.jsxs)("div", {
176
+ css: mainNavStyles?.mainNav,
177
+ children: [(0, _jsxRuntime.jsxs)("div", {
178
+ ref: headerRef,
179
+ css: mainNavStyles?.header,
180
+ children: [(0, _jsxRuntime.jsx)(_index3.InstitutionLogo, {
181
+ logo: logo,
182
+ collapsed: collapsed
183
+ }), (0, _jsxRuntime.jsx)(_index.CollapseButton, {
184
+ collapsed: collapsed,
185
+ collapseLabel: collapseLabel,
186
+ expandLabel: expandLabel,
187
+ onCollapse: onCollapse,
188
+ elementRef: element => {
189
+ collapseButtonRef.current = element;
190
+ }
191
+ })]
192
+ }), !collapsed && (0, _jsxRuntime.jsx)("div", {
193
+ css: mainNavStyles?.divider
194
+ }), (0, _jsxRuntime.jsx)("ul", {
195
+ css: mainNavStyles?.items,
196
+ children: items.map(item => (0, _jsxRuntime.jsx)(_index4.MainNavItem, {
197
+ item: item,
198
+ collapsed: collapsed,
199
+ open: openSubNav === item.itemID,
200
+ subNavId: openItem?.itemID === item.itemID ? subNavId : undefined,
201
+ onActivate: handleItemActivate,
202
+ elementRef: element => {
203
+ if (element) {
204
+ triggerRefs.current.set(item.itemID, element);
205
+ } else {
206
+ triggerRefs.current.delete(item.itemID);
207
+ }
208
+ }
209
+ }, item.itemID))
210
+ })]
211
+ }), openItem?.subNav ? (0, _jsxRuntime.jsx)(_index5.SubNav, {
212
+ subNav: openItem.subNav,
213
+ subNavId: subNavId,
214
+ titleId: titleId,
215
+ collapsible: collapsible,
216
+ closeSubNavLabel: collapsible ? collapseSubNavLabel ?? closeSubNavLabel : closeSubNavLabel,
217
+ backLabel: backLabel,
218
+ onClose: handleSubNavClose,
219
+ focusIntentRef: focusIntentRef
220
+ }, openItem.itemID) : currentSectionItem && (0, _jsxRuntime.jsx)(_index2.CollapsedSubNav, {
221
+ label: expandSubNavLabel,
222
+ onExpand: handleSubNavExpand
223
+ })]
224
+ })
225
+ });
226
+ });
227
+ GlobalNav.displayName = 'GlobalNav';
228
+ var _default = exports.default = GlobalNav;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.allowedProps = void 0;
7
+ /*
8
+ * The MIT License (MIT)
9
+ *
10
+ * Copyright (c) 2015 - present Instructure, Inc.
11
+ *
12
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ * of this software and associated documentation files (the "Software"), to deal
14
+ * in the Software without restriction, including without limitation the rights
15
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ * copies of the Software, and to permit persons to whom the Software is
17
+ * furnished to do so, subject to the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be included in all
20
+ * copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ * SOFTWARE.
29
+ */
30
+
31
+ // a SubNav shows either items or custom content, never both
32
+
33
+ const allowedProps = exports.allowedProps = ['label', 'collapsed', 'onCollapse', 'collapseLabel', 'expandLabel', 'backLabel', 'closeSubNavLabel', 'collapseSubNavLabel', 'expandSubNavLabel', 'openSubNav', 'onSubNavChange', 'items', 'logo', 'account'];
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.generateMainNavStyle = exports.default = void 0;
7
+ var _uiThemes = require("@instructure/ui-themes");
8
+ /*
9
+ * The MIT License (MIT)
10
+ *
11
+ * Copyright (c) 2015 - present Instructure, Inc.
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ * copies of the Software, and to permit persons to whom the Software is
18
+ * furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all
21
+ * copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ * SOFTWARE.
30
+ */
31
+
32
+ /**
33
+ * ---
34
+ * private: true
35
+ * ---
36
+ * Generates the style object from the theme and provided additional information
37
+ * @param componentTheme The theme variable object.
38
+ * @param params Additional parameters to customize the style.
39
+ * @return The final style object, which will be used in the component
40
+ */
41
+ const generateStyle = (componentTheme, params) => {
42
+ const {
43
+ collapsed,
44
+ subNavOpen
45
+ } = params;
46
+ return {
47
+ globalNav: {
48
+ label: 'globalNav',
49
+ display: 'flex',
50
+ // fixed while no SubNav is open, so showing the strip doesn't move the page
51
+ width: subNavOpen ? 'fit-content' : collapsed ? componentTheme.minimizedminWidth : componentTheme.minWidth,
52
+ flexShrink: 0,
53
+ height: '100%',
54
+ boxSizing: 'border-box',
55
+ // the width tokens include the outer gap, which is this padding
56
+ padding: collapsed ? componentTheme.minimizedMargin : componentTheme.margin
57
+ },
58
+ rail: {
59
+ label: 'globalNav__rail',
60
+ display: 'flex',
61
+ // the rail can be wider than the width tokens, so it overflows into the padding instead of shrinking
62
+ flexShrink: 0,
63
+ boxSizing: 'border-box',
64
+ backgroundColor: componentTheme.backgroundColor,
65
+ border: `${componentTheme.borderWidth} solid ${componentTheme.borderColor}`,
66
+ borderRadius: collapsed ? componentTheme.minimizedBorderRadius : componentTheme.borderRadius,
67
+ boxShadow: (0, _uiThemes.boxShadowObjectsToCSSString)(componentTheme.boxShadow)
68
+ }
69
+ };
70
+ };
71
+
72
+ /**
73
+ * Generates the style object of the main column from the `MainNav` tokens
74
+ */
75
+ const generateMainNavStyle = (componentTheme, params) => {
76
+ const {
77
+ collapsed
78
+ } = params;
79
+ return {
80
+ mainNav: {
81
+ label: 'mainNav',
82
+ width: collapsed ? componentTheme.minimizedWidth : componentTheme.width,
83
+ flexShrink: 0,
84
+ boxSizing: 'border-box',
85
+ display: 'flex',
86
+ flexDirection: 'column',
87
+ gap: collapsed ? componentTheme.minimizedGap : componentTheme.gap,
88
+ padding: collapsed ? `${componentTheme.minimizedGap} ${componentTheme.minimizedMargin}` : componentTheme.margin
89
+ },
90
+ header: {
91
+ label: 'mainNav__header',
92
+ display: 'flex',
93
+ flexDirection: collapsed ? 'column' : 'row',
94
+ alignItems: 'center',
95
+ justifyContent: collapsed ? 'center' : 'flex-end',
96
+ gap: collapsed ? componentTheme.minimizedGap : componentTheme.gap
97
+ },
98
+ items: {
99
+ label: 'mainNav__items',
100
+ display: 'flex',
101
+ flexDirection: 'column',
102
+ alignItems: collapsed ? 'center' : 'stretch',
103
+ gap: componentTheme.navItemsGap,
104
+ listStyle: 'none',
105
+ margin: 0,
106
+ padding: 0
107
+ },
108
+ divider: {
109
+ label: 'mainNav__divider',
110
+ // MainNav has no divider width token
111
+ borderTop: `0.0625rem solid ${componentTheme.strokeColor}`
112
+ }
113
+ };
114
+ };
115
+ exports.generateMainNavStyle = generateMainNavStyle;
116
+ var _default = exports.default = generateStyle;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getItemElementProps = exports.default = void 0;
7
+ var _uiUtils = require("@instructure/ui-utils");
8
+ /*
9
+ * The MIT License (MIT)
10
+ *
11
+ * Copyright (c) 2015 - present Instructure, Inc.
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ * copies of the Software, and to permit persons to whom the Software is
18
+ * furnished to do so, subject to the following conditions:
19
+ *
20
+ * The above copyright notice and this permission notice shall be included in all
21
+ * copies or substantial portions of the Software.
22
+ *
23
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ * SOFTWARE.
30
+ */
31
+
32
+ /**
33
+ * ---
34
+ * private: true
35
+ * ---
36
+ * Returns the props of the item's `<a>` or `<button>`, and `isLink` to tell which one to render
37
+ */
38
+ const getItemElementProps = (item, onActivate, disclosureProps) => {
39
+ const isLink = !!item.href && !item.subNav;
40
+ const handleClick = event => {
41
+ item.onClick?.(event);
42
+ onActivate?.(event);
43
+ };
44
+ const ownProps = isLink ? {
45
+ // drops unsafe hrefs, for example javascript: URLs that would run code on click
46
+ ...(0, _uiUtils.safeLinkProps)({
47
+ href: item.href,
48
+ tag: 'a',
49
+ attr: 'href',
50
+ target: item.elementProps?.target,
51
+ rel: item.elementProps?.rel
52
+ }),
53
+ onClick: handleClick
54
+ } : {
55
+ type: 'button',
56
+ onClick: handleClick,
57
+ ...disclosureProps
58
+ };
59
+ return {
60
+ isLink,
61
+ // InstUI's own props come last, so the app can't override them
62
+ props: {
63
+ ...item.elementProps,
64
+ ...ownProps,
65
+ 'aria-current': item.current ? 'page' : undefined
66
+ }
67
+ };
68
+ };
69
+ exports.getItemElementProps = getItemElementProps;
70
+ var _default = exports.default = getItemElementProps;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "GlobalNav", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _index.GlobalNav;
10
+ }
11
+ });
12
+ var _index = require("../GlobalNav/v1/index.js");
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
package/package.json CHANGED
@@ -1,6 +1,80 @@
1
1
  {
2
2
  "name": "@instructure/ui-global-nav",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "11.7.10",
4
+ "description": "Main navigation of an app: a rail with items, sub navigation and an account menu.",
5
+ "author": "Instructure, Inc. Engineering and Product Design",
6
+ "module": "./es/index.js",
7
+ "main": "./lib/index.js",
8
+ "types": "./types/index.d.ts",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/instructure/instructure-ui.git"
12
+ },
13
+ "homepage": "https://instructure.github.io/instructure-ui/",
14
+ "bugs": "https://github.com/instructure/instructure-ui/issues",
15
+ "license": "MIT",
16
+ "dependencies": {
17
+ "@babel/runtime": "^7.29.7",
18
+ "@instructure/emotion": "11.7.10",
19
+ "@instructure/shared-types": "11.7.10",
20
+ "@instructure/ui-a11y-content": "11.7.10",
21
+ "@instructure/ui-badge": "11.7.10",
22
+ "@instructure/ui-buttons": "11.7.10",
23
+ "@instructure/ui-dom-utils": "11.7.10",
24
+ "@instructure/ui-icons": "11.7.10",
25
+ "@instructure/ui-react-utils": "11.7.10",
26
+ "@instructure/ui-text": "11.7.10",
27
+ "@instructure/ui-themes": "11.7.10",
28
+ "@instructure/ui-tooltip": "11.7.10",
29
+ "@instructure/ui-utils": "11.7.10"
30
+ },
31
+ "devDependencies": {
32
+ "@instructure/ui-axe-check": "11.7.10",
33
+ "@instructure/ui-babel-preset": "11.7.10",
34
+ "vitest": "^5.0.0"
35
+ },
36
+ "peerDependencies": {
37
+ "react": ">=18 <=19"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "sideEffects": false,
43
+ "exports": {
44
+ "./lib/*": "./lib/*",
45
+ "./es/*": "./es/*",
46
+ "./types/*": "./types/*",
47
+ "./package.json": "./package.json",
48
+ "./src/*": "./src/*",
49
+ ".": {
50
+ "src": "./src/exports/a.ts",
51
+ "types": "./types/exports/a.d.ts",
52
+ "import": "./es/exports/a.js",
53
+ "require": "./lib/exports/a.js",
54
+ "default": "./es/exports/a.js"
55
+ },
56
+ "./v11_7": {
57
+ "src": "./src/exports/a.ts",
58
+ "types": "./types/exports/a.d.ts",
59
+ "import": "./es/exports/a.js",
60
+ "require": "./lib/exports/a.js",
61
+ "default": "./es/exports/a.js"
62
+ },
63
+ "./latest": {
64
+ "src": "./src/exports/a.ts",
65
+ "types": "./types/exports/a.d.ts",
66
+ "import": "./es/exports/a.js",
67
+ "require": "./lib/exports/a.js",
68
+ "default": "./es/exports/a.js"
69
+ }
70
+ },
71
+ "scripts": {
72
+ "lint": "ui-scripts lint",
73
+ "lint:fix": "ui-scripts lint --fix",
74
+ "clean": "ui-scripts clean",
75
+ "build": "ui-scripts build --modules es,cjs",
76
+ "build:watch": "pnpm run ts:check -- --watch & ui-scripts build --watch",
77
+ "build:types": "tsc -p tsconfig.build.json",
78
+ "ts:check": "tsc -p tsconfig.build.json --noEmit --emitDeclarationOnly false"
79
+ }
6
80
  }
@@ -0,0 +1,87 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import type { SyntheticEvent } from 'react'
26
+
27
+ import { useStyleNew } from '@instructure/emotion'
28
+ import { IconButton } from '@instructure/ui-buttons/latest'
29
+ import {
30
+ PanelRightCloseInstUIIcon,
31
+ PanelRightOpenInstUIIcon
32
+ } from '@instructure/ui-icons'
33
+
34
+ import type { CollapseButtonProps } from './props.js'
35
+ import generateStyle, { generateIconStyle } from './styles.js'
36
+
37
+ /**
38
+ ---
39
+ private: true
40
+ id: GlobalNav.CollapseButton
41
+ ---
42
+ **/
43
+ const CollapseButton = (props: CollapseButtonProps) => {
44
+ const { collapsed, collapseLabel, expandLabel, onCollapse, elementRef } =
45
+ props
46
+
47
+ const styles = useStyleNew({
48
+ generateStyle,
49
+ params: { collapsed },
50
+ componentId: 'CollapseButton'
51
+ })
52
+
53
+ // MainNavItem is a separate token set, and useStyleNew reads one set per call
54
+ const iconStyles = useStyleNew({
55
+ generateStyle: generateIconStyle,
56
+ componentId: 'CollapseButton',
57
+ useTokensFrom: 'MainNavItem'
58
+ })
59
+
60
+ const label = collapsed ? expandLabel : collapseLabel
61
+
62
+ return (
63
+ <div css={styles?.collapseButton}>
64
+ <IconButton
65
+ screenReaderLabel={label}
66
+ renderIcon={
67
+ collapsed ? PanelRightCloseInstUIIcon : PanelRightOpenInstUIIcon
68
+ }
69
+ withBackground={false}
70
+ withBorder={false}
71
+ size="small"
72
+ elementRef={elementRef}
73
+ // the cast is safe: the click event is typed for ViewProps, but React passes the DOM button's event
74
+ onClick={(event) =>
75
+ onCollapse(event as unknown as SyntheticEvent, !collapsed)
76
+ }
77
+ themeOverride={{
78
+ ...styles?.iconButtonThemeOverride,
79
+ ...iconStyles?.iconButtonThemeOverride
80
+ }}
81
+ />
82
+ </div>
83
+ )
84
+ }
85
+
86
+ export default CollapseButton
87
+ export { CollapseButton }