1- import React , { forwardRef , HTMLAttributes , useEffect , useRef , useState } from 'react'
1+ import React , { ElementType , forwardRef , HTMLAttributes , useEffect , useRef , useState } from 'react'
22import { createPortal } from 'react-dom'
33import PropTypes from 'prop-types'
44import classNames from 'classnames'
@@ -7,8 +7,13 @@ import { CBackdrop } from '../backdrop'
77
88import { isInViewport } from '../../utils'
99import { useForkedRef } from '../../hooks'
10+ import { PolymorphicRefForwardingComponent } from '../../helpers'
1011
1112export interface CSidebarProps extends HTMLAttributes < HTMLDivElement > {
13+ /**
14+ * Component used for the root node. Either a string to use a HTML element or a component.
15+ */
16+ as ?: ElementType
1217 /**
1318 * A string of all className you want applied to the component.
1419 */
@@ -65,10 +70,14 @@ export interface CSidebarProps extends HTMLAttributes<HTMLDivElement> {
6570const isOnMobile = ( element : HTMLDivElement ) =>
6671 Boolean ( getComputedStyle ( element ) . getPropertyValue ( '--cui-is-mobile' ) )
6772
68- export const CSidebar = forwardRef < HTMLDivElement , CSidebarProps > (
73+ export const CSidebar : PolymorphicRefForwardingComponent < 'div' , CSidebarProps > = forwardRef <
74+ HTMLDivElement ,
75+ CSidebarProps
76+ > (
6977 (
7078 {
7179 children,
80+ as : Component = 'div' ,
7281 className,
7382 colorScheme,
7483 narrow,
@@ -183,7 +192,7 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
183192
184193 return (
185194 < >
186- < div
195+ < Component
187196 className = { classNames (
188197 'sidebar' ,
189198 {
@@ -203,7 +212,7 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
203212 ref = { forkedRef }
204213 >
205214 { children }
206- </ div >
215+ </ Component >
207216 { typeof window !== 'undefined' &&
208217 mobile &&
209218 createPortal (
@@ -216,6 +225,7 @@ export const CSidebar = forwardRef<HTMLDivElement, CSidebarProps>(
216225)
217226
218227CSidebar . propTypes = {
228+ as : PropTypes . elementType ,
219229 children : PropTypes . node ,
220230 className : PropTypes . string ,
221231 colorScheme : PropTypes . oneOf ( [ 'dark' , 'light' ] ) ,
@@ -231,4 +241,4 @@ CSidebar.propTypes = {
231241 visible : PropTypes . bool ,
232242}
233243
234- CSidebar . displayName = 'CSidebar'
244+ CSidebar . displayName = 'CSidebar'
0 commit comments