2023-07-25 16:29:47 +08:00
|
|
|
import * as React from 'react';
|
|
|
|
import useEvent from 'rc-util/lib/hooks/useEvent';
|
2022-12-28 23:20:22 +08:00
|
|
|
import showWaveEffect from './WaveEffect';
|
2023-07-25 16:29:47 +08:00
|
|
|
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;
|
2022-12-28 23:20:22 +08:00
|
|
|
|
|
|
|
export default function useWave(
|
|
|
|
nodeRef: React.RefObject<HTMLElement>,
|
|
|
|
className: string,
|
2023-07-25 16:29:47 +08:00
|
|
|
component?: string,
|
|
|
|
) {
|
|
|
|
const { wave } = React.useContext(ConfigContext);
|
|
|
|
const [, token] = useToken();
|
|
|
|
|
|
|
|
const showWave = useEvent((event: MouseEvent) => {
|
2022-12-28 23:20:22 +08:00
|
|
|
const node = nodeRef.current!;
|
|
|
|
|
2023-07-25 16:29:47 +08:00
|
|
|
if (wave?.disabled || !node) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { showEffect } = wave || {};
|
|
|
|
|
|
|
|
// Customize wave effect
|
|
|
|
(showEffect || showWaveEffect)(node, { className, token, component, event });
|
|
|
|
});
|
2022-12-28 23:20:22 +08:00
|
|
|
|
|
|
|
return showWave;
|
|
|
|
}
|