mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-03-25 20:29:45 -04:00
Add a prop to Modal that allows you to hide the close button. Set it to show by default and have the standalone join flow page set it to hidden.
This commit is contained in:
parent
c609d99e0e
commit
0d60b64c39
4 changed files with 57 additions and 12 deletions
|
@ -49,17 +49,20 @@ class Modal extends React.Component {
|
|||
}}
|
||||
{...omit(this.props, ['className', 'overlayClassName'])}
|
||||
>
|
||||
<div
|
||||
className="modal-content-close"
|
||||
onClick={this.handleRequestClose}
|
||||
>
|
||||
<img
|
||||
alt="close-icon"
|
||||
className="modal-content-close-img"
|
||||
draggable="false"
|
||||
src="/svgs/modal/close-x.svg"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{this.props.showCloseButton && (
|
||||
<div
|
||||
className="modal-content-close"
|
||||
onClick={this.handleRequestClose}
|
||||
>
|
||||
<img
|
||||
alt="close-icon"
|
||||
className="modal-content-close-img"
|
||||
draggable="false"
|
||||
src="/svgs/modal/close-x.svg"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{this.props.children}
|
||||
</ReactModal>
|
||||
);
|
||||
|
@ -70,7 +73,11 @@ Modal.propTypes = {
|
|||
children: PropTypes.node,
|
||||
className: PropTypes.string,
|
||||
overlayClassName: PropTypes.string,
|
||||
showCloseButton: PropTypes.bool,
|
||||
useStandardSizes: PropTypes.bool
|
||||
};
|
||||
|
||||
Modal.defaultProps = {
|
||||
showCloseButton: true
|
||||
};
|
||||
module.exports = Modal;
|
||||
|
|
|
@ -12,6 +12,7 @@ const JoinModal = ({
|
|||
}) => (
|
||||
<Modal
|
||||
isOpen
|
||||
showCloseButton
|
||||
useStandardSizes
|
||||
className="mod-join"
|
||||
shouldCloseOnOverlayClick={false}
|
||||
|
@ -26,7 +27,8 @@ const JoinModal = ({
|
|||
|
||||
JoinModal.propTypes = {
|
||||
onCompleteRegistration: PropTypes.func,
|
||||
onRequestClose: PropTypes.func
|
||||
onRequestClose: PropTypes.func,
|
||||
showCloseButton: PropTypes.bool
|
||||
};
|
||||
|
||||
module.exports = JoinModal;
|
||||
|
|
|
@ -6,11 +6,13 @@ const ErrorBoundary = require('../../components/errorboundary/errorboundary.jsx'
|
|||
const Page = require('../../components/page/www/page.jsx'); // eslint-disable-line no-unused-vars
|
||||
|
||||
const openModal = true;
|
||||
const showCloseButton = false;
|
||||
const Register = () => (
|
||||
<ErrorBoundary>
|
||||
<JoinModal
|
||||
isOpen={openModal}
|
||||
key="scratch3registration"
|
||||
showCloseButton={showCloseButton}
|
||||
/>
|
||||
</ErrorBoundary>
|
||||
);
|
||||
|
|
34
test/unit/components/modal.test.jsx
Normal file
34
test/unit/components/modal.test.jsx
Normal file
|
@ -0,0 +1,34 @@
|
|||
const React = require('react');
|
||||
const {shallowWithIntl} = require('../../helpers/intl-helpers.jsx');
|
||||
const Modal = require('../../../src/components/modal/base/modal.jsx');
|
||||
|
||||
describe('Modal', () => {
|
||||
test('Close button not shown when showCloseButton false', () => {
|
||||
const showClose = true;
|
||||
const component = shallowWithIntl(
|
||||
<Modal
|
||||
showCloseButton={showClose}
|
||||
/>
|
||||
);
|
||||
expect(component.find('div.modal-content-close').exists()).toBe(true);
|
||||
expect(component.find('img.modal-content-close-img').exists()).toBe(true);
|
||||
});
|
||||
test('Close button shown by default', () => {
|
||||
const component = shallowWithIntl(
|
||||
<Modal />
|
||||
);
|
||||
expect(component.find('div.modal-content-close').exists()).toBe(true);
|
||||
expect(component.find('img.modal-content-close-img').exists()).toBe(true);
|
||||
});
|
||||
|
||||
test('Close button shown when showCloseButton true', () => {
|
||||
const showClose = false;
|
||||
const component = shallowWithIntl(
|
||||
<Modal
|
||||
showCloseButton={showClose}
|
||||
/>
|
||||
);
|
||||
expect(component.find('div.modal-content-close').exists()).toBe(false);
|
||||
expect(component.find('img.modal-content-close-img').exists()).toBe(false);
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue