| 1 |
import useAction from 'elementor-app/hooks/use-action'; |
| 2 |
|
| 3 |
import Button from './header-button'; |
| 4 |
|
| 5 |
export default function HeaderButtons( props ) { |
| 6 |
const action = useAction(); |
| 7 |
|
| 8 |
const actionOnClose = () => { |
| 9 |
if ( props.onClose ) { |
| 10 |
props.onClose(); |
| 11 |
} else { |
| 12 |
action.backToDashboard(); |
| 13 |
} |
| 14 |
}; |
| 15 |
|
| 16 |
let tools = ''; |
| 17 |
|
| 18 |
if ( props.buttons.length ) { |
| 19 |
const buttons = props.buttons.map( ( button ) => { |
| 20 |
return <Button key={ button.id } { ...button } />; |
| 21 |
} ); |
| 22 |
|
| 23 |
tools = ( |
| 24 |
<> |
| 25 |
{ buttons } |
| 26 |
</> |
| 27 |
); |
| 28 |
} |
| 29 |
|
| 30 |
return ( |
| 31 |
<div className="eps-app__header-buttons"> |
| 32 |
<Button |
| 33 |
text={ __( 'Close', 'elementor' ) } |
| 34 |
icon="eicon-close" |
| 35 |
className="eps-app__close-button" |
| 36 |
onClick={ actionOnClose } |
| 37 |
/> |
| 38 |
{ tools } |
| 39 |
</div> |
| 40 |
); |
| 41 |
} |
| 42 |
|
| 43 |
HeaderButtons.propTypes = { |
| 44 |
buttons: PropTypes.arrayOf( PropTypes.object ), |
| 45 |
onClose: PropTypes.func, |
| 46 |
}; |
| 47 |
|
| 48 |
HeaderButtons.defaultProps = { |
| 49 |
buttons: [], |
| 50 |
}; |
| 51 |
|