-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(component): replaced
SideNavMenuItem.js
-> `SideNavMenuItem.ts…
…x` 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>
- Loading branch information
1 parent
a349643
commit 57db818
Showing
4 changed files
with
83 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2023 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import cx from 'classnames'; | ||
import PropTypes from 'prop-types'; | ||
import React, { ElementType, ForwardedRef, HTMLAttributes, Ref } from 'react'; | ||
import SideNavLinkText from './SideNavLinkText'; | ||
import Link from './Link'; | ||
import { usePrefix } from '../../internal/usePrefix'; | ||
|
||
interface SideNavMenuItemProps extends HTMLAttributes<HTMLElement> { | ||
/** | ||
* Specify the children to be rendered inside of the `SideNavMenuItem` | ||
*/ | ||
children?: React.ReactNode; | ||
|
||
/** | ||
* Provide an optional class to be applied to the containing node | ||
*/ | ||
className?: string; | ||
|
||
/** | ||
* Optionally specify whether the link is "active". An active link is one that | ||
* has an href that is the same as the current page. Can also pass in | ||
* `aria-current="page"`, as well. | ||
*/ | ||
isActive?: boolean; | ||
} | ||
|
||
const SideNavMenuItem = React.forwardRef<HTMLElement, SideNavMenuItemProps>( | ||
function SideNavMenuItem(props, ref: ForwardedRef<HTMLElement>) { | ||
const prefix = usePrefix(); | ||
const { children, className: customClassName, isActive, ...rest } = props; | ||
const className = cx(`${prefix}--side-nav__menu-item`, customClassName); | ||
const linkClassName = cx({ | ||
[`${prefix}--side-nav__link`]: true, | ||
[`${prefix}--side-nav__link--current`]: isActive, | ||
}); | ||
|
||
return ( | ||
<li className={className}> | ||
<Link {...rest} className={linkClassName} ref={ref as Ref<ElementType>}> | ||
<SideNavLinkText>{children}</SideNavLinkText> | ||
</Link> | ||
</li> | ||
); | ||
} | ||
); | ||
|
||
SideNavMenuItem.displayName = 'SideNavMenuItem'; | ||
SideNavMenuItem.propTypes = { | ||
/** | ||
* Specify the children to be rendered inside of the `SideNavMenuItem` | ||
*/ | ||
children: PropTypes.node, | ||
|
||
/** | ||
* Provide an optional class to be applied to the containing node | ||
*/ | ||
className: PropTypes.string, | ||
|
||
/** | ||
* Optionally specify whether the link is "active". An active link is one that | ||
* has an href that is the same as the current page. Can also pass in | ||
* `aria-current="page"`, as well. | ||
*/ | ||
isActive: PropTypes.bool, | ||
}; | ||
|
||
export default SideNavMenuItem; |