Skip to content

Commit 6e8995f

Browse files
committed
refactor: use button and link components on compare page
1 parent 8202b52 commit 6e8995f

File tree

6 files changed

+55
-86
lines changed

6 files changed

+55
-86
lines changed

app/components/Compare/ComparisonGrid.vue

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ function getReplacementTooltip(col: ComparisonGridColumn): string {
4040
<!-- Package columns -->
4141
<div v-for="col in columns" :key="col.name" class="comparison-cell comparison-cell-header">
4242
<span class="inline-flex items-center gap-1.5 truncate">
43-
<NuxtLink
43+
<LinkBase
4444
:to="packageRoute(col.name, col.version)"
45-
class="link-subtle font-mono text-sm font-medium text-fg truncate"
45+
class="text-sm"
4646
:title="col.version ? `${col.name}@${col.version}` : col.name"
4747
>
4848
{{ col.name }}<template v-if="col.version">@{{ col.version }}</template>
49-
</NuxtLink>
49+
</LinkBase>
5050
<TooltipApp v-if="col.replacement" :text="getReplacementTooltip(col)" position="bottom">
5151
<span
5252
class="i-carbon:idea w-3.5 h-3.5 text-amber-500 shrink-0 cursor-help"
@@ -79,13 +79,9 @@ function getReplacementTooltip(col: ComparisonGridColumn): string {
7979
<p class="text-xs text-fg-muted">
8080
<i18n-t keypath="compare.no_dependency.tooltip_description" tag="span">
8181
<template #link>
82-
<a
83-
href="https://e18e.dev/docs/replacements/"
84-
target="_blank"
85-
rel="noopener noreferrer"
86-
class="text-accent hover:underline"
87-
>{{ $t('compare.no_dependency.e18e_community') }}</a
88-
>
82+
<LinkBase to="https://e18e.dev/docs/replacements/">{{
83+
$t('compare.no_dependency.e18e_community')
84+
}}</LinkBase>
8985
</template>
9086
</i18n-t>
9187
</p>

app/components/Compare/FacetSelector.vue

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,47 +32,39 @@ function isCategoryNoneSelected(category: string): boolean {
3232
<span class="text-3xs text-fg-subtle uppercase tracking-wider">
3333
{{ getCategoryLabel(category) }}
3434
</span>
35-
<button
36-
type="button"
37-
class="text-3xs transition-colors focus-visible:outline-none focus-visible:underline focus-visible:underline-accent"
38-
:class="
39-
isCategoryAllSelected(category)
40-
? 'text-fg-muted'
41-
: 'text-fg-muted/60 hover:text-fg-muted'
42-
"
35+
<!-- TODO: These should be radios, since they are mutually exclusive, and currently this behavior is faked with buttons -->
36+
<ButtonBase
4337
:aria-label="
4438
$t('compare.facets.select_category', { category: getCategoryLabel(category) })
4539
"
40+
:aria-pressed="isCategoryAllSelected(category)"
4641
:disabled="isCategoryAllSelected(category)"
4742
@click="selectCategory(category)"
43+
size="small"
4844
>
4945
{{ $t('compare.facets.all') }}
50-
</button>
46+
</ButtonBase>
5147
<span class="text-2xs text-fg-muted/40">/</span>
52-
<button
53-
type="button"
54-
class="text-3xs transition-colors focus-visible:outline-none focus-visible:underline focus-visible:underline-accent"
55-
:class="
56-
isCategoryNoneSelected(category)
57-
? 'text-fg-muted'
58-
: 'text-fg-muted/60 hover:text-fg-muted'
59-
"
48+
<ButtonBase
6049
:aria-label="
6150
$t('compare.facets.deselect_category', { category: getCategoryLabel(category) })
6251
"
52+
:aria-pressed="isCategoryNoneSelected(category)"
6353
:disabled="isCategoryNoneSelected(category)"
6454
@click="deselectCategory(category)"
55+
size="small"
6556
>
6657
{{ $t('compare.facets.none') }}
67-
</button>
58+
</ButtonBase>
6859
</div>
6960

7061
<!-- Facet buttons -->
7162
<div class="flex items-center gap-1.5 flex-wrap" role="group">
72-
<button
63+
<!-- TODO: These should be checkboxes -->
64+
<ButtonBase
7365
v-for="facet in facetsByCategory[category]"
7466
:key="facet.id"
75-
type="button"
67+
size="small"
7668
:title="facet.comingSoon ? $t('compare.facets.coming_soon') : facet.description"
7769
:disabled="facet.comingSoon"
7870
:aria-pressed="isFacetSelected(facet.id)"
@@ -86,18 +78,19 @@ function isCategoryNoneSelected(category: string): boolean {
8678
: 'text-fg-subtle bg-bg-subtle border-border-subtle hover:text-fg-muted hover:border-border'
8779
"
8880
@click="!facet.comingSoon && toggleFacet(facet.id)"
81+
:classicon="
82+
facet.comingSoon
83+
? undefined
84+
: isFacetSelected(facet.id)
85+
? 'i-carbon:checkmark'
86+
: 'i-carbon:add'
87+
"
8988
>
90-
<span
91-
v-if="!facet.comingSoon"
92-
class="w-3 h-3"
93-
:class="isFacetSelected(facet.id) ? 'i-carbon:checkmark' : 'i-carbon:add'"
94-
aria-hidden="true"
95-
/>
9689
{{ facet.label }}
9790
<span v-if="facet.comingSoon" class="text-4xs"
9891
>({{ $t('compare.facets.coming_soon') }})</span
9992
>
100-
</button>
93+
</ButtonBase>
10194
</div>
10295
</div>
10396
</div>

app/components/Compare/PackageSelector.vue

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -103,38 +103,28 @@ function handleBlur() {
103103
<div class="space-y-3">
104104
<!-- Selected packages -->
105105
<div v-if="packages.length > 0" class="flex flex-wrap gap-2">
106-
<div
107-
v-for="pkg in packages"
108-
:key="pkg"
109-
class="inline-flex items-center gap-2 px-3 py-1.5 bg-bg-subtle border border-border rounded-md"
110-
>
106+
<TagStatic v-for="pkg in packages" :key="pkg">
111107
<!-- No dependency display -->
112108
<template v-if="pkg === NO_DEPENDENCY_ID">
113109
<span class="text-sm text-accent italic flex items-center gap-1.5">
114110
<span class="i-carbon:clean w-3.5 h-3.5" aria-hidden="true" />
115111
{{ $t('compare.no_dependency.label') }}
116112
</span>
117113
</template>
118-
<NuxtLink
119-
v-else
120-
:to="packageRoute(pkg)"
121-
class="font-mono text-sm text-fg hover:text-accent transition-colors"
122-
>
114+
<LinkBase v-else :to="packageRoute(pkg)" class="text-sm">
123115
{{ pkg }}
124-
</NuxtLink>
125-
<button
126-
type="button"
127-
class="text-fg-subtle hover:text-fg transition-colors rounded"
116+
</LinkBase>
117+
<ButtonBase
118+
size="small"
128119
:aria-label="
129120
$t('compare.selector.remove_package', {
130121
package: pkg === NO_DEPENDENCY_ID ? $t('compare.no_dependency.label') : pkg,
131122
})
132123
"
133124
@click="removePackage(pkg)"
134-
>
135-
<span class="i-carbon:close flex items-center w-3.5 h-3.5" aria-hidden="true" />
136-
</button>
137-
</div>
125+
classicon="i-carbon:close"
126+
/>
127+
</TagStatic>
138128
</div>
139129

140130
<!-- Add package input -->
@@ -181,10 +171,9 @@ function handleBlur() {
181171
class="absolute top-full inset-x-0 mt-1 bg-bg-elevated border border-border rounded-lg shadow-lg z-50 max-h-64 overflow-y-auto"
182172
>
183173
<!-- No dependency option (easter egg with James) -->
184-
<button
174+
<ButtonBase
185175
v-if="showNoDependencyOption"
186-
type="button"
187-
class="w-full text-start px-4 py-2.5 hover:bg-bg-muted transition-colors focus-visible:outline-none focus-visible:bg-bg-muted border-b border-border/50"
176+
class="block w-full text-start"
188177
:aria-label="$t('compare.no_dependency.add_column')"
189178
@click="addPackage(NO_DEPENDENCY_ID)"
190179
>
@@ -195,23 +184,22 @@ function handleBlur() {
195184
<div class="text-xs text-fg-muted truncate mt-0.5">
196185
{{ $t('compare.no_dependency.typeahead_description') }}
197186
</div>
198-
</button>
187+
</ButtonBase>
199188

200189
<div v-if="isSearching" class="px-4 py-3 text-sm text-fg-muted">
201190
{{ $t('compare.selector.searching') }}
202191
</div>
203-
<button
192+
<ButtonBase
204193
v-for="result in filteredResults"
205194
:key="result.name"
206-
type="button"
207-
class="w-full text-start px-4 py-2.5 hover:bg-bg-muted transition-colors focus-visible:outline-none focus-visible:bg-bg-muted"
195+
class="block w-full text-start"
208196
@click="addPackage(result.name)"
209197
>
210198
<div class="font-mono text-sm text-fg">{{ result.name }}</div>
211199
<div v-if="result.description" class="text-xs text-fg-muted truncate mt-0.5">
212200
{{ result.description }}
213201
</div>
214-
</button>
202+
</ButtonBase>
215203
</div>
216204
</Transition>
217205
</div>

app/components/Compare/ReplacementSuggestion.vue

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,18 @@ const docUrl = computed(() => {
6464
</div>
6565

6666
<!-- No dependency action button -->
67-
<button
67+
<ButtonBase
6868
v-if="variant === 'nodep' && showAction !== false"
69-
type="button"
70-
class="flex-shrink-0 px-2 py-1 text-xs font-medium bg-amber-500/20 hover:bg-amber-500/30 rounded transition-colors"
69+
size="small"
7170
:aria-label="$t('compare.no_dependency.add_column')"
7271
@click="emit('addNoDep')"
7372
>
7473
{{ $t('package.replacement.consider_no_dep') }}
75-
</button>
74+
</ButtonBase>
7675

7776
<!-- Info link -->
78-
<a
79-
v-else-if="docUrl"
80-
:href="docUrl"
81-
target="_blank"
82-
rel="noopener noreferrer"
83-
class="flex-shrink-0 px-2 py-1 text-xs font-medium bg-blue-500/20 hover:bg-blue-500/30 rounded transition-colors inline-flex items-center gap-1"
84-
>
77+
<LinkBase v-else-if="docUrl" :to="docUrl" variant="button-secondary" size="small">
8578
{{ $t('package.replacement.learn_more') }}
86-
<span class="i-carbon:launch w-3 h-3" />
87-
</a>
79+
</LinkBase>
8880
</div>
8981
</template>

app/composables/useCompareReplacements.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export function useCompareReplacements(packageNames: MaybeRefOrGetter<string[]>)
7474
const allSuggestions = computed(() => {
7575
const result: ReplacementSuggestion[] = []
7676

77+
console.log({ packages })
78+
7779
for (const pkg of packages.value) {
7880
const replacement = replacements.value.get(pkg)
7981
if (!replacement) continue

app/pages/compare.vue

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,27 +168,25 @@ useSeoMeta({
168168
<h2 id="facets-heading" class="text-xs text-fg-subtle uppercase tracking-wider">
169169
{{ $t('compare.packages.section_facets') }}
170170
</h2>
171-
<button
172-
type="button"
173-
class="text-3xs transition-colors focus-visible:outline-none focus-visible:underline focus-visible:underline-accent"
174-
:class="isAllSelected ? 'text-fg-muted' : 'text-fg-muted/60 hover:text-fg-muted'"
171+
<ButtonBase
172+
size="small"
173+
:aria-pressed="isAllSelected"
175174
:disabled="isAllSelected"
176175
:aria-label="$t('compare.facets.select_all')"
177176
@click="selectAll"
178177
>
179178
{{ $t('compare.facets.all') }}
180-
</button>
179+
</ButtonBase>
181180
<span class="text-3xs text-fg-muted/40" aria-hidden="true">/</span>
182-
<button
183-
type="button"
184-
class="text-3xs transition-colors focus-visible:outline-none focus-visible:underline focus-visible:underline-accent"
185-
:class="isNoneSelected ? 'text-fg-muted' : 'text-fg-muted/60 hover:text-fg-muted'"
181+
<ButtonBase
182+
size="small"
183+
:aria-pressed="isNoneSelected"
186184
:disabled="isNoneSelected"
187185
:aria-label="$t('compare.facets.deselect_all')"
188186
@click="deselectAll"
189187
>
190188
{{ $t('compare.facets.none') }}
191-
</button>
189+
</ButtonBase>
192190
</div>
193191
<CompareFacetSelector />
194192
</section>

0 commit comments

Comments
 (0)