Skip to content

Commit e18951d

Browse files
ktranDevtools-frontend LUCI CQ
authored andcommitted
[docs] Move Tooltip docs to static documentation
This moves the documentation to https://chromedevtools.github.io/devtools-frontend/ Screenshot: https://b.corp.google.com/issues/414332459#comment14 Bug: 414332459 Change-Id: Ic895c65fdaac8859c949e6fb014dde11738ba80c Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/7099142 Reviewed-by: Philip Pfaffe <[email protected]> Auto-Submit: Kim-Anh Tran <[email protected]> Commit-Queue: Kim-Anh Tran <[email protected]>
1 parent 14e2654 commit e18951d

File tree

7 files changed

+83
-127
lines changed

7 files changed

+83
-127
lines changed

front_end/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ group("docs") {
303303
"ui/components/buttons:docs",
304304
"ui/components/icon_button:docs",
305305
"ui/components/spinners:docs",
306+
"ui/components/tooltips:docs",
306307
"ui/legacy:copy_stylesheets_for_server",
307308
]
308309
}

front_end/ui/components/docs/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ group("docs") {
4848
"./switch",
4949
"./text_prompt",
5050
"./theme_colors",
51-
"./tooltip",
5251
"./tree_outline",
5352
"./user_agent_client_hints",
5453
]

front_end/ui/components/docs/tooltip/BUILD.gn

Lines changed: 0 additions & 24 deletions
This file was deleted.

front_end/ui/components/docs/tooltip/basic.html

Lines changed: 0 additions & 20 deletions
This file was deleted.

front_end/ui/components/docs/tooltip/basic.ts

Lines changed: 0 additions & 82 deletions
This file was deleted.

front_end/ui/components/tooltips/BUILD.gn

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Use of this source code is governed by a BSD-style license that can be
33
# found in the LICENSE file.
44

5+
import("../../../../scripts/build/ninja/component_doc.gni")
56
import("../../../../scripts/build/ninja/devtools_entrypoint.gni")
67
import("../../../../scripts/build/ninja/devtools_module.gni")
78
import("../../../../scripts/build/ninja/generate_css.gni")
@@ -43,3 +44,8 @@ devtools_ui_module("unittests") {
4344
"../../../testing",
4445
]
4546
}
47+
48+
component_doc("docs") {
49+
sources = [ "Tooltip.docs.ts" ]
50+
deps = [ ":bundle" ]
51+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2025 The Chromium Authors
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import * as Lit from '../../lit/lit.js';
6+
7+
import {Tooltip} from './Tooltip.js';
8+
9+
const {html} = Lit;
10+
11+
export async function render(container: HTMLElement) {
12+
Lit.render(
13+
html`
14+
<div style="position: relative; z-index: 0;">
15+
<button aria-describedby="simple-tooltip" style="position: absolute; left: 16px; top: 16px;">
16+
Simple
17+
</button>
18+
<devtools-tooltip id="simple-tooltip">Simple content</devtools-tooltip>
19+
</div>
20+
<div style="position: relative; z-index: 0;">
21+
<span
22+
aria-details="rich-tooltip"
23+
style="position: absolute; left: 16px; top: 116px; border: 1px solid black;"
24+
>
25+
Non-button click trigger
26+
</span>
27+
<devtools-tooltip id="rich-tooltip" variant="rich" use-click>
28+
<p>Rich tooltip</p>
29+
<button>Action</button>
30+
</devtools-tooltip>
31+
</div>
32+
<div style="position: relative; z-index: 0;">
33+
<button
34+
id="removable"
35+
@click=${() => document.getElementById('removable')?.remove()}
36+
class="anchor"
37+
aria-details="programatic"
38+
style="position: absolute; left: 16px; top: 216px;"
39+
>
40+
Click to remove anchor
41+
</button>
42+
</div>
43+
`,
44+
container);
45+
46+
const anchor = container.querySelector('.anchor') as HTMLElement;
47+
const programmaticTooltip = new Tooltip({id: 'programatic', variant: 'rich', anchor});
48+
programmaticTooltip.append('Text content');
49+
anchor.insertAdjacentElement('afterend', programmaticTooltip);
50+
51+
// Make the buttons draggable, so that we can experiment with the position of the tooltip.
52+
container.querySelectorAll('button,span').forEach(anchor => draggable(anchor as HTMLElement));
53+
function draggable(element: HTMLElement|null): void {
54+
if (!element) {
55+
return;
56+
}
57+
element.addEventListener('mousedown', event => {
58+
const target = event.target as HTMLElement;
59+
const offsetX = event.clientX - target.getBoundingClientRect().left + container.getBoundingClientRect().left;
60+
const offsetY = event.clientY - target.getBoundingClientRect().top + container.getBoundingClientRect().top;
61+
62+
function onMouseMove(event: MouseEvent) {
63+
target.style.left = `${event.clientX - offsetX}px`;
64+
target.style.top = `${event.clientY - offsetY}px`;
65+
}
66+
67+
function onMouseUp() {
68+
document.removeEventListener('mousemove', onMouseMove);
69+
document.removeEventListener('mouseup', onMouseUp);
70+
}
71+
72+
document.addEventListener('mousemove', onMouseMove);
73+
document.addEventListener('mouseup', onMouseUp);
74+
});
75+
}
76+
}

0 commit comments

Comments
 (0)