@justeattakeaway/pie-tooltip 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/custom-elements.json +112 -7
- package/dist/index.d.ts +13 -2
- package/dist/index.js +299 -196
- package/dist/react.d.ts +13 -2
- package/package.json +1 -1
- package/src/defs.ts +4 -1
- package/src/index.ts +286 -22
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ Ideally, you should install the component using the **`@justeattakeaway/pie-webc
|
|
|
47
47
|
|---|---|---|---|
|
|
48
48
|
| `trigger` | Any string | The `id` of the element the panel is anchored to. The trigger lives elsewhere in the DOM and is never slotted into the tooltip. | `undefined` |
|
|
49
49
|
| `isOpen` | `true`, `false` | When true, the panel is visible. The component never writes to this property. | `false` |
|
|
50
|
-
| `position` | `top`, `top-start`, `top-end`, `bottom`, `bottom-start`, `bottom-end`, `left`, `left-start`, `left-end`, `right`, `right-start`, `right-end` | The side of the trigger the panel sits on, and its alignment along the cross axis. | `top` |
|
|
50
|
+
| `position` | `top`, `top-start`, `top-end`, `bottom`, `bottom-start`, `bottom-end`, `left`, `left-start`, `left-end`, `right`, `right-start`, `right-end` | The preferred side of the trigger the panel sits on, and its alignment along the cross axis. The panel repositions itself when this would collide with the viewport or a clipping scroll container. | `top` |
|
|
51
51
|
| `size` | `default`, `fit-to-content`, `fill-container` | How the panel sizes itself. `default` is a fixed 280px and wraps, `fit-to-content` is as wide as its content, and `fill-container` matches the inline size of the trigger's parent element. Not applied when `type` is `icon`. | `default` |
|
|
52
52
|
| `variant` | `default`, `inverse` | The colour treatment of the panel. `default` is the dark panel, `inverse` the light one. | `default` |
|
|
53
53
|
| `type` | `default`, `icon` | The presentation of the panel. `icon` is the compact treatment intended for icon triggers: it has no arrow and is always as wide as its content, so `size` and `--tooltip-width` have no effect on it. | `default` |
|
|
@@ -99,6 +99,17 @@ right right-start right-end
|
|
|
99
99
|
|
|
100
100
|
In right-to-left languages, everything on the inline axis mirrors. The alignments follow the reading direction, so `top-start` aligns against the right-hand edge, and `left` and `right` swap: a panel asked for on the left appears on the right. The `-start` and `-end` alignments of `left` and `right` are on the block axis, which has no direction to mirror, so only the side moves.
|
|
101
101
|
|
|
102
|
+
### Collision detection
|
|
103
|
+
|
|
104
|
+
`position` is a preference, not a guarantee. Before the panel is shown, and on every scroll, resize or direction change while it is open, the component measures the panel against the space available and repositions it if the preferred position would collide.
|
|
105
|
+
|
|
106
|
+
- It flips to the opposite side first: `top` to `bottom`, and so on.
|
|
107
|
+
- It then tries the remaining sides.
|
|
108
|
+
- Within a side, it shifts the alignment (for example `top-start` to `top-end`) so the panel stays fully in view.
|
|
109
|
+
- If no position fits entirely, it uses whichever position shows the most of the panel.
|
|
110
|
+
|
|
111
|
+
The available space is the viewport, narrowed by any ancestor that clips the panel. Collision detection is always on and cannot be disabled.
|
|
112
|
+
|
|
102
113
|
## Sizing
|
|
103
114
|
|
|
104
115
|
| `size` | Behaviour |
|
package/custom-elements.json
CHANGED
|
@@ -343,6 +343,14 @@
|
|
|
343
343
|
"privacy": "private",
|
|
344
344
|
"default": "true"
|
|
345
345
|
},
|
|
346
|
+
{
|
|
347
|
+
"kind": "field",
|
|
348
|
+
"name": "_resolvedPosition",
|
|
349
|
+
"type": {
|
|
350
|
+
"text": "TooltipProps['position'] | undefined"
|
|
351
|
+
},
|
|
352
|
+
"privacy": "private"
|
|
353
|
+
},
|
|
346
354
|
{
|
|
347
355
|
"kind": "field",
|
|
348
356
|
"name": "_clippedTriggerElement",
|
|
@@ -361,6 +369,33 @@
|
|
|
361
369
|
"privacy": "private",
|
|
362
370
|
"default": "[]"
|
|
363
371
|
},
|
|
372
|
+
{
|
|
373
|
+
"kind": "field",
|
|
374
|
+
"name": "_overlayClippers",
|
|
375
|
+
"type": {
|
|
376
|
+
"text": "Array<Element>"
|
|
377
|
+
},
|
|
378
|
+
"privacy": "private",
|
|
379
|
+
"default": "[]"
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
"kind": "field",
|
|
383
|
+
"name": "_collisionSignature",
|
|
384
|
+
"type": {
|
|
385
|
+
"text": "string | null"
|
|
386
|
+
},
|
|
387
|
+
"privacy": "private",
|
|
388
|
+
"default": "null"
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
"kind": "field",
|
|
392
|
+
"name": "_overlayModeDirty",
|
|
393
|
+
"type": {
|
|
394
|
+
"text": "boolean"
|
|
395
|
+
},
|
|
396
|
+
"privacy": "private",
|
|
397
|
+
"default": "true"
|
|
398
|
+
},
|
|
364
399
|
{
|
|
365
400
|
"kind": "field",
|
|
366
401
|
"name": "_triggerTrackingController",
|
|
@@ -404,20 +439,20 @@
|
|
|
404
439
|
},
|
|
405
440
|
{
|
|
406
441
|
"kind": "field",
|
|
407
|
-
"name": "
|
|
442
|
+
"name": "_hoverCloseTimer",
|
|
408
443
|
"type": {
|
|
409
|
-
"text": "
|
|
444
|
+
"text": "ReturnType<typeof setTimeout> | undefined"
|
|
410
445
|
},
|
|
411
|
-
"privacy": "private"
|
|
412
|
-
"default": "false"
|
|
446
|
+
"privacy": "private"
|
|
413
447
|
},
|
|
414
448
|
{
|
|
415
449
|
"kind": "field",
|
|
416
|
-
"name": "
|
|
450
|
+
"name": "_openedByClick",
|
|
417
451
|
"type": {
|
|
418
|
-
"text": "
|
|
452
|
+
"text": "boolean"
|
|
419
453
|
},
|
|
420
|
-
"privacy": "private"
|
|
454
|
+
"privacy": "private",
|
|
455
|
+
"default": "false"
|
|
421
456
|
},
|
|
422
457
|
{
|
|
423
458
|
"kind": "field",
|
|
@@ -478,6 +513,76 @@
|
|
|
478
513
|
}
|
|
479
514
|
}
|
|
480
515
|
},
|
|
516
|
+
{
|
|
517
|
+
"kind": "method",
|
|
518
|
+
"name": "resolveCollision",
|
|
519
|
+
"privacy": "private",
|
|
520
|
+
"return": {
|
|
521
|
+
"type": {
|
|
522
|
+
"text": "void"
|
|
523
|
+
}
|
|
524
|
+
},
|
|
525
|
+
"parameters": [
|
|
526
|
+
{
|
|
527
|
+
"name": "anchorRect",
|
|
528
|
+
"type": {
|
|
529
|
+
"text": "DOMRect"
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
]
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
"kind": "method",
|
|
536
|
+
"name": "_setResolvedPosition",
|
|
537
|
+
"privacy": "private",
|
|
538
|
+
"return": {
|
|
539
|
+
"type": {
|
|
540
|
+
"text": "void"
|
|
541
|
+
}
|
|
542
|
+
},
|
|
543
|
+
"parameters": [
|
|
544
|
+
{
|
|
545
|
+
"name": "position",
|
|
546
|
+
"type": {
|
|
547
|
+
"text": "TooltipProps['position']"
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
]
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
"kind": "method",
|
|
554
|
+
"name": "_getCollisionBoundary",
|
|
555
|
+
"privacy": "private",
|
|
556
|
+
"return": {
|
|
557
|
+
"type": {
|
|
558
|
+
"text": "DOMRect | null"
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
{
|
|
563
|
+
"kind": "method",
|
|
564
|
+
"name": "_getCandidatePositions",
|
|
565
|
+
"privacy": "private",
|
|
566
|
+
"return": {
|
|
567
|
+
"type": {
|
|
568
|
+
"text": "Array<{ side: TooltipSide; alignment: TooltipAlignment }>"
|
|
569
|
+
}
|
|
570
|
+
},
|
|
571
|
+
"parameters": [
|
|
572
|
+
{
|
|
573
|
+
"name": "preferredSide",
|
|
574
|
+
"type": {
|
|
575
|
+
"text": "TooltipSide"
|
|
576
|
+
}
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
"name": "preferredAlignment",
|
|
580
|
+
"type": {
|
|
581
|
+
"text": "TooltipAlignment"
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
]
|
|
585
|
+
},
|
|
481
586
|
{
|
|
482
587
|
"kind": "method",
|
|
483
588
|
"name": "_refreshTriggerClippers",
|
package/dist/index.d.ts
CHANGED
|
@@ -59,15 +59,19 @@ export declare class PieTooltip extends PieElement implements TooltipProps {
|
|
|
59
59
|
private _hasActionContent;
|
|
60
60
|
private _isPositioned;
|
|
61
61
|
private _isAnchorVisible;
|
|
62
|
+
private _resolvedPosition;
|
|
62
63
|
private _clippedTriggerElement;
|
|
63
64
|
private _triggerClippers;
|
|
65
|
+
private _overlayClippers;
|
|
66
|
+
private _collisionSignature;
|
|
67
|
+
private _overlayModeDirty;
|
|
64
68
|
private _triggerTrackingController;
|
|
65
69
|
private _interactionController;
|
|
66
70
|
private _directionObserver;
|
|
67
71
|
private _triggerObserver;
|
|
68
72
|
private _reanchorFrame;
|
|
69
|
-
private _shouldResolveOverlayMode;
|
|
70
73
|
private _hoverCloseTimer;
|
|
74
|
+
private _openedByClick;
|
|
71
75
|
static styles: CSSResult;
|
|
72
76
|
private get _mode();
|
|
73
77
|
protected firstUpdated(): void;
|
|
@@ -78,6 +82,10 @@ export declare class PieTooltip extends PieElement implements TooltipProps {
|
|
|
78
82
|
private resolveMode;
|
|
79
83
|
private resolveOverlayMode;
|
|
80
84
|
private projectOverTrigger;
|
|
85
|
+
private resolveCollision;
|
|
86
|
+
private _setResolvedPosition;
|
|
87
|
+
private _getCollisionBoundary;
|
|
88
|
+
private _getCandidatePositions;
|
|
81
89
|
private _refreshTriggerClippers;
|
|
82
90
|
private handleCloseButtonClick;
|
|
83
91
|
private _getTriggerElement;
|
|
@@ -110,7 +118,10 @@ export declare interface TooltipProps {
|
|
|
110
118
|
*/
|
|
111
119
|
isOpen?: boolean;
|
|
112
120
|
/**
|
|
113
|
-
* The side of the trigger the panel sits on, and its alignment along the cross axis.
|
|
121
|
+
* The preferred side of the trigger the panel sits on, and its alignment along the cross axis.
|
|
122
|
+
* The component repositions the panel automatically — flipping to the opposite side and/or
|
|
123
|
+
* shifting its alignment — when the preferred position would collide with the viewport or with
|
|
124
|
+
* a clipping scroll container. This behaviour cannot be disabled.
|
|
114
125
|
*/
|
|
115
126
|
position?: typeof positions[number];
|
|
116
127
|
/**
|