mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 01:25:52 -05:00
Merge pull request #3357 from picklesrus/join-modal-x-button
One approach to hiding the close button in the modal.
This commit is contained in:
commit
036937bbfb
4 changed files with 57 additions and 14 deletions
|
@ -49,6 +49,8 @@ class Modal extends React.Component {
|
||||||
}}
|
}}
|
||||||
{...omit(this.props, ['className', 'overlayClassName'])}
|
{...omit(this.props, ['className', 'overlayClassName'])}
|
||||||
>
|
>
|
||||||
|
|
||||||
|
{this.props.showCloseButton && (
|
||||||
<div
|
<div
|
||||||
className="modal-content-close"
|
className="modal-content-close"
|
||||||
onClick={this.handleRequestClose}
|
onClick={this.handleRequestClose}
|
||||||
|
@ -60,6 +62,7 @@ class Modal extends React.Component {
|
||||||
src="/svgs/modal/close-x.svg"
|
src="/svgs/modal/close-x.svg"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
{this.props.children}
|
{this.props.children}
|
||||||
</ReactModal>
|
</ReactModal>
|
||||||
);
|
);
|
||||||
|
@ -70,7 +73,11 @@ Modal.propTypes = {
|
||||||
children: PropTypes.node,
|
children: PropTypes.node,
|
||||||
className: PropTypes.string,
|
className: PropTypes.string,
|
||||||
overlayClassName: PropTypes.string,
|
overlayClassName: PropTypes.string,
|
||||||
|
showCloseButton: PropTypes.bool,
|
||||||
useStandardSizes: PropTypes.bool
|
useStandardSizes: PropTypes.bool
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Modal.defaultProps = {
|
||||||
|
showCloseButton: true
|
||||||
|
};
|
||||||
module.exports = Modal;
|
module.exports = Modal;
|
||||||
|
|
|
@ -12,6 +12,7 @@ const JoinModal = ({
|
||||||
}) => (
|
}) => (
|
||||||
<Modal
|
<Modal
|
||||||
isOpen
|
isOpen
|
||||||
|
showCloseButton
|
||||||
useStandardSizes
|
useStandardSizes
|
||||||
className="mod-join"
|
className="mod-join"
|
||||||
shouldCloseOnOverlayClick={false}
|
shouldCloseOnOverlayClick={false}
|
||||||
|
@ -26,7 +27,8 @@ const JoinModal = ({
|
||||||
|
|
||||||
JoinModal.propTypes = {
|
JoinModal.propTypes = {
|
||||||
onCompleteRegistration: PropTypes.func,
|
onCompleteRegistration: PropTypes.func,
|
||||||
onRequestClose: PropTypes.func
|
onRequestClose: PropTypes.func,
|
||||||
|
showCloseButton: PropTypes.bool
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = JoinModal;
|
module.exports = JoinModal;
|
||||||
|
|
|
@ -5,12 +5,12 @@ const ErrorBoundary = require('../../components/errorboundary/errorboundary.jsx'
|
||||||
// Require this even though we don't use it because, without it, webpack runs out of memory...
|
// Require this even though we don't use it because, without it, webpack runs out of memory...
|
||||||
const Page = require('../../components/page/www/page.jsx'); // eslint-disable-line no-unused-vars
|
const Page = require('../../components/page/www/page.jsx'); // eslint-disable-line no-unused-vars
|
||||||
|
|
||||||
const openModal = true;
|
|
||||||
const Register = () => (
|
const Register = () => (
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<JoinModal
|
<JoinModal
|
||||||
isOpen={openModal}
|
isOpen
|
||||||
key="scratch3registration"
|
key="scratch3registration"
|
||||||
|
showCloseButton={false}
|
||||||
/>
|
/>
|
||||||
</ErrorBoundary>
|
</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…
Reference in a new issue