@aquera/nile-elements 0.1.34 → 0.1.35-beta-1.2

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 (188) hide show
  1. package/README.md +29 -8
  2. package/demo/index.css +7 -4
  3. package/demo/index.html +20 -36
  4. package/demo/variables.css +13 -0
  5. package/demo/variables_v2.css +13 -0
  6. package/dist/{fixture-161dee0b.cjs.js → fixture-d5b55278.cjs.js} +3 -3
  7. package/dist/fixture-d5b55278.cjs.js.map +1 -0
  8. package/dist/{fixture-372df3b0.esm.js → fixture-df8b52d7.esm.js} +1 -1
  9. package/dist/index.cjs.js +1 -1
  10. package/dist/index.esm.js +1 -1
  11. package/dist/internal/animate.cjs.js +1 -1
  12. package/dist/internal/animate.cjs.js.map +1 -1
  13. package/dist/internal/animate.esm.js +1 -1
  14. package/dist/nile-accordion/nile-accordian.test.cjs.js +1 -1
  15. package/dist/nile-accordion/nile-accordian.test.esm.js +1 -1
  16. package/dist/nile-auto-complete/nile-auto-complete.test.cjs.js +1 -1
  17. package/dist/nile-auto-complete/nile-auto-complete.test.esm.js +1 -1
  18. package/dist/nile-avatar/nile-avatar.test.cjs.js +1 -1
  19. package/dist/nile-avatar/nile-avatar.test.esm.js +1 -1
  20. package/dist/nile-badge/nile-badge.test.cjs.js +1 -1
  21. package/dist/nile-badge/nile-badge.test.esm.js +1 -1
  22. package/dist/nile-button/nile-button.test.cjs.js +1 -1
  23. package/dist/nile-button/nile-button.test.esm.js +1 -1
  24. package/dist/nile-button-toggle-group/nile-button-toggle-group.test.cjs.js +1 -1
  25. package/dist/nile-button-toggle-group/nile-button-toggle-group.test.esm.js +1 -1
  26. package/dist/nile-calendar/nile-calendar.test.cjs.js +1 -1
  27. package/dist/nile-calendar/nile-calendar.test.esm.js +1 -1
  28. package/dist/nile-card/nile-card.test.cjs.js +1 -1
  29. package/dist/nile-card/nile-card.test.esm.js +1 -1
  30. package/dist/nile-checkbox/nile-checkbox.test.cjs.js +1 -1
  31. package/dist/nile-checkbox/nile-checkbox.test.esm.js +1 -1
  32. package/dist/nile-chip/nile-chip.test.cjs.js +1 -1
  33. package/dist/nile-chip/nile-chip.test.esm.js +1 -1
  34. package/dist/nile-code-editor/extensionSetup.cjs.js +1 -1
  35. package/dist/nile-code-editor/extensionSetup.cjs.js.map +1 -1
  36. package/dist/nile-code-editor/extensionSetup.esm.js +1 -1
  37. package/dist/nile-code-editor/nile-code-editor.cjs.js +1 -1
  38. package/dist/nile-code-editor/nile-code-editor.cjs.js.map +1 -1
  39. package/dist/nile-code-editor/nile-code-editor.esm.js +2 -2
  40. package/dist/nile-dialog/nile-dialog.test.cjs.js +1 -1
  41. package/dist/nile-dialog/nile-dialog.test.esm.js +1 -1
  42. package/dist/nile-drawer/nile-drawer.test.cjs.js +1 -1
  43. package/dist/nile-drawer/nile-drawer.test.esm.js +1 -1
  44. package/dist/nile-dropdown/nile-dropdown.test.cjs.js +1 -1
  45. package/dist/nile-dropdown/nile-dropdown.test.esm.js +1 -1
  46. package/dist/nile-empty-state/nile-empty-state.test.cjs.js +1 -1
  47. package/dist/nile-empty-state/nile-empty-state.test.esm.js +1 -1
  48. package/dist/nile-error-message/nile-error-message.cjs.js +1 -1
  49. package/dist/nile-error-message/nile-error-message.cjs.js.map +1 -1
  50. package/dist/nile-error-message/nile-error-message.css.cjs.js +1 -1
  51. package/dist/nile-error-message/nile-error-message.css.cjs.js.map +1 -1
  52. package/dist/nile-error-message/nile-error-message.css.esm.js +6 -4
  53. package/dist/nile-error-message/nile-error-message.esm.js +4 -4
  54. package/dist/nile-error-message/nile-error-message.test.cjs.js +1 -1
  55. package/dist/nile-error-message/nile-error-message.test.esm.js +1 -1
  56. package/dist/nile-error-notification/nile-error-notification.css.cjs.js +1 -1
  57. package/dist/nile-error-notification/nile-error-notification.css.cjs.js.map +1 -1
  58. package/dist/nile-error-notification/nile-error-notification.css.esm.js +1 -1
  59. package/dist/nile-filter-chip/index.cjs.js +2 -0
  60. package/dist/nile-filter-chip/index.cjs.js.map +1 -0
  61. package/dist/nile-filter-chip/index.esm.js +1 -0
  62. package/dist/nile-filter-chip/nile-filter-chip.cjs.js +2 -0
  63. package/dist/nile-filter-chip/nile-filter-chip.cjs.js.map +1 -0
  64. package/dist/nile-filter-chip/nile-filter-chip.css.cjs.js +2 -0
  65. package/dist/nile-filter-chip/nile-filter-chip.css.cjs.js.map +1 -0
  66. package/dist/nile-filter-chip/nile-filter-chip.css.esm.js +98 -0
  67. package/dist/nile-filter-chip/nile-filter-chip.esm.js +34 -0
  68. package/dist/nile-filter-chip/nile-filter-chip.test.cjs.js +2 -0
  69. package/dist/nile-filter-chip/nile-filter-chip.test.cjs.js.map +1 -0
  70. package/dist/nile-filter-chip/nile-filter-chip.test.esm.js +20 -0
  71. package/dist/nile-form-group/nile-form-group.test.cjs.js +1 -1
  72. package/dist/nile-form-group/nile-form-group.test.esm.js +1 -1
  73. package/dist/nile-form-help-text/nile-form-help-text.test.cjs.js +1 -1
  74. package/dist/nile-form-help-text/nile-form-help-text.test.esm.js +1 -1
  75. package/dist/nile-hero/nile-hero.test.cjs.js +1 -1
  76. package/dist/nile-hero/nile-hero.test.esm.js +1 -1
  77. package/dist/nile-icon/nile-icon.test.cjs.js +1 -1
  78. package/dist/nile-icon/nile-icon.test.esm.js +1 -1
  79. package/dist/nile-input/nile-input.test.cjs.js +1 -1
  80. package/dist/nile-input/nile-input.test.esm.js +1 -1
  81. package/dist/nile-link/nile-link.test.cjs.js +1 -1
  82. package/dist/nile-link/nile-link.test.esm.js +1 -1
  83. package/dist/nile-loader/nile-loader.test.cjs.js +1 -1
  84. package/dist/nile-loader/nile-loader.test.esm.js +1 -1
  85. package/dist/nile-popover/nile-popover.test.cjs.js +1 -1
  86. package/dist/nile-popover/nile-popover.test.esm.js +1 -1
  87. package/dist/nile-popup/nile-popup.test.cjs.js +1 -1
  88. package/dist/nile-popup/nile-popup.test.esm.js +1 -1
  89. package/dist/nile-progress-bar/nile-progress-bar.css.cjs.js +1 -1
  90. package/dist/nile-progress-bar/nile-progress-bar.css.cjs.js.map +1 -1
  91. package/dist/nile-progress-bar/nile-progress-bar.css.esm.js +1 -0
  92. package/dist/nile-progress-bar/nile-progress-bar.test.cjs.js +1 -1
  93. package/dist/nile-progress-bar/nile-progress-bar.test.esm.js +1 -1
  94. package/dist/nile-radio/nile-radio.test.cjs.js +1 -1
  95. package/dist/nile-radio/nile-radio.test.esm.js +1 -1
  96. package/dist/nile-radio-group/nile-radio-group.test.cjs.js +1 -1
  97. package/dist/nile-radio-group/nile-radio-group.test.esm.js +1 -1
  98. package/dist/nile-select/nile-select.cjs.js +1 -1
  99. package/dist/nile-select/nile-select.cjs.js.map +1 -1
  100. package/dist/nile-select/nile-select.esm.js +1 -1
  101. package/dist/nile-select/nile-select.test.cjs.js +1 -1
  102. package/dist/nile-select/nile-select.test.esm.js +1 -1
  103. package/dist/nile-slide-toggle/nile-slide-toggle.test.cjs.js +1 -1
  104. package/dist/nile-slide-toggle/nile-slide-toggle.test.esm.js +1 -1
  105. package/dist/nile-tab-group/nile-tab-group.test.cjs.js +1 -1
  106. package/dist/nile-tab-group/nile-tab-group.test.esm.js +1 -1
  107. package/dist/nile-table/nile-table.cjs.js.map +1 -1
  108. package/dist/nile-textarea/nile-textarea.test.cjs.js +1 -1
  109. package/dist/nile-textarea/nile-textarea.test.esm.js +1 -1
  110. package/dist/nile-tooltip/index.cjs.js +1 -1
  111. package/dist/nile-tooltip/index.esm.js +1 -1
  112. package/dist/nile-tooltip/nile-tooltip-utils.cjs.js +2 -0
  113. package/dist/nile-tooltip/nile-tooltip-utils.cjs.js.map +1 -0
  114. package/dist/nile-tooltip/nile-tooltip-utils.esm.js +1 -0
  115. package/dist/nile-tooltip/nile-tooltip.cjs.js +1 -1
  116. package/dist/nile-tooltip/nile-tooltip.cjs.js.map +1 -1
  117. package/dist/nile-tooltip/nile-tooltip.css.cjs.js +1 -1
  118. package/dist/nile-tooltip/nile-tooltip.css.cjs.js.map +1 -1
  119. package/dist/nile-tooltip/nile-tooltip.css.esm.js +78 -45
  120. package/dist/nile-tooltip/nile-tooltip.esm.js +23 -28
  121. package/dist/nile-tooltip/nile-tooltip.test.cjs.js +2 -0
  122. package/dist/nile-tooltip/nile-tooltip.test.cjs.js.map +1 -0
  123. package/dist/nile-tooltip/nile-tooltip.test.esm.js +47 -0
  124. package/dist/src/index.d.ts +1 -0
  125. package/dist/src/index.js +1 -0
  126. package/dist/src/index.js.map +1 -1
  127. package/dist/src/nile-code-editor/extensionSetup.d.ts +2 -1
  128. package/dist/src/nile-code-editor/extensionSetup.js +8 -0
  129. package/dist/src/nile-code-editor/extensionSetup.js.map +1 -1
  130. package/dist/src/nile-code-editor/nile-code-editor.d.ts +2 -0
  131. package/dist/src/nile-code-editor/nile-code-editor.js +12 -3
  132. package/dist/src/nile-code-editor/nile-code-editor.js.map +1 -1
  133. package/dist/src/nile-error-message/nile-error-message.css.js +6 -4
  134. package/dist/src/nile-error-message/nile-error-message.css.js.map +1 -1
  135. package/dist/src/nile-error-message/nile-error-message.d.ts +4 -0
  136. package/dist/src/nile-error-message/nile-error-message.js +20 -0
  137. package/dist/src/nile-error-message/nile-error-message.js.map +1 -1
  138. package/dist/src/nile-error-notification/nile-error-notification.css.js +1 -1
  139. package/dist/src/nile-error-notification/nile-error-notification.css.js.map +1 -1
  140. package/dist/src/nile-filter-chip/index.d.ts +1 -0
  141. package/dist/src/nile-filter-chip/index.js +2 -0
  142. package/dist/src/nile-filter-chip/index.js.map +1 -0
  143. package/dist/src/nile-filter-chip/nile-filter-chip.css.d.ts +12 -0
  144. package/dist/src/nile-filter-chip/nile-filter-chip.css.js +110 -0
  145. package/dist/src/nile-filter-chip/nile-filter-chip.css.js.map +1 -0
  146. package/dist/src/nile-filter-chip/nile-filter-chip.d.ts +35 -0
  147. package/dist/src/nile-filter-chip/nile-filter-chip.js +128 -0
  148. package/dist/src/nile-filter-chip/nile-filter-chip.js.map +1 -0
  149. package/dist/src/nile-filter-chip/nile-filter-chip.test.d.ts +1 -0
  150. package/dist/src/nile-filter-chip/nile-filter-chip.test.js +80 -0
  151. package/dist/src/nile-filter-chip/nile-filter-chip.test.js.map +1 -0
  152. package/dist/src/nile-progress-bar/nile-progress-bar.css.js +1 -0
  153. package/dist/src/nile-progress-bar/nile-progress-bar.css.js.map +1 -1
  154. package/dist/src/nile-select/nile-select.js +1 -1
  155. package/dist/src/nile-select/nile-select.js.map +1 -1
  156. package/dist/src/nile-table/nile-table.js.map +1 -1
  157. package/dist/src/nile-tooltip/nile-tooltip-utils.d.ts +18 -0
  158. package/dist/src/nile-tooltip/nile-tooltip-utils.js +216 -0
  159. package/dist/src/nile-tooltip/nile-tooltip-utils.js.map +1 -0
  160. package/dist/src/nile-tooltip/nile-tooltip.css.js +76 -43
  161. package/dist/src/nile-tooltip/nile-tooltip.css.js.map +1 -1
  162. package/dist/src/nile-tooltip/nile-tooltip.d.ts +24 -46
  163. package/dist/src/nile-tooltip/nile-tooltip.js +235 -232
  164. package/dist/src/nile-tooltip/nile-tooltip.js.map +1 -1
  165. package/dist/src/nile-tooltip/nile-tooltip.test.d.ts +1 -0
  166. package/dist/src/nile-tooltip/nile-tooltip.test.js +148 -0
  167. package/dist/src/nile-tooltip/nile-tooltip.test.js.map +1 -0
  168. package/dist/tsconfig.tsbuildinfo +1 -1
  169. package/package.json +2 -2
  170. package/src/index.ts +2 -1
  171. package/src/nile-code-editor/extensionSetup.ts +13 -1
  172. package/src/nile-code-editor/nile-code-editor.ts +9 -4
  173. package/src/nile-error-message/nile-error-message.css.ts +6 -4
  174. package/src/nile-error-message/nile-error-message.ts +18 -0
  175. package/src/nile-error-notification/nile-error-notification.css.ts +1 -1
  176. package/src/nile-filter-chip/index.ts +1 -0
  177. package/src/nile-filter-chip/nile-filter-chip.css.ts +115 -0
  178. package/src/nile-filter-chip/nile-filter-chip.test.ts +92 -0
  179. package/src/nile-filter-chip/nile-filter-chip.ts +125 -0
  180. package/src/nile-progress-bar/nile-progress-bar.css.ts +1 -0
  181. package/src/nile-select/nile-select.ts +1 -1
  182. package/src/nile-table/nile-table.ts +2 -2
  183. package/src/nile-tooltip/nile-tooltip-utils.ts +271 -0
  184. package/src/nile-tooltip/nile-tooltip.css.ts +77 -44
  185. package/src/nile-tooltip/nile-tooltip.test.ts +168 -0
  186. package/src/nile-tooltip/nile-tooltip.ts +268 -230
  187. package/vscode-html-custom-data.json +150 -96
  188. package/dist/fixture-161dee0b.cjs.js.map +0 -1
@@ -0,0 +1,216 @@
1
+ export function isInViewport(element) {
2
+ const rect = element.getBoundingClientRect();
3
+ return (rect.top >= 0 &&
4
+ rect.left >= 0 &&
5
+ rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
6
+ rect.right <= (window.innerWidth || document.documentElement.clientWidth));
7
+ }
8
+ export function getValidTooltipPosition(triggerRect, tooltipRect, originalPlacement, distance, skidding, caretSize, viewportWidth, viewportHeight) {
9
+ const triggerCenterX = triggerRect.left + triggerRect.width / 2;
10
+ const getCandidatePosition = (placement) => {
11
+ let top = 0;
12
+ let left = 0;
13
+ switch (placement) {
14
+ case 'top':
15
+ top = triggerRect.top - tooltipRect.height - distance;
16
+ left = triggerRect.left + (triggerRect.width - tooltipRect.width) / 2 + skidding;
17
+ break;
18
+ case 'top-start': {
19
+ top = triggerRect.top - tooltipRect.height - distance;
20
+ const centeredLeft = triggerRect.left + (triggerRect.width / 2) - (tooltipRect.width / 2) + skidding;
21
+ left = Math.max(triggerRect.left + skidding, centeredLeft);
22
+ break;
23
+ }
24
+ case 'top-end': {
25
+ top = triggerRect.top - tooltipRect.height - distance;
26
+ const centeredLeft = triggerRect.left + (triggerRect.width / 2) - (tooltipRect.width / 2) + skidding;
27
+ const maxLeft = triggerRect.right - tooltipRect.width + skidding;
28
+ left = Math.min(centeredLeft, maxLeft);
29
+ break;
30
+ }
31
+ case 'bottom':
32
+ top = triggerRect.bottom + distance;
33
+ left = triggerRect.left + (triggerRect.width - tooltipRect.width) / 2 + skidding;
34
+ break;
35
+ case 'bottom-start': {
36
+ top = triggerRect.bottom + distance;
37
+ const centeredLeft = triggerRect.left + (triggerRect.width / 2) - (tooltipRect.width / 2) + skidding;
38
+ left = Math.max(triggerRect.left + skidding, centeredLeft);
39
+ break;
40
+ }
41
+ case 'bottom-end': {
42
+ top = triggerRect.bottom + distance;
43
+ const centeredLeft = triggerRect.left + (triggerRect.width / 2) - (tooltipRect.width / 2) + skidding;
44
+ const maxLeft = triggerRect.right - tooltipRect.width + skidding;
45
+ left = Math.min(centeredLeft, maxLeft);
46
+ break;
47
+ }
48
+ case 'left':
49
+ top = triggerRect.top + (triggerRect.height - tooltipRect.height) / 2 + skidding;
50
+ left = triggerRect.left - tooltipRect.width - distance;
51
+ break;
52
+ case 'left-start': {
53
+ const triggerCenterY = triggerRect.top + triggerRect.height / 2;
54
+ top = triggerCenterY - tooltipRect.height / 2;
55
+ left = triggerRect.left - tooltipRect.width - distance;
56
+ if (top < triggerRect.top) {
57
+ top = triggerRect.top;
58
+ }
59
+ break;
60
+ }
61
+ case 'left-end': {
62
+ const triggerCenterY = triggerRect.top + triggerRect.height / 2;
63
+ top = triggerCenterY - tooltipRect.height / 2;
64
+ left = triggerRect.left - tooltipRect.width - distance;
65
+ if (top + tooltipRect.height > triggerRect.bottom) {
66
+ top = triggerRect.bottom - tooltipRect.height;
67
+ }
68
+ break;
69
+ }
70
+ case 'right':
71
+ top = triggerRect.top + (triggerRect.height - tooltipRect.height) / 2 + skidding;
72
+ left = triggerRect.right + distance;
73
+ break;
74
+ case 'right-start': {
75
+ const triggerCenterY = triggerRect.top + triggerRect.height / 2;
76
+ top = triggerCenterY - tooltipRect.height / 2;
77
+ left = triggerRect.right + distance;
78
+ if (top < triggerRect.top) {
79
+ top = triggerRect.top;
80
+ }
81
+ break;
82
+ }
83
+ case 'right-end': {
84
+ const triggerCenterY = triggerRect.top + triggerRect.height / 2;
85
+ top = triggerCenterY - tooltipRect.height / 2;
86
+ left = triggerRect.right + distance;
87
+ if (top + tooltipRect.height > triggerRect.bottom) {
88
+ top = triggerRect.bottom - tooltipRect.height;
89
+ }
90
+ break;
91
+ }
92
+ default:
93
+ top = triggerRect.top - tooltipRect.height - distance;
94
+ left = triggerRect.left + (triggerRect.width - tooltipRect.width) / 2 + skidding;
95
+ }
96
+ return { top, left };
97
+ };
98
+ const candidateFits = (top, left) => top >= 0 &&
99
+ left >= 0 &&
100
+ top + tooltipRect.height <= viewportHeight &&
101
+ left + tooltipRect.width <= viewportWidth;
102
+ let placement = originalPlacement;
103
+ let candidate = getCandidatePosition(placement);
104
+ if (!candidateFits(candidate.top, candidate.left)) {
105
+ if (['top', 'top-start', 'top-end'].includes(originalPlacement)) {
106
+ placement = 'bottom';
107
+ }
108
+ else if (['bottom', 'bottom-start', 'bottom-end'].includes(originalPlacement)) {
109
+ placement = 'top';
110
+ }
111
+ else if (['right', 'right-start', 'right-end'].includes(originalPlacement)) {
112
+ placement = 'left';
113
+ }
114
+ else if (['left', 'left-start', 'left-end'].includes(originalPlacement)) {
115
+ placement = 'right';
116
+ }
117
+ candidate = getCandidatePosition(placement);
118
+ const leftCandidate = getCandidatePosition('left');
119
+ const bottomCandidate = getCandidatePosition('bottom');
120
+ const topCandidate = getCandidatePosition('top');
121
+ if (!candidateFits(leftCandidate.top, leftCandidate.left) &&
122
+ !candidateFits(bottomCandidate.top, bottomCandidate.left) &&
123
+ !candidateFits(topCandidate.top, topCandidate.left)) {
124
+ placement = 'right';
125
+ candidate = getCandidatePosition(placement);
126
+ }
127
+ else {
128
+ const rightCandidate = getCandidatePosition('right');
129
+ if (!candidateFits(rightCandidate.top, rightCandidate.left) &&
130
+ !candidateFits(bottomCandidate.top, bottomCandidate.left) &&
131
+ !candidateFits(topCandidate.top, topCandidate.left)) {
132
+ placement = 'left';
133
+ candidate = getCandidatePosition(placement);
134
+ }
135
+ }
136
+ }
137
+ if (candidate.left < 0) {
138
+ candidate.left = 5;
139
+ }
140
+ else if (candidate.left + tooltipRect.width > viewportWidth) {
141
+ candidate.left = viewportWidth - tooltipRect.width - 5;
142
+ }
143
+ if (candidate.top < 0) {
144
+ candidate.top = 5;
145
+ }
146
+ else if (candidate.top + tooltipRect.height > viewportHeight) {
147
+ candidate.top = viewportHeight - tooltipRect.height - 5;
148
+ }
149
+ return { ...candidate, placement };
150
+ }
151
+ export function getCaretPosition({ placement, tooltipRect, triggerRect, caretSize, left, top }) {
152
+ const triggerCenterX = triggerRect.left + triggerRect.width / 2;
153
+ const triggerCenterY = triggerRect.top + triggerRect.height / 2;
154
+ const [primaryPlacement, secondaryPlacement] = placement.split('-');
155
+ let caretLeft = 0;
156
+ let caretTop = 0;
157
+ switch (primaryPlacement) {
158
+ case 'top':
159
+ caretTop = tooltipRect.height - caretSize;
160
+ caretLeft = triggerCenterX - left - caretSize;
161
+ if (placement === 'top-end') {
162
+ caretLeft = triggerCenterX - left - caretSize;
163
+ }
164
+ else if (secondaryPlacement === 'start') {
165
+ caretLeft = triggerCenterX - left - caretSize;
166
+ }
167
+ else if (secondaryPlacement === 'end') {
168
+ caretLeft = tooltipRect.width - 2 * caretSize + 8;
169
+ }
170
+ caretLeft = Math.max(caretSize, Math.min(caretLeft, tooltipRect.width - 2 * caretSize));
171
+ break;
172
+ case 'bottom':
173
+ caretTop = -caretSize;
174
+ caretLeft = triggerCenterX - left - caretSize;
175
+ break;
176
+ case 'left':
177
+ caretLeft = tooltipRect.width - caretSize;
178
+ if (secondaryPlacement === 'start') {
179
+ const computedCaretTop = triggerCenterY - top - caretSize;
180
+ const minCaretTop = triggerRect.top - top;
181
+ caretTop = Math.max(computedCaretTop, minCaretTop);
182
+ }
183
+ else if (secondaryPlacement === 'end') {
184
+ const computedCaretTop = triggerCenterY - top - caretSize;
185
+ const maxCaretTop = triggerRect.bottom - top - 2 * caretSize;
186
+ caretTop = Math.min(computedCaretTop, maxCaretTop);
187
+ }
188
+ else {
189
+ caretTop = triggerCenterY - top - caretSize;
190
+ }
191
+ caretTop = Math.max(caretSize, Math.min(caretTop, tooltipRect.height - 2 * caretSize));
192
+ break;
193
+ case 'right':
194
+ caretLeft = -caretSize;
195
+ if (secondaryPlacement === 'start') {
196
+ const computedCaretTop = triggerCenterY - top - caretSize;
197
+ const minCaretTop = triggerRect.top - top;
198
+ caretTop = Math.max(computedCaretTop, minCaretTop);
199
+ }
200
+ else if (secondaryPlacement === 'end') {
201
+ const computedCaretTop = triggerCenterY - top - caretSize;
202
+ const maxCaretTop = triggerRect.bottom - top - 2 * caretSize;
203
+ caretTop = Math.min(computedCaretTop, maxCaretTop);
204
+ }
205
+ else {
206
+ caretTop = triggerCenterY - top - caretSize;
207
+ }
208
+ caretTop = Math.max(caretSize, Math.min(caretTop, tooltipRect.height - 2 * caretSize));
209
+ break;
210
+ default:
211
+ caretLeft = tooltipRect.width / 2 - caretSize;
212
+ caretTop = tooltipRect.height / 2 - caretSize;
213
+ }
214
+ return { caretLeft, caretTop };
215
+ }
216
+ //# sourceMappingURL=nile-tooltip-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nile-tooltip-utils.js","sourceRoot":"","sources":["../../../src/nile-tooltip/nile-tooltip-utils.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,YAAY,CAAC,OAAoB;IAC/C,MAAM,IAAI,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAC7C,OAAO,CACL,IAAI,CAAC,GAAG,IAAI,CAAC;QACb,IAAI,CAAC,IAAI,IAAI,CAAC;QACd,IAAI,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,IAAI,QAAQ,CAAC,eAAe,CAAC,YAAY,CAAC;QAC5E,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,QAAQ,CAAC,eAAe,CAAC,WAAW,CAAC,CAC1E,CAAC;AACJ,CAAC;AAGD,MAAM,UAAU,uBAAuB,CACrC,WAAoB,EACpB,WAAoB,EACpB,iBAAyB,EACzB,QAAgB,EAChB,QAAgB,EAChB,SAAiB,EACjB,aAAq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AAG,GAAG,GAAG,SAAS,CAAC;gBAC1D,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,SAAS,CAAC;gBAC7D,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAC;YACrD,CAAC;iBAAM,CAAC;gBACN,QAAQ,GAAG,cAAc,GAAG,GAAG,GAAG,SAAS,CAAC;YAC9C,CAAC;YACD,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC;YACvF,MAAM;QAGR;YACE,SAAS,GAAG,WAAW,CAAC,KAAK,GAAG,CAAC,GAAG,SAAS,CAAC;YAC9C,QAAQ,GAAG,WAAW,CAAC,MAAM,GAAG,CAAC,GAAG,SAAS,CAAC;IAClD,CAAC;IAED,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;AACjC,CAAC","sourcesContent":["export function isInViewport(element: HTMLElement): boolean {\n const rect = element.getBoundingClientRect();\n return (\n rect.top >= 0 &&\n rect.left >= 0 &&\n rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&\n rect.right <= (window.innerWidth || document.documentElement.clientWidth)\n );\n}\n\n\nexport function getValidTooltipPosition(\n triggerRect: DOMRect,\n tooltipRect: DOMRect,\n originalPlacement: string,\n distance: number,\n skidding: number,\n caretSize: number,\n viewportWidth: number,\n viewportHeight: number\n): { top: number; left: number; placement: string } {\n const triggerCenterX = triggerRect.left + triggerRect.width / 2;\n\n const getCandidatePosition = (placement: string) => {\n let top = 0;\n let left = 0;\n\n switch (placement) {\n case 'top':\n top = triggerRect.top - tooltipRect.height - distance;\n left = triggerRect.left + (triggerRect.width - tooltipRect.width) / 2 + skidding;\n break;\n case 'top-start': {\n top = triggerRect.top - tooltipRect.height - distance;\n const centeredLeft = triggerRect.left + (triggerRect.width / 2) - (tooltipRect.width / 2) + skidding;\n left = Math.max(triggerRect.left + skidding, centeredLeft);\n break;\n }\n case 'top-end': {\n top = triggerRect.top - tooltipRect.height - distance;\n const centeredLeft = triggerRect.left + (triggerRect.width / 2) - (tooltipRect.width / 2) + skidding;\n const maxLeft = triggerRect.right - tooltipRect.width + skidding;\n left = Math.min(centeredLeft, maxLeft);\n break;\n }\n\n case 'bottom':\n top = triggerRect.bottom + distance;\n left = triggerRect.left + (triggerRect.width - tooltipRect.width) / 2 + skidding;\n break;\n case 'bottom-start': {\n top = triggerRect.bottom + distance;\n const centeredLeft = triggerRect.left + (triggerRect.width / 2) - (tooltipRect.width / 2) + skidding;\n left = Math.max(triggerRect.left + skidding, centeredLeft);\n\n break;\n }\n\n case 'bottom-end': {\n top = triggerRect.bottom + distance;\n const centeredLeft = triggerRect.left + (triggerRect.width / 2) - (tooltipRect.width / 2) + skidding;\n const maxLeft = triggerRect.right - tooltipRect.width + skidding;\n left = Math.min(centeredLeft, maxLeft);\n break;\n }\n\n case 'left':\n top = triggerRect.top + (triggerRect.height - tooltipRect.height) / 2 + skidding;\n left = triggerRect.left - tooltipRect.width - distance;\n break;\n case 'left-start': {\n const triggerCenterY = triggerRect.top + triggerRect.height / 2;\n top = triggerCenterY - tooltipRect.height / 2;\n left = triggerRect.left - tooltipRect.width - distance;\n if (top < triggerRect.top) {\n top = triggerRect.top;\n }\n break;\n }\n\n case 'left-end': {\n const triggerCenterY = triggerRect.top + triggerRect.height / 2;\n top = triggerCenterY - tooltipRect.height / 2;\n left = triggerRect.left - tooltipRect.width - distance;\n if (top + tooltipRect.height > triggerRect.bottom) {\n top = triggerRect.bottom - tooltipRect.height;\n }\n\n break;\n }\n\n case 'right':\n top = triggerRect.top + (triggerRect.height - tooltipRect.height) / 2 + skidding;\n left = triggerRect.right + distance;\n break;\n case 'right-start': {\n const triggerCenterY = triggerRect.top + triggerRect.height / 2;\n top = triggerCenterY - tooltipRect.height / 2;\n left = triggerRect.right + distance;\n if (top < triggerRect.top) {\n top = triggerRect.top;\n }\n\n break;\n }\n\n case 'right-end': {\n const triggerCenterY = triggerRect.top + triggerRect.height / 2;\n top = triggerCenterY - tooltipRect.height / 2;\n left = triggerRect.right + distance;\n if (top + tooltipRect.height > triggerRect.bottom) {\n top = triggerRect.bottom - tooltipRect.height;\n }\n\n break;\n }\n\n default:\n top = triggerRect.top - tooltipRect.height - distance;\n left = triggerRect.left + (triggerRect.width - tooltipRect.width) / 2 + skidding;\n }\n\n return { top, left };\n };\n\n const candidateFits = (top: number, left: number) =>\n top >= 0 &&\n left >= 0 &&\n top + tooltipRect.height <= viewportHeight &&\n left + tooltipRect.width <= viewportWidth;\n\n let placement = originalPlacement;\n let candidate = getCandidatePosition(placement);\n\n if (!candidateFits(candidate.top, candidate.left)) {\n if (['top', 'top-start', 'top-end'].includes(originalPlacement)) {\n placement = 'bottom';\n } else if (['bottom', 'bottom-start', 'bottom-end'].includes(originalPlacement)) {\n placement = 'top';\n } else if (['right', 'right-start', 'right-end'].includes(originalPlacement)) {\n placement = 'left';\n } else if (['left', 'left-start', 'left-end'].includes(originalPlacement)) {\n placement = 'right';\n }\n candidate = getCandidatePosition(placement);\n const leftCandidate = getCandidatePosition('left');\n const bottomCandidate = getCandidatePosition('bottom');\n const topCandidate = getCandidatePosition('top');\n if (\n !candidateFits(leftCandidate.top, leftCandidate.left) &&\n !candidateFits(bottomCandidate.top, bottomCandidate.left) &&\n !candidateFits(topCandidate.top, topCandidate.left)\n ) {\n placement = 'right';\n candidate = getCandidatePosition(placement);\n }\n else {\n const rightCandidate = getCandidatePosition('right');\n if (\n !candidateFits(rightCandidate.top, rightCandidate.left) &&\n !candidateFits(bottomCandidate.top, bottomCandidate.left) &&\n !candidateFits(topCandidate.top, topCandidate.left)\n ) {\n placement = 'left';\n candidate = getCandidatePosition(placement);\n }\n }\n }\n\n if (candidate.left < 0) {\n candidate.left = 5;\n } else if (candidate.left + tooltipRect.width > viewportWidth) {\n candidate.left = viewportWidth - tooltipRect.width - 5;\n }\n\n if (candidate.top < 0) {\n candidate.top = 5;\n } else if (candidate.top + tooltipRect.height > viewportHeight) {\n candidate.top = viewportHeight - tooltipRect.height - 5;\n }\n\n return { ...candidate, placement };\n}\n\n\n\nexport interface CaretPositionInput {\n placement: string;\n tooltipRect: DOMRect;\n triggerRect: DOMRect;\n caretSize: number;\n left: number;\n top: number;\n}\n\nexport function getCaretPosition({\n placement,\n tooltipRect,\n triggerRect,\n caretSize,\n left,\n top\n}: CaretPositionInput): { caretLeft: number; caretTop: number } {\n const triggerCenterX = triggerRect.left + triggerRect.width / 2;\n const triggerCenterY = triggerRect.top + triggerRect.height / 2;\n\n const [primaryPlacement, secondaryPlacement] = placement.split('-');\n\n let caretLeft = 0;\n let caretTop = 0;\n\n switch (primaryPlacement) {\n case 'top':\n caretTop = tooltipRect.height - caretSize;\n caretLeft = triggerCenterX - left - caretSize;\n if (placement === 'top-end') {\n caretLeft = triggerCenterX - left - caretSize;\n } else if (secondaryPlacement === 'start') {\n caretLeft = triggerCenterX - left - caretSize;\n } else if (secondaryPlacement === 'end') {\n caretLeft = tooltipRect.width - 2 * caretSize + 8;\n }\n caretLeft = Math.max(caretSize, Math.min(caretLeft, tooltipRect.width - 2 * caretSize));\n break;\n\n case 'bottom':\n caretTop = -caretSize;\n caretLeft = triggerCenterX - left - caretSize;\n break;\n\n case 'left':\n caretLeft = tooltipRect.width - caretSize;\n if (secondaryPlacement === 'start') {\n const computedCaretTop = triggerCenterY - top - caretSize;\n const minCaretTop = triggerRect.top - top;\n caretTop = Math.max(computedCaretTop, minCaretTop);\n } else if (secondaryPlacement === 'end') {\n const computedCaretTop = triggerCenterY - top - caretSize;\n const maxCaretTop = triggerRect.bottom - top - 2 * caretSize;\n caretTop = Math.min(computedCaretTop, maxCaretTop);\n } else {\n caretTop = triggerCenterY - top - caretSize;\n }\n caretTop = Math.max(caretSize, Math.min(caretTop, tooltipRect.height - 2 * caretSize));\n break;\n\n\n case 'right':\n caretLeft = -caretSize;\n if (secondaryPlacement === 'start') {\n const computedCaretTop = triggerCenterY - top - caretSize;\n const minCaretTop = triggerRect.top - top;\n caretTop = Math.max(computedCaretTop, minCaretTop);\n } else if (secondaryPlacement === 'end') {\n const computedCaretTop = triggerCenterY - top - caretSize;\n const maxCaretTop = triggerRect.bottom - top - 2 * caretSize;\n caretTop = Math.min(computedCaretTop, maxCaretTop);\n } else {\n caretTop = triggerCenterY - top - caretSize;\n }\n caretTop = Math.max(caretSize, Math.min(caretTop, tooltipRect.height - 2 * caretSize));\n break;\n\n\n default:\n caretLeft = tooltipRect.width / 2 - caretSize;\n caretTop = tooltipRect.height / 2 - caretSize;\n }\n\n return { caretLeft, caretTop };\n}\n"]}
@@ -9,60 +9,93 @@ import { css } from 'lit';
9
9
  * Tooltip CSS
10
10
  */
11
11
  export const styles = css `
12
- :host {
13
- --max-width: 20rem;
14
- --hide-delay: 0ms;
15
- --show-delay: 150ms;
16
12
 
17
- display: contents;
18
- }
19
13
 
20
- .tooltip {
21
- --arrow-size: 6px;
22
- --arrow-color: var(--nile-tooltip-color-background);
23
- }
14
+ :host {
15
+ position: relative;
16
+ display: inline-block;
17
+ }
18
+ .tooltip {
19
+ position: fixed;
20
+ z-index: 1000;
21
+ background-color: var(--nile-tooltip-color-background, #333);
22
+ color: var(--nile-colors-white-base, #fff);
23
+ padding: 6px 10px;
24
+ border-radius: 4px;
25
+ font-size: var(--nile-tooltip-font-size-sm, 14px);
26
+ line-height: var(--nile-tooltip-line-height-sm, 1.5);
27
+ opacity: 0;
28
+ transition: opacity 0.2s, transform 0.2s;
29
+ pointer-events: none;
30
+ white-space: normal;
31
+ visibility: hidden;
32
+ overflow: visible;
33
+
34
+ }
35
+ :host([open]) .tooltip {
36
+ opacity: 1;
37
+ visibility: visible;
38
+ pointer-events: auto;
39
+ }
40
+ .tooltip-content {
41
+ overflow: auto;
42
+ max-width: 250px;
43
+ max-height: 116px;
44
+ }
45
+ .tooltip-caret {
46
+ position: absolute;
47
+ width: calc(2 * var(--caret-size, 6px));
48
+ height: calc(2 * var(--caret-size, 6px));
49
+ background-color: inherit;
50
+ transform: rotate(45deg);
51
+ z-index: -1;
52
+ }
53
+ .trigger-container {
54
+ display: inline-block;
55
+ }
56
+
57
+
58
+ :host([open]) .tooltip {
59
+ visibility: visible;
60
+ pointer-events: auto;
61
+ animation: fadeIn 150ms forwards;
62
+ }
24
63
 
25
- .tooltip::part(popup) {
26
- pointer-events: none;
27
- z-index: 1000;
28
- }
64
+
65
+ .tooltip.hide {
66
+ animation: fadeOut 100ms forwards;
67
+ }
29
68
 
30
- .tooltip[placement^='top']::part(popup) {
31
- transform-origin: bottom;
69
+
70
+ @keyframes fadeIn {
71
+ from {
72
+ opacity: 0;
73
+ transform: translateY(5px);
32
74
  }
33
-
34
- .tooltip[placement^='bottom']::part(popup) {
35
- transform-origin: top;
75
+ to {
76
+ opacity: 1;
77
+ transform: translateY(0);
36
78
  }
79
+ }
37
80
 
38
- .tooltip[placement^='left']::part(popup) {
39
- transform-origin: right;
81
+
82
+ @keyframes fadeOut {
83
+ from {
84
+ opacity: 1;
85
+ transform: translateY(0);
40
86
  }
41
-
42
- .tooltip[placement^='right']::part(popup) {
43
- transform-origin: left;
87
+ to {
88
+ opacity: 0;
89
+ transform: translateY(5px);
44
90
  }
91
+ }
45
92
 
46
- .tooltip__body {
47
- display: block;
48
- width: max-content;
49
- max-width: var(--max-width);
50
- border-radius: 4px;
51
- background-color: var(--nile-tooltip-color-background);
52
- font-size: var(--nile-tooltip-font-size-sm);
53
- font-weight: var(--nile-tooltip-font-weight-sm);
54
- line-height: var(--nile-tooltip-line-height-sm);
55
- padding: var(--nile-tooltip-padding-y) var(--nile-tooltip-padding-x);
56
- color: var(--nile-colors-white-base);
57
- pointer-events: none;
58
- word-break: break-word;
59
- }
60
93
 
61
- .tooltip__body--large {
62
- font-size: var(--nile-tooltip-font-size-lg);
63
- line-height: var(--nile-tooltip-line-height-lg);
64
- font-weight: var(--nile-tooltip-font-weight-lg);
65
- }
94
+
95
+
96
+
97
+
98
+
66
99
  `;
67
100
  export default [styles];
68
101
  //# sourceMappingURL=nile-tooltip.css.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nile-tooltip.css.js","sourceRoot":"","sources":["../../../src/nile-tooltip/nile-tooltip.css.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuDxB,CAAC;AAEF,eAAe,CAAC,MAAM,CAAC,CAAC","sourcesContent":["/**\n * Copyright Aquera Inc 2023\n *\n * This source code is licensed under the BSD-3-Clause license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { css } from 'lit';\n\n/**\n * Tooltip CSS\n */\nexport const styles = css`\n :host {\n --max-width: 20rem;\n --hide-delay: 0ms;\n --show-delay: 150ms;\n\n display: contents;\n }\n\n .tooltip {\n --arrow-size: 6px;\n --arrow-color: var(--nile-tooltip-color-background);\n }\n\n .tooltip::part(popup) {\n pointer-events: none;\n z-index: 1000;\n }\n\n .tooltip[placement^='top']::part(popup) {\n transform-origin: bottom;\n }\n\n .tooltip[placement^='bottom']::part(popup) {\n transform-origin: top;\n }\n\n .tooltip[placement^='left']::part(popup) {\n transform-origin: right;\n }\n\n .tooltip[placement^='right']::part(popup) {\n transform-origin: left;\n }\n\n .tooltip__body {\n display: block;\n width: max-content;\n max-width: var(--max-width);\n border-radius: 4px;\n background-color: var(--nile-tooltip-color-background);\n font-size: var(--nile-tooltip-font-size-sm);\n font-weight: var(--nile-tooltip-font-weight-sm);\n line-height: var(--nile-tooltip-line-height-sm);\n padding: var(--nile-tooltip-padding-y) var(--nile-tooltip-padding-x);\n color: var(--nile-colors-white-base);\n pointer-events: none;\n word-break: break-word;\n }\n\n .tooltip__body--large {\n font-size: var(--nile-tooltip-font-size-lg);\n line-height: var(--nile-tooltip-line-height-lg);\n font-weight: var(--nile-tooltip-font-weight-lg);\n }\n`;\n\nexport default [styles];\n"]}
1
+ {"version":3,"file":"nile-tooltip.css.js","sourceRoot":"","sources":["../../../src/nile-tooltip/nile-tooltip.css.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B;;GAEG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwFxB,CAAC;AAEF,eAAe,CAAC,MAAM,CAAC,CAAC","sourcesContent":["/**\n * Copyright Aquera Inc 2023\n *\n * This source code is licensed under the BSD-3-Clause license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\nimport { css } from 'lit';\n\n/**\n * Tooltip CSS\n */\nexport const styles = css`\n\n\n:host {\n position: relative;\n display: inline-block;\n }\n .tooltip {\n position: fixed;\n z-index: 1000;\n background-color: var(--nile-tooltip-color-background, #333);\n color: var(--nile-colors-white-base, #fff);\n padding: 6px 10px;\n border-radius: 4px;\n font-size: var(--nile-tooltip-font-size-sm, 14px);\n line-height: var(--nile-tooltip-line-height-sm, 1.5);\n opacity: 0;\n transition: opacity 0.2s, transform 0.2s;\n pointer-events: none;\n white-space: normal;\n visibility: hidden;\n overflow: visible;\n \n }\n :host([open]) .tooltip {\n opacity: 1;\n visibility: visible;\n pointer-events: auto;\n }\n .tooltip-content {\n overflow: auto;\n max-width: 250px;\n max-height: 116px;\n }\n .tooltip-caret {\n position: absolute;\n width: calc(2 * var(--caret-size, 6px));\n height: calc(2 * var(--caret-size, 6px));\n background-color: inherit;\n transform: rotate(45deg);\n z-index: -1;\n }\n .trigger-container {\n display: inline-block;\n }\n \n \n:host([open]) .tooltip {\n visibility: visible;\n pointer-events: auto;\n animation: fadeIn 150ms forwards;\n}\n\n \n.tooltip.hide {\n animation: fadeOut 100ms forwards;\n}\n\n \n@keyframes fadeIn {\n from {\n opacity: 0;\n transform: translateY(5px);\n }\n to {\n opacity: 1;\n transform: translateY(0);\n }\n}\n\n \n@keyframes fadeOut {\n from {\n opacity: 1;\n transform: translateY(0);\n }\n to {\n opacity: 0;\n transform: translateY(5px);\n }\n}\n\n\n\n\n\n\n \n`;\n\nexport default [styles];"]}
@@ -4,75 +4,53 @@
4
4
  * This source code is licensed under the BSD-3-Clause license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import { CSSResultArray, TemplateResult } from 'lit';
8
- import '../nile-popup/nile-popup';
7
+ import { CSSResultArray } from 'lit';
9
8
  import NileElement from '../internal/nile-element';
10
- import type NilePopup from '../nile-popup/nile-popup';
11
9
  /**
12
- * Nile icon component.
10
+ * Nile tooltip component.
13
11
  *
14
12
  * @tag nile-tooltip
15
13
  *
16
14
  */
17
15
  export declare class NileTooltip extends NileElement {
18
- /**
19
- * The styles for Tooltip
20
- * @remarks If you are extending this class you can extend the base styles with super. Eg `return [super(), myCustomStyles]`
21
- */
22
- static get styles(): CSSResultArray;
23
- private hoverTimeout;
24
- defaultSlot: HTMLSlotElement;
25
- body: HTMLElement;
26
- popup: NilePopup;
27
- /** The tooltip's content. If you need to display HTML, use the `content` slot instead. */
28
16
  content: string;
29
- /** Size Property to decide the tool tip size */
30
- size: 'small' | 'large';
31
- /**
32
- * The preferred placement of the tooltip. Note that the actual placement may vary as needed to keep the tooltip
33
- * inside of the viewport.
34
- */
35
17
  placement: 'top' | 'top-start' | 'top-end' | 'right' | 'right-start' | 'right-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end';
36
- /** Disables the tooltip so it won't show when triggered. */
37
18
  disabled: boolean;
38
- /** The distance in pixels from which to offset the tooltip away from its target. */
39
- distance: number;
40
- /** Indicates whether or not the tooltip is open. You can use this in lieu of the show/hide methods. */
41
19
  open: boolean;
42
- /** The distance in pixels from which to offset the tooltip along its target. */
43
- skidding: number;
44
20
  /**
45
21
  * Controls how the tooltip is activated. Possible options include `click`, `hover`, `focus`, and `manual`. Multiple
46
22
  * options can be passed by separating them with a space. When manual is used, the tooltip must be activated
47
23
  * programmatically.
48
24
  */
49
25
  trigger: string;
50
- /**
51
- * Enable this option to prevent the tooltip from being clipped when the component is placed inside a container with
52
- * `overflow: auto|hidden|scroll`. Hoisting uses a fixed positioning strategy that works in many, but not all,
53
- * scenarios.
54
- */
26
+ distance: number;
27
+ private readonly SHIFT_OFFSET;
28
+ /** The distance in pixels from which to offset the tooltip along its target. */
29
+ skidding: number;
55
30
  hoist: boolean;
31
+ tooltip: HTMLElement;
32
+ triggerContainer: HTMLElement;
33
+ caret: HTMLElement;
34
+ tooltipSlot: HTMLSlotElement;
35
+ private hasTooltipSlot;
36
+ private hoverTimeout;
37
+ private caretSize;
38
+ private originalPlacement;
39
+ static get styles(): CSSResultArray;
56
40
  connectedCallback(): void;
57
- firstUpdated(): void;
41
+ updated(changedProps: Map<string, unknown>): void;
58
42
  disconnectedCallback(): void;
59
- private handleBlur;
60
- private handleClick;
61
- private handleFocus;
62
- private handleKeyDown;
43
+ private handleTooltipSlotChange;
44
+ private updateTooltipPosition;
45
+ private showTooltip;
46
+ private hideTooltip;
63
47
  private handleMouseOver;
64
48
  private handleMouseOut;
65
- private hasTrigger;
66
- handleOpenChange(): Promise<void>;
67
- handleOptionsChange(): Promise<void>;
68
- handleDisabledChange(): void;
69
- /** Shows the tooltip. */
70
- show(): Promise<void>;
71
- /** Hides the tooltip */
72
- hide(): Promise<void>;
73
- render(): TemplateResult<1>;
49
+ private handleClick;
50
+ private handleFocus;
51
+ private handleBlur;
52
+ render(): import("lit-html").TemplateResult<1>;
74
53
  }
75
- export default NileTooltip;
76
54
  declare global {
77
55
  interface HTMLElementTagNameMap {
78
56
  'nile-tooltip': NileTooltip;