forked from microsoft/fluentui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make callouts aware of the WindowSegments
- Loading branch information
Showing
4 changed files
with
103 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { IPoint } from '../IPoint'; | ||
import { Rectangle } from '../Rectangle'; | ||
|
||
export function getRenderedContainer( | ||
content?: Element | string | MouseEvent | IPoint | null | React.RefObject<Element>, | ||
possibleContainers?: DOMRect[] | ClientRect[] | ||
): DOMRect | ClientRect | undefined { | ||
if (!content || !possibleContainers || possibleContainers.length <= 0) { | ||
return undefined; | ||
} | ||
|
||
let contentRect: DOMRect | ClientRect | Rectangle; | ||
|
||
if ((content as MouseEvent).preventDefault) { | ||
const ev = content as MouseEvent; | ||
contentRect = new Rectangle(ev.clientX, ev.clientX, ev.clientY, ev.clientY); | ||
} else if ((content as Element).getBoundingClientRect) { | ||
contentRect = (content as Element).getBoundingClientRect(); | ||
} else if (content as IPoint) { | ||
const point: IPoint = content as IPoint; | ||
contentRect = new Rectangle(point.x, point.x, point.y, point.y); | ||
} else { | ||
return undefined; | ||
} | ||
|
||
return ( | ||
possibleContainers && | ||
possibleContainers.find((possibleContainerRect: DOMRect | ClientRect) => { | ||
return ( | ||
contentRect.left >= possibleContainerRect.left && | ||
contentRect.top >= possibleContainerRect.top && | ||
contentRect.right <= possibleContainerRect.left + possibleContainerRect.width && | ||
contentRect.bottom <= possibleContainerRect.top + possibleContainerRect.height | ||
); | ||
}) | ||
); | ||
} |