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

View File

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

View File

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