Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/npm_and_yarn-3fb24e0890
Browse files Browse the repository at this point in the history
  • Loading branch information
eng618 authored Sep 12, 2024
2 parents 303e109 + 66a5131 commit d1d9eef
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [4.0.10](https://github.com/carbon-design-system/gatsby-theme-carbon/compare/v4.0.9...v4.0.10) (2024-09-11)


### Bug Fixes

* prevent nav from collapsing during local development ([#1510](https://github.com/carbon-design-system/gatsby-theme-carbon/issues/1510)) ([b907d88](https://github.com/carbon-design-system/gatsby-theme-carbon/commit/b907d887db00ecff8a34f9ea1f36dc103cf6881c))

## [4.0.9](https://github.com/carbon-design-system/gatsby-theme-carbon/compare/v4.0.8...v4.0.9) (2024-09-11)


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gatsby-theme-carbon-workspace",
"private": true,
"version": "4.0.9",
"version": "4.0.10",
"packageManager": "[email protected]",
"repository": {
"url": "[email protected]:carbon-design-system/gatsby-theme-carbon.git",
Expand Down
4 changes: 2 additions & 2 deletions packages/example/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "example",
"private": true,
"version": "4.0.9",
"version": "4.0.10",
"license": "Apache 2.0",
"scripts": {
"dev": "gatsby develop -H 0.0.0.0",
Expand All @@ -14,7 +14,7 @@
"dependencies": {
"@carbon/icons-react": "^11.43.0",
"gatsby": "^5.13.6",
"gatsby-theme-carbon": "^4.0.9",
"gatsby-theme-carbon": "^4.0.10",
"react": "^18.3.1",
"react-dom": "^18.3.1"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-theme-carbon/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-theme-carbon",
"version": "4.0.9",
"version": "4.0.10",
"main": "index.js",
"author": "vpicone <[email protected]> (@vpicone)",
"repository": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const LeftNav = (props) => {
leftNavScrollTop,
setLeftNavScrollTop,
toggleNavState,
pathPrefix,
} = useContext(NavContext);

const [isTreeView, setIsTreeView] = useState();
Expand Down Expand Up @@ -97,7 +98,11 @@ const LeftNav = (props) => {
onClick={closeSwitcher}
onKeyPress={closeSwitcher}>
{isTreeView ? (
<LeftNavTree items={navItems} theme={props.theme} />
<LeftNavTree
items={navItems}
theme={props.theme}
pathPrefix={pathPrefix}
/>
) : (
<SideNav
ref={sideNavRef}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ import * as styles from './LeftNavTree.module.scss';
import { dfs } from '../../util/NavTree';

import LeftNavResourceLinks from './ResourceLinks';
import usePathprefix from '../../util/hooks/usePathprefix';

const LeftNavTree = ({ items, theme }) => {
const LeftNavTree = ({ items, theme, pathPrefix }) => {
const [itemNodes, setItemNodes] = useState([]);
const [treeActiveItem, setTreeActiveItem] = useState({});
const [activePath, setActivePath] = useState('');
const location = useLocation();
const pathPrefix = usePathprefix();

const themeValue = theme === 'dark' ? 'g100' : theme;

Expand Down Expand Up @@ -68,12 +66,11 @@ const LeftNavTree = ({ items, theme }) => {
useEffect(() => {
const stripTrailingSlash = (str) =>
str.endsWith('/') ? str.slice(0, -1) : str;

const base = pathPrefix
? location.pathname.replace(pathPrefix, '')
: location.pathname;
setActivePath(stripTrailingSlash(base));
}, [location.pathname]);
}, [location.pathname, pathPrefix]);

const getItemPath = (item) =>
item.path || slugify(item.title, { lower: true, strict: true });
Expand Down Expand Up @@ -103,7 +100,7 @@ const LeftNavTree = ({ items, theme }) => {
activeNode = dfs(itemNodes, isTabActive);
}
setTreeActiveItem(activeNode);
}, [isTreeNodeActive, itemNodes]);
}, [isTreeNodeActive, itemNodes, isTabActive]);

const isTreeNodeExpanded = (node) =>
!!dfs([node], (evalNode) =>
Expand Down
4 changes: 4 additions & 0 deletions packages/gatsby-theme-carbon/src/util/context/NavContext.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useMemo, useReducer, useState } from 'react';
import usePathprefix from '../hooks/usePathprefix';

const NavContext = React.createContext({
leftNavIsOpen: false,
Expand All @@ -19,6 +20,7 @@ const reducer = (state, action) => {
}
};
export const NavContextProvider = ({ children }) => {
const pathPrefix = usePathprefix();
const [
{ leftNavIsOpen, searchIsOpen, switcherIsOpen, leftNavScrollOffset },
dispatch,
Expand Down Expand Up @@ -47,6 +49,7 @@ export const NavContextProvider = ({ children }) => {
leftNavScrollOffset,
leftNavScrollTop,
setLeftNavScrollTop,
pathPrefix,
}),
[
leftNavIsOpen,
Expand All @@ -58,6 +61,7 @@ export const NavContextProvider = ({ children }) => {
leftNavScrollOffset,
leftNavScrollTop,
setLeftNavScrollTop,
pathPrefix,
]
);

Expand Down

0 comments on commit d1d9eef

Please sign in to comment.