primer_view_components 0.0.71 → 0.0.74
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +82 -42
- data/app/assets/javascripts/primer_view_components.js +1 -1
- data/app/assets/javascripts/primer_view_components.js.map +1 -1
- data/app/components/primer/alpha/{tooltip.d.ts → tool-tip-element.d.ts} +2 -3
- data/app/components/primer/alpha/{tooltip.js → tool-tip-element.js} +74 -105
- data/app/components/primer/alpha/{tooltip.ts → tool-tip-element.ts} +48 -81
- data/app/components/primer/beta/auto_complete.rb +15 -1
- data/app/components/primer/clipboard_copy_component.ts +1 -1
- data/app/components/primer/link_component.erb +1 -4
- data/app/components/primer/primer.d.ts +1 -1
- data/app/components/primer/primer.js +1 -1
- data/app/components/primer/primer.ts +1 -1
- data/lib/primer/view_components/linters/super_in_component_templates.rb +65 -0
- data/lib/primer/view_components/version.rb +1 -1
- data/lib/rubocop/config/default.yml +3 -0
- data/lib/rubocop/cop/primer/deprecated_components.rb +80 -0
- metadata +7 -7
- data/app/components/primer/alpha/navigation_list_element.d.ts +0 -11
- data/app/components/primer/alpha/navigation_list_element.js +0 -42
@@ -1,5 +1,5 @@
|
|
1
1
|
declare type Direction = 'n' | 's' | 'e' | 'w' | 'ne' | 'se' | 'nw' | 'sw';
|
2
|
-
declare class
|
2
|
+
declare class ToolTipElement extends HTMLElement {
|
3
3
|
#private;
|
4
4
|
styles(): string;
|
5
5
|
get htmlFor(): string;
|
@@ -9,7 +9,6 @@ declare class TooltipElement extends HTMLElement {
|
|
9
9
|
get direction(): Direction;
|
10
10
|
set direction(value: Direction);
|
11
11
|
get control(): HTMLElement | null;
|
12
|
-
constructor();
|
13
12
|
connectedCallback(): void;
|
14
13
|
disconnectedCallback(): void;
|
15
14
|
handleEvent(event: Event): void;
|
@@ -18,7 +17,7 @@ declare class TooltipElement extends HTMLElement {
|
|
18
17
|
}
|
19
18
|
declare global {
|
20
19
|
interface Window {
|
21
|
-
|
20
|
+
ToolTipElement: typeof ToolTipElement;
|
22
21
|
}
|
23
22
|
}
|
24
23
|
export {};
|
@@ -9,10 +9,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11
11
|
};
|
12
|
-
var
|
12
|
+
var _ToolTipElement_instances, _ToolTipElement_abortController, _ToolTipElement_align, _ToolTipElement_side, _ToolTipElement_allowUpdatePosition, _ToolTipElement_update, _ToolTipElement_updatePosition;
|
13
13
|
import { getAnchoredPosition } from '@primer/behaviors';
|
14
14
|
const TOOLTIP_OPEN_CLASS = 'tooltip-open';
|
15
|
-
const TOOLTIP_ARROW_EDGE_OFFSET =
|
15
|
+
const TOOLTIP_ARROW_EDGE_OFFSET = 6;
|
16
16
|
const DIRECTION_CLASSES = [
|
17
17
|
'tooltip-n',
|
18
18
|
'tooltip-s',
|
@@ -23,21 +23,14 @@ const DIRECTION_CLASSES = [
|
|
23
23
|
'tooltip-nw',
|
24
24
|
'tooltip-sw'
|
25
25
|
];
|
26
|
-
class
|
26
|
+
class ToolTipElement extends HTMLElement {
|
27
27
|
constructor() {
|
28
|
-
super();
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
const shadow = this.attachShadow({ mode: 'open' });
|
35
|
-
shadow.innerHTML = `
|
36
|
-
<style>
|
37
|
-
${this.styles()}
|
38
|
-
</style>
|
39
|
-
<slot></slot>
|
40
|
-
`;
|
28
|
+
super(...arguments);
|
29
|
+
_ToolTipElement_instances.add(this);
|
30
|
+
_ToolTipElement_abortController.set(this, void 0);
|
31
|
+
_ToolTipElement_align.set(this, 'center');
|
32
|
+
_ToolTipElement_side.set(this, 'outside-bottom');
|
33
|
+
_ToolTipElement_allowUpdatePosition.set(this, false);
|
41
34
|
}
|
42
35
|
styles() {
|
43
36
|
return `
|
@@ -63,7 +56,7 @@ class TooltipElement extends HTMLElement {
|
|
63
56
|
white-space: normal;
|
64
57
|
width: max-content;
|
65
58
|
}
|
66
|
-
|
59
|
+
|
67
60
|
:host:before{
|
68
61
|
position: absolute;
|
69
62
|
z-index: 1000001;
|
@@ -72,7 +65,7 @@ class TooltipElement extends HTMLElement {
|
|
72
65
|
border: 6px solid transparent;
|
73
66
|
opacity: 0
|
74
67
|
}
|
75
|
-
|
68
|
+
|
76
69
|
@keyframes tooltip-appear {
|
77
70
|
from {
|
78
71
|
opacity: 0
|
@@ -81,7 +74,7 @@ class TooltipElement extends HTMLElement {
|
|
81
74
|
opacity: 1
|
82
75
|
}
|
83
76
|
}
|
84
|
-
|
77
|
+
|
85
78
|
:host:after{
|
86
79
|
position: absolute;
|
87
80
|
display: block;
|
@@ -90,7 +83,7 @@ class TooltipElement extends HTMLElement {
|
|
90
83
|
height: 12px;
|
91
84
|
content: ""
|
92
85
|
}
|
93
|
-
|
86
|
+
|
94
87
|
:host(.${TOOLTIP_OPEN_CLASS}),
|
95
88
|
:host(.${TOOLTIP_OPEN_CLASS}):before {
|
96
89
|
animation-name: tooltip-appear;
|
@@ -99,52 +92,51 @@ class TooltipElement extends HTMLElement {
|
|
99
92
|
animation-timing-function: ease-in;
|
100
93
|
animation-delay: .4s
|
101
94
|
}
|
102
|
-
|
95
|
+
|
103
96
|
:host(.tooltip-s):before,
|
104
97
|
:host(.tooltip-n):before {
|
105
98
|
right: 50%;
|
99
|
+
margin-right: -${TOOLTIP_ARROW_EDGE_OFFSET}px;
|
106
100
|
}
|
107
101
|
|
108
102
|
:host(.tooltip-s):before,
|
109
103
|
:host(.tooltip-se):before,
|
110
104
|
:host(.tooltip-sw):before {
|
111
105
|
bottom: 100%;
|
112
|
-
margin-right: -${TOOLTIP_ARROW_EDGE_OFFSET}px;
|
113
106
|
border-bottom-color: var(--color-neutral-emphasis-plus)
|
114
107
|
}
|
115
|
-
|
108
|
+
|
116
109
|
:host(.tooltip-s):after,
|
117
110
|
:host(.tooltip-se):after,
|
118
111
|
:host(.tooltip-sw):after {
|
119
112
|
bottom: 100%
|
120
113
|
}
|
121
|
-
|
114
|
+
|
122
115
|
:host(.tooltip-n):before,
|
123
116
|
:host(.tooltip-ne):before,
|
124
117
|
:host(.tooltip-nw):before {
|
125
118
|
top: 100%;
|
126
|
-
margin-right: -${TOOLTIP_ARROW_EDGE_OFFSET}px;
|
127
119
|
border-top-color: var(--color-neutral-emphasis-plus)
|
128
120
|
}
|
129
|
-
|
121
|
+
|
130
122
|
:host(.tooltip-n):after,
|
131
123
|
:host(.tooltip-ne):after,
|
132
124
|
:host(.tooltip-nw):after {
|
133
125
|
top: 100%
|
134
126
|
}
|
135
|
-
|
127
|
+
|
136
128
|
:host(.tooltip-se):before,
|
137
129
|
:host(.tooltip-ne):before {
|
138
130
|
left: 0;
|
139
131
|
margin-left: ${TOOLTIP_ARROW_EDGE_OFFSET}px;
|
140
132
|
}
|
141
|
-
|
133
|
+
|
142
134
|
:host(.tooltip-sw):before,
|
143
135
|
:host(.tooltip-nw):before {
|
144
136
|
right: 0;
|
145
137
|
margin-right: ${TOOLTIP_ARROW_EDGE_OFFSET}px;
|
146
138
|
}
|
147
|
-
|
139
|
+
|
148
140
|
:host(.tooltip-w):before {
|
149
141
|
top: 50%;
|
150
142
|
bottom: 50%;
|
@@ -152,7 +144,7 @@ class TooltipElement extends HTMLElement {
|
|
152
144
|
margin-top: -6px;
|
153
145
|
border-left-color: var(--color-neutral-emphasis-plus)
|
154
146
|
}
|
155
|
-
|
147
|
+
|
156
148
|
:host(.tooltip-e):before {
|
157
149
|
top: 50%;
|
158
150
|
right: 100%;
|
@@ -186,27 +178,37 @@ class TooltipElement extends HTMLElement {
|
|
186
178
|
}
|
187
179
|
connectedCallback() {
|
188
180
|
var _a;
|
181
|
+
if (!this.shadowRoot) {
|
182
|
+
const shadow = this.attachShadow({ mode: 'open' });
|
183
|
+
shadow.innerHTML = `
|
184
|
+
<style>
|
185
|
+
${this.styles()}
|
186
|
+
</style>
|
187
|
+
<slot></slot>
|
188
|
+
`;
|
189
|
+
}
|
189
190
|
this.hidden = true;
|
190
|
-
__classPrivateFieldSet(this,
|
191
|
+
__classPrivateFieldSet(this, _ToolTipElement_allowUpdatePosition, true, "f");
|
191
192
|
if (!this.id) {
|
192
193
|
this.id = `tooltip-${Date.now()}-${(Math.random() * 10000).toFixed(0)}`;
|
193
194
|
}
|
194
195
|
if (!this.control)
|
195
196
|
return;
|
196
197
|
this.setAttribute('role', 'tooltip');
|
197
|
-
(_a = __classPrivateFieldGet(this,
|
198
|
-
__classPrivateFieldSet(this,
|
199
|
-
const { signal } = __classPrivateFieldGet(this,
|
198
|
+
(_a = __classPrivateFieldGet(this, _ToolTipElement_abortController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
|
199
|
+
__classPrivateFieldSet(this, _ToolTipElement_abortController, new AbortController(), "f");
|
200
|
+
const { signal } = __classPrivateFieldGet(this, _ToolTipElement_abortController, "f");
|
200
201
|
this.addEventListener('mouseleave', this, { signal });
|
201
202
|
this.control.addEventListener('mouseenter', this, { signal });
|
202
203
|
this.control.addEventListener('mouseleave', this, { signal });
|
203
204
|
this.control.addEventListener('focus', this, { signal });
|
204
205
|
this.control.addEventListener('blur', this, { signal });
|
205
206
|
this.ownerDocument.addEventListener('keydown', this, { signal });
|
207
|
+
__classPrivateFieldGet(this, _ToolTipElement_instances, "m", _ToolTipElement_update).call(this);
|
206
208
|
}
|
207
209
|
disconnectedCallback() {
|
208
210
|
var _a;
|
209
|
-
(_a = __classPrivateFieldGet(this,
|
211
|
+
(_a = __classPrivateFieldGet(this, _ToolTipElement_abortController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
|
210
212
|
}
|
211
213
|
handleEvent(event) {
|
212
214
|
if (!this.control)
|
@@ -241,109 +243,76 @@ class TooltipElement extends HTMLElement {
|
|
241
243
|
this.control.setAttribute('aria-describedby', describedBy);
|
242
244
|
}
|
243
245
|
}
|
244
|
-
else if (name === 'hidden') {
|
245
|
-
|
246
|
-
this.classList.remove(TOOLTIP_OPEN_CLASS, ...DIRECTION_CLASSES);
|
247
|
-
}
|
248
|
-
else {
|
249
|
-
this.classList.add(TOOLTIP_OPEN_CLASS);
|
250
|
-
for (const tooltip of this.ownerDocument.querySelectorAll(this.tagName)) {
|
251
|
-
if (tooltip !== this)
|
252
|
-
tooltip.hidden = true;
|
253
|
-
}
|
254
|
-
__classPrivateFieldGet(this, _TooltipElement_instances, "m", _TooltipElement_updatePosition).call(this);
|
255
|
-
}
|
246
|
+
else if (this.isConnected && name === 'hidden') {
|
247
|
+
__classPrivateFieldGet(this, _ToolTipElement_instances, "m", _ToolTipElement_update).call(this);
|
256
248
|
}
|
257
249
|
else if (name === 'data-direction') {
|
258
250
|
this.classList.remove(...DIRECTION_CLASSES);
|
259
251
|
const direction = this.direction;
|
260
252
|
if (direction === 'n') {
|
261
|
-
__classPrivateFieldSet(this,
|
262
|
-
__classPrivateFieldSet(this,
|
253
|
+
__classPrivateFieldSet(this, _ToolTipElement_align, 'center', "f");
|
254
|
+
__classPrivateFieldSet(this, _ToolTipElement_side, 'outside-top', "f");
|
263
255
|
}
|
264
256
|
else if (direction === 'ne') {
|
265
|
-
__classPrivateFieldSet(this,
|
266
|
-
__classPrivateFieldSet(this,
|
257
|
+
__classPrivateFieldSet(this, _ToolTipElement_align, 'start', "f");
|
258
|
+
__classPrivateFieldSet(this, _ToolTipElement_side, 'outside-top', "f");
|
267
259
|
}
|
268
260
|
else if (direction === 'e') {
|
269
|
-
__classPrivateFieldSet(this,
|
270
|
-
__classPrivateFieldSet(this,
|
261
|
+
__classPrivateFieldSet(this, _ToolTipElement_align, 'center', "f");
|
262
|
+
__classPrivateFieldSet(this, _ToolTipElement_side, 'outside-right', "f");
|
271
263
|
}
|
272
264
|
else if (direction === 'se') {
|
273
|
-
__classPrivateFieldSet(this,
|
274
|
-
__classPrivateFieldSet(this,
|
265
|
+
__classPrivateFieldSet(this, _ToolTipElement_align, 'start', "f");
|
266
|
+
__classPrivateFieldSet(this, _ToolTipElement_side, 'outside-bottom', "f");
|
275
267
|
}
|
276
268
|
else if (direction === 's') {
|
277
|
-
__classPrivateFieldSet(this,
|
278
|
-
__classPrivateFieldSet(this,
|
269
|
+
__classPrivateFieldSet(this, _ToolTipElement_align, 'center', "f");
|
270
|
+
__classPrivateFieldSet(this, _ToolTipElement_side, 'outside-bottom', "f");
|
279
271
|
}
|
280
272
|
else if (direction === 'sw') {
|
281
|
-
__classPrivateFieldSet(this,
|
282
|
-
__classPrivateFieldSet(this,
|
273
|
+
__classPrivateFieldSet(this, _ToolTipElement_align, 'end', "f");
|
274
|
+
__classPrivateFieldSet(this, _ToolTipElement_side, 'outside-bottom', "f");
|
283
275
|
}
|
284
276
|
else if (direction === 'w') {
|
285
|
-
__classPrivateFieldSet(this,
|
286
|
-
__classPrivateFieldSet(this,
|
277
|
+
__classPrivateFieldSet(this, _ToolTipElement_align, 'center', "f");
|
278
|
+
__classPrivateFieldSet(this, _ToolTipElement_side, 'outside-left', "f");
|
287
279
|
}
|
288
280
|
else if (direction === 'nw') {
|
289
|
-
__classPrivateFieldSet(this,
|
290
|
-
__classPrivateFieldSet(this,
|
281
|
+
__classPrivateFieldSet(this, _ToolTipElement_align, 'end', "f");
|
282
|
+
__classPrivateFieldSet(this, _ToolTipElement_side, 'outside-top', "f");
|
291
283
|
}
|
292
284
|
}
|
293
285
|
}
|
294
286
|
}
|
295
|
-
|
296
|
-
if (
|
297
|
-
|
298
|
-
const tooltipPosition = this.getBoundingClientRect();
|
299
|
-
const targetPosition = this.control.getBoundingClientRect();
|
300
|
-
const tooltipWidth = tooltipPosition.width;
|
301
|
-
const tooltipCenter = tooltipPosition.left + tooltipWidth / 2;
|
302
|
-
const targetCenter = targetPosition.x + targetPosition.width / 2;
|
303
|
-
if (Math.abs(tooltipCenter - targetCenter) < 2 || anchorSide === 'outside-left' || anchorSide === 'outside-right') {
|
304
|
-
return 'center';
|
305
|
-
}
|
306
|
-
else if (tooltipPosition.left === targetPosition.left) {
|
307
|
-
return 'start';
|
308
|
-
}
|
309
|
-
else if (tooltipPosition.right === targetPosition.right) {
|
310
|
-
return 'end';
|
311
|
-
}
|
312
|
-
else if (tooltipCenter < targetCenter) {
|
313
|
-
if (tooltipPosition.left === 0)
|
314
|
-
return 'start';
|
315
|
-
return 'end';
|
287
|
+
_ToolTipElement_abortController = new WeakMap(), _ToolTipElement_align = new WeakMap(), _ToolTipElement_side = new WeakMap(), _ToolTipElement_allowUpdatePosition = new WeakMap(), _ToolTipElement_instances = new WeakSet(), _ToolTipElement_update = function _ToolTipElement_update() {
|
288
|
+
if (this.hidden) {
|
289
|
+
this.classList.remove(TOOLTIP_OPEN_CLASS, ...DIRECTION_CLASSES);
|
316
290
|
}
|
317
291
|
else {
|
318
|
-
|
319
|
-
|
320
|
-
|
292
|
+
this.classList.add(TOOLTIP_OPEN_CLASS);
|
293
|
+
for (const tooltip of this.ownerDocument.querySelectorAll(this.tagName)) {
|
294
|
+
if (tooltip !== this)
|
295
|
+
tooltip.hidden = true;
|
296
|
+
}
|
297
|
+
__classPrivateFieldGet(this, _ToolTipElement_instances, "m", _ToolTipElement_updatePosition).call(this);
|
321
298
|
}
|
322
|
-
},
|
299
|
+
}, _ToolTipElement_updatePosition = function _ToolTipElement_updatePosition() {
|
323
300
|
if (!this.control)
|
324
301
|
return;
|
325
|
-
if (!__classPrivateFieldGet(this,
|
302
|
+
if (!__classPrivateFieldGet(this, _ToolTipElement_allowUpdatePosition, "f") || this.hidden)
|
326
303
|
return;
|
327
304
|
const TOOLTIP_OFFSET = 10;
|
328
305
|
this.style.left = `0px`; // Ensures we have reliable tooltip width in `getAnchoredPosition`
|
329
|
-
|
330
|
-
side: __classPrivateFieldGet(this,
|
331
|
-
align: __classPrivateFieldGet(this,
|
306
|
+
const position = getAnchoredPosition(this, this.control, {
|
307
|
+
side: __classPrivateFieldGet(this, _ToolTipElement_side, "f"),
|
308
|
+
align: __classPrivateFieldGet(this, _ToolTipElement_align, "f"),
|
332
309
|
anchorOffset: TOOLTIP_OFFSET
|
333
310
|
});
|
334
|
-
|
335
|
-
|
311
|
+
const anchorSide = position.anchorSide;
|
312
|
+
const align = position.anchorAlign;
|
336
313
|
this.style.top = `${position.top}px`;
|
337
314
|
this.style.left = `${position.left}px`;
|
338
315
|
let direction = 's';
|
339
|
-
const align = __classPrivateFieldGet(this, _TooltipElement_instances, "m", _TooltipElement_adjustedAnchorAlignment).call(this, anchorSide);
|
340
|
-
if (!align)
|
341
|
-
return;
|
342
|
-
this.style.left = `0px`; // Reset tooltip position again to ensure accurate width in `getAnchoredPosition`
|
343
|
-
position = getAnchoredPosition(this, this.control, { side: anchorSide, align, anchorOffset: TOOLTIP_OFFSET });
|
344
|
-
anchorSide = position.anchorSide;
|
345
|
-
this.style.top = `${position.top}px`;
|
346
|
-
this.style.left = `${position.left}px`;
|
347
316
|
if (anchorSide === 'outside-left') {
|
348
317
|
direction = 'w';
|
349
318
|
}
|
@@ -374,8 +343,8 @@ _TooltipElement_abortController = new WeakMap(), _TooltipElement_align = new Wea
|
|
374
343
|
}
|
375
344
|
this.classList.add(`tooltip-${direction}`);
|
376
345
|
};
|
377
|
-
|
346
|
+
ToolTipElement.observedAttributes = ['data-type', 'data-direction', 'id', 'hidden'];
|
378
347
|
if (!window.customElements.get('tool-tip')) {
|
379
|
-
window.
|
380
|
-
window.customElements.define('tool-tip',
|
348
|
+
window.ToolTipElement = ToolTipElement;
|
349
|
+
window.customElements.define('tool-tip', ToolTipElement);
|
381
350
|
}
|
@@ -1,8 +1,9 @@
|
|
1
|
+
// eslint-disable-next-line prettier/prettier
|
1
2
|
import type {AnchorAlignment, AnchorSide} from '@primer/behaviors'
|
2
3
|
import {getAnchoredPosition} from '@primer/behaviors'
|
3
4
|
|
4
5
|
const TOOLTIP_OPEN_CLASS = 'tooltip-open'
|
5
|
-
const TOOLTIP_ARROW_EDGE_OFFSET =
|
6
|
+
const TOOLTIP_ARROW_EDGE_OFFSET = 6
|
6
7
|
|
7
8
|
type Direction = 'n' | 's' | 'e' | 'w' | 'ne' | 'se' | 'nw' | 'sw'
|
8
9
|
|
@@ -17,7 +18,7 @@ const DIRECTION_CLASSES = [
|
|
17
18
|
'tooltip-sw'
|
18
19
|
]
|
19
20
|
|
20
|
-
class
|
21
|
+
class ToolTipElement extends HTMLElement {
|
21
22
|
styles() {
|
22
23
|
return `
|
23
24
|
:host {
|
@@ -42,7 +43,7 @@ class TooltipElement extends HTMLElement {
|
|
42
43
|
white-space: normal;
|
43
44
|
width: max-content;
|
44
45
|
}
|
45
|
-
|
46
|
+
|
46
47
|
:host:before{
|
47
48
|
position: absolute;
|
48
49
|
z-index: 1000001;
|
@@ -51,7 +52,7 @@ class TooltipElement extends HTMLElement {
|
|
51
52
|
border: 6px solid transparent;
|
52
53
|
opacity: 0
|
53
54
|
}
|
54
|
-
|
55
|
+
|
55
56
|
@keyframes tooltip-appear {
|
56
57
|
from {
|
57
58
|
opacity: 0
|
@@ -60,7 +61,7 @@ class TooltipElement extends HTMLElement {
|
|
60
61
|
opacity: 1
|
61
62
|
}
|
62
63
|
}
|
63
|
-
|
64
|
+
|
64
65
|
:host:after{
|
65
66
|
position: absolute;
|
66
67
|
display: block;
|
@@ -69,7 +70,7 @@ class TooltipElement extends HTMLElement {
|
|
69
70
|
height: 12px;
|
70
71
|
content: ""
|
71
72
|
}
|
72
|
-
|
73
|
+
|
73
74
|
:host(.${TOOLTIP_OPEN_CLASS}),
|
74
75
|
:host(.${TOOLTIP_OPEN_CLASS}):before {
|
75
76
|
animation-name: tooltip-appear;
|
@@ -78,52 +79,51 @@ class TooltipElement extends HTMLElement {
|
|
78
79
|
animation-timing-function: ease-in;
|
79
80
|
animation-delay: .4s
|
80
81
|
}
|
81
|
-
|
82
|
+
|
82
83
|
:host(.tooltip-s):before,
|
83
84
|
:host(.tooltip-n):before {
|
84
85
|
right: 50%;
|
86
|
+
margin-right: -${TOOLTIP_ARROW_EDGE_OFFSET}px;
|
85
87
|
}
|
86
88
|
|
87
89
|
:host(.tooltip-s):before,
|
88
90
|
:host(.tooltip-se):before,
|
89
91
|
:host(.tooltip-sw):before {
|
90
92
|
bottom: 100%;
|
91
|
-
margin-right: -${TOOLTIP_ARROW_EDGE_OFFSET}px;
|
92
93
|
border-bottom-color: var(--color-neutral-emphasis-plus)
|
93
94
|
}
|
94
|
-
|
95
|
+
|
95
96
|
:host(.tooltip-s):after,
|
96
97
|
:host(.tooltip-se):after,
|
97
98
|
:host(.tooltip-sw):after {
|
98
99
|
bottom: 100%
|
99
100
|
}
|
100
|
-
|
101
|
+
|
101
102
|
:host(.tooltip-n):before,
|
102
103
|
:host(.tooltip-ne):before,
|
103
104
|
:host(.tooltip-nw):before {
|
104
105
|
top: 100%;
|
105
|
-
margin-right: -${TOOLTIP_ARROW_EDGE_OFFSET}px;
|
106
106
|
border-top-color: var(--color-neutral-emphasis-plus)
|
107
107
|
}
|
108
|
-
|
108
|
+
|
109
109
|
:host(.tooltip-n):after,
|
110
110
|
:host(.tooltip-ne):after,
|
111
111
|
:host(.tooltip-nw):after {
|
112
112
|
top: 100%
|
113
113
|
}
|
114
|
-
|
114
|
+
|
115
115
|
:host(.tooltip-se):before,
|
116
116
|
:host(.tooltip-ne):before {
|
117
117
|
left: 0;
|
118
118
|
margin-left: ${TOOLTIP_ARROW_EDGE_OFFSET}px;
|
119
119
|
}
|
120
|
-
|
120
|
+
|
121
121
|
:host(.tooltip-sw):before,
|
122
122
|
:host(.tooltip-nw):before {
|
123
123
|
right: 0;
|
124
124
|
margin-right: ${TOOLTIP_ARROW_EDGE_OFFSET}px;
|
125
125
|
}
|
126
|
-
|
126
|
+
|
127
127
|
:host(.tooltip-w):before {
|
128
128
|
top: 50%;
|
129
129
|
bottom: 50%;
|
@@ -131,7 +131,7 @@ class TooltipElement extends HTMLElement {
|
|
131
131
|
margin-top: -6px;
|
132
132
|
border-left-color: var(--color-neutral-emphasis-plus)
|
133
133
|
}
|
134
|
-
|
134
|
+
|
135
135
|
:host(.tooltip-e):before {
|
136
136
|
top: 50%;
|
137
137
|
right: 100%;
|
@@ -176,18 +176,16 @@ class TooltipElement extends HTMLElement {
|
|
176
176
|
return this.ownerDocument.getElementById(this.htmlFor)
|
177
177
|
}
|
178
178
|
|
179
|
-
constructor() {
|
180
|
-
super()
|
181
|
-
const shadow = this.attachShadow({mode: 'open'})
|
182
|
-
shadow.innerHTML = `
|
183
|
-
<style>
|
184
|
-
${this.styles()}
|
185
|
-
</style>
|
186
|
-
<slot></slot>
|
187
|
-
`
|
188
|
-
}
|
189
|
-
|
190
179
|
connectedCallback() {
|
180
|
+
if (!this.shadowRoot) {
|
181
|
+
const shadow = this.attachShadow({mode: 'open'})
|
182
|
+
shadow.innerHTML = `
|
183
|
+
<style>
|
184
|
+
${this.styles()}
|
185
|
+
</style>
|
186
|
+
<slot></slot>
|
187
|
+
`
|
188
|
+
}
|
191
189
|
this.hidden = true
|
192
190
|
this.#allowUpdatePosition = true
|
193
191
|
|
@@ -209,6 +207,7 @@ class TooltipElement extends HTMLElement {
|
|
209
207
|
this.control.addEventListener('focus', this, {signal})
|
210
208
|
this.control.addEventListener('blur', this, {signal})
|
211
209
|
this.ownerDocument.addEventListener('keydown', this, {signal})
|
210
|
+
this.#update()
|
212
211
|
}
|
213
212
|
|
214
213
|
disconnectedCallback() {
|
@@ -237,6 +236,18 @@ class TooltipElement extends HTMLElement {
|
|
237
236
|
|
238
237
|
static observedAttributes = ['data-type', 'data-direction', 'id', 'hidden']
|
239
238
|
|
239
|
+
#update() {
|
240
|
+
if (this.hidden) {
|
241
|
+
this.classList.remove(TOOLTIP_OPEN_CLASS, ...DIRECTION_CLASSES)
|
242
|
+
} else {
|
243
|
+
this.classList.add(TOOLTIP_OPEN_CLASS)
|
244
|
+
for (const tooltip of this.ownerDocument.querySelectorAll<HTMLElement>(this.tagName)) {
|
245
|
+
if (tooltip !== this) tooltip.hidden = true
|
246
|
+
}
|
247
|
+
this.#updatePosition()
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
240
251
|
attributeChangedCallback(name: string) {
|
241
252
|
if (name === 'id' || name === 'data-type') {
|
242
253
|
if (!this.id || !this.control) return
|
@@ -247,16 +258,8 @@ class TooltipElement extends HTMLElement {
|
|
247
258
|
describedBy ? (describedBy = `${describedBy} ${this.id}`) : (describedBy = this.id)
|
248
259
|
this.control.setAttribute('aria-describedby', describedBy)
|
249
260
|
}
|
250
|
-
} else if (name === 'hidden') {
|
251
|
-
|
252
|
-
this.classList.remove(TOOLTIP_OPEN_CLASS, ...DIRECTION_CLASSES)
|
253
|
-
} else {
|
254
|
-
this.classList.add(TOOLTIP_OPEN_CLASS)
|
255
|
-
for (const tooltip of this.ownerDocument.querySelectorAll<HTMLElement>(this.tagName)) {
|
256
|
-
if (tooltip !== this) tooltip.hidden = true
|
257
|
-
}
|
258
|
-
this.#updatePosition()
|
259
|
-
}
|
261
|
+
} else if (this.isConnected && name === 'hidden') {
|
262
|
+
this.#update()
|
260
263
|
} else if (name === 'data-direction') {
|
261
264
|
this.classList.remove(...DIRECTION_CLASSES)
|
262
265
|
const direction = this.direction
|
@@ -288,34 +291,6 @@ class TooltipElement extends HTMLElement {
|
|
288
291
|
}
|
289
292
|
}
|
290
293
|
|
291
|
-
// `getAnchoredPosition` may calibrate `anchoredSide` but does not recalibrate `align`.
|
292
|
-
// Therefore, we need to determine which `align` is best based on the initial `getAnchoredPosition` calcluation.
|
293
|
-
// Related: https://github.com/primer/behaviors/issues/63
|
294
|
-
#adjustedAnchorAlignment(anchorSide: AnchorSide): AnchorAlignment | undefined {
|
295
|
-
if (!this.control) return
|
296
|
-
|
297
|
-
const tooltipPosition = this.getBoundingClientRect()
|
298
|
-
const targetPosition = this.control.getBoundingClientRect()
|
299
|
-
const tooltipWidth = tooltipPosition.width
|
300
|
-
|
301
|
-
const tooltipCenter = tooltipPosition.left + tooltipWidth / 2
|
302
|
-
const targetCenter = targetPosition.x + targetPosition.width / 2
|
303
|
-
|
304
|
-
if (Math.abs(tooltipCenter - targetCenter) < 2 || anchorSide === 'outside-left' || anchorSide === 'outside-right') {
|
305
|
-
return 'center'
|
306
|
-
} else if (tooltipPosition.left === targetPosition.left) {
|
307
|
-
return 'start'
|
308
|
-
} else if (tooltipPosition.right === targetPosition.right) {
|
309
|
-
return 'end'
|
310
|
-
} else if (tooltipCenter < targetCenter) {
|
311
|
-
if (tooltipPosition.left === 0) return 'start'
|
312
|
-
return 'end'
|
313
|
-
} else {
|
314
|
-
if (tooltipPosition.right === 0) return 'end'
|
315
|
-
return 'start'
|
316
|
-
}
|
317
|
-
}
|
318
|
-
|
319
294
|
#updatePosition() {
|
320
295
|
if (!this.control) return
|
321
296
|
if (!this.#allowUpdatePosition || this.hidden) return
|
@@ -323,27 +298,19 @@ class TooltipElement extends HTMLElement {
|
|
323
298
|
const TOOLTIP_OFFSET = 10
|
324
299
|
|
325
300
|
this.style.left = `0px` // Ensures we have reliable tooltip width in `getAnchoredPosition`
|
326
|
-
|
301
|
+
|
302
|
+
const position = getAnchoredPosition(this, this.control, {
|
327
303
|
side: this.#side,
|
328
304
|
align: this.#align,
|
329
305
|
anchorOffset: TOOLTIP_OFFSET
|
330
306
|
})
|
331
|
-
|
307
|
+
const anchorSide = position.anchorSide
|
308
|
+
const align = position.anchorAlign
|
332
309
|
|
333
|
-
// We need to set tooltip position in order to determine ideal align.
|
334
310
|
this.style.top = `${position.top}px`
|
335
311
|
this.style.left = `${position.left}px`
|
336
|
-
let direction: Direction = 's'
|
337
312
|
|
338
|
-
|
339
|
-
if (!align) return
|
340
|
-
|
341
|
-
this.style.left = `0px` // Reset tooltip position again to ensure accurate width in `getAnchoredPosition`
|
342
|
-
position = getAnchoredPosition(this, this.control, {side: anchorSide, align, anchorOffset: TOOLTIP_OFFSET})
|
343
|
-
anchorSide = position.anchorSide
|
344
|
-
|
345
|
-
this.style.top = `${position.top}px`
|
346
|
-
this.style.left = `${position.left}px`
|
313
|
+
let direction: Direction = 's'
|
347
314
|
|
348
315
|
if (anchorSide === 'outside-left') {
|
349
316
|
direction = 'w'
|
@@ -372,12 +339,12 @@ class TooltipElement extends HTMLElement {
|
|
372
339
|
}
|
373
340
|
|
374
341
|
if (!window.customElements.get('tool-tip')) {
|
375
|
-
window.
|
376
|
-
window.customElements.define('tool-tip',
|
342
|
+
window.ToolTipElement = ToolTipElement
|
343
|
+
window.customElements.define('tool-tip', ToolTipElement)
|
377
344
|
}
|
378
345
|
|
379
346
|
declare global {
|
380
347
|
interface Window {
|
381
|
-
|
348
|
+
ToolTipElement: typeof ToolTipElement
|
382
349
|
}
|
383
350
|
}
|
@@ -131,7 +131,7 @@ module Primer
|
|
131
131
|
@with_icon = with_icon
|
132
132
|
@is_clearable = is_clearable
|
133
133
|
|
134
|
-
@label_classes =
|
134
|
+
@label_classes = label_classes(is_label_visible: is_label_visible, is_label_inline: is_label_inline)
|
135
135
|
@system_arguments = deny_tag_argument(**system_arguments)
|
136
136
|
@system_arguments[:tag] = "auto-complete"
|
137
137
|
@system_arguments[:src] = src
|
@@ -143,6 +143,20 @@ module Primer
|
|
143
143
|
results(classes: "") unless results
|
144
144
|
input(classes: "") unless input
|
145
145
|
end
|
146
|
+
|
147
|
+
private
|
148
|
+
|
149
|
+
# Private: determines the label classes based on component configration.
|
150
|
+
#
|
151
|
+
# If the label is not visible, return an empty string.
|
152
|
+
#
|
153
|
+
# @param args [Hash] The component configuration.
|
154
|
+
# @return [String] The label classes.
|
155
|
+
def label_classes(**args)
|
156
|
+
return "" if args[:is_label_visible] == false
|
157
|
+
|
158
|
+
args[:is_label_inline] ? "autocomplete-label-inline" : "autocomplete-label-stacked"
|
159
|
+
end
|
146
160
|
end
|
147
161
|
end
|
148
162
|
end
|