Skip to content

Commit 146bf12

Browse files
committed
feat: add prefill buttons to search on product landing page
See: FE-94
1 parent b292772 commit 146bf12

File tree

5 files changed

+103
-7
lines changed

5 files changed

+103
-7
lines changed

frontend/i18n/locales/en.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,16 @@
12341234
}
12351235
},
12361236
"search": {
1237+
"examples": {
1238+
"address": "Address",
1239+
"latest_block": "Latest Block",
1240+
"latest_epoch": "Latest Epoch",
1241+
"title": "Examples:",
1242+
"token": "Token",
1243+
"transaction": "Transaction",
1244+
"tx": "TX",
1245+
"validator": "Validator"
1246+
},
12371247
"filter_aria_label": "Filter by type",
12381248
"history": {
12391249
"action": {

frontend/layers/base/app/components/BaseChip.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<script setup lang="ts">
2+
import type { IconName } from '#layers/base/app/components/BaseIcon.vue'
3+
24
const {
35
size = 'sm',
46
variant = 'neutral',
57
} = defineProps<{
8+
icon?: IconName,
69
isSelected: boolean,
710
size?: 'sm',
811
variant?: 'neutral',
@@ -12,12 +15,18 @@ const {
1215
<template>
1316
<button
1417
class="text-nowrap border-1 font-semibold focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-brand-300"
18+
type="button"
1519
:class="[
1620
variant === 'neutral' && 'bg-gray-100 dark:bg-gray-900 border-gray-200 dark:border-gray-800 text-gray-600 dark:text-gray-400 aria-pressed:bg-gray-200 dark:aria-pressed:bg-gray-700 aria-pressed:border-gray-300 dark:aria-pressed:border-gray-700 aria-pressed:text-black dark:aria-pressed:text-white aria-pressed:shadow-none',
1721
size === 'sm' && 'px-md py-xs rounded-md ',
22+
icon && 'flex items-center gap-md',
1823
]"
1924
:aria-pressed="isSelected"
2025
>
26+
<BaseIcon
27+
v-if="icon"
28+
:name="icon"
29+
/>
2130
<slot />
2231
</button>
2332
</template>

frontend/layers/base/app/components/BaseSearchInput.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ watchDebounced(
3333
async () => {
3434
emit('search', input.value)
3535
},
36-
{
37-
immediate: false,
38-
},
3936
)
4037
4138
const groupedResults = computed(() => {
@@ -182,6 +179,13 @@ const idSearchInput = useId()
182179
</div>
183180
</RkComboboxContent>
184181
</RkComboboxRoot>
182+
183+
<div
184+
v-if="$slots['search-examples']"
185+
class="overflow-x-auto p-2xl z-10 bg-gray-50 dark:bg-gray-950 mt-xl rounded-xl shadow-[inset_0_-1px_0_0_rgba(255,255,255,0.18)]"
186+
>
187+
<slot name="search-examples" />
188+
</div>
185189
</form>
186190
</template>
187191

@@ -191,6 +195,7 @@ form {
191195
192196
&:before {
193197
position: absolute;
198+
z-index: -1;
194199
content: '';
195200
top: 0;
196201
left: 0;

frontend/layers/products/app/components/BlockchainSearchInput.vue

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const { t: $t } = useTranslation()
2121
2222
const emit = defineEmits<{
2323
(e: 'search', input: string): void,
24+
(e: 'click:example', type: 'address' | 'token' | 'transaction' | 'validator'): void,
2425
}>()
2526
2627
const searchParams = defineModel<BlockchainSearchParams>({
@@ -108,6 +109,44 @@ watch(hasResults, () => {
108109
:results="resultsOrHistory"
109110
@search="handleSearch"
110111
>
112+
<template #search-examples>
113+
<div class="flex items-center">
114+
<section class="flex gap-lg">
115+
<div class="py-xs px-md border-gray-400 font-semibold text-gray-400">
116+
{{ $t('products.landing_page.search.examples.title') }}
117+
</div>
118+
<BaseChip
119+
:is-selected="false"
120+
icon="switch-horizontal"
121+
:aria-label="$t('products.landing_page.search.examples.transaction')"
122+
@click="emit('click:example', 'transaction')"
123+
>
124+
{{ $t('products.landing_page.search.examples.tx') }}
125+
</BaseChip>
126+
<BaseChip
127+
:is-selected="false"
128+
icon="hash"
129+
@click="emit('click:example', 'address')"
130+
>
131+
{{ $t('products.landing_page.search.examples.address') }}
132+
</BaseChip>
133+
<BaseChip
134+
:is-selected="false"
135+
icon="stack-2"
136+
@click="emit('click:example', 'validator')"
137+
>
138+
{{ $t('products.landing_page.search.examples.validator') }}
139+
</BaseChip>
140+
<BaseChip
141+
:is-selected="false"
142+
icon="hexagon"
143+
@click="emit('click:example', 'token')"
144+
>
145+
{{ $t('products.landing_page.search.examples.token') }}
146+
</BaseChip>
147+
</section>
148+
</div>
149+
</template>
111150
<template #dropdown-fixed-header="{ idSearchInput }">
112151
<div
113152
class="min-h-fit overflow-x-auto overscroll-contain flex gap-md items-center px-2xl py-lg"

frontend/layers/products/app/pages/products/index.vue

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ const searchTypes: BlockchainSearchParams['types'] = [
4444
'validator_by_public_key',
4545
'validators_by_withdrawal_credential',
4646
]
47+
const networks = [
48+
1,
49+
560048,
50+
] satisfies ChainId[]
4751
const searchParams = ref<BlockchainSearchParams>({
4852
input: '',
49-
networks: [
50-
1,
51-
560048,
52-
],
53+
networks,
5354
types: searchTypes,
5455
})
5556
@@ -71,6 +72,37 @@ const handleSearch = (input: string) => {
7172
}
7273
execute()
7374
}
75+
76+
const handleExampleClick = (type: 'address' | 'token' | 'transaction' | 'validator') => {
77+
if (type === 'address') {
78+
searchParams.value = {
79+
...searchParams.value,
80+
input: '0x5AbfEc25f74Cd88437631A7731906932776356f9',
81+
types: [ 'address' ],
82+
}
83+
}
84+
if (type === 'token') {
85+
searchParams.value = {
86+
...searchParams.value,
87+
input: '0x26D5Bd2dfEDa983ECD6c39899e69DAE6431Dffbb',
88+
types: [ 'token' ],
89+
}
90+
}
91+
if (type === 'transaction') {
92+
searchParams.value = {
93+
...searchParams.value,
94+
input: '0x4978b2aeed51747c2fd1d681e7da3fd73e7ef328c3634c1a2dc1e7829f1c2622',
95+
types: [ 'transaction' ],
96+
}
97+
}
98+
if (type === 'validator') {
99+
searchParams.value = {
100+
...searchParams.value,
101+
input: '5',
102+
types: [ 'validator_by_index' ],
103+
}
104+
}
105+
}
74106
</script>
75107

76108
<template>
@@ -101,6 +133,7 @@ const handleSearch = (input: string) => {
101133
:is-loading="status === 'pending'"
102134
:has-error="!!error"
103135
@search="handleSearch"
136+
@click:example="handleExampleClick"
104137
/>
105138
</ProductLandingpageSection>
106139
<ProductLandingpageSection class="mt-11xl">

0 commit comments

Comments
 (0)