@carbon-labs/react-ui-shell 0.7.0 → 0.9.0
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/es/components/SideNav.js +131 -3
- package/es/components/SideNavItems.d.ts +24 -0
- package/es/components/SideNavItems.js +61 -0
- package/es/components/SideNavMenu.d.ts +49 -0
- package/es/components/SideNavMenu.js +274 -0
- package/es/components/SideNavMenuItem.d.ts +38 -0
- package/es/components/SideNavMenuItem.js +84 -0
- package/es/index.d.ts +4 -1
- package/es/index.js +4 -1
- package/es/node_modules/@carbon/icons-react/es/generated/bucket-3.js +3119 -0
- package/lib/components/SideNav.js +129 -1
- package/lib/components/SideNavItems.d.ts +24 -0
- package/lib/components/SideNavItems.js +63 -0
- package/lib/components/SideNavMenu.d.ts +49 -0
- package/lib/components/SideNavMenu.js +295 -0
- package/lib/components/SideNavMenuItem.d.ts +38 -0
- package/lib/components/SideNavMenuItem.js +86 -0
- package/lib/index.d.ts +4 -1
- package/lib/index.js +7 -0
- package/lib/node_modules/@carbon/icons-react/es/generated/bucket-3.js +3245 -0
- package/package.json +2 -2
- package/scss/styles/_side-nav.scss +18 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2024
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { extends as _extends } from '../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
+
import cx from '../_virtual/index.js';
|
|
10
|
+
import PropTypes from 'prop-types';
|
|
11
|
+
import React, { useRef, useEffect } from 'react';
|
|
12
|
+
import SideNavLinkText from '@carbon/react/lib/components/UIShell/SideNavLinkText';
|
|
13
|
+
import Link from '@carbon/react/lib/components/UIShell/Link';
|
|
14
|
+
import { usePrefix } from '@carbon/react/lib/internal/usePrefix';
|
|
15
|
+
import { useMergedRefs } from '@carbon/react/lib/internal/useMergedRefs';
|
|
16
|
+
|
|
17
|
+
const SideNavMenuItem = /*#__PURE__*/React.forwardRef(function SideNavMenuItem(props, ref) {
|
|
18
|
+
const prefix = usePrefix();
|
|
19
|
+
const {
|
|
20
|
+
children,
|
|
21
|
+
className: customClassName,
|
|
22
|
+
depth: propDepth,
|
|
23
|
+
as: Component = Link,
|
|
24
|
+
isActive,
|
|
25
|
+
...rest
|
|
26
|
+
} = props;
|
|
27
|
+
const className = cx(`${prefix}--side-nav__menu-item`, customClassName);
|
|
28
|
+
const depth = propDepth;
|
|
29
|
+
const linkClassName = cx({
|
|
30
|
+
[`${prefix}--side-nav__link`]: true,
|
|
31
|
+
[`${prefix}--side-nav__link--current`]: isActive
|
|
32
|
+
});
|
|
33
|
+
const linkRef = useRef(null);
|
|
34
|
+
const itemRef = useMergedRefs([linkRef, ref]);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const calcLinkOffset = () => {
|
|
37
|
+
return 4 + Math.max(0, depth - 1) * 1;
|
|
38
|
+
};
|
|
39
|
+
if (linkRef.current) {
|
|
40
|
+
linkRef.current.style.paddingLeft = `${calcLinkOffset()}rem`;
|
|
41
|
+
}
|
|
42
|
+
}, []);
|
|
43
|
+
return /*#__PURE__*/React.createElement("li", {
|
|
44
|
+
role: "treeitem",
|
|
45
|
+
"aria-selected": isActive ? 'true' : 'false',
|
|
46
|
+
className: className
|
|
47
|
+
}, /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
|
|
48
|
+
className: linkClassName,
|
|
49
|
+
tabIndex: -1,
|
|
50
|
+
ref: itemRef
|
|
51
|
+
}), /*#__PURE__*/React.createElement(SideNavLinkText, null, children)));
|
|
52
|
+
});
|
|
53
|
+
SideNavMenuItem.displayName = 'SideNavMenuItem';
|
|
54
|
+
SideNavMenuItem.propTypes = {
|
|
55
|
+
/**
|
|
56
|
+
* Specify the children to be rendered inside of the `SideNavMenuItem`
|
|
57
|
+
*/
|
|
58
|
+
children: PropTypes.node,
|
|
59
|
+
/**
|
|
60
|
+
* Provide an optional class to be applied to the containing node
|
|
61
|
+
*/
|
|
62
|
+
className: PropTypes.string,
|
|
63
|
+
/**
|
|
64
|
+
* **Note:** this is controlled by the parent SideNavMenu component, do not set manually.
|
|
65
|
+
* SideNavMenu depth to determine spacing
|
|
66
|
+
*/
|
|
67
|
+
depth: PropTypes.number,
|
|
68
|
+
/**
|
|
69
|
+
* Optionally provide an href for the underlying li`
|
|
70
|
+
*/
|
|
71
|
+
href: PropTypes.string,
|
|
72
|
+
/**
|
|
73
|
+
* Optionally specify whether the link is "active". An active link is one that
|
|
74
|
+
* has an href that is the same as the current page. Can also pass in
|
|
75
|
+
* `aria-current="page"`, as well.
|
|
76
|
+
*/
|
|
77
|
+
isActive: PropTypes.bool,
|
|
78
|
+
/**
|
|
79
|
+
* Optional component to render instead of default Link
|
|
80
|
+
*/
|
|
81
|
+
as: PropTypes.elementType
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export { SideNavMenuItem };
|
package/es/index.d.ts
CHANGED
|
@@ -6,5 +6,8 @@
|
|
|
6
6
|
* This source code is licensed under the Apache-2.0 license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
-
export { SideNav } from './components/SideNav.js';
|
|
9
|
+
export { SideNav, SIDE_NAV_TYPE } from './components/SideNav.js';
|
|
10
|
+
export { SideNavItems } from './components/SideNavItems.js';
|
|
11
|
+
export { SideNavMenu } from './components/SideNavMenu.js';
|
|
12
|
+
export { SideNavMenuItem } from './components/SideNavMenuItem.js';
|
|
10
13
|
export { HeaderPanel } from './components/HeaderPanel';
|
package/es/index.js
CHANGED
|
@@ -5,5 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
export { SideNav } from './components/SideNav.js';
|
|
8
|
+
export { SIDE_NAV_TYPE, SideNav } from './components/SideNav.js';
|
|
9
|
+
export { SideNavItems } from './components/SideNavItems.js';
|
|
10
|
+
export { SideNavMenu } from './components/SideNavMenu.js';
|
|
11
|
+
export { SideNavMenuItem } from './components/SideNavMenuItem.js';
|
|
9
12
|
export { HeaderPanel } from './components/HeaderPanel.js';
|