@justeattakeaway/pie-tooltip 0.1.1 → 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/README.md +344 -15
- package/custom-elements.json +644 -3
- package/dist/index.d.ts +153 -2
- package/dist/index.js +390 -18
- package/dist/react.d.ts +159 -3
- package/dist/react.js +25 -7
- package/package.json +6 -4
- package/src/defs.ts +129 -3
- package/src/index.ts +691 -9
- package/src/react.ts +11 -3
- package/src/tooltip.scss +408 -2
package/dist/react.d.ts
CHANGED
|
@@ -1,21 +1,177 @@
|
|
|
1
|
+
import { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
1
2
|
import { CSSResult } from 'lit';
|
|
2
3
|
import { PieElement } from '@justeattakeaway/pie-webc-core/src/internals/PieElement';
|
|
4
|
+
import { PropertyValues } from 'lit';
|
|
3
5
|
import * as React_2 from 'react';
|
|
4
|
-
import { TemplateResult } from 'lit
|
|
6
|
+
import { TemplateResult } from 'lit';
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
declare type AriaProps = {
|
|
9
|
+
/**
|
|
10
|
+
* The accessible name for the close button. Required whenever `isDismissible` is set.
|
|
11
|
+
*/
|
|
12
|
+
close?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The accessible name for the panel in dialog mode. Only used when `heading` is not provided.
|
|
15
|
+
*/
|
|
16
|
+
label?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export declare const componentClass = "c-tooltip";
|
|
20
|
+
|
|
21
|
+
export declare const componentSelector = "pie-tooltip";
|
|
22
|
+
|
|
23
|
+
export declare type DefaultProps = ComponentDefaultProps<TooltipProps, keyof Omit<TooltipProps, 'trigger' | 'heading' | 'aria' | 'triggers'>>;
|
|
24
|
+
|
|
25
|
+
export declare const defaultProps: DefaultProps;
|
|
26
|
+
|
|
27
|
+
export declare const headingLevels: readonly ["h2", "h3", "h4", "h5", "h6"];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The two patterns the panel can present as. Inferred from the `action` slot rather than
|
|
31
|
+
* configured: an empty `action` slot is a tooltip, a filled one is a non-modal dialog.
|
|
32
|
+
*/
|
|
33
|
+
export declare const modes: readonly ["tooltip", "dialog"];
|
|
34
|
+
|
|
35
|
+
export declare const ON_TOOLTIP_CLOSE_EVENT = "pie-tooltip-close";
|
|
36
|
+
|
|
37
|
+
export declare const ON_TOOLTIP_OPEN_EVENT = "pie-tooltip-open";
|
|
38
|
+
|
|
39
|
+
export declare const PieTooltip: React_2.ForwardRefExoticComponent<React_2.PropsWithChildren<Omit<React_2.PropsWithoutRef<TooltipProps>, "children">> & React_2.RefAttributes<PieTooltip_2> & PieTooltipEvents & ReactBaseType>;
|
|
7
40
|
|
|
8
41
|
/**
|
|
9
42
|
* @tagname pie-tooltip
|
|
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.
|
|
45
|
+
* @slot content - The descriptive content of the panel. Must not contain focusable elements.
|
|
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.
|
|
10
47
|
*/
|
|
11
48
|
declare class PieTooltip_2 extends PieElement implements TooltipProps {
|
|
12
|
-
|
|
49
|
+
trigger: TooltipProps['trigger'];
|
|
50
|
+
isOpen: boolean;
|
|
51
|
+
position: "top" | "top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "left" | "left-start" | "left-end" | "right" | "right-start" | "right-end";
|
|
52
|
+
size: "default" | "fit-to-content" | "fill-container";
|
|
53
|
+
variant: "default" | "inverse";
|
|
54
|
+
type: "default" | "icon";
|
|
55
|
+
isDismissible: boolean;
|
|
56
|
+
heading: TooltipProps['heading'];
|
|
57
|
+
headingLevel: "h2" | "h3" | "h4" | "h5" | "h6";
|
|
58
|
+
aria: TooltipProps['aria'];
|
|
59
|
+
triggers: TooltipProps['triggers'];
|
|
60
|
+
private _assignedActionElements;
|
|
61
|
+
private _originElement;
|
|
62
|
+
private _hasActionContent;
|
|
63
|
+
private _isPositioned;
|
|
64
|
+
private _isAnchorVisible;
|
|
65
|
+
private _clippedTriggerElement;
|
|
66
|
+
private _triggerClippers;
|
|
67
|
+
private _triggerTrackingController;
|
|
68
|
+
private _interactionController;
|
|
69
|
+
private _directionObserver;
|
|
70
|
+
private _triggerObserver;
|
|
71
|
+
private _reanchorFrame;
|
|
72
|
+
private _shouldResolveOverlayMode;
|
|
73
|
+
private _hoverCloseTimer;
|
|
13
74
|
static styles: CSSResult;
|
|
75
|
+
private get _mode();
|
|
76
|
+
protected firstUpdated(): void;
|
|
77
|
+
protected updated(changedProperties: PropertyValues<this>): void;
|
|
78
|
+
disconnectedCallback(): void;
|
|
79
|
+
private startTrackingTrigger;
|
|
80
|
+
private stopTrackingTrigger;
|
|
81
|
+
private resolveMode;
|
|
82
|
+
private resolveOverlayMode;
|
|
83
|
+
private projectOverTrigger;
|
|
84
|
+
private _refreshTriggerClippers;
|
|
85
|
+
private handleCloseButtonClick;
|
|
86
|
+
private _getTriggerElement;
|
|
87
|
+
private _requestOpen;
|
|
88
|
+
private _requestClose;
|
|
89
|
+
private _startHoverCloseTimer;
|
|
90
|
+
private _cancelHoverCloseTimer;
|
|
91
|
+
private _rebuildInteractionListeners;
|
|
92
|
+
private _teardownInteractionListeners;
|
|
93
|
+
private renderHeading;
|
|
94
|
+
private renderCloseButton;
|
|
95
|
+
render(): TemplateResult;
|
|
14
96
|
}
|
|
15
97
|
|
|
98
|
+
declare type PieTooltipEvents = {
|
|
99
|
+
onPieTooltipOpen?: (event: Event) => void;
|
|
100
|
+
onPieTooltipClose?: (event: Event) => void;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export declare const positions: readonly ["top", "top-start", "top-end", "bottom", "bottom-start", "bottom-end", "left", "left-start", "left-end", "right", "right-start", "right-end"];
|
|
104
|
+
|
|
16
105
|
declare type ReactBaseType = React_2.HTMLAttributes<HTMLElement>;
|
|
17
106
|
|
|
107
|
+
export declare const sizes: readonly ["default", "fit-to-content", "fill-container"];
|
|
108
|
+
|
|
109
|
+
export declare type TooltipMode = typeof modes[number];
|
|
110
|
+
|
|
18
111
|
export declare interface TooltipProps {
|
|
112
|
+
/**
|
|
113
|
+
* The `id` of the element the panel is anchored to. The trigger lives elsewhere in the
|
|
114
|
+
* DOM and is never slotted into the tooltip.
|
|
115
|
+
*/
|
|
116
|
+
trigger?: string;
|
|
117
|
+
/**
|
|
118
|
+
* When true, the panel is visible. The component never writes to this property: the
|
|
119
|
+
* consumer owns it and updates it in response to the close event.
|
|
120
|
+
*/
|
|
121
|
+
isOpen?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* The side of the trigger the panel sits on, and its alignment along the cross axis.
|
|
124
|
+
*/
|
|
125
|
+
position?: typeof positions[number];
|
|
126
|
+
/**
|
|
127
|
+
* How the panel sizes itself. `default` is a fixed 280px and wraps, `fit-to-content` is as
|
|
128
|
+
* wide as its content, and `fill-container` matches the inline size of the trigger's parent
|
|
129
|
+
* element. Not applied when `type` is `icon`.
|
|
130
|
+
*/
|
|
131
|
+
size?: typeof sizes[number];
|
|
132
|
+
/**
|
|
133
|
+
* The colour treatment of the panel. `default` is the dark panel, `inverse` the light one.
|
|
134
|
+
*/
|
|
135
|
+
variant?: typeof variants[number];
|
|
136
|
+
/**
|
|
137
|
+
* The presentation of the panel. `icon` is the compact treatment intended for icon triggers:
|
|
138
|
+
* it has no arrow and is always as wide as its content, so `size` and `--tooltip-width` have
|
|
139
|
+
* no effect on it.
|
|
140
|
+
*/
|
|
141
|
+
type?: typeof types[number];
|
|
142
|
+
/**
|
|
143
|
+
* When true, a close button is rendered inside the panel.
|
|
144
|
+
*/
|
|
145
|
+
isDismissible?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* The text to display in the panel's heading. In dialog mode this also provides the
|
|
148
|
+
* panel's accessible name.
|
|
149
|
+
*/
|
|
150
|
+
heading?: string;
|
|
151
|
+
/**
|
|
152
|
+
* The HTML heading tag to use for the panel's heading. Can be h2-h6.
|
|
153
|
+
*/
|
|
154
|
+
headingLevel?: typeof headingLevels[number];
|
|
155
|
+
/**
|
|
156
|
+
* The ARIA labels used for various parts of the tooltip.
|
|
157
|
+
*/
|
|
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>;
|
|
19
167
|
}
|
|
20
168
|
|
|
169
|
+
export declare type TooltipTrigger = typeof triggers[number];
|
|
170
|
+
|
|
171
|
+
export declare const triggers: readonly ["hover", "focus", "click"];
|
|
172
|
+
|
|
173
|
+
export declare const types: readonly ["default", "icon"];
|
|
174
|
+
|
|
175
|
+
export declare const variants: readonly ["default", "inverse"];
|
|
176
|
+
|
|
21
177
|
export { }
|
package/dist/react.js
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
import * as o from "react";
|
|
2
|
-
import { createComponent as
|
|
3
|
-
import { PieTooltip as
|
|
4
|
-
|
|
2
|
+
import { createComponent as e } from "@lit/react";
|
|
3
|
+
import { PieTooltip as t } 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
|
+
const i = e({
|
|
5
6
|
displayName: "PieTooltip",
|
|
6
|
-
elementClass:
|
|
7
|
+
elementClass: t,
|
|
7
8
|
react: o,
|
|
8
9
|
tagName: "pie-tooltip",
|
|
9
|
-
events: {
|
|
10
|
-
|
|
10
|
+
events: {
|
|
11
|
+
onPieTooltipOpen: "pie-tooltip-open",
|
|
12
|
+
// When a configured trigger asks for the panel. Set `isOpen` to `true` in response.
|
|
13
|
+
onPieTooltipClose: "pie-tooltip-close"
|
|
14
|
+
// When the close button is clicked, or a configured trigger asks to dismiss the panel. Set `isOpen` to `false` in response.
|
|
15
|
+
}
|
|
16
|
+
}), l = i;
|
|
11
17
|
export {
|
|
12
|
-
|
|
18
|
+
r as ON_TOOLTIP_CLOSE_EVENT,
|
|
19
|
+
m as ON_TOOLTIP_OPEN_EVENT,
|
|
20
|
+
l as PieTooltip,
|
|
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
|
|
13
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.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -36,11 +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.
|
|
40
|
-
"@justeattakeaway/pie-monorepo-utils": "0.9.
|
|
39
|
+
"@justeattakeaway/pie-css": "1.9.0",
|
|
40
|
+
"@justeattakeaway/pie-monorepo-utils": "0.9.10"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@justeattakeaway/pie-
|
|
43
|
+
"@justeattakeaway/pie-icon-button": "2.7.35",
|
|
44
|
+
"@justeattakeaway/pie-icons-webc": "1.29.4",
|
|
45
|
+
"@justeattakeaway/pie-webc-core": "22.0.0"
|
|
44
46
|
},
|
|
45
47
|
"customElements": "custom-elements.json",
|
|
46
48
|
"sideEffects": [
|
package/src/defs.ts
CHANGED
|
@@ -1,3 +1,129 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import { type ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
2
|
+
|
|
3
|
+
export const positions = [
|
|
4
|
+
'top',
|
|
5
|
+
'top-start',
|
|
6
|
+
'top-end',
|
|
7
|
+
'bottom',
|
|
8
|
+
'bottom-start',
|
|
9
|
+
'bottom-end',
|
|
10
|
+
'left',
|
|
11
|
+
'left-start',
|
|
12
|
+
'left-end',
|
|
13
|
+
'right',
|
|
14
|
+
'right-start',
|
|
15
|
+
'right-end',
|
|
16
|
+
] as const;
|
|
17
|
+
|
|
18
|
+
export const sizes = ['default', 'fit-to-content', 'fill-container'] as const;
|
|
19
|
+
export const variants = ['default', 'inverse'] as const;
|
|
20
|
+
export const types = ['default', 'icon'] as const;
|
|
21
|
+
export const headingLevels = ['h2', 'h3', 'h4', 'h5', 'h6'] as const;
|
|
22
|
+
export const triggers = ['hover', 'focus', 'click'] as const;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The two patterns the panel can present as. Inferred from the `action` slot rather than
|
|
26
|
+
* configured: an empty `action` slot is a tooltip, a filled one is a non-modal dialog.
|
|
27
|
+
*/
|
|
28
|
+
export const modes = ['tooltip', 'dialog'] as const;
|
|
29
|
+
|
|
30
|
+
export type TooltipMode = typeof modes[number];
|
|
31
|
+
export type TooltipTrigger = typeof triggers[number];
|
|
32
|
+
|
|
33
|
+
type AriaProps = {
|
|
34
|
+
/**
|
|
35
|
+
* The accessible name for the close button. Required whenever `isDismissible` is set.
|
|
36
|
+
*/
|
|
37
|
+
close?: string;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The accessible name for the panel in dialog mode. Only used when `heading` is not provided.
|
|
41
|
+
*/
|
|
42
|
+
label?: string;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export interface TooltipProps {
|
|
46
|
+
/**
|
|
47
|
+
* The `id` of the element the panel is anchored to. The trigger lives elsewhere in the
|
|
48
|
+
* DOM and is never slotted into the tooltip.
|
|
49
|
+
*/
|
|
50
|
+
trigger?: string;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* When true, the panel is visible. The component never writes to this property: the
|
|
54
|
+
* consumer owns it and updates it in response to the close event.
|
|
55
|
+
*/
|
|
56
|
+
isOpen?: boolean;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The side of the trigger the panel sits on, and its alignment along the cross axis.
|
|
60
|
+
*/
|
|
61
|
+
position?: typeof positions[number];
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* How the panel sizes itself. `default` is a fixed 280px and wraps, `fit-to-content` is as
|
|
65
|
+
* wide as its content, and `fill-container` matches the inline size of the trigger's parent
|
|
66
|
+
* element. Not applied when `type` is `icon`.
|
|
67
|
+
*/
|
|
68
|
+
size?: typeof sizes[number];
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The colour treatment of the panel. `default` is the dark panel, `inverse` the light one.
|
|
72
|
+
*/
|
|
73
|
+
variant?: typeof variants[number];
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* The presentation of the panel. `icon` is the compact treatment intended for icon triggers:
|
|
77
|
+
* it has no arrow and is always as wide as its content, so `size` and `--tooltip-width` have
|
|
78
|
+
* no effect on it.
|
|
79
|
+
*/
|
|
80
|
+
type?: typeof types[number];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* When true, a close button is rendered inside the panel.
|
|
84
|
+
*/
|
|
85
|
+
isDismissible?: boolean;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The text to display in the panel's heading. In dialog mode this also provides the
|
|
89
|
+
* panel's accessible name.
|
|
90
|
+
*/
|
|
91
|
+
heading?: string;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The HTML heading tag to use for the panel's heading. Can be h2-h6.
|
|
95
|
+
*/
|
|
96
|
+
headingLevel?: typeof headingLevels[number];
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The ARIA labels used for various parts of the tooltip.
|
|
100
|
+
*/
|
|
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>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export const componentSelector = 'pie-tooltip';
|
|
114
|
+
export const componentClass = 'c-tooltip';
|
|
115
|
+
|
|
116
|
+
export const ON_TOOLTIP_OPEN_EVENT = `${componentSelector}-open`;
|
|
117
|
+
export const ON_TOOLTIP_CLOSE_EVENT = `${componentSelector}-close`;
|
|
118
|
+
|
|
119
|
+
export type DefaultProps = ComponentDefaultProps<TooltipProps, keyof Omit<TooltipProps, 'trigger' | 'heading' | 'aria' | 'triggers'>>;
|
|
120
|
+
|
|
121
|
+
export const defaultProps: DefaultProps = {
|
|
122
|
+
isOpen: false,
|
|
123
|
+
position: 'top',
|
|
124
|
+
size: 'default',
|
|
125
|
+
variant: 'default',
|
|
126
|
+
type: 'default',
|
|
127
|
+
isDismissible: false,
|
|
128
|
+
headingLevel: 'h2',
|
|
129
|
+
};
|