@digital-realty/ix-tooltip 1.0.1

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/.editorconfig ADDED
@@ -0,0 +1,29 @@
1
+ # EditorConfig helps developers define and maintain consistent
2
+ # coding styles between different editors and IDEs
3
+ # editorconfig.org
4
+
5
+ root = true
6
+
7
+
8
+ [*]
9
+
10
+ # Change these settings to your own preference
11
+ indent_style = space
12
+ indent_size = 2
13
+
14
+ # We recommend you to keep these unchanged
15
+ end_of_line = lf
16
+ charset = utf-8
17
+ trim_trailing_whitespace = true
18
+ insert_final_newline = true
19
+
20
+ [*.md]
21
+ trim_trailing_whitespace = false
22
+
23
+ [*.json]
24
+ indent_size = 2
25
+
26
+ [*.{html,js,md}]
27
+ block_comment_start = /**
28
+ block_comment = *
29
+ block_comment_end = */
@@ -0,0 +1 @@
1
+ ./node_modules/.bin/lint-staged
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ix-tooltip
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # \<ix-tooltip>
2
+
3
+ This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i ix-tooltip
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```html
14
+ <script type="module">
15
+ import '@digital-realty/ix-tooltip/ix-tooltip.js';
16
+ </script>
17
+
18
+ <ix-tooltip></ix-tooltip>
19
+ ```
20
+
21
+ Look at /demo/index.html for futher details.
22
+
23
+ ## Linting and formatting
24
+
25
+ To scan the project for linting and formatting errors, run
26
+
27
+ ```bash
28
+ npm run lint
29
+ ```
30
+
31
+ To automatically fix linting and formatting errors, run
32
+
33
+ ```bash
34
+ npm run format
35
+ ```
36
+
37
+ ## Testing with Web Test Runner
38
+
39
+ To execute a single test run:
40
+
41
+ ```bash
42
+ npm run test
43
+ ```
44
+
45
+ To run the tests in interactive watch mode run:
46
+
47
+ ```bash
48
+ npm run test:watch
49
+ ```
50
+
51
+ ## Demoing with Storybook
52
+
53
+ To run a local instance of Storybook for your component, run
54
+
55
+ ```bash
56
+ npm run storybook
57
+ ```
58
+
59
+ To build a production version of Storybook, run
60
+
61
+ ```bash
62
+ npm run storybook:build
63
+ ```
64
+
65
+
66
+ ## Tooling configs
67
+
68
+ For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
69
+
70
+ If you customize the configuration a lot, you can consider moving them to individual files.
71
+
72
+ ## Local Demo with `web-dev-server`
73
+
74
+ ```bash
75
+ npm start
76
+ ```
77
+
78
+ To run a local development server that serves the basic demo located in `demo/index.html`
@@ -0,0 +1,151 @@
1
+ <!doctype html>
2
+ <html lang="en-GB">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
6
+ <style>
7
+ body {
8
+ background: #fafafa;
9
+ }
10
+ </style>
11
+ </head>
12
+ <body>
13
+ <h1>Tooltip Demo</h1>
14
+ <p>Hover over these links.</p>
15
+ <div id="demo"></div>
16
+ <p>This tooltip has 'built in mode', see `handleShow` in the source:
17
+ </p>
18
+ <pre>
19
+ document.dispatchEvent(
20
+ new CustomEvent('show-tooltip', {
21
+ detail: {
22
+ target: e.target,
23
+ tooltip: html`&ltix-simple-tooltip&gt
24
+ ${target.getAttribute('data-tooltip')}
25
+ &lt/ix-simple-tooltip&gt`,
26
+ placement: target.getAttribute('data-tooltip-placement'),
27
+ strategy: target.getAttribute('data-tooltip-strategy'),
28
+ },
29
+ }),
30
+ </pre>
31
+ <p>
32
+ This means you only have to add the attribute `aria-describedby="tooltip"` and the text in `data-tooltip="some text"`
33
+ will be shown.
34
+ </p>
35
+ <p>
36
+ You can use this same strategy and put any element as the `tooltip`.
37
+ </p>
38
+ <h2>Properties</h2>
39
+ <p>
40
+ The following properties should typically be provided via the `detail` of a CustomEvent named `show-tooltip`. (note: it is
41
+ possible to customise the event name by importing `IxTooltip` and overriding the static `_hideTooltip` and `_showTooltip` properties.)
42
+ </p>
43
+
44
+ <table border="1" cellpadding="4">
45
+ <thead>
46
+ <tr>
47
+ <th>
48
+ Property
49
+ </th>
50
+ <th>
51
+ Value
52
+ </th>
53
+ <th>
54
+ Default
55
+ </th>
56
+ </tr>
57
+ </thead>
58
+ <tr>
59
+ <td>
60
+ placement
61
+ </td>
62
+ <td>
63
+ 'top' | 'top-start' | 'top-end' | 'right' | 'right-start' | 'right-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end'
64
+ </td>
65
+ <td>
66
+ <p>
67
+ No default, the 'autoPlacement' middleware will provide an optimal placement.
68
+ </p>
69
+ <p>
70
+ If a placement is provided, it will be the only placement allowed.
71
+ </p>
72
+ </td>
73
+ </tr>
74
+ <tr>
75
+ <td>
76
+ strategy
77
+ </td>
78
+ <td>
79
+ 'fixed' | 'absolute'
80
+ </td>
81
+ <td>
82
+ fixed
83
+ </td>
84
+ </tr>
85
+ <tr>
86
+ <td>
87
+ tooltip
88
+ </td>
89
+ <td>
90
+ The tooltip, should be a lit `TemplateResult` provided by html``
91
+ </td>
92
+ <td></td>
93
+ </tr>
94
+ <tr>
95
+ <td>
96
+ target
97
+ </td>
98
+ <td>
99
+ The element to show the tooltip on
100
+ </td>
101
+ <td>
102
+ </td>
103
+ </tr>
104
+ <tr>
105
+ <td>
106
+ hidingDuration
107
+ </td>
108
+ <td>
109
+ How long it takes for the tooltip to fade out. Note that if this is too low, a user will not be able to hover on the tooltip.
110
+ </td>
111
+ <td>
112
+ 500
113
+ </td>
114
+ </tr>
115
+ <tr>
116
+ <td>
117
+ autoPlacementOptions
118
+ </td>
119
+ <td>
120
+ Have a look at the type `AutoPlacementOptions` and refer to <a href="https://floating-ui.com/docs/autoPlacement">this document</a>.
121
+ </td>
122
+ <td>
123
+ `allowedPlacements` is set if a `placement` is provided.
124
+ </td>
125
+ </tr>
126
+ <tr>
127
+ <td>
128
+ offsetOptions
129
+ </td>
130
+ <td>
131
+ Have a look at the type `OffsetOptions` and refer to <a href="https://floating-ui.com/docs/offset">this document</a>.
132
+ </td>
133
+ <td>
134
+ { mainAxis: 10 }
135
+ </td>
136
+ </tr>
137
+ </table>
138
+
139
+ <script type="module">
140
+ import { html, render } from 'lit';
141
+ import '../dist/test/ix-tooltip-test-harness.js';
142
+
143
+ render(
144
+ html`
145
+ <ix-tooltip-test-harness></ix-tooltip-test-harness>
146
+ `,
147
+ document.querySelector('#demo')
148
+ );
149
+ </script>
150
+ </body>
151
+ </html>
@@ -0,0 +1,45 @@
1
+ import { LitElement, TemplateResult } from 'lit';
2
+ import { Strategy, Placement, AutoPlacementOptions, OffsetOptions } from '@floating-ui/dom';
3
+ import './templates/ix-simple-tooltip.js';
4
+ export declare class IxTooltip extends LitElement {
5
+ static _placement: Placement | undefined;
6
+ static _strategy: Strategy;
7
+ static _tagName: string;
8
+ static _offsetOptions: OffsetOptions;
9
+ static _hidingDuration: number;
10
+ static _showTooltip: string;
11
+ static _hideTooltip: string;
12
+ id: string;
13
+ role: string;
14
+ placement: Placement | undefined;
15
+ strategy: Strategy;
16
+ tooltip: TemplateResult | undefined;
17
+ target: HTMLElement | undefined;
18
+ hidding: boolean;
19
+ autoPlacementOptions: AutoPlacementOptions | undefined;
20
+ offsetOptions: OffsetOptions;
21
+ hidingDuration: number;
22
+ hideTimeout: ReturnType<typeof setTimeout> | undefined;
23
+ cleanup: () => void;
24
+ connectedCallback(): void;
25
+ disconnectedCallback(): void;
26
+ handleEscapeKey: (e: KeyboardEvent) => void;
27
+ handleShow: (e: Event) => void;
28
+ clearHideTimeout(): void;
29
+ handleHide: (e: Event) => void;
30
+ show: (e: any) => void;
31
+ hide: () => void;
32
+ getAutoPlacementOptions(): {
33
+ crossAxis?: boolean;
34
+ alignment?: import("@floating-ui/utils").Alignment | null;
35
+ autoAlignment?: boolean;
36
+ allowedPlacements?: Array<Placement>;
37
+ rootBoundary?: import("@floating-ui/core").RootBoundary;
38
+ elementContext?: import("@floating-ui/core").ElementContext;
39
+ altBoundary?: boolean;
40
+ padding?: import("@floating-ui/utils").Padding;
41
+ boundary?: import("@floating-ui/dom").Boundary;
42
+ };
43
+ updatePosition: () => void;
44
+ render(): TemplateResult<1>;
45
+ }
@@ -0,0 +1,181 @@
1
+ import { __decorate } from "tslib";
2
+ /* eslint-disable class-methods-use-this */
3
+ import { html, LitElement, nothing } from 'lit';
4
+ import { property, state } from 'lit/decorators.js';
5
+ import { computePosition, autoUpdate, autoPlacement, offset, } from '@floating-ui/dom';
6
+ import './templates/ix-simple-tooltip.js';
7
+ export class IxTooltip extends LitElement {
8
+ constructor() {
9
+ super(...arguments);
10
+ // eslint-disable-next-line lit/no-native-attributes
11
+ this.id = 'tooltip';
12
+ // eslint-disable-next-line lit/no-native-attributes
13
+ this.role = 'tooltip';
14
+ this.placement = IxTooltip._placement;
15
+ this.strategy = IxTooltip._strategy;
16
+ this.tooltip = undefined;
17
+ this.target = undefined;
18
+ this.hidding = false;
19
+ this.autoPlacementOptions = undefined;
20
+ this.offsetOptions = IxTooltip._offsetOptions;
21
+ this.hidingDuration = IxTooltip._hidingDuration;
22
+ this.hideTimeout = undefined;
23
+ this.cleanup = () => undefined;
24
+ this.handleEscapeKey = (e) => {
25
+ if (this.tooltip && e.key === 'Escape') {
26
+ this.hide();
27
+ }
28
+ };
29
+ this.handleShow = (e) => {
30
+ const target = e.composedPath()[0]; // I hate the shadowDOM
31
+ const eventTarget = e.target;
32
+ if (eventTarget &&
33
+ eventTarget.tagName === IxTooltip._tagName.toUpperCase()) {
34
+ clearTimeout(this.hideTimeout);
35
+ }
36
+ if (target && target.hasAttribute('data-tooltip')) {
37
+ this.clearHideTimeout();
38
+ document.dispatchEvent(new CustomEvent('show-tooltip', {
39
+ detail: {
40
+ target: e.target,
41
+ tooltip: html `<ix-simple-tooltip
42
+ >${target.getAttribute('data-tooltip')}</ix-simple-tooltip
43
+ >`,
44
+ placement: target.getAttribute('data-tooltip-placement'),
45
+ strategy: target.getAttribute('data-tooltip-strategy'),
46
+ },
47
+ }));
48
+ }
49
+ };
50
+ this.handleHide = (e) => {
51
+ if (this.tooltip &&
52
+ ((e.type === 'focusout' && this.shadowRoot?.activeElement !== null) ||
53
+ e.type === 'mouseout')) {
54
+ this.clearHideTimeout();
55
+ this.hidding = true;
56
+ this.hideTimeout = setTimeout(() => {
57
+ this.hide();
58
+ }, this.hidingDuration);
59
+ }
60
+ };
61
+ this.show = (e) => {
62
+ const { placement, strategy, target, tooltip, autoPlacementOptions, offsetOptions, hidingDuration, } = e.detail;
63
+ this.target = target;
64
+ this.placement = placement || IxTooltip._placement;
65
+ this.strategy = strategy || IxTooltip._strategy;
66
+ this.tooltip = tooltip;
67
+ this.autoPlacementOptions = autoPlacementOptions;
68
+ this.offsetOptions = offsetOptions || IxTooltip._offsetOptions;
69
+ this.hidingDuration =
70
+ hidingDuration !== undefined ? hidingDuration : IxTooltip._hidingDuration;
71
+ this.cleanup = autoUpdate(target, this, this.updatePosition);
72
+ this.hidding = false;
73
+ };
74
+ this.hide = () => {
75
+ this.cleanup();
76
+ this.placement = IxTooltip._placement;
77
+ this.strategy = IxTooltip._strategy;
78
+ this.offsetOptions = IxTooltip._offsetOptions;
79
+ this.hidingDuration = IxTooltip._hidingDuration;
80
+ this.target = undefined;
81
+ this.autoPlacementOptions = undefined;
82
+ this.tooltip = undefined;
83
+ this.hidding = false;
84
+ };
85
+ this.updatePosition = () => {
86
+ if (this.target) {
87
+ computePosition(this.target, this, {
88
+ strategy: this.strategy,
89
+ placement: this.placement,
90
+ middleware: [
91
+ autoPlacement(this.getAutoPlacementOptions()),
92
+ offset(this.offsetOptions),
93
+ ],
94
+ }).then(({ x, y }) => {
95
+ Object.assign(this.style, {
96
+ left: `${x}px`,
97
+ top: `${y}px`,
98
+ position: this.strategy,
99
+ });
100
+ });
101
+ }
102
+ else {
103
+ this.hide();
104
+ }
105
+ };
106
+ }
107
+ connectedCallback() {
108
+ super.connectedCallback();
109
+ document.addEventListener(IxTooltip._showTooltip, this.show);
110
+ document.addEventListener(IxTooltip._hideTooltip, this.hide);
111
+ document.addEventListener('keydown', this.handleEscapeKey);
112
+ document.addEventListener('focusin', this.handleShow);
113
+ document.addEventListener('focusout', this.handleHide);
114
+ document.addEventListener('mouseover', this.handleShow);
115
+ document.addEventListener('mouseout', this.handleHide);
116
+ }
117
+ disconnectedCallback() {
118
+ super.disconnectedCallback();
119
+ document.removeEventListener(IxTooltip._showTooltip, this.show);
120
+ document.removeEventListener(IxTooltip._hideTooltip, this.hide);
121
+ document.removeEventListener('keydown', this.handleEscapeKey);
122
+ document.removeEventListener('focusin', this.handleShow);
123
+ document.removeEventListener('focusout', this.handleHide);
124
+ document.removeEventListener('mouseover', this.handleShow);
125
+ document.removeEventListener('mouseout', this.handleHide);
126
+ this.hide();
127
+ }
128
+ clearHideTimeout() {
129
+ if (this.hideTimeout) {
130
+ this.hidding = false;
131
+ clearTimeout(this.hideTimeout);
132
+ }
133
+ }
134
+ getAutoPlacementOptions() {
135
+ const autoPlacementOptions = {
136
+ ...this.autoPlacementOptions,
137
+ };
138
+ if (this.placement) {
139
+ autoPlacementOptions.allowedPlacements = [this.placement];
140
+ }
141
+ return autoPlacementOptions;
142
+ }
143
+ render() {
144
+ return html `<div
145
+ tabindex="0"
146
+ class="wrapper ${this.hidding ? 'hidding' : ''}"
147
+ style="transition:${this.hidingDuration}ms opacity;"
148
+ >
149
+ ${this.tooltip || nothing}
150
+ </div> `;
151
+ }
152
+ }
153
+ IxTooltip._placement = undefined;
154
+ IxTooltip._strategy = 'fixed';
155
+ IxTooltip._tagName = 'ix-tooltip';
156
+ IxTooltip._offsetOptions = { mainAxis: 10 };
157
+ IxTooltip._hidingDuration = 500; // milliseconds
158
+ IxTooltip._showTooltip = 'show-tooltip';
159
+ IxTooltip._hideTooltip = 'hide-tooltip';
160
+ __decorate([
161
+ property({ type: String, reflect: true })
162
+ ], IxTooltip.prototype, "id", void 0);
163
+ __decorate([
164
+ property({ type: String, reflect: true })
165
+ ], IxTooltip.prototype, "role", void 0);
166
+ __decorate([
167
+ property({ type: String, reflect: true })
168
+ ], IxTooltip.prototype, "placement", void 0);
169
+ __decorate([
170
+ property({ type: String, reflect: true })
171
+ ], IxTooltip.prototype, "strategy", void 0);
172
+ __decorate([
173
+ state()
174
+ ], IxTooltip.prototype, "tooltip", void 0);
175
+ __decorate([
176
+ state()
177
+ ], IxTooltip.prototype, "target", void 0);
178
+ __decorate([
179
+ state()
180
+ ], IxTooltip.prototype, "hidding", void 0);
181
+ //# sourceMappingURL=IxTooltip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IxTooltip.js","sourceRoot":"","sources":["../../src/IxTooltip.ts"],"names":[],"mappings":";AAAA,2CAA2C;AAC3C,OAAO,EAAE,IAAI,EAAE,UAAU,EAAkB,OAAO,EAAE,MAAM,KAAK,CAAC;AAChE,OAAO,E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AAY,AAAvB,CAAwB;AAEhC,wBAAc,GAAkB,EAAE,QAAQ,EAAE,EAAE,EAAE,AAAlC,CAAmC;AAEjD,yBAAe,GAAW,GAAG,AAAd,CAAe,CAAC,eAAe;AAE9C,sBAAY,GAAW,cAAc,AAAzB,CAA0B;AAEtC,sBAAY,GAAW,cAAc,AAAzB,CAA0B;AAGF;IAA1C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;qCAAwB;AAGvB;IAA1C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;uCAA0B;AAEzB;IAA1C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;4CACnB;AAEoB;IAA1C,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;2CACpB;AAEb;IAAR,KAAK,EAAE;0CAAiD;AAEhD;IAAR,KAAK,EAAE;yCAA6C;AAE5C;IAAR,KAAK,EAAE;0CAA0B","sourcesContent":["/* eslint-disable class-methods-use-this */\nimport { html, LitElement, TemplateResult, nothing } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport {\n computePosition,\n Strategy,\n Placement,\n autoUpdate,\n autoPlacement,\n AutoPlacementOptions,\n offset,\n OffsetOptions,\n} from '@floating-ui/dom';\nimport './templates/ix-simple-tooltip.js';\n\nexport class IxTooltip extends LitElement {\n static _placement: Placement | undefined = undefined;\n\n static _strategy: Strategy = 'fixed';\n\n static _tagName: string = 'ix-tooltip';\n\n static _offsetOptions: OffsetOptions = { mainAxis: 10 };\n\n static _hidingDuration: number = 500; // milliseconds\n\n static _showTooltip: string = 'show-tooltip';\n\n static _hideTooltip: string = 'hide-tooltip';\n\n // eslint-disable-next-line lit/no-native-attributes\n @property({ type: String, reflect: true }) id: string = 'tooltip';\n\n // eslint-disable-next-line lit/no-native-attributes\n @property({ type: String, reflect: true }) role: string = 'tooltip';\n\n @property({ type: String, reflect: true }) placement: Placement | undefined =\n IxTooltip._placement;\n\n @property({ type: String, reflect: true }) strategy: Strategy =\n IxTooltip._strategy;\n\n @state() tooltip: TemplateResult | undefined = undefined;\n\n @state() target: HTMLElement | undefined = undefined;\n\n @state() hidding: boolean = false;\n\n autoPlacementOptions: AutoPlacementOptions | undefined = undefined;\n\n offsetOptions: OffsetOptions = IxTooltip._offsetOptions;\n\n hidingDuration: number = IxTooltip._hidingDuration;\n\n hideTimeout: ReturnType<typeof setTimeout> | undefined = undefined;\n\n cleanup: () => void = () => undefined;\n\n connectedCallback(): void {\n super.connectedCallback();\n document.addEventListener(IxTooltip._showTooltip, this.show);\n document.addEventListener(IxTooltip._hideTooltip, this.hide);\n document.addEventListener('keydown', this.handleEscapeKey);\n document.addEventListener('focusin', this.handleShow);\n document.addEventListener('focusout', this.handleHide);\n document.addEventListener('mouseover', this.handleShow);\n document.addEventListener('mouseout', this.handleHide);\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback();\n document.removeEventListener(IxTooltip._showTooltip, this.show);\n document.removeEventListener(IxTooltip._hideTooltip, this.hide);\n document.removeEventListener('keydown', this.handleEscapeKey);\n document.removeEventListener('focusin', this.handleShow);\n document.removeEventListener('focusout', this.handleHide);\n document.removeEventListener('mouseover', this.handleShow);\n document.removeEventListener('mouseout', this.handleHide);\n this.hide();\n }\n\n handleEscapeKey = (e: KeyboardEvent) => {\n if (this.tooltip && e.key === 'Escape') {\n this.hide();\n }\n };\n\n handleShow = (e: Event) => {\n const target = <HTMLElement>e.composedPath()[0]; // I hate the shadowDOM\n const eventTarget = <HTMLElement>e.target;\n\n if (\n eventTarget &&\n eventTarget.tagName === IxTooltip._tagName.toUpperCase()\n ) {\n clearTimeout(this.hideTimeout);\n }\n\n if (target && target.hasAttribute('data-tooltip')) {\n this.clearHideTimeout();\n document.dispatchEvent(\n new CustomEvent('show-tooltip', {\n detail: {\n target: e.target,\n tooltip: html`<ix-simple-tooltip\n >${target.getAttribute('data-tooltip')}</ix-simple-tooltip\n >`,\n placement: target.getAttribute('data-tooltip-placement'),\n strategy: target.getAttribute('data-tooltip-strategy'),\n },\n }),\n );\n }\n };\n\n clearHideTimeout() {\n if (this.hideTimeout) {\n this.hidding = false;\n clearTimeout(this.hideTimeout);\n }\n }\n\n handleHide = (e: Event) => {\n if (\n this.tooltip &&\n ((e.type === 'focusout' && this.shadowRoot?.activeElement !== null) ||\n e.type === 'mouseout')\n ) {\n this.clearHideTimeout();\n this.hidding = true;\n this.hideTimeout = setTimeout(() => {\n this.hide();\n }, this.hidingDuration);\n }\n };\n\n show = (e: any) => {\n const {\n placement,\n strategy,\n target,\n tooltip,\n autoPlacementOptions,\n offsetOptions,\n hidingDuration,\n } = e.detail;\n\n this.target = target;\n this.placement = placement || IxTooltip._placement;\n this.strategy = strategy || IxTooltip._strategy;\n this.tooltip = tooltip;\n this.autoPlacementOptions = autoPlacementOptions;\n this.offsetOptions = offsetOptions || IxTooltip._offsetOptions;\n this.hidingDuration =\n hidingDuration !== undefined ? hidingDuration : IxTooltip._hidingDuration;\n this.cleanup = autoUpdate(target, this, this.updatePosition);\n this.hidding = false;\n };\n\n hide = () => {\n this.cleanup();\n this.placement = IxTooltip._placement;\n this.strategy = IxTooltip._strategy;\n this.offsetOptions = IxTooltip._offsetOptions;\n this.hidingDuration = IxTooltip._hidingDuration;\n this.target = undefined;\n this.autoPlacementOptions = undefined;\n this.tooltip = undefined;\n this.hidding = false;\n };\n\n getAutoPlacementOptions() {\n const autoPlacementOptions = {\n ...this.autoPlacementOptions,\n };\n\n if (this.placement) {\n autoPlacementOptions.allowedPlacements = [this.placement];\n }\n\n return autoPlacementOptions;\n }\n\n updatePosition = () => {\n if (this.target) {\n computePosition(this.target, this, {\n strategy: this.strategy,\n placement: this.placement,\n middleware: [\n autoPlacement(this.getAutoPlacementOptions()),\n offset(this.offsetOptions),\n ],\n }).then(({ x, y }) => {\n Object.assign(this.style, {\n left: `${x}px`,\n top: `${y}px`,\n position: this.strategy,\n });\n });\n } else {\n this.hide();\n }\n };\n\n render() {\n return html`<div\n tabindex=\"0\"\n class=\"wrapper ${this.hidding ? 'hidding' : ''}\"\n style=\"transition:${this.hidingDuration}ms opacity;\"\n >\n ${this.tooltip || nothing}\n </div> `;\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export { IxTooltip } from './IxTooltip.js';
@@ -0,0 +1,2 @@
1
+ export { IxTooltip } from './IxTooltip.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export { IxTooltip } from './IxTooltip.js';\n"]}
@@ -0,0 +1,4 @@
1
+ import { IxTooltip } from './IxTooltip.js';
2
+ export declare class IxTooltipStyled extends IxTooltip {
3
+ static styles: import("lit").CSSResult;
4
+ }
@@ -0,0 +1,35 @@
1
+ import { css } from 'lit';
2
+ import { IxTooltip } from './IxTooltip.js';
3
+ export class IxTooltipStyled extends IxTooltip {
4
+ }
5
+ /*
6
+ * Are you about to try and modify the width?
7
+ * Don't try and do it with CSS vars, you won't get very far because this element should not be deeply nested
8
+ * What you should do instead is add this middleware https://floating-ui.com/docs/size
9
+ */
10
+ IxTooltipStyled.styles = css `
11
+ :host {
12
+ position: fixed;
13
+ top: 0;
14
+ left: 0;
15
+ width: max-content;
16
+ }
17
+
18
+ .wrapper {
19
+ opacity: 1;
20
+
21
+ &:focus {
22
+ outline: 0;
23
+ }
24
+
25
+ &.hidding {
26
+ opacity: 0;
27
+ }
28
+
29
+ &:hover {
30
+ opacity: 1;
31
+ }
32
+ }
33
+ `;
34
+ window.customElements.define('ix-tooltip', IxTooltipStyled);
35
+ //# sourceMappingURL=ix-tooltip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ix-tooltip.js","sourceRoot":"","sources":["../../src/ix-tooltip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,OAAO,eAAgB,SAAQ,SAAS;;AAC5C;;;;GAIG;AACa,sBAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;GAuB3B,CAAC;AAGJ,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC","sourcesContent":["import { css } from 'lit';\nimport { IxTooltip } from './IxTooltip.js';\n\nexport class IxTooltipStyled extends IxTooltip {\n /*\n * Are you about to try and modify the width?\n * Don't try and do it with CSS vars, you won't get very far because this element should not be deeply nested\n * What you should do instead is add this middleware https://floating-ui.com/docs/size\n */\n static override styles = css`\n :host {\n position: fixed;\n top: 0;\n left: 0;\n width: max-content;\n }\n\n .wrapper {\n opacity: 1;\n\n &:focus {\n outline: 0;\n }\n\n &.hidding {\n opacity: 0;\n }\n\n &:hover {\n opacity: 1;\n }\n }\n `;\n}\n\nwindow.customElements.define('ix-tooltip', IxTooltipStyled);\n"]}
@@ -0,0 +1,5 @@
1
+ import { LitElement } from 'lit';
2
+ export declare class IxSimpleTooltip extends LitElement {
3
+ static styles: import("lit").CSSResult;
4
+ render(): import("lit").TemplateResult<1>;
5
+ }
@@ -0,0 +1,22 @@
1
+ import { html, css, LitElement } from 'lit';
2
+ export class IxSimpleTooltip extends LitElement {
3
+ render() {
4
+ return html ` <slot></slot>`;
5
+ }
6
+ }
7
+ IxSimpleTooltip.styles = css `
8
+ :host {
9
+ background: var(
10
+ --ix-simple-tooltip-background-color,
11
+ var(--md-sys-color-on-primary-container, #000)
12
+ );
13
+ border-radius: var(--ix-simple-tooltip-border-radius, 5px);
14
+ color: var(
15
+ --ix-simple-tooltip-text-color,
16
+ var(--md-sys-color-on-primary, #fff)
17
+ );
18
+ padding: var(--ix-simple-tooltip-padding, 0.3rem 0.5rem);
19
+ }
20
+ `;
21
+ window.customElements.define('ix-simple-tooltip', IxSimpleTooltip);
22
+ //# sourceMappingURL=ix-simple-tooltip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ix-simple-tooltip.js","sourceRoot":"","sources":["../../../src/templates/ix-simple-tooltip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAE5C,MAAM,OAAO,eAAgB,SAAQ,UAAU;IAgB7C,MAAM;QACJ,OAAO,IAAI,CAAA,gBAAgB,CAAC;IAC9B,CAAC;;AAjBM,sBAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;GAalB,CAAC;AAOJ,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAC","sourcesContent":["import { html, css, LitElement } from 'lit';\n\nexport class IxSimpleTooltip extends LitElement {\n static styles = css`\n :host {\n background: var(\n --ix-simple-tooltip-background-color,\n var(--md-sys-color-on-primary-container, #000)\n );\n border-radius: var(--ix-simple-tooltip-border-radius, 5px);\n color: var(\n --ix-simple-tooltip-text-color,\n var(--md-sys-color-on-primary, #fff)\n );\n padding: var(--ix-simple-tooltip-padding, 0.3rem 0.5rem);\n }\n `;\n\n render() {\n return html` <slot></slot>`;\n }\n}\n\nwindow.customElements.define('ix-simple-tooltip', IxSimpleTooltip);\n"]}
@@ -0,0 +1,7 @@
1
+ import { LitElement } from 'lit';
2
+ import '../src/ix-tooltip.js';
3
+ export declare class IxTooltipTestHarness extends LitElement {
4
+ protected createRenderRoot(): Element | ShadowRoot;
5
+ handleFancyMouseOver(e: Event): void;
6
+ render(): import("lit").TemplateResult<1>;
7
+ }