Skip to content

Commit 671281e

Browse files
committed
fix: typing
1 parent bf289db commit 671281e

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

packages/ui/src/components/Popup/helpers.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import type { RefObject } from 'react'
22

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'
94

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
118

12-
export type PopupPlacement = AutoPlacements | NonAutoPlacements
9+
type AutoPlacements =
10+
| AddPrefixToUnion<Exclude<Placements, 'nested-menu'>, 'auto-'>
11+
| 'auto'
1312

13+
export type PopupPlacement = AutoPlacements | Placements
1414
export type PopupAlign = 'start' | 'center'
15+
1516
export const DEFAULT_ARROW_WIDTH = 8 // in px
1617
const SPACE = 4 // in px
1718
const TOTAL_USED_SPACE = 0 // in px
@@ -166,7 +167,7 @@ const findOffsetParent = (element: RefObject<HTMLDivElement>) => {
166167
* @param popupStructuredRef the rect of the popup, the popup itself
167168
*/
168169
const getPopupOverflowFromParent = (
169-
position: NonAutoPlacements,
170+
position: Placements,
170171
offsetParentRect: { top: number; left: number; right: number },
171172
childrenRect: DOMRect,
172173
popupStructuredRef: DOMRect,
@@ -319,7 +320,7 @@ export const computePositions = ({
319320
: childrenLeft - parentLeft + childrenWidth
320321

321322
const popupOverflow = getPopupOverflowFromParent(
322-
placementBasedOnWindowSize as NonAutoPlacements,
323+
placementBasedOnWindowSize as Placements,
323324
offsetParentRect,
324325
childrenRect,
325326
popupStructuredRef,

0 commit comments

Comments
 (0)