mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 09:57:02 +01:00
Add optional portal to Popover component (#8253)
This commit is contained in:
parent
079db2fdb4
commit
d1f761956a
@ -9,6 +9,7 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="app-content"></div>
|
||||
<div id="popover-content"></div>
|
||||
<script src="./ui-libs.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="./ui.js" type="text/javascript" charset="utf-8"></script>
|
||||
</body>
|
||||
|
@ -36,6 +36,7 @@
|
||||
<img id="loading__logo" src="./images/logo/metamask-fox.svg" />
|
||||
<img id="loading__spinner" src="./images/spinner.gif" />
|
||||
</div>
|
||||
<div id="popover-content"></div>
|
||||
<script src="./ui-libs.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="./ui.js" type="text/javascript" charset="utf-8"></script>
|
||||
</body>
|
||||
|
@ -9,6 +9,7 @@
|
||||
</head>
|
||||
<body style="width:357px; height:600px;">
|
||||
<div id="app-content"></div>
|
||||
<div id="popover-content"></div>
|
||||
<script src="./ui-libs.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script src="./ui.js" type="text/javascript" charset="utf-8"></script>
|
||||
</body>
|
||||
|
@ -1,4 +1,5 @@
|
||||
import React from 'react'
|
||||
import React, { PureComponent } from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import PropTypes from 'prop-types'
|
||||
import PopoverHeader from './popover.header.component'
|
||||
|
||||
@ -20,4 +21,33 @@ Popover.propTypes = {
|
||||
onClose: PropTypes.func.isRequired,
|
||||
}
|
||||
|
||||
export default Popover
|
||||
export default class PopoverPortal extends PureComponent {
|
||||
static propTypes = Popover.propTypes
|
||||
|
||||
rootNode = document.getElementById('popover-content')
|
||||
|
||||
instanceNode = document.createElement('div')
|
||||
|
||||
componentDidMount () {
|
||||
if (!this.rootNode) {
|
||||
return
|
||||
}
|
||||
|
||||
this.rootNode.appendChild(this.instanceNode)
|
||||
}
|
||||
|
||||
componentWillUnmount () {
|
||||
if (!this.rootNode) {
|
||||
return
|
||||
}
|
||||
|
||||
this.rootNode.removeChild(this.instanceNode)
|
||||
}
|
||||
|
||||
render () {
|
||||
const children = <Popover {...this.props} />
|
||||
return this.rootNode
|
||||
? ReactDOM.createPortal(children, this.instanceNode)
|
||||
: children
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user