1
1
import cx from 'clsx'
2
2
import _ from 'lodash'
3
3
import PropTypes from 'prop-types'
4
- import React , { Component } from 'react'
4
+ import React from 'react'
5
5
6
6
import {
7
7
childrenUtils ,
@@ -10,35 +10,31 @@ import {
10
10
getUnhandledProps ,
11
11
getElementType ,
12
12
useKeyOnly ,
13
+ useEventCallback ,
13
14
} from '../../lib'
14
15
15
16
/**
16
17
* A section sub-component for Breadcrumb component.
17
18
*/
18
- export default class BreadcrumbSection extends Component {
19
- computeElementType = ( ) => {
20
- const { link, onClick } = this . props
19
+ const BreadcrumbSection = React . forwardRef ( function ( props , ref ) {
20
+ const { active, children, className, content, href, link, onClick } = props
21
21
22
+ const classes = cx ( useKeyOnly ( active , 'active' ) , 'section' , className )
23
+ const rest = getUnhandledProps ( BreadcrumbSection , props )
24
+ const ElementType = getElementType ( BreadcrumbSection , props , ( ) => {
22
25
if ( link || onClick ) return 'a'
23
- }
26
+ } )
24
27
25
- handleClick = ( e ) => _ . invoke ( this . props , 'onClick' , e , this . props )
28
+ const handleClick = useEventCallback ( ( e ) => _ . invoke ( props , 'onClick' , e , props ) )
26
29
27
- render ( ) {
28
- const { active, children, className, content, href } = this . props
29
-
30
- const classes = cx ( useKeyOnly ( active , 'active' ) , 'section' , className )
31
- const rest = getUnhandledProps ( BreadcrumbSection , this . props )
32
- const ElementType = getElementType ( BreadcrumbSection , this . props , this . computeElementType )
33
-
34
- return (
35
- < ElementType { ...rest } className = { classes } href = { href } onClick = { this . handleClick } >
36
- { childrenUtils . isNil ( children ) ? content : children }
37
- </ ElementType >
38
- )
39
- }
40
- }
30
+ return (
31
+ < ElementType { ...rest } className = { classes } href = { href } onClick = { handleClick } ref = { ref } >
32
+ { childrenUtils . isNil ( children ) ? content : children }
33
+ </ ElementType >
34
+ )
35
+ } )
41
36
37
+ BreadcrumbSection . displayName = 'BreadcrumbSection'
42
38
BreadcrumbSection . propTypes = {
43
39
/** An element type to render as (string or function). */
44
40
as : PropTypes . elementType ,
@@ -75,3 +71,5 @@ BreadcrumbSection.create = createShorthandFactory(BreadcrumbSection, (content) =
75
71
content,
76
72
link : true ,
77
73
} ) )
74
+
75
+ export default BreadcrumbSection
0 commit comments