mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 11:08:45 +08:00
improve code style
This commit is contained in:
parent
10d650ee59
commit
fa776b9481
@ -6,8 +6,7 @@ import getPlacements from '../popover/placements';
|
|||||||
|
|
||||||
const placements = getPlacements();
|
const placements = getPlacements();
|
||||||
const prefixCls = 'ant-popover';
|
const prefixCls = 'ant-popover';
|
||||||
const noop = function () {
|
const noop = () => {};
|
||||||
};
|
|
||||||
|
|
||||||
export default class Popconfirm extends React.Component {
|
export default class Popconfirm extends React.Component {
|
||||||
static defaultProps = {
|
static defaultProps = {
|
||||||
@ -17,8 +16,7 @@ export default class Popconfirm extends React.Component {
|
|||||||
overlayStyle: {},
|
overlayStyle: {},
|
||||||
onConfirm: noop,
|
onConfirm: noop,
|
||||||
onCancel: noop,
|
onCancel: noop,
|
||||||
onVisibleChange() {
|
onVisibleChange: noop,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static contextTypes = {
|
static contextTypes = {
|
||||||
|
@ -14,4 +14,3 @@ ReactDOM.render(
|
|||||||
</Tooltip>
|
</Tooltip>
|
||||||
, mountNode);
|
, mountNode);
|
||||||
````
|
````
|
||||||
|
|
||||||
|
@ -12,13 +12,13 @@ export default class Tooltip extends React.Component {
|
|||||||
placement: 'top',
|
placement: 'top',
|
||||||
transitionName: 'zoom-big',
|
transitionName: 'zoom-big',
|
||||||
mouseEnterDelay: 0.1,
|
mouseEnterDelay: 0.1,
|
||||||
mouseLeaveDelay: 0.1
|
mouseLeaveDelay: 0.1,
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
visible: false
|
visible: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,30 +26,35 @@ export default class Tooltip extends React.Component {
|
|||||||
this.setState({ visible });
|
this.setState({ visible });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 动态设置动画点
|
||||||
onPopupAlign = (domNode, align) => {
|
onPopupAlign = (domNode, align) => {
|
||||||
// 当前返回的位置;
|
// 当前返回的位置
|
||||||
let placement;
|
const placement = Object.keys(placements).filter(
|
||||||
Object.keys(placements).forEach(key => {
|
key => (
|
||||||
const item = placements[key];
|
placements[key].points[0] === align.points[0] &&
|
||||||
if (item.points[0] === align.points[0] && item.points[1] === align.points[1]) {
|
placements[key].points[1] === align.points[1]
|
||||||
placement = key;
|
)
|
||||||
}
|
)[0];
|
||||||
});
|
if (!placement) {
|
||||||
// 当前坐标;
|
return;
|
||||||
|
}
|
||||||
|
// 根据当前坐标设置动画点
|
||||||
const rect = domNode.getBoundingClientRect();
|
const rect = domNode.getBoundingClientRect();
|
||||||
let top = '50%';
|
const transformOrigin = {
|
||||||
let left = '50%';
|
top: '50%',
|
||||||
|
left: '50%',
|
||||||
|
};
|
||||||
if (placement.indexOf('top') >= 0 || placement.indexOf('Bottom') >= 0) {
|
if (placement.indexOf('top') >= 0 || placement.indexOf('Bottom') >= 0) {
|
||||||
top = `${rect.height - align.offset[1]}px`;
|
transformOrigin.top = `${rect.height - align.offset[1]}px`;
|
||||||
} else if (placement.indexOf('Top') >= 0 || placement.indexOf('bottom') >= 0) {
|
} else if (placement.indexOf('Top') >= 0 || placement.indexOf('bottom') >= 0) {
|
||||||
top = `${-align.offset[1]}px`;
|
transformOrigin.top = `${-align.offset[1]}px`;
|
||||||
}
|
}
|
||||||
if (placement.indexOf('left') >= 0 || placement.indexOf('Right') >= 0) {
|
if (placement.indexOf('left') >= 0 || placement.indexOf('Right') >= 0) {
|
||||||
left = `${rect.width - align.offset[0]}px`;
|
transformOrigin.left = `${rect.width - align.offset[0]}px`;
|
||||||
} else if (placement.indexOf('right') >= 0 || placement.indexOf('Left') >= 0) {
|
} else if (placement.indexOf('right') >= 0 || placement.indexOf('Left') >= 0) {
|
||||||
left = `${-align.offset[0]}px`;
|
transformOrigin.left = `${-align.offset[0]}px`;
|
||||||
}
|
}
|
||||||
domNode.style.transformOrigin = `${left} ${top}`;
|
domNode.style.transformOrigin = `${transformOrigin.left} ${transformOrigin.top}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
Loading…
Reference in New Issue
Block a user