swarm-ui: keep the table filter popover inside the window
This commit is contained in:
parent
c2f17799fc
commit
16c9e0ae3b
1 changed files with 53 additions and 2 deletions
19
frontend/packages/swarm-ui/src/ui/table/popover-position.ts
Normal file
19
frontend/packages/swarm-ui/src/ui/table/popover-position.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// Where a table's filter popover sits, without a DOM.
|
||||
|
||||
// Space kept between a floating box and the viewport's edge.
|
||||
export const POPOVER_EDGE_PX = 8;
|
||||
|
||||
/**
|
||||
* The left edge for a popover of `width` that wants to start at `left`:
|
||||
* pulled in so its right edge stays on screen, but never past the left edge.
|
||||
* A filterable column near the right of the window would otherwise open
|
||||
* partly outside it.
|
||||
*/
|
||||
export function clampLeft(
|
||||
left: number,
|
||||
width: number,
|
||||
viewportWidth: number,
|
||||
): number {
|
||||
const maxLeft = viewportWidth - width - POPOVER_EDGE_PX;
|
||||
return Math.max(POPOVER_EDGE_PX, Math.min(left, maxLeft));
|
||||
}
|
||||
Loading…
Reference in a new issue