-
-
Notifications
You must be signed in to change notification settings - Fork 425
Expand file tree
/
Copy pathInstantSearch.vue
More file actions
57 lines (53 loc) · 1.82 KB
/
InstantSearch.vue
File metadata and controls
57 lines (53 loc) · 1.82 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
<script setup lang="ts">
const instantSearch = useInstantSearchPreference()
onPrehydrate(el => {
let userPreferences: Record<string, unknown> = {}
try {
userPreferences = JSON.parse(localStorage.getItem('npmx-user-preferences') || '{}')
} catch {}
const enabled = userPreferences.instantSearch
if (enabled === false) {
el.querySelector('[data-instant-search-on]')!.className = 'hidden'
el.querySelector('[data-instant-search-off]')!.className = ''
}
})
</script>
<template>
<p id="instant-search-advisory" class="text-fg-muted text-sm text-pretty">
<span
class="i-lucide:zap align-middle text-fg relative top-[-0.1em] me-1"
style="font-size: 0.8em"
aria-hidden="true"
/>
<span data-instant-search-on :class="instantSearch ? '' : 'hidden'">
<i18n-t keypath="search.instant_search_advisory">
<template #label>
{{ $t('search.instant_search') }}
</template>
<template #state>
<strong>{{ $t('search.instant_search_on') }}</strong>
</template>
<template #action>
<button type="button" class="underline" @click="instantSearch = false">
{{ $t('search.instant_search_turn_off') }}
</button>
</template>
</i18n-t>
</span>
<span data-instant-search-off :class="instantSearch ? 'hidden' : ''">
<i18n-t keypath="search.instant_search_advisory">
<template #label>
{{ $t('search.instant_search') }}
</template>
<template #state>
<strong>{{ $t('search.instant_search_off') }}</strong>
</template>
<template #action>
<button type="button" class="underline" @click="instantSearch = true">
{{ $t('search.instant_search_turn_on') }}
</button>
</template>
</i18n-t>
</span>
</p>
</template>