mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-25 03:29:59 +08:00
8f1d496972
* docs: fix typo in docs * remove rc-util/lib/Dom/addEventListener * fix * fix
27 lines
873 B
TypeScript
27 lines
873 B
TypeScript
export type BindElement = HTMLElement | Window | null | undefined;
|
|
|
|
export function getTargetRect(target: BindElement): DOMRect {
|
|
return target !== window
|
|
? (target as HTMLElement).getBoundingClientRect()
|
|
: ({ top: 0, bottom: window.innerHeight } as DOMRect);
|
|
}
|
|
|
|
export function getFixedTop(placeholderRect: DOMRect, targetRect: DOMRect, offsetTop?: number) {
|
|
if (offsetTop !== undefined && targetRect.top > placeholderRect.top - offsetTop) {
|
|
return offsetTop + targetRect.top;
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
export function getFixedBottom(
|
|
placeholderRect: DOMRect,
|
|
targetRect: DOMRect,
|
|
offsetBottom?: number,
|
|
) {
|
|
if (offsetBottom !== undefined && targetRect.bottom < placeholderRect.bottom + offsetBottom) {
|
|
const targetBottomOffset = window.innerHeight - targetRect.bottom;
|
|
return offsetBottom + targetBottomOffset;
|
|
}
|
|
return undefined;
|
|
}
|