Fix store item variant defaults and listing sorting
Auto-select first option in variation modals and sort store items by availability, then update time. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
b861ab3dc1
commit
5f4b0b4f92
@@ -0,0 +1,35 @@
|
||||
const GAP = 8
|
||||
const VIEWPORT_PAD = 8
|
||||
|
||||
export type FixedPopoverCoords = {
|
||||
top: number
|
||||
left: number
|
||||
}
|
||||
|
||||
export function fitFixedPopover(
|
||||
trigger: DOMRect,
|
||||
size: { width: number; height: number },
|
||||
align: 'end' | 'center' = 'end',
|
||||
): FixedPopoverCoords {
|
||||
const vw = window.innerWidth
|
||||
const vh = window.innerHeight
|
||||
const width = Math.max(1, size.width)
|
||||
const height = Math.max(1, size.height)
|
||||
|
||||
const spaceBelow = vh - trigger.bottom - VIEWPORT_PAD
|
||||
const spaceAbove = trigger.top - VIEWPORT_PAD
|
||||
const placeBelow = spaceBelow >= height + GAP || spaceBelow >= spaceAbove
|
||||
|
||||
let top = placeBelow ? trigger.bottom + GAP : trigger.top - GAP - height
|
||||
top = Math.min(Math.max(top, VIEWPORT_PAD), Math.max(VIEWPORT_PAD, vh - VIEWPORT_PAD - height))
|
||||
|
||||
let left =
|
||||
align === 'center'
|
||||
? trigger.left + trigger.width / 2 - width / 2
|
||||
: trigger.right - width
|
||||
|
||||
const maxLeft = Math.max(VIEWPORT_PAD, vw - VIEWPORT_PAD - width)
|
||||
left = Math.min(Math.max(left, VIEWPORT_PAD), maxLeft)
|
||||
|
||||
return { top, left }
|
||||
}
|
||||
Reference in New Issue
Block a user