forked from npmx-dev/npmx.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComparisonGrid.vue
More file actions
150 lines (133 loc) · 4.78 KB
/
ComparisonGrid.vue
File metadata and controls
150 lines (133 loc) · 4.78 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
<script setup lang="ts">
import type { ModuleReplacement } from 'module-replacements'
export interface ComparisonGridColumn {
name: string
version?: string
/** Module replacement data for this package (if available) */
replacement?: ModuleReplacement | null
}
const props = defineProps<{
/** Column definitions for each package being compared */
columns: ComparisonGridColumn[]
/** Whether to show the "no dependency" baseline as the last column */
showNoDependency?: boolean
}>()
/** Total column count including the optional no-dep column */
const totalColumns = computed(() => props.columns.length + (props.showNoDependency ? 1 : 0))
/** Compute plain-text tooltip for a replacement column */
function getReplacementTooltip(col: ComparisonGridColumn): string {
if (!col.replacement) return ''
return [$t('package.replacement.title'), $t('package.replacement.learn_more_above')].join(' ')
}
</script>
<template>
<div class="overflow-x-auto">
<div class="comparison-grid" :style="{ '--package-count': totalColumns }">
<!-- Header row -->
<div class="comparison-header">
<div class="comparison-label" />
<!-- Package columns -->
<div
v-for="col in columns"
:key="col.name"
class="comparison-cell comparison-cell-header min-w-0"
>
<div class="flex items-start justify-center gap-1.5 min-w-0">
<LinkBase
:to="packageRoute(col.name, col.version)"
class="flex min-w-0 flex-col items-center text-center text-sm"
:title="col.version ? `${col.name}@${col.version}` : col.name"
>
<span class="min-w-0 break-words line-clamp-1">
{{ col.name }}
</span>
<span v-if="col.version" class="text-fg-muted line-clamp-1">
@{{ col.version }}
</span>
</LinkBase>
<TooltipApp v-if="col.replacement" :text="getReplacementTooltip(col)" position="bottom">
<span
class="i-lucide:lightbulb mt-0.5 h-3.5 w-3.5 shrink-0 cursor-help text-amber-500"
role="img"
:aria-label="$t('package.replacement.title')"
/>
</TooltipApp>
</div>
</div>
<!-- "No dep" column (always last) -->
<div
v-if="showNoDependency"
class="comparison-cell comparison-cell-header comparison-cell-nodep"
>
<span
class="inline-flex items-center gap-1.5 text-sm font-medium text-accent italic truncate"
>
{{ $t('compare.no_dependency.label') }}
<TooltipApp interactive position="bottom">
<span
class="i-lucide:lightbulb w-3.5 h-3.5 text-amber-500 shrink-0 cursor-help"
role="img"
:aria-label="$t('compare.no_dependency.tooltip_title')"
/>
<template #content>
<p class="text-sm font-medium text-fg mb-1">
{{ $t('compare.no_dependency.tooltip_title') }}
</p>
<p class="text-xs text-fg-muted">
<i18n-t keypath="compare.no_dependency.tooltip_description" tag="span">
<template #link>
<LinkBase to="https://e18e.dev/docs/replacements/">{{
$t('compare.no_dependency.e18e_community')
}}</LinkBase>
</template>
</i18n-t>
</p>
</template>
</TooltipApp>
</span>
</div>
</div>
<!-- Facet rows -->
<slot />
</div>
</div>
</template>
<style scoped>
.comparison-grid {
display: grid;
gap: 0;
grid-template-columns:
minmax(110px, 150px)
repeat(var(--package-count), minmax(0, 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-nodep {
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>