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