gatsby-theme-carbon 4.0.7 → 4.0.9
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.
package/package.json
CHANGED
|
@@ -10,12 +10,14 @@ import * as styles from './LeftNavTree.module.scss';
|
|
|
10
10
|
import { dfs } from '../../util/NavTree';
|
|
11
11
|
|
|
12
12
|
import LeftNavResourceLinks from './ResourceLinks';
|
|
13
|
+
import usePathprefix from '../../util/hooks/usePathprefix';
|
|
13
14
|
|
|
14
15
|
const LeftNavTree = ({ items, theme }) => {
|
|
15
16
|
const [itemNodes, setItemNodes] = useState([]);
|
|
16
17
|
const [treeActiveItem, setTreeActiveItem] = useState({});
|
|
17
18
|
const [activePath, setActivePath] = useState('');
|
|
18
19
|
const location = useLocation();
|
|
20
|
+
const pathPrefix = usePathprefix();
|
|
19
21
|
|
|
20
22
|
const themeValue = theme === 'dark' ? 'g100' : theme;
|
|
21
23
|
|
|
@@ -66,7 +68,11 @@ const LeftNavTree = ({ items, theme }) => {
|
|
|
66
68
|
useEffect(() => {
|
|
67
69
|
const stripTrailingSlash = (str) =>
|
|
68
70
|
str.endsWith('/') ? str.slice(0, -1) : str;
|
|
69
|
-
|
|
71
|
+
|
|
72
|
+
const base = pathPrefix
|
|
73
|
+
? location.pathname.replace(pathPrefix, '')
|
|
74
|
+
: location.pathname;
|
|
75
|
+
setActivePath(stripTrailingSlash(base));
|
|
70
76
|
}, [location.pathname]);
|
|
71
77
|
|
|
72
78
|
const getItemPath = (item) =>
|
|
@@ -79,8 +85,23 @@ const LeftNavTree = ({ items, theme }) => {
|
|
|
79
85
|
[activePath]
|
|
80
86
|
);
|
|
81
87
|
|
|
88
|
+
const isTabActive = useCallback(
|
|
89
|
+
(node) => {
|
|
90
|
+
const pathname = removeHashAndQuery(activePath);
|
|
91
|
+
const isActive =
|
|
92
|
+
`${node.path?.split('/')[1]}/${node.path?.split('/')[2]}` ===
|
|
93
|
+
`${pathname.split('/')[1]}/${pathname.split('/')[2]}`;
|
|
94
|
+
|
|
95
|
+
return isActive;
|
|
96
|
+
},
|
|
97
|
+
[activePath]
|
|
98
|
+
);
|
|
99
|
+
|
|
82
100
|
useEffect(() => {
|
|
83
|
-
|
|
101
|
+
let activeNode = dfs(itemNodes, isTreeNodeActive);
|
|
102
|
+
if (!activeNode) {
|
|
103
|
+
activeNode = dfs(itemNodes, isTabActive);
|
|
104
|
+
}
|
|
84
105
|
setTreeActiveItem(activeNode);
|
|
85
106
|
}, [isTreeNodeActive, itemNodes]);
|
|
86
107
|
|