Skip to content

Commit c0b468c

Browse files
committed
feat(CSidebarBrand): allows to rendering the component as a link
1 parent ad08245 commit c0b468c

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

packages/coreui-react/src/components/sidebar/CSidebarBrand.tsx

+21-11
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
1-
import React, { forwardRef, HTMLAttributes } from 'react'
1+
import React, { ElementType, forwardRef, HTMLAttributes } from 'react'
22
import PropTypes from 'prop-types'
33
import classNames from 'classnames'
44

5-
export interface CSidebarBrandProps extends HTMLAttributes<HTMLDivElement> {
5+
import { PolymorphicRefForwardingComponent } from '../../helpers'
6+
7+
export interface CSidebarBrandProps extends HTMLAttributes<HTMLAnchorElement | HTMLDivElement> {
8+
/**
9+
* Component used for the root node. Either a string to use a HTML element or a component.
10+
*
11+
* @since 5.0.0-rc.0
12+
*/
13+
as?: ElementType
614
/**
715
* A string of all className you want applied to the component.
816
*/
917
className?: string
1018
}
1119

12-
export const CSidebarBrand = forwardRef<HTMLDivElement, CSidebarBrandProps>(
13-
({ children, className, ...rest }, ref) => {
14-
return (
15-
<div className={classNames('sidebar-brand', className)} ref={ref} {...rest}>
16-
{children}
17-
</div>
18-
)
19-
},
20-
)
20+
export const CSidebarBrand: PolymorphicRefForwardingComponent<'a', CSidebarBrandProps> = forwardRef<
21+
HTMLAnchorElement | HTMLDivElement,
22+
CSidebarBrandProps
23+
>(({ children, as: Component = 'a', className, ...rest }, ref) => {
24+
return (
25+
<Component className={classNames('sidebar-brand', className)} ref={ref} {...rest}>
26+
{children}
27+
</Component>
28+
)
29+
})
2130

2231
CSidebarBrand.propTypes = {
32+
as: PropTypes.elementType,
2333
children: PropTypes.node,
2434
className: PropTypes.string,
2535
}

0 commit comments

Comments
 (0)