fix action info popup position adjusting

This commit is contained in:
Val Erastov 2018-11-30 01:06:49 -08:00
parent f5cb8bfcec
commit bb5440caa3
2 changed files with 17 additions and 12 deletions

View file

@ -1,8 +1,15 @@
import React from 'react';
export default class AdjustableAbs extends React.Component {
export default function AdjustableAbs(props) {
if (!props.visible) {
return null;
}
return <Adjuster {...props}/>
}
export class Adjuster extends React.Component {
fit() {
fit = () => {
if (!this.el) {
return;
}
@ -14,9 +21,9 @@ export default class AdjustableAbs extends React.Component {
let pos = this.props[prop];
if (pos !== undefined) {
if (pos + dim > holderDim) {
pos = holderDim - dim;
this.el.style[prop] = pos + 'px';
pos = (holderDim - dim) - 5;
}
this.el.style[prop] = pos + 'px';
}
};
@ -41,14 +48,11 @@ export default class AdjustableAbs extends React.Component {
fit('right', w, holder.offsetWidth);
fit('top', h, holder.offsetHeight);
fit('bottom', h, holder.offsetHeight);
}
this.el.style.visibility = 'visible';
};
componentDidMount() {
this.fit();
}
componentDidUpdate() {
this.fit();
setTimeout(this.fit);
}
componentWillUnmount() {
@ -59,8 +63,8 @@ export default class AdjustableAbs extends React.Component {
let {left, top, right, bottom, children, style, zIndex, visible, centered, ...props} = this.props;
return <div ref={el => this.el = el}
style={{
display: visible ? 'block' : 'none',
position: 'absolute', left, top, right, bottom, zIndex,
visibility: 'hidden',
position: 'absolute', zIndex,
...style}} {...props}>
{children}
</div>;

View file

@ -2,6 +2,7 @@
.root {
display: flex;
flex-direction: column;
pointer-events:none;
padding: 2px 5px;
max-width: 400px;