11import cx from 'clsx'
22import _ from 'lodash'
33import PropTypes from 'prop-types'
4- import React , { Component } from 'react'
4+ import React from 'react'
55
66import {
77 childrenUtils ,
@@ -15,45 +15,45 @@ import Button from '../../elements/Button'
1515/**
1616 * A modal can contain a row of actions.
1717 */
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
2520
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 )
4624
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 ) ) {
4733 return (
4834 < ElementType { ...rest } className = { classes } >
49- { _ . map ( actions , ( action ) =>
50- Button . create ( action , { overrideProps : this . handleButtonOverrides } ) ,
51- ) }
35+ { content }
5236 </ ElementType >
5337 )
5438 }
55- }
5639
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'
5757ModalActions . propTypes = {
5858 /** An element type to render as (string or function). */
5959 as : PropTypes . elementType ,
@@ -80,3 +80,5 @@ ModalActions.propTypes = {
8080}
8181
8282ModalActions . create = createShorthandFactory ( ModalActions , ( actions ) => ( { actions } ) )
83+
84+ export default ModalActions
0 commit comments