|
@ -7,6 +7,8 @@ export default class Wave extends React.Component<{insertExtraNode?: boolean}> { |
|
|
cancel: () => void; |
|
|
cancel: () => void; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
private extraNode: HTMLDivElement; |
|
|
|
|
|
private clickWaveTimeoutId: number; |
|
|
private styleForPesudo: HTMLStyleElement | null; |
|
|
private styleForPesudo: HTMLStyleElement | null; |
|
|
|
|
|
|
|
|
isNotGrey(color: string) { |
|
|
isNotGrey(color: string) { |
|
@ -17,22 +19,17 @@ export default class Wave extends React.Component<{insertExtraNode?: boolean}> { |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
onClick = (node: HTMLElement) => { |
|
|
onClick = (node: HTMLElement, waveColor: string) => { |
|
|
if (node.className.indexOf('-leave') >= 0) { |
|
|
if (node.className.indexOf('-leave') >= 0) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
this.removeExtraStyleNode(); |
|
|
|
|
|
const { insertExtraNode } = this.props; |
|
|
const { insertExtraNode } = this.props; |
|
|
const extraNode = document.createElement('div'); |
|
|
this.extraNode = document.createElement('div'); |
|
|
|
|
|
const extraNode = this.extraNode; |
|
|
extraNode.className = 'ant-click-animating-node'; |
|
|
extraNode.className = 'ant-click-animating-node'; |
|
|
const attributeName = insertExtraNode ? 'ant-click-animating' : 'ant-click-animating-without-extra-node'; |
|
|
const attributeName = this.getAttributeName(); |
|
|
node.removeAttribute(attributeName); |
|
|
node.removeAttribute(attributeName); |
|
|
node.setAttribute(attributeName, 'true'); |
|
|
node.setAttribute(attributeName, 'true'); |
|
|
// Get wave color from target
|
|
|
|
|
|
const waveColor = |
|
|
|
|
|
getComputedStyle(node).getPropertyValue('border-top-color') || // Firefox Compatible
|
|
|
|
|
|
getComputedStyle(node).getPropertyValue('border-color') || |
|
|
|
|
|
getComputedStyle(node).getPropertyValue('background-color'); |
|
|
|
|
|
// Not white or transparnt or grey
|
|
|
// Not white or transparnt or grey
|
|
|
if (waveColor && |
|
|
if (waveColor && |
|
|
waveColor !== '#ffffff' && |
|
|
waveColor !== '#ffffff' && |
|
@ -49,18 +46,7 @@ export default class Wave extends React.Component<{insertExtraNode?: boolean}> { |
|
|
if (insertExtraNode) { |
|
|
if (insertExtraNode) { |
|
|
node.appendChild(extraNode); |
|
|
node.appendChild(extraNode); |
|
|
} |
|
|
} |
|
|
const transitionEnd = (e: AnimationEvent) => { |
|
|
TransitionEvents.addEndEventListener(node, this.onTransitionEnd); |
|
|
if (e.animationName !== 'fadeEffect') { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
node.removeAttribute(attributeName); |
|
|
|
|
|
this.removeExtraStyleNode(); |
|
|
|
|
|
if (insertExtraNode) { |
|
|
|
|
|
node.removeChild(extraNode); |
|
|
|
|
|
} |
|
|
|
|
|
TransitionEvents.removeEndEventListener(node, transitionEnd); |
|
|
|
|
|
}; |
|
|
|
|
|
TransitionEvents.addEndEventListener(node, transitionEnd); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bindAnimationEvent = (node: HTMLElement) => { |
|
|
bindAnimationEvent = (node: HTMLElement) => { |
|
@ -73,7 +59,13 @@ export default class Wave extends React.Component<{insertExtraNode?: boolean}> { |
|
|
if ((e.target as HTMLElement).tagName === 'INPUT') { |
|
|
if ((e.target as HTMLElement).tagName === 'INPUT') { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
setTimeout(() => this.onClick(node), 0); |
|
|
this.resetEffect(node); |
|
|
|
|
|
// Get wave color from target
|
|
|
|
|
|
const waveColor = |
|
|
|
|
|
getComputedStyle(node).getPropertyValue('border-top-color') || // Firefox Compatible
|
|
|
|
|
|
getComputedStyle(node).getPropertyValue('border-color') || |
|
|
|
|
|
getComputedStyle(node).getPropertyValue('background-color'); |
|
|
|
|
|
this.clickWaveTimeoutId = window.setTimeout(() => this.onClick(node, waveColor), 0); |
|
|
}; |
|
|
}; |
|
|
node.addEventListener('click', onClick, true); |
|
|
node.addEventListener('click', onClick, true); |
|
|
return { |
|
|
return { |
|
@ -83,6 +75,29 @@ export default class Wave extends React.Component<{insertExtraNode?: boolean}> { |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
getAttributeName() { |
|
|
|
|
|
const { insertExtraNode } = this.props; |
|
|
|
|
|
return insertExtraNode ? 'ant-click-animating' : 'ant-click-animating-without-extra-node'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
resetEffect(node: HTMLElement) { |
|
|
|
|
|
const { insertExtraNode } = this.props; |
|
|
|
|
|
const attributeName = this.getAttributeName(); |
|
|
|
|
|
node.removeAttribute(attributeName); |
|
|
|
|
|
this.removeExtraStyleNode(); |
|
|
|
|
|
if (insertExtraNode) { |
|
|
|
|
|
node.removeChild(this.extraNode); |
|
|
|
|
|
} |
|
|
|
|
|
TransitionEvents.removeEndEventListener(node, this.onTransitionEnd); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
onTransitionEnd = (e: AnimationEvent) => { |
|
|
|
|
|
if (e.animationName !== 'fadeEffect') { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
this.resetEffect(e.target as HTMLElement); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
removeExtraStyleNode() { |
|
|
removeExtraStyleNode() { |
|
|
if (this.styleForPesudo && document.body.contains(this.styleForPesudo)) { |
|
|
if (this.styleForPesudo && document.body.contains(this.styleForPesudo)) { |
|
|
document.body.removeChild(this.styleForPesudo); |
|
|
document.body.removeChild(this.styleForPesudo); |
|
@ -98,6 +113,9 @@ export default class Wave extends React.Component<{insertExtraNode?: boolean}> { |
|
|
if (this.instance) { |
|
|
if (this.instance) { |
|
|
this.instance.cancel(); |
|
|
this.instance.cancel(); |
|
|
} |
|
|
} |
|
|
|
|
|
if (this.clickWaveTimeoutId) { |
|
|
|
|
|
clearTimeout(this.clickWaveTimeoutId); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
render() { |
|
|
render() { |
|
|