mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-15 13:38:29 +02:00

* chore: add unstable entrance * chore: rest of it * chore: use React 19 * chore: fix lint * chore: fix lint * chore: fix lint * chore: fix lint * chore: fix lint * chore: fix lint * chore: fix lint * chore: test ignore 19 preload * chore: bump rc-util * fix: warning of pure render * fix: warning of 19 * chore: adjust ts * test: fix test logic * test: fix test case * test: fix test case * test: fix test case * test: fix test case * test: fix test case * test: fix test case * test: fix test case * test: fix test case * chore: restore file * test: fix test case * test: fix test case * test: fix test case * test: fix test case * test: fix test case * test: update test * test: fix test case * test: update snapshot * test: fix coverage * test: fix coverage * test: add ignore image
33 lines
887 B
TypeScript
33 lines
887 B
TypeScript
import * as React from 'react';
|
|
import useEvent from 'rc-util/lib/hooks/useEvent';
|
|
|
|
export interface WatermarkContextProps {
|
|
add: (ele: HTMLElement) => void;
|
|
remove: (ele: HTMLElement) => void;
|
|
}
|
|
|
|
function voidFunc() {}
|
|
|
|
const WatermarkContext = React.createContext<WatermarkContextProps>({
|
|
add: voidFunc,
|
|
remove: voidFunc,
|
|
});
|
|
|
|
export function usePanelRef(panelSelector?: string) {
|
|
const watermark = React.useContext(WatermarkContext);
|
|
|
|
const panelEleRef = React.useRef<HTMLElement>(null);
|
|
const panelRef = useEvent((ele: HTMLElement | null) => {
|
|
if (ele) {
|
|
const innerContentEle = panelSelector ? ele.querySelector<HTMLElement>(panelSelector)! : ele;
|
|
watermark.add(innerContentEle);
|
|
panelEleRef.current = innerContentEle;
|
|
} else {
|
|
watermark.remove(panelEleRef.current!);
|
|
}
|
|
});
|
|
|
|
return panelRef;
|
|
}
|
|
|
|
export default WatermarkContext;
|