2022-06-28 01:49:37 +08:00
|
|
|
import { Keyframes, useStyleRegister } from '@ant-design/cssinjs';
|
|
|
|
import { useContext } from 'react';
|
|
|
|
import { ConfigContext } from '../../config-provider';
|
2022-11-23 20:22:38 +08:00
|
|
|
import type { AliasToken, GenerateStyle, UseComponentStyleResult } from '../../theme/internal';
|
|
|
|
import { useToken } from '../../theme/internal';
|
2022-06-28 01:49:37 +08:00
|
|
|
|
|
|
|
interface WaveToken extends AliasToken {
|
|
|
|
hashId: string;
|
|
|
|
clickAnimatingNode: string;
|
|
|
|
clickAnimatingTrue: string;
|
|
|
|
clickAnimatingWithoutExtraNodeTrue: string;
|
|
|
|
clickAnimatingWithoutExtraNodeTrueAfter: string;
|
|
|
|
}
|
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
const genWaveStyle: GenerateStyle<WaveToken> = (token) => {
|
2022-06-28 01:49:37 +08:00
|
|
|
const waveEffect = new Keyframes('waveEffect', {
|
|
|
|
'100%': {
|
2022-06-28 15:20:09 +08:00
|
|
|
boxShadow: `0 0 0 6px var(--antd-wave-shadow-color)`,
|
2022-06-28 01:49:37 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const fadeEffect = new Keyframes('fadeEffect', {
|
|
|
|
'100%': {
|
|
|
|
opacity: 0,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
[`${token.clickAnimatingWithoutExtraNodeTrue},
|
|
|
|
${token.clickAnimatingTrue}`]: {
|
2022-06-28 15:20:09 +08:00
|
|
|
'--antd-wave-shadow-color': token.colorPrimary,
|
|
|
|
'--scroll-bar': 0,
|
2022-06-28 01:49:37 +08:00
|
|
|
position: 'relative',
|
|
|
|
},
|
|
|
|
[`${token.clickAnimatingWithoutExtraNodeTrueAfter},
|
|
|
|
& ${token.clickAnimatingNode}`]: {
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
insetInlineStart: 0,
|
|
|
|
insetInlineEnd: 0,
|
|
|
|
bottom: 0,
|
|
|
|
display: 'block',
|
|
|
|
borderRadius: 'inherit',
|
2022-06-28 15:20:09 +08:00
|
|
|
boxShadow: `0 0 0 0 var(--antd-wave-shadow-color)`,
|
2022-06-28 01:49:37 +08:00
|
|
|
opacity: 0.2,
|
2022-06-28 15:20:09 +08:00
|
|
|
animation: {
|
|
|
|
_skip_check_: true,
|
|
|
|
value: `${fadeEffect.getName(token.hashId)} 2s ${
|
|
|
|
token.motionEaseOutCirc
|
|
|
|
}, ${waveEffect.getName(token.hashId)} 0.4s ${token.motionEaseOutCirc}`,
|
|
|
|
},
|
2022-06-28 01:49:37 +08:00
|
|
|
animationFillMode: 'forwards',
|
|
|
|
content: '""',
|
|
|
|
pointerEvents: 'none',
|
|
|
|
},
|
|
|
|
},
|
2022-06-28 15:20:09 +08:00
|
|
|
{},
|
2022-06-28 01:49:37 +08:00
|
|
|
waveEffect,
|
|
|
|
fadeEffect,
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
export default (): UseComponentStyleResult => {
|
|
|
|
const [theme, token, hashId] = useToken();
|
|
|
|
const { getPrefixCls } = useContext(ConfigContext);
|
|
|
|
const rootPrefixCls = getPrefixCls();
|
|
|
|
|
|
|
|
const clickAnimatingTrue = `[${rootPrefixCls}-click-animating='true']`;
|
|
|
|
const clickAnimatingWithoutExtraNodeTrue = `[${rootPrefixCls}-click-animating-without-extra-node='true']`;
|
|
|
|
const clickAnimatingNode = `.${rootPrefixCls}-click-animating-node`;
|
|
|
|
|
|
|
|
const waveToken: WaveToken = {
|
|
|
|
...token,
|
|
|
|
hashId,
|
|
|
|
clickAnimatingNode,
|
|
|
|
clickAnimatingTrue,
|
|
|
|
clickAnimatingWithoutExtraNodeTrue,
|
|
|
|
clickAnimatingWithoutExtraNodeTrueAfter: `${clickAnimatingWithoutExtraNodeTrue}::after`,
|
|
|
|
};
|
|
|
|
|
|
|
|
return [
|
|
|
|
useStyleRegister({ theme, token, hashId, path: ['wave'] }, () => [genWaveStyle(waveToken)]),
|
|
|
|
hashId,
|
|
|
|
];
|
|
|
|
};
|