-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathComparisonGrid.vue
More file actions
314 lines (287 loc) · 9.75 KB
/
ComparisonGrid.vue
File metadata and controls
314 lines (287 loc) · 9.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<script setup lang="ts">
import type { ModuleReplacement } from 'module-replacements'
const props = defineProps<{
/** Number of columns (2-4) */
columns: number
/** Column headers (package names or version numbers) */
headers: string[]
/** Which columns are the "no dependency" column */
specialColumns?: boolean[]
/** Replacement data for each column (if available) */
replacements?: (ModuleReplacement | null)[]
}>()
// Tooltip state
const activeTooltip = shallowRef<{
type: 'nodep' | 'replacement'
index: number
} | null>(null)
// Computed message for active replacement tooltip
const activeReplacementMessage = computed<
[string, { replacement?: string; nodeVersion?: string }] | null
>(() => {
if (activeTooltip.value?.type !== 'replacement') return null
const replacement = props.replacements?.[activeTooltip.value.index]
if (!replacement) return null
switch (replacement.type) {
case 'native':
return [
'package.replacement.native',
{
replacement: replacement.replacement,
nodeVersion: replacement.nodeVersion,
},
]
case 'simple':
return [
'package.replacement.simple',
{
replacement: replacement.replacement,
},
]
case 'documented':
return ['package.replacement.documented', {}]
default:
return null
}
})
const tooltipTrigger = shallowRef<HTMLElement | null>(null)
const tooltipPosition = shallowRef({ top: 0, left: 0 })
const hideTimeout = shallowRef<ReturnType<typeof setTimeout> | null>(null)
function updateTooltipPosition() {
if (!tooltipTrigger.value) return
const rect = tooltipTrigger.value.getBoundingClientRect()
tooltipPosition.value = {
top: rect.bottom + 8,
left: rect.left + rect.width / 2,
}
}
function cancelHide() {
if (hideTimeout.value) {
clearTimeout(hideTimeout.value)
hideTimeout.value = null
}
}
function showNoDep(event: MouseEvent | FocusEvent) {
cancelHide()
tooltipTrigger.value = event.currentTarget as HTMLElement
updateTooltipPosition()
activeTooltip.value = { type: 'nodep', index: -1 }
}
function showReplacement(event: MouseEvent | FocusEvent, index: number) {
cancelHide()
tooltipTrigger.value = event.currentTarget as HTMLElement
updateTooltipPosition()
activeTooltip.value = { type: 'replacement', index }
}
function hideTooltip() {
hideTimeout.value = setTimeout(() => {
activeTooltip.value = null
}, 150)
}
function onTooltipEnter() {
cancelHide()
}
function onTooltipLeave() {
activeTooltip.value = null
}
</script>
<template>
<div class="overflow-x-auto">
<div
class="comparison-grid"
:class="[columns === 4 ? 'min-w-[800px]' : 'min-w-[600px]', `columns-${columns}`]"
:style="{ '--columns': columns }"
>
<!-- Header row -->
<div class="comparison-header">
<div class="comparison-label" />
<div
v-for="(header, index) in headers"
:key="index"
class="comparison-cell comparison-cell-header"
:class="{ 'comparison-cell-special': specialColumns?.[index] }"
>
<!-- "No dep" header with tooltip (James easter egg) -->
<button
v-if="specialColumns?.[index]"
type="button"
class="inline-flex items-center gap-1.5 cursor-help bg-transparent border-0 p-0"
:aria-label="$t('compare.no_dependency.label')"
@mouseenter="showNoDep"
@mouseleave="hideTooltip"
@focus="showNoDep"
@blur="hideTooltip"
>
<span class="text-sm font-medium text-accent italic truncate">
{{ header }}
</span>
<span class="i-carbon:help w-3 h-3 text-accent/60" aria-hidden="true" />
</button>
<!-- Package header with replacement info -->
<button
v-else-if="replacements?.[index]"
type="button"
class="inline-flex items-center gap-1.5 cursor-help bg-transparent border-0 p-0"
:aria-label="$t('package.replacement.title')"
@mouseenter="showReplacement($event, index)"
@mouseleave="hideTooltip"
@focus="showReplacement($event, index)"
@blur="hideTooltip"
>
<span class="font-mono text-sm font-medium text-fg truncate" :title="header">
{{ header }}
</span>
<span class="i-carbon:idea w-3.5 h-3.5 text-amber-500" aria-hidden="true" />
</button>
<!-- Regular package header (no replacement) -->
<span v-else class="font-mono text-sm font-medium text-fg truncate" :title="header">
{{ header }}
</span>
</div>
</div>
<!-- Facet rows -->
<slot />
</div>
<!-- Tooltips (teleported to body to avoid overflow clipping) -->
<Teleport to="body">
<Transition
enter-active-class="transition-opacity duration-150"
enter-from-class="opacity-0"
leave-active-class="transition-opacity duration-100"
leave-to-class="opacity-0"
>
<!-- "No dep" tooltip -->
<div
v-if="activeTooltip?.type === 'nodep'"
role="tooltip"
class="fixed z-[100] w-72 p-3 bg-bg-elevated border border-border rounded-lg shadow-lg text-start -translate-x-1/2"
:style="{
top: `${tooltipPosition.top}px`,
left: `${tooltipPosition.left}px`,
}"
@mouseenter="onTooltipEnter"
@mouseleave="onTooltipLeave"
>
<div class="flex gap-3">
<img
src="/43081j.png"
alt="James Garbutt"
class="w-12 h-12 rounded-lg object-cover flex-shrink-0"
/>
<div class="min-w-0">
<p class="text-xs text-accent italic mb-0.5">
{{ $t('compare.no_dependency.james_says') }}
</p>
<p class="text-sm font-medium text-fg mb-1">
{{ $t('package.replacement.title') }}
</p>
<p class="text-xs text-fg-muted">
<i18n-t keypath="compare.no_dependency.tooltip_description" tag="span">
<template #link>
<a
href="https://e18e.dev/docs/replacements/"
target="_blank"
rel="noopener noreferrer"
class="text-accent hover:underline"
>{{ $t('compare.no_dependency.e18e_community') }}</a
>
</template>
</i18n-t>
</p>
</div>
</div>
<!-- Tooltip arrow -->
<div
class="absolute -top-1.5 left-1/2 -translate-x-1/2 w-3 h-3 bg-bg-elevated border-t border-l border-border rotate-45"
/>
</div>
<!-- Replacement tooltip -->
<div
v-else-if="activeReplacementMessage"
role="tooltip"
class="fixed z-[100] w-80 p-3 bg-bg-elevated border border-amber-600/30 rounded-lg shadow-lg text-start -translate-x-1/2"
:style="{
top: `${tooltipPosition.top}px`,
left: `${tooltipPosition.left}px`,
}"
@mouseenter="onTooltipEnter"
@mouseleave="onTooltipLeave"
>
<div class="flex items-start gap-2">
<span
class="i-carbon:idea w-4 h-4 text-amber-500 flex-shrink-0 mt-0.5"
aria-hidden="true"
/>
<div class="min-w-0">
<p class="text-sm font-medium text-fg mb-1">
{{ $t('package.replacement.title') }}
</p>
<p class="text-xs text-fg-muted">
<i18n-t :keypath="activeReplacementMessage[0]" tag="span">
<template #replacement>
{{ activeReplacementMessage[1].replacement ?? '' }}
</template>
<template #nodeVersion>
{{ activeReplacementMessage[1].nodeVersion ?? '' }}
</template>
<template #community>
{{ $t('package.replacement.community') }}
</template>
</i18n-t>
</p>
</div>
</div>
<!-- Tooltip arrow -->
<div
class="absolute -top-1.5 left-1/2 -translate-x-1/2 w-3 h-3 bg-bg-elevated border-t border-l border-amber-600/30 rotate-45"
/>
</div>
</Transition>
</Teleport>
</div>
</template>
<style scoped>
.comparison-grid {
display: grid;
gap: 0;
}
.comparison-grid.columns-2 {
grid-template-columns: minmax(120px, 180px) repeat(2, 1fr);
}
.comparison-grid.columns-3 {
grid-template-columns: minmax(120px, 160px) repeat(3, 1fr);
}
.comparison-grid.columns-4 {
grid-template-columns: minmax(100px, 140px) repeat(4, 1fr);
}
.comparison-header {
display: contents;
}
.comparison-header > .comparison-label {
padding: 0.75rem 1rem;
border-bottom: 1px solid var(--color-border);
}
.comparison-header > .comparison-cell-header {
padding: 0.75rem 1rem;
background: var(--color-bg-subtle);
border-bottom: 1px solid var(--color-border);
text-align: center;
}
/* "No dep" column styling */
.comparison-header > .comparison-cell-header.comparison-cell-special {
background: linear-gradient(
135deg,
var(--color-bg-subtle) 0%,
color-mix(in srgb, var(--color-accent) 8%, var(--color-bg-subtle)) 100%
);
border-bottom-color: color-mix(in srgb, var(--color-accent) 30%, var(--color-border));
}
/* First header cell rounded top-start */
.comparison-header > .comparison-cell-header:first-of-type {
border-start-start-radius: 0.5rem;
}
/* Last header cell rounded top-end */
.comparison-header > .comparison-cell-header:last-of-type {
border-start-end-radius: 0.5rem;
}
</style>