({
align = "auto",
cellOffset,
cellSize,
containerSize,
currentOffset
}: {
align?: "auto" | "end" | "start" | "center";
cellOffset: number;
cellSize: number;
containerSize: number;
currentOffset: number;
})
| 12 | * @return Offset to use to ensure the specified cell is visible |
| 13 | */ |
| 14 | export function getUpdatedOffsetForIndex({ |
| 15 | align = "auto", |
| 16 | cellOffset, |
| 17 | cellSize, |
| 18 | containerSize, |
| 19 | currentOffset |
| 20 | }: { |
| 21 | align?: "auto" | "end" | "start" | "center"; |
| 22 | cellOffset: number; |
| 23 | cellSize: number; |
| 24 | containerSize: number; |
| 25 | currentOffset: number; |
| 26 | }): number { |
| 27 | const maxOffset = cellOffset; |
| 28 | const minOffset = maxOffset - containerSize + cellSize; |
| 29 | |
| 30 | switch (align) { |
| 31 | case "start": |
| 32 | return maxOffset; |
| 33 | case "end": |
| 34 | return minOffset; |
| 35 | case "center": |
| 36 | return maxOffset - (containerSize - cellSize) / 2; |
| 37 | default: |
| 38 | // A cell that doesn't fit within the container is aligned to its start, so that its start is visible (#1264) |
| 39 | if (cellSize >= containerSize) { |
| 40 | return maxOffset; |
| 41 | } |
| 42 | return Math.max(minOffset, Math.min(maxOffset, currentOffset)); |
| 43 | } |
| 44 | } |
no outgoing calls