mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-30 22:39:34 +08:00
8b19102b0d
* feat: support wave effect * docs: more info * test: add test case * docs: update demo * test: coverage
41 lines
981 B
TypeScript
41 lines
981 B
TypeScript
import * as React from 'react';
|
|
import useEvent from 'rc-util/lib/hooks/useEvent';
|
|
import showWaveEffect from './WaveEffect';
|
|
import { ConfigContext } from '../../config-provider';
|
|
import useToken from '../../theme/useToken';
|
|
import type { GlobalToken } from '../../theme';
|
|
|
|
export type ShowWaveEffect = (
|
|
element: HTMLElement,
|
|
info: {
|
|
className: string;
|
|
token: GlobalToken;
|
|
component?: string;
|
|
event: MouseEvent;
|
|
},
|
|
) => void;
|
|
|
|
export default function useWave(
|
|
nodeRef: React.RefObject<HTMLElement>,
|
|
className: string,
|
|
component?: string,
|
|
) {
|
|
const { wave } = React.useContext(ConfigContext);
|
|
const [, token] = useToken();
|
|
|
|
const showWave = useEvent((event: MouseEvent) => {
|
|
const node = nodeRef.current!;
|
|
|
|
if (wave?.disabled || !node) {
|
|
return;
|
|
}
|
|
|
|
const { showEffect } = wave || {};
|
|
|
|
// Customize wave effect
|
|
(showEffect || showWaveEffect)(node, { className, token, component, event });
|
|
});
|
|
|
|
return showWave;
|
|
}
|