gatsby-theme-carbon 4.2.9 → 4.2.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,8 +1,9 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
1
|
+
import React, { useContext, useEffect } from 'react';
|
|
2
2
|
import { Link } from 'gatsby';
|
|
3
3
|
import { Location } from '@reach/router';
|
|
4
4
|
import cx from 'classnames';
|
|
5
5
|
import { useNetworkState } from 'react-use';
|
|
6
|
+
import { breakpoints } from '@carbon/elements';
|
|
6
7
|
|
|
7
8
|
import { SideNavLink, SideNavMenu, SideNavMenuItem } from '@carbon/react';
|
|
8
9
|
|
|
@@ -16,9 +17,22 @@ export const SERVICE_WORKER_UPDATE_FOUND = 'GTC-ServiceWorkerUpdateFound';
|
|
|
16
17
|
|
|
17
18
|
const LeftNavItem = (props) => {
|
|
18
19
|
const { items, category, hasDivider } = props;
|
|
19
|
-
const { toggleNavState } = useContext(NavContext);
|
|
20
|
+
const { toggleNavState, leftNavIsOpen } = useContext(NavContext);
|
|
20
21
|
const { isServiceWorkerEnabled } = useMetadata();
|
|
21
22
|
const isOnline = useNetworkState();
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (typeof window !== 'undefined') {
|
|
25
|
+
const isLgWindow = window.matchMedia(
|
|
26
|
+
`(min-width: ${breakpoints.lg.width})`
|
|
27
|
+
).matches;
|
|
28
|
+
|
|
29
|
+
if (isLgWindow) {
|
|
30
|
+
toggleNavState('leftNavIsOpen', 'open');
|
|
31
|
+
} else {
|
|
32
|
+
toggleNavState('leftNavIsOpen', 'close');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}, []);
|
|
22
36
|
|
|
23
37
|
const handleClick = (event, to) => {
|
|
24
38
|
toggleNavState('leftNavIsOpen', 'close');
|
|
@@ -48,6 +62,8 @@ const LeftNavItem = (props) => {
|
|
|
48
62
|
return (
|
|
49
63
|
<>
|
|
50
64
|
<SideNavLink
|
|
65
|
+
isSideNavExpanded={leftNavIsOpen}
|
|
66
|
+
tabIndex={!leftNavIsOpen ? -1 : 0}
|
|
51
67
|
onClick={(e) => handleClick(e, to)}
|
|
52
68
|
icon={<span>dummy icon</span>}
|
|
53
69
|
element={Link}
|
|
@@ -68,7 +84,9 @@ const LeftNavItem = (props) => {
|
|
|
68
84
|
icon={<span>dummy icon</span>}
|
|
69
85
|
isActive={isActive} // TODO similar categories
|
|
70
86
|
defaultExpanded={isActive}
|
|
71
|
-
title={category}
|
|
87
|
+
title={category}
|
|
88
|
+
isSideNavExpanded={leftNavIsOpen}
|
|
89
|
+
tabIndex={!leftNavIsOpen ? -1 : 0}>
|
|
72
90
|
<SubNavItems
|
|
73
91
|
onClick={handleClick}
|
|
74
92
|
items={items}
|
|
@@ -1,17 +1,34 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useContext, useEffect } from 'react';
|
|
2
2
|
import { SideNavLink } from '@carbon/react';
|
|
3
3
|
import { Link } from 'gatsby';
|
|
4
4
|
import { Launch as LaunchIcon } from '@carbon/react/icons';
|
|
5
5
|
import cx from 'classnames';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
7
|
+
import { breakpoints } from '@carbon/elements';
|
|
7
8
|
|
|
8
9
|
import { outboundLink, divider, dividerSpace } from './LeftNav.module.scss';
|
|
10
|
+
import NavContext from '../../util/context/NavContext';
|
|
9
11
|
|
|
10
12
|
const LeftNavResourceLinks = ({
|
|
11
13
|
links,
|
|
12
14
|
shouldOpenNewTabs,
|
|
13
15
|
includeDividerSpace = true,
|
|
14
16
|
}) => {
|
|
17
|
+
const { toggleNavState, leftNavIsOpen } = useContext(NavContext);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (typeof window !== 'undefined') {
|
|
20
|
+
const isLgWindow = window.matchMedia(
|
|
21
|
+
`(min-width: ${breakpoints.lg.width})`
|
|
22
|
+
).matches;
|
|
23
|
+
|
|
24
|
+
if (isLgWindow) {
|
|
25
|
+
toggleNavState('leftNavIsOpen', 'open');
|
|
26
|
+
} else {
|
|
27
|
+
toggleNavState('leftNavIsOpen', 'close');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
15
32
|
if (!links) return null;
|
|
16
33
|
|
|
17
34
|
const shouldOpenNewTabsProps = {
|
|
@@ -37,6 +54,7 @@ const LeftNavResourceLinks = ({
|
|
|
37
54
|
href={href}
|
|
38
55
|
className={cx({ [outboundLink]: outbound })}
|
|
39
56
|
element={outbound ? 'a' : Link}
|
|
57
|
+
tabIndex={!leftNavIsOpen ? -1 : 0}
|
|
40
58
|
{...shouldOpenNewTabsProps}>
|
|
41
59
|
{title}
|
|
42
60
|
</SideNavLink>
|