@primer/view-components 0.3.1 → 0.4.0-rc.26cca393

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.
Files changed (30) hide show
  1. package/app/assets/javascripts/app/components/primer/alpha/action_menu/action_menu_element.d.ts +30 -0
  2. package/app/assets/javascripts/app/components/primer/alpha/dropdown/menu.d.ts +1 -0
  3. package/app/assets/javascripts/app/components/primer/alpha/dropdown.d.ts +1 -0
  4. package/app/assets/javascripts/app/components/primer/alpha/image_crop.d.ts +1 -0
  5. package/app/assets/javascripts/app/components/primer/alpha/modal_dialog.d.ts +18 -0
  6. package/app/assets/javascripts/app/components/primer/alpha/nav_list.d.ts +28 -0
  7. package/app/assets/javascripts/app/components/primer/alpha/segmented_control.d.ts +12 -0
  8. package/app/assets/javascripts/app/components/primer/alpha/tab_container.d.ts +1 -0
  9. package/app/assets/javascripts/app/components/primer/alpha/toggle_switch.d.ts +30 -0
  10. package/app/assets/javascripts/app/components/primer/alpha/tool_tip.d.ts +26 -0
  11. package/app/assets/javascripts/app/components/primer/alpha/x_banner.d.ts +11 -0
  12. package/app/assets/javascripts/app/components/primer/anchored_position.d.ts +27 -0
  13. package/app/assets/javascripts/app/components/primer/beta/auto_complete/auto_complete.d.ts +1 -0
  14. package/app/assets/javascripts/app/components/primer/beta/clipboard_copy.d.ts +1 -0
  15. package/app/assets/javascripts/app/components/primer/beta/relative_time.d.ts +1 -0
  16. package/app/assets/javascripts/app/components/primer/focus_group.d.ts +19 -0
  17. package/app/assets/javascripts/app/components/primer/primer.d.ts +20 -0
  18. package/app/assets/javascripts/lib/primer/forms/primer_multi_input.d.ts +10 -0
  19. package/app/assets/javascripts/lib/primer/forms/primer_text_field.d.ts +1 -0
  20. package/app/assets/javascripts/lib/primer/forms/toggle_switch_input.d.ts +5 -0
  21. package/app/assets/javascripts/primer_view_components.js +1 -1
  22. package/app/assets/javascripts/primer_view_components.js.map +1 -1
  23. package/app/assets/styles/primer_view_components.css +1 -1
  24. package/app/assets/styles/primer_view_components.css.map +1 -1
  25. package/app/components/primer/alpha/action_menu/action_menu_element.d.ts +2 -2
  26. package/app/components/primer/alpha/tool_tip.d.ts +3 -2
  27. package/app/components/primer/alpha/tool_tip.js +81 -43
  28. package/package.json +4 -4
  29. package/static/info_arch.json +472 -0
  30. package/static/previews.json +472 -0
@@ -1,6 +1,6 @@
1
1
  import IncludeFragmentElement from '@github/include-fragment-element';
2
- declare type SelectVariant = 'none' | 'single' | 'multiple' | null;
3
- declare type SelectedItem = {
2
+ type SelectVariant = 'none' | 'single' | 'multiple' | null;
3
+ type SelectedItem = {
4
4
  label: string | null | undefined;
5
5
  value: string | null | undefined;
6
6
  element: Element;
@@ -1,4 +1,5 @@
1
- declare type Direction = 'n' | 's' | 'e' | 'w' | 'ne' | 'se' | 'nw' | 'sw';
1
+ import '@oddbird/popover-polyfill';
2
+ type Direction = 'n' | 's' | 'e' | 'w' | 'ne' | 'se' | 'nw' | 'sw';
2
3
  declare class ToolTipElement extends HTMLElement {
3
4
  #private;
4
5
  styles(): string;
@@ -13,7 +14,7 @@ declare class ToolTipElement extends HTMLElement {
13
14
  get hiddenFromView(): true | false;
14
15
  connectedCallback(): void;
15
16
  disconnectedCallback(): void;
16
- handleEvent(event: Event): void;
17
+ handleEvent(event: Event): Promise<void>;
17
18
  static observedAttributes: string[];
18
19
  attributeChangedCallback(name: string): void;
19
20
  }
@@ -10,10 +10,11 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
10
10
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
11
  };
12
12
  var _ToolTipElement_instances, _ToolTipElement_abortController, _ToolTipElement_align, _ToolTipElement_side, _ToolTipElement_allowUpdatePosition, _ToolTipElement_update, _ToolTipElement_updateControlReference, _ToolTipElement_updateDirection, _ToolTipElement_updatePosition;
13
+ import '@oddbird/popover-polyfill';
13
14
  import { getAnchoredPosition } from '@primer/behaviors';
14
- const TOOLTIP_OPEN_CLASS = 'tooltip-open';
15
15
  const TOOLTIP_ARROW_EDGE_OFFSET = 6;
16
16
  const TOOLTIP_SR_ONLY_CLASS = 'sr-only';
17
+ const TOOLTIP_OFFSET = 10;
17
18
  const DIRECTION_CLASSES = [
18
19
  'tooltip-n',
19
20
  'tooltip-s',
@@ -24,6 +25,13 @@ const DIRECTION_CLASSES = [
24
25
  'tooltip-nw',
25
26
  'tooltip-sw'
26
27
  ];
28
+ function focusOutListener() {
29
+ for (const tooltip of openTooltips) {
30
+ tooltip.hidePopover();
31
+ }
32
+ }
33
+ const tooltips = new Set();
34
+ const openTooltips = new Set();
27
35
  class ToolTipElement extends HTMLElement {
28
36
  constructor() {
29
37
  super(...arguments);
@@ -36,12 +44,10 @@ class ToolTipElement extends HTMLElement {
36
44
  styles() {
37
45
  return `
38
46
  :host {
39
- position: absolute;
40
- z-index: 1000000;
41
- padding: .5em .75em;
47
+ padding: .5em .75em !important;
42
48
  font: normal normal 11px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
43
49
  -webkit-font-smoothing: subpixel-antialiased;
44
- color: var(--color-fg-on-emphasis);
50
+ color: var(--color-fg-on-emphasis) !important;
45
51
  text-align: center;
46
52
  text-decoration: none;
47
53
  text-shadow: none;
@@ -49,13 +55,16 @@ class ToolTipElement extends HTMLElement {
49
55
  letter-spacing: normal;
50
56
  word-wrap: break-word;
51
57
  white-space: pre;
52
- background: var(--color-neutral-emphasis-plus);
58
+ background: var(--color-neutral-emphasis-plus) !important;
53
59
  border-radius: 6px;
60
+ border: 0 !important;
54
61
  opacity: 0;
55
62
  max-width: 250px;
56
63
  word-wrap: break-word;
57
64
  white-space: normal;
58
- width: max-content;
65
+ width: max-content !important;
66
+ inset: var(--tool-tip-position-top, 0) auto auto var(--tool-tip-position-left, 0) !important;
67
+ overflow: visible !important;
59
68
  }
60
69
 
61
70
  :host:before{
@@ -69,7 +78,7 @@ class ToolTipElement extends HTMLElement {
69
78
 
70
79
  @keyframes tooltip-appear {
71
80
  from {
72
- opacity: 0
81
+ opacity: 0;
73
82
  }
74
83
  to {
75
84
  opacity: 1
@@ -85,8 +94,17 @@ class ToolTipElement extends HTMLElement {
85
94
  content: ""
86
95
  }
87
96
 
88
- :host(.${TOOLTIP_OPEN_CLASS}),
89
- :host(.${TOOLTIP_OPEN_CLASS}):before {
97
+ :host(:popover-open),
98
+ :host(:popover-open):before {
99
+ animation-name: tooltip-appear;
100
+ animation-duration: .1s;
101
+ animation-fill-mode: forwards;
102
+ animation-timing-function: ease-in;
103
+ animation-delay: .4s
104
+ }
105
+
106
+ :host(.\\:popover-open),
107
+ :host(.\\:popover-open):before {
90
108
  animation-name: tooltip-appear;
91
109
  animation-duration: .1s;
92
110
  animation-fill-mode: forwards;
@@ -177,16 +195,22 @@ class ToolTipElement extends HTMLElement {
177
195
  get control() {
178
196
  return this.ownerDocument.getElementById(this.htmlFor);
179
197
  }
198
+ /* @deprecated */
180
199
  set hiddenFromView(value) {
181
- this.classList.toggle(TOOLTIP_SR_ONLY_CLASS, value);
182
- if (this.isConnected)
183
- __classPrivateFieldGet(this, _ToolTipElement_instances, "m", _ToolTipElement_update).call(this);
200
+ if (value) {
201
+ this.hidePopover();
202
+ }
203
+ else {
204
+ this.showPopover();
205
+ }
184
206
  }
207
+ /* @deprecated */
185
208
  get hiddenFromView() {
186
- return this.classList.contains(TOOLTIP_SR_ONLY_CLASS);
209
+ return !this.matches(':popover-open');
187
210
  }
188
211
  connectedCallback() {
189
- var _a;
212
+ var _a, _b;
213
+ tooltips.add(this);
190
214
  __classPrivateFieldGet(this, _ToolTipElement_instances, "m", _ToolTipElement_updateControlReference).call(this);
191
215
  __classPrivateFieldGet(this, _ToolTipElement_instances, "m", _ToolTipElement_updateDirection).call(this);
192
216
  if (!this.shadowRoot) {
@@ -195,7 +219,7 @@ class ToolTipElement extends HTMLElement {
195
219
  style.textContent = this.styles();
196
220
  shadow.appendChild(document.createElement('slot'));
197
221
  }
198
- this.hiddenFromView = true;
222
+ __classPrivateFieldGet(this, _ToolTipElement_instances, "m", _ToolTipElement_update).call(this, false);
199
223
  __classPrivateFieldSet(this, _ToolTipElement_allowUpdatePosition, true, "f");
200
224
  if (!this.control)
201
225
  return;
@@ -204,35 +228,48 @@ class ToolTipElement extends HTMLElement {
204
228
  __classPrivateFieldSet(this, _ToolTipElement_abortController, new AbortController(), "f");
205
229
  const { signal } = __classPrivateFieldGet(this, _ToolTipElement_abortController, "f");
206
230
  this.addEventListener('mouseleave', this, { signal });
231
+ this.addEventListener('toggle', this, { signal });
207
232
  this.control.addEventListener('mouseenter', this, { signal });
208
233
  this.control.addEventListener('mouseleave', this, { signal });
209
234
  this.control.addEventListener('focus', this, { signal });
210
- this.control.addEventListener('blur', this, { signal });
235
+ this.control.addEventListener('mousedown', this, { signal });
236
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
237
+ // @ts-ignore popoverTargetElement is not in the type definition
238
+ (_b = this.control.popoverTargetElement) === null || _b === void 0 ? void 0 : _b.addEventListener('beforetoggle', this, {
239
+ signal
240
+ });
241
+ this.ownerDocument.addEventListener('focusout', focusOutListener);
211
242
  this.ownerDocument.addEventListener('keydown', this, { signal });
212
- __classPrivateFieldGet(this, _ToolTipElement_instances, "m", _ToolTipElement_update).call(this);
213
243
  }
214
244
  disconnectedCallback() {
215
245
  var _a;
246
+ tooltips.delete(this);
247
+ openTooltips.delete(this);
216
248
  (_a = __classPrivateFieldGet(this, _ToolTipElement_abortController, "f")) === null || _a === void 0 ? void 0 : _a.abort();
217
249
  }
218
- handleEvent(event) {
250
+ async handleEvent(event) {
219
251
  if (!this.control)
220
252
  return;
253
+ const showing = this.matches(':popover-open');
221
254
  // Ensures that tooltip stays open when hovering between tooltip and element
222
255
  // WCAG Success Criterion 1.4.13 Hoverable
223
- if ((event.type === 'mouseenter' || event.type === 'focus') && this.hiddenFromView) {
224
- this.hiddenFromView = false;
225
- }
226
- else if (event.type === 'blur') {
227
- this.hiddenFromView = true;
228
- }
229
- else if (event.type === 'mouseleave' &&
256
+ const shouldShow = event.type === 'mouseenter' || event.type === 'focus';
257
+ const isMouseLeaveFromButton = event.type === 'mouseleave' &&
230
258
  event.relatedTarget !== this.control &&
231
- event.relatedTarget !== this) {
232
- this.hiddenFromView = true;
259
+ event.relatedTarget !== this;
260
+ const isEscapeKeydown = event.type === 'keydown' && event.key === 'Escape';
261
+ const isMouseDownOnButton = event.type === 'mousedown' && event.currentTarget === this.control;
262
+ const isOpeningOtherPopover = event.type === 'beforetoggle' && event.currentTarget !== this;
263
+ const shouldHide = isMouseLeaveFromButton || isEscapeKeydown || isMouseDownOnButton || isOpeningOtherPopover;
264
+ await Promise.resolve();
265
+ if (!showing && shouldShow) {
266
+ this.showPopover();
233
267
  }
234
- else if (event.type === 'keydown' && event.key === 'Escape' && !this.hiddenFromView) {
235
- this.hiddenFromView = true;
268
+ else if (showing && shouldHide) {
269
+ this.hidePopover();
270
+ }
271
+ if (event.type === 'toggle') {
272
+ __classPrivateFieldGet(this, _ToolTipElement_instances, "m", _ToolTipElement_update).call(this, event.newState === 'open');
236
273
  }
237
274
  }
238
275
  attributeChangedCallback(name) {
@@ -246,18 +283,21 @@ class ToolTipElement extends HTMLElement {
246
283
  }
247
284
  }
248
285
  }
249
- _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() {
250
- if (this.hiddenFromView) {
251
- this.classList.remove(TOOLTIP_OPEN_CLASS, ...DIRECTION_CLASSES);
252
- }
253
- else {
254
- this.classList.add(TOOLTIP_OPEN_CLASS);
255
- for (const tooltip of this.ownerDocument.querySelectorAll(this.tagName)) {
286
+ _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(isOpen) {
287
+ if (isOpen) {
288
+ openTooltips.add(this);
289
+ this.classList.remove(TOOLTIP_SR_ONLY_CLASS);
290
+ for (const tooltip of tooltips) {
256
291
  if (tooltip !== this)
257
- tooltip.hiddenFromView = true;
292
+ tooltip.hidePopover();
258
293
  }
259
294
  __classPrivateFieldGet(this, _ToolTipElement_instances, "m", _ToolTipElement_updatePosition).call(this);
260
295
  }
296
+ else {
297
+ openTooltips.delete(this);
298
+ this.classList.remove(...DIRECTION_CLASSES);
299
+ this.classList.add(TOOLTIP_SR_ONLY_CLASS);
300
+ }
261
301
  }, _ToolTipElement_updateControlReference = function _ToolTipElement_updateControlReference() {
262
302
  if (!this.id || !this.control)
263
303
  return;
@@ -331,10 +371,8 @@ _ToolTipElement_abortController = new WeakMap(), _ToolTipElement_align = new Wea
331
371
  }, _ToolTipElement_updatePosition = function _ToolTipElement_updatePosition() {
332
372
  if (!this.control)
333
373
  return;
334
- if (!__classPrivateFieldGet(this, _ToolTipElement_allowUpdatePosition, "f") || this.hiddenFromView)
374
+ if (!__classPrivateFieldGet(this, _ToolTipElement_allowUpdatePosition, "f") || !this.matches(':popover-open'))
335
375
  return;
336
- const TOOLTIP_OFFSET = 10;
337
- this.style.left = `0px`; // Ensures we have reliable tooltip width in `getAnchoredPosition`
338
376
  const position = getAnchoredPosition(this, this.control, {
339
377
  side: __classPrivateFieldGet(this, _ToolTipElement_side, "f"),
340
378
  align: __classPrivateFieldGet(this, _ToolTipElement_align, "f"),
@@ -342,8 +380,8 @@ _ToolTipElement_abortController = new WeakMap(), _ToolTipElement_align = new Wea
342
380
  });
343
381
  const anchorSide = position.anchorSide;
344
382
  const align = position.anchorAlign;
345
- this.style.top = `${position.top}px`;
346
- this.style.left = `${position.left}px`;
383
+ this.style.setProperty('--tool-tip-position-top', `${position.top}px`);
384
+ this.style.setProperty('--tool-tip-position-left', `${position.left}px`);
347
385
  let direction = 's';
348
386
  if (anchorSide === 'outside-left') {
349
387
  direction = 'w';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/view-components",
3
- "version": "0.3.1",
3
+ "version": "0.4.0-rc.26cca393",
4
4
  "description": "ViewComponents for the Primer Design System",
5
5
  "main": "app/assets/javascripts/primer_view_components.js",
6
6
  "module": "app/components/primer/primer.js",
@@ -58,12 +58,11 @@
58
58
  },
59
59
  "devDependencies": {
60
60
  "@changesets/changelog-github": "^0.4.6",
61
- "@changesets/cli": "^2.24.1",
62
61
  "@github/axe-github": "^0.5.0",
63
62
  "@github/browserslist-config": "^1.0.0",
64
63
  "@github/markdownlint-github": "^0.2.2",
65
64
  "@github/prettier-config": "0.0.4",
66
- "@playwright/test": "^1.27.1",
65
+ "@playwright/test": "^1.35.1",
67
66
  "@primer/css": "21.0.2",
68
67
  "@primer/primitives": "^7.11.11",
69
68
  "@rollup/plugin-node-resolve": "^13.3.0",
@@ -79,7 +78,7 @@
79
78
  "eslint-plugin-prettier": "^4.2.1",
80
79
  "markdownlint-cli2": "^0.5.1",
81
80
  "mocha": "^10.0.0",
82
- "playwright": "^1.27.1",
81
+ "playwright": "^1.35.1",
83
82
  "postcss": "^8.4.16",
84
83
  "postcss-cli": "^10.1.0",
85
84
  "postcss-custom-properties-fallback": "^1.0.2",
@@ -87,6 +86,7 @@
87
86
  "postcss-mixins": "^9.0.3",
88
87
  "postcss-preset-env": "^7.8.0",
89
88
  "prettier": "2.7.1",
89
+ "primer-changesets-cli": "2.1.0",
90
90
  "rollup": "^2.77.1",
91
91
  "rollup-plugin-terser": "^7.0.2",
92
92
  "stylelint": "^14.13.0",