diff --git a/src/common/ModalDialog/ModalDialog.js b/src/common/ModalDialog/ModalDialog.js index c12442c37..32f76a468 100644 --- a/src/common/ModalDialog/ModalDialog.js +++ b/src/common/ModalDialog/ModalDialog.js @@ -6,14 +6,27 @@ const Icon = require('stremio-icons/dom'); const { Modal } = require('stremio-router'); const styles = require('./styles'); -const ModalDialog = ({ className, children, title, buttons, visible, onClose }) => { +const ModalDialog = ({ className, children, title, buttons, onClose }) => { + // Close with the Escape key + // TODO: Maybe we should consider a global actions mapping so the 'close' key can be globbaly changed + React.useEffect(() => { + const onKeyUp = (event) => { + if (event.key === 'Escape' && typeof onClose === 'function') { + onClose(); + } + }; + window.addEventListener('keyup', onKeyUp); + return () => { + window.removeEventListener('keyup', onKeyUp); + }; + }, [onClose]); const onModalContainerClick = React.useCallback(event => { - if(event.target === event.currentTarget) { + if (event.target === event.currentTarget && typeof onClose === 'function') { onClose(event); } - }); + }, [onClose]); return ( - +
{Array.isArray(buttons) && buttons.length ? buttons.map((button, key) => ( - +
+ + { + modalVisible + ? + + {modalDummyContents} + + : + null + } - - - - {modalDummyContents} - - - {modalDummyContents} - - + + { + modalBVisible + ? + + {modalDummyContents} + + : + null + } +
); }); \ No newline at end of file diff --git a/storybook/stories/ModalDialog/styles.less b/storybook/stories/ModalDialog/styles.less index d6ae29b64..91e9557e6 100644 --- a/storybook/stories/ModalDialog/styles.less +++ b/storybook/stories/ModalDialog/styles.less @@ -1,39 +1,8 @@ -.button { - display: inline-block; - background-color: var(--color-signal3); - width: 15rem; - text-align: center; - padding: 1rem; - margin: .5rem; -} - .modal-dialog { width: 45rem; - .content-container { - display: flex; - flex-flow: row; - margin: 0 -0.5rem; - - .content-column { - flex: 1 0 0; - padding: 0 0.5rem; - - p { - text-align: justify; - } - } - } .custom-button { - display: flex; - align-items: center; - justify-content: center; - flex: 1 0 0; - text-align: center; - color: var(--color-surfacelighter); background-color: var(--color-signal3); - padding: 1rem; - margin: 0.5rem; &:hover { background-color: var(--color-signal380); @@ -51,4 +20,30 @@ margin-right: 0.5rem; } } + + // This is only for the content. Not relevant for the demo + .content-container { + display: flex; + flex-flow: row; + margin: 0 -0.5rem; + + .content-column { + flex: 1 0 0; + padding: 0 0.5rem; + + p { + text-align: justify; + } + } + } } + +// This is only for the buttons that show the modals. Not relevant for the demo +.show-modal-button { + display: inline-block; + background-color: var(--color-signal4); + width: 15rem; + text-align: center; + padding: 1rem; + margin: .5rem; +} \ No newline at end of file