-
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: Add Typescript typings to Breadcrumb, BreadcrumbItems, and Brea…
…dcrumbSkeleton (#15033) * feat: add types for Breadcrumbs * revert: undo PropType changes and supress TS error instead --------- Co-authored-by: Andrea N. Cardona <[email protected]>
- Loading branch information
1 parent
a72c87c
commit c8dcddc
Showing
7 changed files
with
231 additions
and
170 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 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,82 @@ | ||
/** | ||
* 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 PropTypes from 'prop-types'; | ||
import React, { PropsWithChildren } from 'react'; | ||
import cx from 'classnames'; | ||
import { usePrefix } from '../../internal/usePrefix'; | ||
import { ForwardRefReturn } from '../../types/common'; | ||
|
||
export interface BreadcrumbProps extends React.HTMLAttributes<HTMLElement> { | ||
/** | ||
* Specify the label for the breadcrumb container | ||
*/ | ||
'aria-label'?: string; | ||
|
||
/** | ||
* Specify an optional className to be applied to the container node | ||
*/ | ||
className?: string; | ||
|
||
/** | ||
* Optional prop to omit the trailing slash for the breadcrumbs | ||
*/ | ||
noTrailingSlash?: boolean; | ||
} | ||
|
||
const Breadcrumb: ForwardRefReturn<HTMLElement, BreadcrumbProps> = | ||
React.forwardRef(function Breadcrumb( | ||
{ | ||
'aria-label': ariaLabel, | ||
children, | ||
className: customClassNameNav, | ||
noTrailingSlash, | ||
...rest | ||
}: PropsWithChildren<BreadcrumbProps>, | ||
ref: React.Ref<HTMLElement> | ||
) { | ||
const prefix = usePrefix(); | ||
const className = cx({ | ||
[`${prefix}--breadcrumb`]: true, | ||
[`${prefix}--breadcrumb--no-trailing-slash`]: noTrailingSlash, | ||
}); | ||
|
||
return ( | ||
<nav | ||
className={customClassNameNav} | ||
aria-label={ariaLabel ? ariaLabel : 'Breadcrumb'} | ||
ref={ref} | ||
{...rest}> | ||
<ol className={className}>{children}</ol> | ||
</nav> | ||
); | ||
}); | ||
|
||
Breadcrumb.displayName = 'Breadcrumb'; | ||
Breadcrumb.propTypes = { | ||
/** | ||
* Specify the label for the breadcrumb container | ||
*/ | ||
'aria-label': PropTypes.string, | ||
|
||
/** | ||
* Pass in the BreadcrumbItem's for your Breadcrumb | ||
*/ | ||
children: PropTypes.node, | ||
|
||
/** | ||
* Specify an optional className to be applied to the container node | ||
*/ | ||
className: PropTypes.string, | ||
|
||
/** | ||
* Optional prop to omit the trailing slash for the breadcrumbs | ||
*/ | ||
noTrailingSlash: PropTypes.bool, | ||
}; | ||
|
||
export default Breadcrumb; |
106 changes: 0 additions & 106 deletions
106
packages/react/src/components/Breadcrumb/BreadcrumbItem.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.