ant-design/components/_util/wave/useWave.ts
二货爱吃白萝卜 8b19102b0d
feat: wave effect config (#43784)
* feat: support wave effect

* docs: more info

* test: add test case

* docs: update demo

* test: coverage
2023-07-25 16:29:47 +08:00

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;
}