Skip to content

Commit e784d3a

Browse files
committed
Refine compare grid header layout
1 parent 5db5dc6 commit e784d3a

File tree

3 files changed

+42
-57
lines changed

3 files changed

+42
-57
lines changed

app/components/Compare/ComparisonGrid.vue

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,39 @@ function getReplacementTooltip(col: ComparisonGridColumn): string {
2828

2929
<template>
3030
<div class="overflow-x-auto">
31-
<div
32-
class="comparison-grid"
33-
:class="[totalColumns === 4 ? 'min-w-[800px]' : 'min-w-[600px]', `columns-${totalColumns}`]"
34-
:style="{ '--columns': totalColumns }"
35-
>
31+
<div class="comparison-grid" :style="{ '--package-count': totalColumns }">
3632
<!-- Header row -->
3733
<div class="comparison-header">
3834
<div class="comparison-label" />
3935

4036
<!-- Package columns -->
41-
<div v-for="col in columns" :key="col.name" class="comparison-cell comparison-cell-header">
42-
<span class="inline-flex items-center gap-1.5 truncate">
37+
<div
38+
v-for="col in columns"
39+
:key="col.name"
40+
class="comparison-cell comparison-cell-header min-w-0"
41+
>
42+
<div class="flex items-start justify-center gap-1.5 min-w-0">
4343
<LinkBase
4444
:to="packageRoute(col.name, col.version)"
45-
class="text-sm truncate"
46-
block
45+
class="flex min-w-0 flex-col items-center text-center text-sm"
4746
:title="col.version ? `${col.name}@${col.version}` : col.name"
4847
>
49-
{{ col.name }}<template v-if="col.version">@{{ col.version }}</template>
48+
<span class="min-w-0 break-words line-clamp-1">
49+
{{ col.name }}
50+
</span>
51+
<span v-if="col.version" class="text-fg-muted line-clamp-1">
52+
@{{ col.version }}
53+
</span>
5054
</LinkBase>
55+
5156
<TooltipApp v-if="col.replacement" :text="getReplacementTooltip(col)" position="bottom">
5257
<span
53-
class="i-lucide:lightbulb w-3.5 h-3.5 text-amber-500 shrink-0 cursor-help"
58+
class="i-lucide:lightbulb mt-0.5 h-3.5 w-3.5 shrink-0 cursor-help text-amber-500"
5459
role="img"
5560
:aria-label="$t('package.replacement.title')"
5661
/>
5762
</TooltipApp>
58-
</span>
63+
</div>
5964
</div>
6065

6166
<!-- "No dep" column (always last) -->
@@ -102,18 +107,9 @@ function getReplacementTooltip(col: ComparisonGridColumn): string {
102107
.comparison-grid {
103108
display: grid;
104109
gap: 0;
105-
}
106-
107-
.comparison-grid.columns-2 {
108-
grid-template-columns: minmax(120px, 180px) repeat(2, 1fr);
109-
}
110-
111-
.comparison-grid.columns-3 {
112-
grid-template-columns: minmax(120px, 160px) repeat(3, 1fr);
113-
}
114-
115-
.comparison-grid.columns-4 {
116-
grid-template-columns: minmax(100px, 140px) repeat(4, 1fr);
110+
grid-template-columns:
111+
minmax(110px, 150px)
112+
repeat(var(--package-count), minmax(0, 1fr));
117113
}
118114
119115
.comparison-header {

test/e2e/interactions.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test.describe('Compare Page', () => {
3838
await expect(page).toHaveURL(/packages=vue,nuxt,__no_dependency__/)
3939

4040
// Verify column order in the grid: vue, nuxt, then no-dep
41-
const headerLinks = grid.locator('.comparison-cell-header a.truncate')
41+
const headerLinks = grid.locator('.comparison-cell-header a[title]')
4242
await expect(headerLinks).toHaveCount(2)
4343
await expect(headerLinks.nth(0)).toContainText('vue')
4444
await expect(headerLinks.nth(1)).toContainText('nuxt')

test/nuxt/components/compare/ComparisonGrid.spec.ts

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ describe('ComparisonGrid', () => {
1717
columns: cols('lodash@4.17.21', 'underscore@1.13.6'),
1818
},
1919
})
20-
expect(component.text()).toContain('lodash@4.17.21')
21-
expect(component.text()).toContain('underscore@1.13.6')
20+
expect(component.text()).toContain('lodash')
21+
expect(component.text()).toContain('@4.17.21')
22+
expect(component.text()).toContain('underscore')
23+
expect(component.text()).toContain('@1.13.6')
2224
})
2325

2426
it('renders correct number of header cells', async () => {
@@ -43,74 +45,61 @@ describe('ComparisonGrid', () => {
4345
expect(component.find('.comparison-cell-nodep').exists()).toBe(true)
4446
})
4547

46-
it('truncates long header text with title attribute', async () => {
48+
it('renders package name and version on separate clamped lines with a full title attribute', async () => {
4749
const longName = 'very-long-package-name@1.0.0-beta.1'
4850
const component = await mountSuspended(ComparisonGrid, {
4951
props: {
5052
columns: cols(longName, 'short'),
5153
},
5254
})
53-
const links = component.findAll('a.truncate')
54-
const longLink = links.find(a => a.text() === longName)
55-
expect(longLink?.attributes('title')).toBe(longName)
55+
56+
const link = component.find(`a[title="${longName}"]`)
57+
expect(link.exists()).toBe(true)
58+
expect(link.attributes('title')).toBe(longName)
59+
expect(link.findAll('.line-clamp-1')).toHaveLength(2)
5660
})
5761
})
5862

5963
describe('column layout', () => {
60-
it('applies columns-2 class for 2 columns', async () => {
64+
it('sets --package-count to the number of package columns', async () => {
6165
const component = await mountSuspended(ComparisonGrid, {
6266
props: {
6367
columns: cols('a', 'b'),
6468
},
6569
})
66-
expect(component.find('.columns-2').exists()).toBe(true)
70+
const grid = component.find('.comparison-grid')
71+
expect(grid.attributes('style')).toContain('--package-count: 2')
6772
})
6873

69-
it('applies columns-3 class for 2 packages + no-dep', async () => {
74+
it('includes the no-dependency column in --package-count', async () => {
7075
const component = await mountSuspended(ComparisonGrid, {
7176
props: {
7277
columns: cols('a', 'b'),
7378
showNoDependency: true,
7479
},
7580
})
76-
expect(component.find('.columns-3').exists()).toBe(true)
77-
})
78-
79-
it('applies columns-4 class for 4 columns', async () => {
80-
const component = await mountSuspended(ComparisonGrid, {
81-
props: {
82-
columns: cols('a', 'b', 'c', 'd'),
83-
},
84-
})
85-
expect(component.find('.columns-4').exists()).toBe(true)
81+
const grid = component.find('.comparison-grid')
82+
expect(grid.attributes('style')).toContain('--package-count: 3')
8683
})
8784

88-
it('sets min-width for 4 columns to 800px', async () => {
85+
it('supports four package columns with the generic grid layout', async () => {
8986
const component = await mountSuspended(ComparisonGrid, {
9087
props: {
9188
columns: cols('a', 'b', 'c', 'd'),
9289
},
9390
})
94-
expect(component.find('.min-w-\\[800px\\]').exists()).toBe(true)
95-
})
96-
97-
it('sets min-width for 2-3 columns to 600px', async () => {
98-
const component = await mountSuspended(ComparisonGrid, {
99-
props: {
100-
columns: cols('a', 'b'),
101-
},
102-
})
103-
expect(component.find('.min-w-\\[600px\\]').exists()).toBe(true)
91+
const grid = component.find('.comparison-grid')
92+
expect(grid.attributes('style')).toContain('--package-count: 4')
10493
})
10594

106-
it('sets --columns CSS variable', async () => {
95+
it('sets --package-count CSS variable', async () => {
10796
const component = await mountSuspended(ComparisonGrid, {
10897
props: {
10998
columns: cols('a', 'b', 'c'),
11099
},
111100
})
112101
const grid = component.find('.comparison-grid')
113-
expect(grid.attributes('style')).toContain('--columns: 3')
102+
expect(grid.attributes('style')).toContain('--package-count: 3')
114103
})
115104
})
116105

0 commit comments

Comments
 (0)