mirror of
https://github.com/zhigang1992/react.git
synced 2026-01-30 22:48:09 +08:00
* feat: export all types related to components fix(tooltip): fix the vertical offset of the arrow * refactor: optimize events of all popup related components * test: append testcases for popup base component * test: add testcase for visible events * test: update snapshots
34 lines
862 B
TypeScript
34 lines
862 B
TypeScript
import { MutableRefObject } from 'react'
|
|
|
|
export interface ReactiveDomReact {
|
|
top: number
|
|
bottom: number
|
|
left: number
|
|
right: number
|
|
width: number
|
|
height: number
|
|
}
|
|
|
|
const defaultRect: ReactiveDomReact = {
|
|
top: -1000,
|
|
left: -1000,
|
|
right: -1000,
|
|
bottom: -1000,
|
|
width: 0,
|
|
height: 0,
|
|
}
|
|
|
|
export const getRect = (ref: MutableRefObject<HTMLElement | null>): ReactiveDomReact => {
|
|
if (!ref || !ref.current) return defaultRect
|
|
const rect = ref.current.getBoundingClientRect()
|
|
return {
|
|
...rect,
|
|
width: rect.width || rect.right - rect.left,
|
|
height: rect.height || rect.bottom - rect.top,
|
|
top: rect.top + document.documentElement.scrollTop,
|
|
bottom: rect.bottom + document.documentElement.scrollTop,
|
|
left: rect.left + document.documentElement.scrollLeft,
|
|
right: rect.right + document.documentElement.scrollLeft,
|
|
}
|
|
}
|