gatsby-theme-carbon 4.0.9 → 4.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatsby-theme-carbon",
3
- "version": "4.0.9",
3
+ "version": "4.0.10",
4
4
  "main": "index.js",
5
5
  "author": "vpicone <vp@vincepic.one> (@vpicone)",
6
6
  "repository": {
@@ -23,6 +23,7 @@ const LeftNav = (props) => {
23
23
  leftNavScrollTop,
24
24
  setLeftNavScrollTop,
25
25
  toggleNavState,
26
+ pathPrefix,
26
27
  } = useContext(NavContext);
27
28
 
28
29
  const [isTreeView, setIsTreeView] = useState();
@@ -97,7 +98,11 @@ const LeftNav = (props) => {
97
98
  onClick={closeSwitcher}
98
99
  onKeyPress={closeSwitcher}>
99
100
  {isTreeView ? (
100
- <LeftNavTree items={navItems} theme={props.theme} />
101
+ <LeftNavTree
102
+ items={navItems}
103
+ theme={props.theme}
104
+ pathPrefix={pathPrefix}
105
+ />
101
106
  ) : (
102
107
  <SideNav
103
108
  ref={sideNavRef}
@@ -10,14 +10,12 @@ 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';
14
13
 
15
- const LeftNavTree = ({ items, theme }) => {
14
+ const LeftNavTree = ({ items, theme, pathPrefix }) => {
16
15
  const [itemNodes, setItemNodes] = useState([]);
17
16
  const [treeActiveItem, setTreeActiveItem] = useState({});
18
17
  const [activePath, setActivePath] = useState('');
19
18
  const location = useLocation();
20
- const pathPrefix = usePathprefix();
21
19
 
22
20
  const themeValue = theme === 'dark' ? 'g100' : theme;
23
21
 
@@ -68,12 +66,11 @@ const LeftNavTree = ({ items, theme }) => {
68
66
  useEffect(() => {
69
67
  const stripTrailingSlash = (str) =>
70
68
  str.endsWith('/') ? str.slice(0, -1) : str;
71
-
72
69
  const base = pathPrefix
73
70
  ? location.pathname.replace(pathPrefix, '')
74
71
  : location.pathname;
75
72
  setActivePath(stripTrailingSlash(base));
76
- }, [location.pathname]);
73
+ }, [location.pathname, pathPrefix]);
77
74
 
78
75
  const getItemPath = (item) =>
79
76
  item.path || slugify(item.title, { lower: true, strict: true });
@@ -103,7 +100,7 @@ const LeftNavTree = ({ items, theme }) => {
103
100
  activeNode = dfs(itemNodes, isTabActive);
104
101
  }
105
102
  setTreeActiveItem(activeNode);
106
- }, [isTreeNodeActive, itemNodes]);
103
+ }, [isTreeNodeActive, itemNodes, isTabActive]);
107
104
 
108
105
  const isTreeNodeExpanded = (node) =>
109
106
  !!dfs([node], (evalNode) =>
@@ -1,4 +1,5 @@
1
1
  import React, { useMemo, useReducer, useState } from 'react';
2
+ import usePathprefix from '../hooks/usePathprefix';
2
3
 
3
4
  const NavContext = React.createContext({
4
5
  leftNavIsOpen: false,
@@ -19,6 +20,7 @@ const reducer = (state, action) => {
19
20
  }
20
21
  };
21
22
  export const NavContextProvider = ({ children }) => {
23
+ const pathPrefix = usePathprefix();
22
24
  const [
23
25
  { leftNavIsOpen, searchIsOpen, switcherIsOpen, leftNavScrollOffset },
24
26
  dispatch,
@@ -47,6 +49,7 @@ export const NavContextProvider = ({ children }) => {
47
49
  leftNavScrollOffset,
48
50
  leftNavScrollTop,
49
51
  setLeftNavScrollTop,
52
+ pathPrefix,
50
53
  }),
51
54
  [
52
55
  leftNavIsOpen,
@@ -58,6 +61,7 @@ export const NavContextProvider = ({ children }) => {
58
61
  leftNavScrollOffset,
59
62
  leftNavScrollTop,
60
63
  setLeftNavScrollTop,
64
+ pathPrefix,
61
65
  ]
62
66
  );
63
67