popOver支持offset

This commit is contained in:
hantianjiao 2019-06-13 19:32:50 +08:00
parent bfe73e0dfb
commit e4d91d4538
3 changed files with 14 additions and 9 deletions

View File

@ -163,6 +163,15 @@ export default {
{ {
name: "platform", name: "platform",
label: "Platform(s)", label: "Platform(s)",
popOver: {
body: {
type: "tpl",
tpl: "偏了一点的popover"
},
offset: {
y: 100
}
},
sortable: true, sortable: true,
type: "text", type: "text",
toggled: true toggled: true

View File

@ -74,10 +74,9 @@ export class PopOver extends React.PureComponent<PopOverPorps, PopOverState> {
} else { } else {
offset = getOffset as Offset; offset = getOffset as Offset;
} }
this.setState({ this.setState({
xOffset: offset ? (offset as Offset).x : 0, xOffset: (offset && offset.x) ? (offset as Offset).x : 0,
yOffset: offset ? offset.y : 0, yOffset: (offset && offset.y) ? (offset as Offset).y : 0,
}); });
} }
@ -100,7 +99,6 @@ export class PopOver extends React.PureComponent<PopOverPorps, PopOverState> {
} = this.props; } = this.props;
const {xOffset, yOffset} = this.state; const {xOffset, yOffset} = this.state;
const outerStyle = { const outerStyle = {
display: 'block', display: 'block',
...style, ...style,

View File

@ -9,11 +9,9 @@ import {RendererProps} from '../factory';
import cx from 'classnames'; import cx from 'classnames';
import hoistNonReactStatic = require('hoist-non-react-statics'); import hoistNonReactStatic = require('hoist-non-react-statics');
import {RootCloseWrapper} from 'react-overlays'; import {RootCloseWrapper} from 'react-overlays';
import PopOver from '../components/PopOver'; import PopOver, {Offset} from '../components/PopOver';
import Overlay from '../components/Overlay'; import Overlay from '../components/Overlay';
export interface PopOverConfig {}
const allowedPositions = ['center', 'top']; const allowedPositions = ['center', 'top'];
export interface PopOverConfig { export interface PopOverConfig {
@ -33,6 +31,7 @@ export interface PopOverConfig {
| 'fixed-left-bottom' | 'fixed-left-bottom'
| 'fixed-right-bottom'; | 'fixed-right-bottom';
[propName: string]: any; [propName: string]: any;
offset: Offset;
} }
export interface PopOverProps extends RendererProps { export interface PopOverProps extends RendererProps {
@ -125,7 +124,6 @@ export const HocPopOver = (config: Partial<PopOverConfig> = {}) => (Component: R
renderPopOver() { renderPopOver() {
let {popOver, render, popOverContainer, classnames: cx, classPrefix: ns} = this.props; let {popOver, render, popOverContainer, classnames: cx, classPrefix: ns} = this.props;
if ( if (
popOver && popOver &&
((popOver as PopOverConfig).mode === 'dialog' || (popOver as PopOverConfig).mode === 'drawer') ((popOver as PopOverConfig).mode === 'dialog' || (popOver as PopOverConfig).mode === 'drawer')
@ -161,7 +159,7 @@ export const HocPopOver = (config: Partial<PopOverConfig> = {}) => (Component: R
rootClose rootClose
show show
> >
<PopOver classPrefix={ns} className={cx('PopOverAble-popover')}> <PopOver classPrefix={ns} className={cx('PopOverAble-popover')} offset={popOver.offset}>
{content} {content}
</PopOver> </PopOver>
</Overlay> </Overlay>