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 ,
@@ -15,45 +15,45 @@ import Button from '../../elements/Button'
15
15
/**
16
16
* A modal can contain a row of actions.
17
17
*/
18
- export default class ModalActions extends Component {
19
- handleButtonOverrides = ( predefinedProps ) => ( {
20
- onClick : ( e , buttonProps ) => {
21
- _ . invoke ( predefinedProps , 'onClick' , e , buttonProps )
22
- _ . invoke ( this . props , 'onActionClick' , e , buttonProps )
23
- } ,
24
- } )
18
+ const ModalActions = React . forwardRef ( function ( props , ref ) {
19
+ const { actions, children, className, content } = props
25
20
26
- render ( ) {
27
- const { actions, children, className, content } = this . props
28
- const classes = cx ( 'actions' , className )
29
- const rest = getUnhandledProps ( ModalActions , this . props )
30
- const ElementType = getElementType ( ModalActions , this . props )
31
-
32
- if ( ! childrenUtils . isNil ( children ) ) {
33
- return (
34
- < ElementType { ...rest } className = { classes } >
35
- { children }
36
- </ ElementType >
37
- )
38
- }
39
- if ( ! childrenUtils . isNil ( content ) ) {
40
- return (
41
- < ElementType { ...rest } className = { classes } >
42
- { content }
43
- </ ElementType >
44
- )
45
- }
21
+ const classes = cx ( 'actions' , className )
22
+ const rest = getUnhandledProps ( ModalActions , props )
23
+ const ElementType = getElementType ( ModalActions , props )
46
24
25
+ if ( ! childrenUtils . isNil ( children ) ) {
26
+ return (
27
+ < ElementType { ...rest } className = { classes } ref = { ref } >
28
+ { children }
29
+ </ ElementType >
30
+ )
31
+ }
32
+ if ( ! childrenUtils . isNil ( content ) ) {
47
33
return (
48
34
< ElementType { ...rest } className = { classes } >
49
- { _ . map ( actions , ( action ) =>
50
- Button . create ( action , { overrideProps : this . handleButtonOverrides } ) ,
51
- ) }
35
+ { content }
52
36
</ ElementType >
53
37
)
54
38
}
55
- }
56
39
40
+ return (
41
+ < ElementType { ...rest } className = { classes } ref = { ref } >
42
+ { _ . map ( actions , ( action ) =>
43
+ Button . create ( action , {
44
+ overrideProps : ( predefinedProps ) => ( {
45
+ onClick : ( e , buttonProps ) => {
46
+ _ . invoke ( predefinedProps , 'onClick' , e , buttonProps )
47
+ _ . invoke ( props , 'onActionClick' , e , buttonProps )
48
+ } ,
49
+ } ) ,
50
+ } ) ,
51
+ ) }
52
+ </ ElementType >
53
+ )
54
+ } )
55
+
56
+ ModalActions . displayName = 'ModalActions'
57
57
ModalActions . propTypes = {
58
58
/** An element type to render as (string or function). */
59
59
as : PropTypes . elementType ,
@@ -80,3 +80,5 @@ ModalActions.propTypes = {
80
80
}
81
81
82
82
ModalActions . create = createShorthandFactory ( ModalActions , ( actions ) => ( { actions } ) )
83
+
84
+ export default ModalActions
0 commit comments