Skip to content

[pull] main from coreui:main #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 21, 2024
57 changes: 36 additions & 21 deletions packages/coreui-react/src/components/breadcrumb/CBreadcrumbItem.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import React, { forwardRef, HTMLAttributes } from 'react'
import React, { ElementType, forwardRef, HTMLAttributes } from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'

import { CLink } from '../link/CLink'

import { PolymorphicRefForwardingComponent } from '../../helpers'

export interface CBreadcrumbItemProps extends HTMLAttributes<HTMLLIElement> {
/**
* Toggle the active state for the component.
*/
active?: boolean
/**
* Component used for the root node. Either a string to use a HTML element or a component.
*
* @since 5.4.0
*/
as?: ElementType
/**
* A string of all className you want applied to the base component.
*/
Expand All @@ -19,26 +27,33 @@ export interface CBreadcrumbItemProps extends HTMLAttributes<HTMLLIElement> {
href?: string
}

export const CBreadcrumbItem = forwardRef<HTMLLIElement, CBreadcrumbItemProps>(
({ children, active, className, href, ...rest }, ref) => {
return (
<li
className={classNames(
'breadcrumb-item',
{
active: active,
},
className,
)}
{...(active && { 'aria-current': 'page' })}
{...rest}
ref={ref}
>
{href ? <CLink href={href}>{children}</CLink> : children}
</li>
)
},
)
export const CBreadcrumbItem: PolymorphicRefForwardingComponent<'li', CBreadcrumbItemProps> =
forwardRef<HTMLLIElement, CBreadcrumbItemProps>(
({ children, active, as, className, href, ...rest }, ref) => {
return (
<li
className={classNames(
'breadcrumb-item',
{
active: active,
},
className,
)}
{...(active && { 'aria-current': 'page' })}
{...rest}
ref={ref}
>
{href ? (
<CLink as={as} href={href}>
{children}
</CLink>
) : (
children
)}
</li>
)
},
)

CBreadcrumbItem.propTypes = {
active: PropTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion packages/coreui-react/src/components/grid/CRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const CRow = forwardRef<HTMLDivElement, CRowProps>(
})

return (
<div className={classNames('row', repsonsiveClassNames, className)} ref={ref}>
<div className={classNames('row', repsonsiveClassNames, className)} {...rest} ref={ref}>
{children}
</div>
)
Expand Down
5 changes: 5 additions & 0 deletions packages/coreui-react/src/components/tabs/CTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export interface CTabProps extends HTMLAttributes<HTMLButtonElement> {
* A string of all className you want applied to the base component.
*/
className?: string
/**
* Toggle the disabled state for the component.
*/
disabled?: boolean
/**
* Item key.
*/
Expand Down Expand Up @@ -50,6 +54,7 @@ export const CTab = forwardRef<HTMLButtonElement, CTabProps>(
CTab.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
disabled: PropTypes.bool,
itemKey: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
}

Expand Down
11 changes: 7 additions & 4 deletions packages/coreui-react/src/components/toast/CToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface CToastProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title
/**
* @ignore
*/
key?: number
innerKey?: number | string
/**
* Callback fired when the component requests to be closed.
*/
Expand Down Expand Up @@ -76,7 +76,7 @@ export const CToast = forwardRef<HTMLDivElement, CToastProps>(
color,
delay = 5000,
index,
key,
innerKey,
visible = false,
onClose,
onShow,
Expand Down Expand Up @@ -143,7 +143,7 @@ export const CToast = forwardRef<HTMLDivElement, CToastProps>(
onMouseEnter={() => clearTimeout(timeout.current)}
onMouseLeave={() => _autohide()}
{...rest}
key={key}
key={innerKey}
ref={forkedRef}
>
{children}
Expand All @@ -163,7 +163,10 @@ CToast.propTypes = {
color: colorPropType,
delay: PropTypes.number,
index: PropTypes.number,
key: PropTypes.number,
innerKey: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string
]),
onClose: PropTypes.func,
onShow: PropTypes.func,
visible: PropTypes.bool,
Expand Down
2 changes: 1 addition & 1 deletion packages/coreui-react/src/components/toast/CToaster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const CToaster = forwardRef<HTMLDivElement, CToasterProps>(
...state,
React.cloneElement(push, {
index: index.current,
key: index.current,
innerKey: index.current,
onClose: (index: number) =>
setToasts((state) => state.filter((i) => i.props.index !== index)),
}),
Expand Down
1 change: 1 addition & 0 deletions packages/docs/content/api/CBreadcrumbItem.api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ import CBreadcrumbItem from '@coreui/react/src/components/breadcrumb/CBreadcrumb
| Property | Description | Type | Default |
| --- | --- | --- | --- |
| **active** | Toggle the active state for the component. | `boolean` | - |
| **as** **_5.4.0+_** | Component used for the root node. Either a string to use a HTML element or a component. | `(ElementType & 'symbol')` \| `(ElementType & 'object')` \| `(ElementType & 'li')` \| `(ElementType & 'slot')` \| `(ElementType & 'style')` \| `... 174 more ...` \| `(ElementType & FunctionComponent<...>)` | - |
| **className** | A string of all className you want applied to the base component. | `string` | - |
| **href** | The `href` attribute for the inner `<CLink>` component. | `string` | - |
1 change: 1 addition & 0 deletions packages/docs/content/api/CTab.api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import CTab from '@coreui/react/src/components/tabs/CTab'
| Property | Description | Type | Default |
| --- | --- | --- | --- |
| **className** | A string of all className you want applied to the base component. | `string` | - |
| **disabled** | Toggle the disabled state for the component. | `boolean` | - |
| **itemKey** | Item key. | `string` \| `number` | - |