Skip to content

Commit

Permalink
Refactor Modal.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Aug 25, 2024
1 parent abb3a50 commit 50dd90d
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions rdmo/core/assets/js/components/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react'
import PropTypes from 'prop-types'
import { Modal as BootstrapModal } from 'react-bootstrap'

const Modal = ({ bsSize, buttonLabel, buttonProps, title, show, onClose, onSave, children }) => {
const Modal = ({ title, show, modalProps, submitLabel, submitProps, onClose, onSubmit, children }) => {
return (
<BootstrapModal bsSize={bsSize} className="element-modal" onHide={onClose} show={show}>
<BootstrapModal className="element-modal" onHide={onClose} show={show} {...modalProps}>
<BootstrapModal.Header closeButton>
<h2 className="modal-title">{title}</h2>
</BootstrapModal.Header>
Expand All @@ -15,26 +15,27 @@ const Modal = ({ bsSize, buttonLabel, buttonProps, title, show, onClose, onSave,
<button type="button" className="btn btn-default" onClick={onClose}>
{gettext('Close')}
</button>
{ onSave ?
<button type="button" className="btn btn-primary" onClick={onSave} {...buttonProps}>
{buttonLabel ?? gettext('Save')}
</button>
: null
{
onSubmit && (
<button type="button" className="btn btn-primary" onClick={onSubmit} {...submitProps}>
{submitLabel ?? gettext('Save')}
</button>
)
}
</BootstrapModal.Footer>
</BootstrapModal>
)
}

Modal.propTypes = {
bsSize: PropTypes.oneOf(['lg', 'large', 'sm', 'small']),
buttonLabel: PropTypes.string,
buttonProps: PropTypes.object,
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
onClose: PropTypes.func.isRequired,
onSave: PropTypes.func,
show: PropTypes.bool.isRequired,
title: PropTypes.string.isRequired,
show: PropTypes.bool.isRequired,
modalProps: PropTypes.object,
submitLabel: PropTypes.string,
submitProps: PropTypes.object,
onClose: PropTypes.func.isRequired,
onSubmit: PropTypes.func,
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
}

export default Modal

0 comments on commit 50dd90d

Please sign in to comment.