Skip to content

Commit 57db818

Browse files
Nirajsahandreancardonatay1orjones
authored
feat(component): replaced SideNavMenuItem.js -> SideNavMenuItem.tsx component (#14996)
* feat(component): replaced -> component * Update README.md * Update .all-contributorsrc --------- Co-authored-by: Andrea N. Cardona <cardona.n.andrea@gmail.com> Co-authored-by: Taylor Jones <tay1orjones@users.noreply.github.com>
1 parent a349643 commit 57db818

File tree

4 files changed

+83
-53
lines changed

4 files changed

+83
-53
lines changed

.all-contributorsrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,14 @@
12901290
]
12911291
},
12921292
{
1293+
"login": "Nirajsah",
1294+
"name": "Niraj Sah",
1295+
"avatar_url": "https://avatars.githubusercontent.com/u/51414373?v=4",
1296+
"profile": "https://github.com/Nirajsah",
1297+
"contributions": [
1298+
"code"
1299+
]
1300+
},
12931301
"login": "allisonishida",
12941302
"name": "Allison Ishida",
12951303
"avatar_url": "https://avatars.githubusercontent.com/u/22247062?v=4",

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ check out our [Contributing Guide](/.github/CONTRIBUTING.md) and our
258258
<td align="center"><a href="https://github.com/amanlajpal"><img src="https://avatars.githubusercontent.com/u/42869088?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Aman Lajpal</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=amanlajpal" title="Code">💻</a> <a href="https://github.com/carbon-design-system/carbon/commits?author=amanlajpal" title="Documentation">📖</a></td>
259259
</tr>
260260
<tr>
261+
<td align="center"><a href="https://github.com/Nirajsah"><img src="https://avatars.githubusercontent.com/u/51414373?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Niraj Sah</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=Nirajsah" title="Code">💻</a></td>
261262
<td align="center"><a href="https://github.com/allisonishida"><img src="https://avatars.githubusercontent.com/u/22247062?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Allison Ishida</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=allisonishida" title="Code">💻</a></td>
262263
<td align="center"><a href="https://github.com/alewitt2"><img src="https://avatars.githubusercontent.com/u/48691328?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Alex Lewitt</b></sub></a><br /><a href="https://github.com/carbon-design-system/carbon/commits?author=alewitt2" title="Code">💻</a></td>
263264
</tr>

packages/react/src/components/UIShell/SideNavMenuItem.js

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* Copyright IBM Corp. 2016, 2023
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 cx from 'classnames';
9+
import PropTypes from 'prop-types';
10+
import React, { ElementType, ForwardedRef, HTMLAttributes, Ref } from 'react';
11+
import SideNavLinkText from './SideNavLinkText';
12+
import Link from './Link';
13+
import { usePrefix } from '../../internal/usePrefix';
14+
15+
interface SideNavMenuItemProps extends HTMLAttributes<HTMLElement> {
16+
/**
17+
* Specify the children to be rendered inside of the `SideNavMenuItem`
18+
*/
19+
children?: React.ReactNode;
20+
21+
/**
22+
* Provide an optional class to be applied to the containing node
23+
*/
24+
className?: string;
25+
26+
/**
27+
* Optionally specify whether the link is "active". An active link is one that
28+
* has an href that is the same as the current page. Can also pass in
29+
* `aria-current="page"`, as well.
30+
*/
31+
isActive?: boolean;
32+
}
33+
34+
const SideNavMenuItem = React.forwardRef<HTMLElement, SideNavMenuItemProps>(
35+
function SideNavMenuItem(props, ref: ForwardedRef<HTMLElement>) {
36+
const prefix = usePrefix();
37+
const { children, className: customClassName, isActive, ...rest } = props;
38+
const className = cx(`${prefix}--side-nav__menu-item`, customClassName);
39+
const linkClassName = cx({
40+
[`${prefix}--side-nav__link`]: true,
41+
[`${prefix}--side-nav__link--current`]: isActive,
42+
});
43+
44+
return (
45+
<li className={className}>
46+
<Link {...rest} className={linkClassName} ref={ref as Ref<ElementType>}>
47+
<SideNavLinkText>{children}</SideNavLinkText>
48+
</Link>
49+
</li>
50+
);
51+
}
52+
);
53+
54+
SideNavMenuItem.displayName = 'SideNavMenuItem';
55+
SideNavMenuItem.propTypes = {
56+
/**
57+
* Specify the children to be rendered inside of the `SideNavMenuItem`
58+
*/
59+
children: PropTypes.node,
60+
61+
/**
62+
* Provide an optional class to be applied to the containing node
63+
*/
64+
className: PropTypes.string,
65+
66+
/**
67+
* Optionally specify whether the link is "active". An active link is one that
68+
* has an href that is the same as the current page. Can also pass in
69+
* `aria-current="page"`, as well.
70+
*/
71+
isActive: PropTypes.bool,
72+
};
73+
74+
export default SideNavMenuItem;

0 commit comments

Comments
 (0)