|
1 | 1 | import type { RefObject } from 'react' |
2 | 2 |
|
3 | | -type AutoPlacements = |
4 | | - | 'auto' |
5 | | - | 'auto-bottom' |
6 | | - | 'auto-left' |
7 | | - | 'auto-right' |
8 | | - | 'auto-top' |
| 3 | +type Placements = 'top' | 'right' | 'bottom' | 'left' | 'nested-menu' |
9 | 4 |
|
10 | | -type NonAutoPlacements = 'top' | 'right' | 'bottom' | 'left' | 'nested-menu' |
| 5 | +type AddPrefixToUnion<T extends string, P extends string> = T extends string |
| 6 | + ? `${P}${T}` |
| 7 | + : never |
11 | 8 |
|
12 | | -export type PopupPlacement = AutoPlacements | NonAutoPlacements |
| 9 | +type AutoPlacements = |
| 10 | + | AddPrefixToUnion<Exclude<Placements, 'nested-menu'>, 'auto-'> |
| 11 | + | 'auto' |
13 | 12 |
|
| 13 | +export type PopupPlacement = AutoPlacements | Placements |
14 | 14 | export type PopupAlign = 'start' | 'center' |
| 15 | + |
15 | 16 | export const DEFAULT_ARROW_WIDTH = 8 // in px |
16 | 17 | const SPACE = 4 // in px |
17 | 18 | const TOTAL_USED_SPACE = 0 // in px |
@@ -166,7 +167,7 @@ const findOffsetParent = (element: RefObject<HTMLDivElement>) => { |
166 | 167 | * @param popupStructuredRef the rect of the popup, the popup itself |
167 | 168 | */ |
168 | 169 | const getPopupOverflowFromParent = ( |
169 | | - position: NonAutoPlacements, |
| 170 | + position: Placements, |
170 | 171 | offsetParentRect: { top: number; left: number; right: number }, |
171 | 172 | childrenRect: DOMRect, |
172 | 173 | popupStructuredRef: DOMRect, |
@@ -319,7 +320,7 @@ export const computePositions = ({ |
319 | 320 | : childrenLeft - parentLeft + childrenWidth |
320 | 321 |
|
321 | 322 | const popupOverflow = getPopupOverflowFromParent( |
322 | | - placementBasedOnWindowSize as NonAutoPlacements, |
| 323 | + placementBasedOnWindowSize as Placements, |
323 | 324 | offsetParentRect, |
324 | 325 | childrenRect, |
325 | 326 | popupStructuredRef, |
|
0 commit comments