@justeattakeaway/pie-tooltip 0.2.0 → 0.3.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/dist/react.d.ts CHANGED
@@ -20,7 +20,7 @@ export declare const componentClass = "c-tooltip";
20
20
 
21
21
  export declare const componentSelector = "pie-tooltip";
22
22
 
23
- export declare type DefaultProps = ComponentDefaultProps<TooltipProps, keyof Omit<TooltipProps, 'trigger' | 'heading' | 'aria'>>;
23
+ export declare type DefaultProps = ComponentDefaultProps<TooltipProps, keyof Omit<TooltipProps, 'trigger' | 'heading' | 'aria' | 'triggers'>>;
24
24
 
25
25
  export declare const defaultProps: DefaultProps;
26
26
 
@@ -34,11 +34,14 @@ export declare const modes: readonly ["tooltip", "dialog"];
34
34
 
35
35
  export declare const ON_TOOLTIP_CLOSE_EVENT = "pie-tooltip-close";
36
36
 
37
+ export declare const ON_TOOLTIP_OPEN_EVENT = "pie-tooltip-open";
38
+
37
39
  export declare const PieTooltip: React_2.ForwardRefExoticComponent<React_2.PropsWithChildren<Omit<React_2.PropsWithoutRef<TooltipProps>, "children">> & React_2.RefAttributes<PieTooltip_2> & PieTooltipEvents & ReactBaseType>;
38
40
 
39
41
  /**
40
42
  * @tagname pie-tooltip
41
- * @event {Event} pie-tooltip-close - When the close button is clicked. Set `isOpen` to `false` in response.
43
+ * @event {Event} pie-tooltip-open - When a configured trigger asks for the panel. Set `isOpen` to `true` in response.
44
+ * @event {Event} pie-tooltip-close - When the close button is clicked, or a configured trigger asks to dismiss the panel. Set `isOpen` to `false` in response.
42
45
  * @slot content - The descriptive content of the panel. Must not contain focusable elements.
43
46
  * @slot action - An optional slot for interactive content such as a `pie-button`. Filling this slot switches the panel to a non-modal dialog.
44
47
  */
@@ -53,14 +56,21 @@ declare class PieTooltip_2 extends PieElement implements TooltipProps {
53
56
  heading: TooltipProps['heading'];
54
57
  headingLevel: "h2" | "h3" | "h4" | "h5" | "h6";
55
58
  aria: TooltipProps['aria'];
59
+ triggers: TooltipProps['triggers'];
56
60
  private _assignedActionElements;
57
61
  private _originElement;
58
62
  private _hasActionContent;
59
63
  private _isPositioned;
64
+ private _isAnchorVisible;
65
+ private _clippedTriggerElement;
66
+ private _triggerClippers;
60
67
  private _triggerTrackingController;
68
+ private _interactionController;
61
69
  private _directionObserver;
70
+ private _triggerObserver;
62
71
  private _reanchorFrame;
63
72
  private _shouldResolveOverlayMode;
73
+ private _hoverCloseTimer;
64
74
  static styles: CSSResult;
65
75
  private get _mode();
66
76
  protected firstUpdated(): void;
@@ -71,13 +81,22 @@ declare class PieTooltip_2 extends PieElement implements TooltipProps {
71
81
  private resolveMode;
72
82
  private resolveOverlayMode;
73
83
  private projectOverTrigger;
84
+ private _refreshTriggerClippers;
74
85
  private handleCloseButtonClick;
86
+ private _getTriggerElement;
87
+ private _requestOpen;
88
+ private _requestClose;
89
+ private _startHoverCloseTimer;
90
+ private _cancelHoverCloseTimer;
91
+ private _rebuildInteractionListeners;
92
+ private _teardownInteractionListeners;
75
93
  private renderHeading;
76
94
  private renderCloseButton;
77
95
  render(): TemplateResult;
78
96
  }
79
97
 
80
98
  declare type PieTooltipEvents = {
99
+ onPieTooltipOpen?: (event: Event) => void;
81
100
  onPieTooltipClose?: (event: Event) => void;
82
101
  };
83
102
 
@@ -137,8 +156,20 @@ export declare interface TooltipProps {
137
156
  * The ARIA labels used for various parts of the tooltip.
138
157
  */
139
158
  aria?: AriaProps;
159
+ /**
160
+ * Which interactions request that the panel opens and closes. The component never opens or
161
+ * closes itself: a configured interaction emits `pie-tooltip-open` or `pie-tooltip-close`
162
+ * and the consumer decides whether to honour it by setting `isOpen`. Empty by default, so
163
+ * no interaction is watched at all. Configure `hover` and `focus` together for keyboard
164
+ * reachability, and `click` for pointer users.
165
+ */
166
+ triggers?: Array<TooltipTrigger>;
140
167
  }
141
168
 
169
+ export declare type TooltipTrigger = typeof triggers[number];
170
+
171
+ export declare const triggers: readonly ["hover", "focus", "click"];
172
+
142
173
  export declare const types: readonly ["default", "icon"];
143
174
 
144
175
  export declare const variants: readonly ["default", "inverse"];
package/dist/react.js CHANGED
@@ -1,27 +1,31 @@
1
1
  import * as o from "react";
2
2
  import { createComponent as e } from "@lit/react";
3
3
  import { PieTooltip as t } from "./index.js";
4
- import { ON_TOOLTIP_CLOSE_EVENT as n, componentClass as r, componentSelector as c, defaultProps as T, headingLevels as P, modes as f, positions as C, sizes as d, types as N, variants as O } from "./index.js";
4
+ import { ON_TOOLTIP_CLOSE_EVENT as r, ON_TOOLTIP_OPEN_EVENT as m, componentClass as T, componentSelector as P, defaultProps as c, headingLevels as O, modes as N, positions as E, sizes as _, triggers as f, types as C, variants as d } from "./index.js";
5
5
  const i = e({
6
6
  displayName: "PieTooltip",
7
7
  elementClass: t,
8
8
  react: o,
9
9
  tagName: "pie-tooltip",
10
10
  events: {
11
+ onPieTooltipOpen: "pie-tooltip-open",
12
+ // When a configured trigger asks for the panel. Set `isOpen` to `true` in response.
11
13
  onPieTooltipClose: "pie-tooltip-close"
12
- // When the close button is clicked. Set `isOpen` to `false` in response.
14
+ // When the close button is clicked, or a configured trigger asks to dismiss the panel. Set `isOpen` to `false` in response.
13
15
  }
14
16
  }), l = i;
15
17
  export {
16
- n as ON_TOOLTIP_CLOSE_EVENT,
18
+ r as ON_TOOLTIP_CLOSE_EVENT,
19
+ m as ON_TOOLTIP_OPEN_EVENT,
17
20
  l as PieTooltip,
18
- r as componentClass,
19
- c as componentSelector,
20
- T as defaultProps,
21
- P as headingLevels,
22
- f as modes,
23
- C as positions,
24
- d as sizes,
25
- N as types,
26
- O as variants
21
+ T as componentClass,
22
+ P as componentSelector,
23
+ c as defaultProps,
24
+ O as headingLevels,
25
+ N as modes,
26
+ E as positions,
27
+ _ as sizes,
28
+ f as triggers,
29
+ C as types,
30
+ d as variants
27
31
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@justeattakeaway/pie-tooltip",
3
3
  "description": "PIE Design System Tooltip built using Web Components",
4
- "version": "0.2.0",
4
+ "version": "0.3.0",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -36,13 +36,13 @@
36
36
  "license": "Apache-2.0",
37
37
  "devDependencies": {
38
38
  "@justeattakeaway/pie-components-config": "0.21.4",
39
- "@justeattakeaway/pie-css": "1.8.0",
40
- "@justeattakeaway/pie-monorepo-utils": "0.9.9"
39
+ "@justeattakeaway/pie-css": "1.9.0",
40
+ "@justeattakeaway/pie-monorepo-utils": "0.9.10"
41
41
  },
42
42
  "dependencies": {
43
- "@justeattakeaway/pie-icon-button": "2.7.32",
44
- "@justeattakeaway/pie-icons-webc": "1.29.1",
45
- "@justeattakeaway/pie-webc-core": "21.0.0"
43
+ "@justeattakeaway/pie-icon-button": "2.7.35",
44
+ "@justeattakeaway/pie-icons-webc": "1.29.4",
45
+ "@justeattakeaway/pie-webc-core": "22.0.0"
46
46
  },
47
47
  "customElements": "custom-elements.json",
48
48
  "sideEffects": [
package/src/defs.ts CHANGED
@@ -19,6 +19,7 @@ export const sizes = ['default', 'fit-to-content', 'fill-container'] as const;
19
19
  export const variants = ['default', 'inverse'] as const;
20
20
  export const types = ['default', 'icon'] as const;
21
21
  export const headingLevels = ['h2', 'h3', 'h4', 'h5', 'h6'] as const;
22
+ export const triggers = ['hover', 'focus', 'click'] as const;
22
23
 
23
24
  /**
24
25
  * The two patterns the panel can present as. Inferred from the `action` slot rather than
@@ -27,6 +28,7 @@ export const headingLevels = ['h2', 'h3', 'h4', 'h5', 'h6'] as const;
27
28
  export const modes = ['tooltip', 'dialog'] as const;
28
29
 
29
30
  export type TooltipMode = typeof modes[number];
31
+ export type TooltipTrigger = typeof triggers[number];
30
32
 
31
33
  type AriaProps = {
32
34
  /**
@@ -97,14 +99,24 @@ export interface TooltipProps {
97
99
  * The ARIA labels used for various parts of the tooltip.
98
100
  */
99
101
  aria?: AriaProps;
102
+
103
+ /**
104
+ * Which interactions request that the panel opens and closes. The component never opens or
105
+ * closes itself: a configured interaction emits `pie-tooltip-open` or `pie-tooltip-close`
106
+ * and the consumer decides whether to honour it by setting `isOpen`. Empty by default, so
107
+ * no interaction is watched at all. Configure `hover` and `focus` together for keyboard
108
+ * reachability, and `click` for pointer users.
109
+ */
110
+ triggers?: Array<TooltipTrigger>;
100
111
  }
101
112
 
102
113
  export const componentSelector = 'pie-tooltip';
103
114
  export const componentClass = 'c-tooltip';
104
115
 
116
+ export const ON_TOOLTIP_OPEN_EVENT = `${componentSelector}-open`;
105
117
  export const ON_TOOLTIP_CLOSE_EVENT = `${componentSelector}-close`;
106
118
 
107
- export type DefaultProps = ComponentDefaultProps<TooltipProps, keyof Omit<TooltipProps, 'trigger' | 'heading' | 'aria'>>;
119
+ export type DefaultProps = ComponentDefaultProps<TooltipProps, keyof Omit<TooltipProps, 'trigger' | 'heading' | 'aria' | 'triggers'>>;
108
120
 
109
121
  export const defaultProps: DefaultProps = {
110
122
  isOpen: false,