@c2n/tooltip 0.0.6
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/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/tooltip.js +1468 -0
- package/package.json +60 -0
- package/types/src/tooltip.d.ts +101 -0
- package/types/src/tooltip.d.ts.map +1 -0
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@c2n/tooltip",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/tooltip.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"default": "./dist/tooltip.js",
|
|
9
|
+
"types": "./types/src/tooltip.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"./custom-elements.json": "./custom-elements.json"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"types"
|
|
16
|
+
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"tooltip",
|
|
19
|
+
"web component",
|
|
20
|
+
"lit"
|
|
21
|
+
],
|
|
22
|
+
"author": "code2nguyen@gmail.com",
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"registry": "https://registry.npmjs.org",
|
|
25
|
+
"access": "public"
|
|
26
|
+
},
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/code2nguyen/web-components.git"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"dev": "vite",
|
|
33
|
+
"build": "wireit",
|
|
34
|
+
"type-check": "wireit"
|
|
35
|
+
},
|
|
36
|
+
"wireit": {
|
|
37
|
+
"type-check": {
|
|
38
|
+
"dependencies": [
|
|
39
|
+
"../../core:build"
|
|
40
|
+
],
|
|
41
|
+
"command": "tsc -p tsconfig.lib.json --composite false"
|
|
42
|
+
},
|
|
43
|
+
"build": {
|
|
44
|
+
"dependencies": [
|
|
45
|
+
"type-check"
|
|
46
|
+
],
|
|
47
|
+
"command": "vite build"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@c2n/core": "0.0.6",
|
|
52
|
+
"@floating-ui/dom": "1.8.0",
|
|
53
|
+
"lit": "3.3.3"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@c2n/config": "*"
|
|
57
|
+
},
|
|
58
|
+
"customElements": "custom-elements.json",
|
|
59
|
+
"gitHead": "2921054bc75299da66dad11c1e374246ff88a51e"
|
|
60
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { LitElement, type PropertyValues } from 'lit';
|
|
2
|
+
import { type Placement } from '@floating-ui/dom';
|
|
3
|
+
export type { Placement };
|
|
4
|
+
/**
|
|
5
|
+
* Contextual hint shown when its target is hovered or focused. Drop it inside the element it describes (the parent is
|
|
6
|
+
* the target), point it at another element with `for="<id>"`, or use `target-strategy="previousElement"`. The text is
|
|
7
|
+
* the slotted content, or the target's `data-tooltip` attribute when the slot is empty.
|
|
8
|
+
*
|
|
9
|
+
* The tooltip is a `popover="manual"` element: it renders in the top layer, so it is never clipped by scrolling or
|
|
10
|
+
* `overflow: hidden` ancestors and the target is left untouched. floating-ui keeps it beside the target and flips it
|
|
11
|
+
* when there is no room; the side in use is reflected as `current-placement`. It has `role="tooltip"` and the target
|
|
12
|
+
* gets `aria-describedby`, so assistive technology reads it. Escape, pressing on the target, blur and leaving hide it.
|
|
13
|
+
*
|
|
14
|
+
* @tag c2-tooltip
|
|
15
|
+
*
|
|
16
|
+
* @slot - Tooltip content. Falls back to the target's `data-tooltip`.
|
|
17
|
+
*
|
|
18
|
+
* @event {Event} show - Fired when the tooltip becomes visible.
|
|
19
|
+
* @event {Event} hide - Fired when it starts hiding.
|
|
20
|
+
*
|
|
21
|
+
* @cssproperty {background-color} [--c2-tooltip--background-color=#18181b]
|
|
22
|
+
* @cssproperty {color} [--c2-tooltip--color=#fafafa]
|
|
23
|
+
* @cssproperty {border-radius} [--c2-tooltip--border-radius=6px]
|
|
24
|
+
* @cssproperty {box-shadow} [--c2-tooltip--box-shadow=0 4px 12px rgba(0, 0, 0, 0.15)]
|
|
25
|
+
* @cssproperty {border} --c2-tooltip--border
|
|
26
|
+
* @cssproperty {font-size} [--c2-tooltip--font-size=12px]
|
|
27
|
+
* @cssproperty {font-weight} [--c2-tooltip--font-weight=500]
|
|
28
|
+
* @cssproperty {font-style} --c2-tooltip--font-style
|
|
29
|
+
* @cssproperty {font-family} --c2-tooltip--font-family
|
|
30
|
+
* @cssproperty {line-height} [--c2-tooltip--line-height=1.4]
|
|
31
|
+
*
|
|
32
|
+
* @cssproperty {padding} [--c2-tooltip--padding-top=5px]
|
|
33
|
+
* @cssproperty {padding} [--c2-tooltip--padding-right=8px]
|
|
34
|
+
* @cssproperty {padding} [--c2-tooltip--padding-bottom=5px]
|
|
35
|
+
* @cssproperty {padding} [--c2-tooltip--padding-left=8px]
|
|
36
|
+
*
|
|
37
|
+
* @cssproperty {pixel} [--c2-tooltip--max-width=240px]
|
|
38
|
+
* @cssproperty {pixel} [--c2-tooltip--offset=8px] - Distance between the target and the tooltip (arrow included).
|
|
39
|
+
* @cssproperty {pixel} [--c2-tooltip__arrow--size=8px] - Side of the arrow square; `0px` hides it like `hide-arrow`.
|
|
40
|
+
* @cssproperty {time} [--c2-tooltip--transition-duration=120ms]
|
|
41
|
+
* @cssproperty {transform} [--c2-tooltip--enter-transform=scale(0.92)] - Start of the enter animation.
|
|
42
|
+
*/
|
|
43
|
+
export declare class Tooltip extends LitElement {
|
|
44
|
+
static styles: import("lit").CSSResult;
|
|
45
|
+
/** Preferred side; flips when there is no room. */
|
|
46
|
+
placement: Placement;
|
|
47
|
+
/**
|
|
48
|
+
* Legacy: comma-separated list of allowed placements (`"top,bottom"`). When set, the best of those is chosen
|
|
49
|
+
* automatically instead of `placement`.
|
|
50
|
+
*/
|
|
51
|
+
position: string | undefined;
|
|
52
|
+
/** Delay before showing, in milliseconds. */
|
|
53
|
+
delay: number;
|
|
54
|
+
/** Delay before hiding, in milliseconds. */
|
|
55
|
+
hideDelay: number;
|
|
56
|
+
hideArrow: boolean;
|
|
57
|
+
/** `parent` (default) or `previousElement`; ignored when `for` is set. */
|
|
58
|
+
targetStrategy: 'parent' | 'previousElement';
|
|
59
|
+
/** Id of the target element (same document or shadow root). */
|
|
60
|
+
for: string | undefined;
|
|
61
|
+
/** Visible state. Set it to show or hide the tooltip programmatically. */
|
|
62
|
+
open: boolean;
|
|
63
|
+
/** @deprecated Use `open`. */
|
|
64
|
+
get showing(): boolean;
|
|
65
|
+
private targetText;
|
|
66
|
+
private arrowElement?;
|
|
67
|
+
private _target;
|
|
68
|
+
private showTimer;
|
|
69
|
+
private hideTimer;
|
|
70
|
+
private cleanupPosition;
|
|
71
|
+
/** The element the tooltip describes. Assignable. */
|
|
72
|
+
get target(): HTMLElement | null;
|
|
73
|
+
set target(target: HTMLElement | null);
|
|
74
|
+
/**
|
|
75
|
+
* `targetText` is only the slot's fallback content, and the target is resolved from the live DOM, so it is
|
|
76
|
+
* necessarily unknown when the element is server-rendered. Assigning it before the first update would be lost:
|
|
77
|
+
* hydration adopts the server-rendered markup as-is and records the new value as already committed, so the
|
|
78
|
+
* bubble would stay empty forever. Wait for that first update before touching it.
|
|
79
|
+
*/
|
|
80
|
+
private syncTargetText;
|
|
81
|
+
connectedCallback(): void;
|
|
82
|
+
disconnectedCallback(): void;
|
|
83
|
+
private resolveTarget;
|
|
84
|
+
private detachTarget;
|
|
85
|
+
private handleEnter;
|
|
86
|
+
private handleLeave;
|
|
87
|
+
private handleTargetKeydown;
|
|
88
|
+
private clearTimers;
|
|
89
|
+
private readPixels;
|
|
90
|
+
private startPositioning;
|
|
91
|
+
private stopPositioning;
|
|
92
|
+
private updatePosition;
|
|
93
|
+
updated(changed: PropertyValues<this>): void;
|
|
94
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
95
|
+
}
|
|
96
|
+
declare global {
|
|
97
|
+
interface HTMLElementTagNameMap {
|
|
98
|
+
'c2-tooltip': Tooltip;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=tooltip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tooltip.d.ts","sourceRoot":"","sources":["../../src/tooltip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA4B,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;AAG/E,OAAO,EAA0E,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAGzH,YAAY,EAAE,SAAS,EAAE,CAAA;AAOzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,qBACa,OAAQ,SAAQ,UAAU;IACrC,OAAgB,MAAM,0BAAoB;IAE1C,mDAAmD;IACtB,SAAS,EAAE,SAAS,CAAQ;IAEzD;;;OAGG;IACS,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAY;IAEpD,6CAA6C;IACjB,KAAK,SAAM;IAEvC,4CAA4C;IACS,SAAS,SAAI;IAEG,SAAS,UAAQ;IAEtF,0EAA0E;IAC9B,cAAc,EAAE,QAAQ,GAAG,iBAAiB,CAAW;IAEnG,+DAA+D;IACnD,GAAG,EAAE,MAAM,GAAG,SAAS,CAAY;IAE/C,0EAA0E;IAC9B,IAAI,UAAQ;IAExD,8BAA8B;IAC9B,IAAI,OAAO,YAEV;IAEQ,OAAO,CAAC,UAAU,CAAK;IAEH,OAAO,CAAC,YAAY,CAAC,CAAa;IAE/D,OAAO,CAAC,OAAO,CAA2B;IAC1C,OAAO,CAAC,SAAS,CAA2C;IAC5D,OAAO,CAAC,SAAS,CAA2C;IAC5D,OAAO,CAAC,eAAe,CAA4B;IAEnD,qDAAqD;IACrD,IAAI,MAAM,IAAI,WAAW,GAAG,IAAI,CAE/B;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,IAAI,EAapC;IAED;;;;;OAKG;IACH,OAAO,CAAC,cAAc;IAOb,iBAAiB;IAQjB,oBAAoB;IAO7B,OAAO,CAAC,aAAa;IAgBrB,OAAO,CAAC,YAAY;IAYpB,OAAO,CAAC,WAAW,CAOlB;IAED,OAAO,CAAC,WAAW,CAUlB;IAED,OAAO,CAAC,mBAAmB,CAE1B;IAED,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,gBAAgB;IAOxB,OAAO,CAAC,eAAe;YAKT,cAAc;IAuCnB,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;IAyBrC,MAAM;CAQhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,YAAY,EAAE,OAAO,CAAA;KACtB;CACF"}
|