aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/modal.js
diff options
context:
space:
mode:
authorsdtsui <szehungdanieltsui@gmail.com>2017-08-09 04:37:41 +0800
committersdtsui <szehungdanieltsui@gmail.com>2017-08-09 04:37:41 +0800
commitf72f57dc6c75f6c0abfd90765073e41487f6f584 (patch)
treebe0625bd85f3262cd3ef7ad346b061a8e933f3c7 /ui/app/components/modal.js
parentaab0fda9acf58c638a03a43de4260c079adf258f (diff)
downloadtangerine-wallet-browser-f72f57dc6c75f6c0abfd90765073e41487f6f584.tar
tangerine-wallet-browser-f72f57dc6c75f6c0abfd90765073e41487f6f584.tar.gz
tangerine-wallet-browser-f72f57dc6c75f6c0abfd90765073e41487f6f584.tar.bz2
tangerine-wallet-browser-f72f57dc6c75f6c0abfd90765073e41487f6f584.tar.lz
tangerine-wallet-browser-f72f57dc6c75f6c0abfd90765073e41487f6f584.tar.xz
tangerine-wallet-browser-f72f57dc6c75f6c0abfd90765073e41487f6f584.tar.zst
tangerine-wallet-browser-f72f57dc6c75f6c0abfd90765073e41487f6f584.zip
Implement global modal
Diffstat (limited to 'ui/app/components/modal.js')
-rw-r--r--ui/app/components/modal.js75
1 files changed, 75 insertions, 0 deletions
diff --git a/ui/app/components/modal.js b/ui/app/components/modal.js
new file mode 100644
index 000000000..5bbc86ff5
--- /dev/null
+++ b/ui/app/components/modal.js
@@ -0,0 +1,75 @@
+const Component = require('react').Component
+const h = require('react-hyperscript')
+const inherits = require('util').inherits
+const connect = require('react-redux').connect
+// const elementType = require('react-prop-types/lib/elementType')
+// const PropTypes from 'prop-types'
+const FadeModal = require('boron').FadeModal
+const actions = require('../actions')
+
+function mapStateToProps (state) {
+ return {
+ active: state.appState.modalOpen
+ }
+}
+
+function mapDispatchToProps (dispatch) {
+ return {
+ hideModal: () => {
+ dispatch(actions.hideModal())
+ },
+ }
+}
+
+inherits(Modal, Component)
+function Modal () {
+ Component.call(this)
+}
+
+module.exports = connect(mapStateToProps, mapDispatchToProps)(Modal)
+
+Modal.prototype.render = function () {
+
+ return h(FadeModal,
+ {
+ keyboard: false,
+ onHide: () => {this.onHide()},
+ ref: (ref) => {
+ this.modalRef = ref
+ },
+ },
+ this.props.children,
+ )
+}
+
+Modal.prototype.componentWillReceiveProps = function(nextProps) {
+ if (nextProps.active) {
+ this.show()
+ } else if (this.props.active) {
+ this.hide()
+ }
+}
+
+Modal.prototype.onHide = function() {
+ if (this.props.onHideCallback) {
+ this.props.onHideCallback()
+ }
+ this.props.hideModal()
+}
+
+Modal.prototype.hide = function() {
+ this.modalRef.hide()
+}
+
+Modal.prototype.show = function() {
+ this.modalRef.show()
+}
+
+// Modal.defaultProps = {}
+
+// Modal.propTypes = {
+// active: PropTypes.bool,
+// hideModal: PropTypes.func.isRequired,
+// component: elementType,
+// onHideCallback: PropTypes.func,
+// }