Skip to content

Commit 9811530

Browse files
committed
feat: add suggested packages to comparison package selector
1 parent d8a30b4 commit 9811530

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

app/components/Compare/PackageSelector.vue

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ const { data: searchData, status } = useNpmSearch(inputValue, { size: 15 })
1717
1818
const isSearching = computed(() => status.value === 'pending')
1919
20+
const suggestedPackagesCandidates = ['vue', 'svelte', 'solid-js', 'react']
21+
22+
const suggestedPackages = computed(() => {
23+
return suggestedPackagesCandidates.includes(packages.value[0])
24+
? suggestedPackagesCandidates
25+
.filter(name => !packages.value.includes(name))
26+
.slice(0, Math.max(0, 4 - packages.value.length))
27+
: []
28+
})
29+
2030
// Filter out already selected packages
2131
const filteredResults = computed(() => {
2232
if (!searchData.value?.objects) return []
@@ -78,6 +88,30 @@ function handleBlur() {
7888
<span class="i-carbon:close w-3.5 h-3.5" aria-hidden="true" />
7989
</button>
8090
</div>
91+
92+
<p class="flex-1"></p>
93+
94+
<!-- suggested packages -->
95+
<div
96+
v-for="pkg in suggestedPackages"
97+
:key="pkg"
98+
class="inline-flex items-center gap-2 px-3 py-1.5 border-border rounded-md"
99+
>
100+
<NuxtLink
101+
:to="`/${pkg}`"
102+
class="font-mono text-sm text-fg hover:text-accent transition-colors"
103+
>
104+
{{ pkg }}
105+
</NuxtLink>
106+
<button
107+
type="button"
108+
class="text-fg-subtle hover:text-fg transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/50 rounded"
109+
:aria-label="$t('compare.selector.add_package', { package: pkg })"
110+
@click="addPackage(pkg)"
111+
>
112+
<span class="i-carbon:add w-3.5 h-3.5" aria-hidden="true" />
113+
</button>
114+
</div>
81115
</div>
82116

83117
<!-- Add package input -->

0 commit comments

Comments
 (0)