improve code style

This commit is contained in:
afc163 2016-04-07 16:43:00 +08:00
parent 10d650ee59
commit fa776b9481
3 changed files with 25 additions and 23 deletions

View File

@ -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 = {

View File

@ -14,4 +14,3 @@ ReactDOM.render(
</Tooltip>
, mountNode);
````

View File

@ -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() {