docs/.vitepress/theme/components/search/SearchHistory.vue
214 lines · 4520 bytes
1<script setup lang="ts">
2import { ArrowRight, Globe, LocateOff, Regex, X } from 'lucide-vue-next'
3import { searchHistory, type SearchHistoryEntry } from '../../searchState'
4
5defineProps<{
6 searchMotionDiv: string | object
7 emptyStateMotion: Record<string, unknown>
8 filterText: string
9}>()
10
11const emit = defineEmits<{
12 applyHistory: [entry: SearchHistoryEntry]
13 removeFromHistory: [index: number]
14}>()
15</script>
16
17<template>
18 <component
19 :is="searchMotionDiv"
20 v-if="!filterText && searchHistory.length > 0"
21 class="history-list"
22 v-bind="emptyStateMotion"
23 >
24 <div class="history-header">
25 <span>Recent searches</span>
26 <button
27 class="history-clear-all"
28 title="Clear all history"
29 @click.stop="searchHistory = []"
30 >
31 <X :size="16" stroke-width="2" />
32 </button>
33 </div>
34 <ul class="history-items">
35 <li
36 v-for="(entry, index) in searchHistory"
37 :key="index"
38 class="history-item"
39 @click="emit('applyHistory', entry)"
40 >
41 <div class="history-main">
42 <span class="history-query">{{ entry.query }}</span>
43 <template v-if="entry.path?.length">
44 <ArrowRight :size="13" stroke-width="1.5" class="history-arrow" />
45 <template v-for="(seg, si) in entry.path" :key="si">
46 <span
47 class="history-path-seg"
48 :class="{
49 'history-path-end': si === entry.path.length - 1,
50 'history-path-only': entry.path.length === 1
51 }"
52 v-html="seg"
53 />
54 <span v-if="si < entry.path.length - 1" class="history-path-sep">›</span>
55 </template>
56 </template>
57 </div>
58 <component
59 :is="entry.mode === 'exact' ? Regex : entry.mode === 'fuzzy' ? LocateOff : Globe"
60 :size="14"
61 stroke-width="2"
62 class="history-mode-icon"
63 />
64 <button
65 class="history-remove"
66 :title="`Remove '${entry.query}' from history`"
67 @click.stop="emit('removeFromHistory', index)"
68 >
69 <X :size="16" stroke-width="2" />
70 </button>
71 </li>
72 </ul>
73 </component>
74</template>
75
76<style>
77.history-list {
78 display: flex;
79 flex-direction: column;
80 width: 100%;
81 padding: 4px 0;
82}
83
84.history-header {
85 font-size: 0.7rem;
86 font-weight: 600;
87 text-transform: uppercase;
88 letter-spacing: 0.06em;
89 color: var(--vp-c-text-3);
90 padding: 4px 12px 8px;
91 display: flex;
92 align-items: center;
93 justify-content: space-between;
94}
95
96.history-clear-all {
97 display: flex;
98 align-items: center;
99 justify-content: center;
100 flex-shrink: 0;
101 padding: 0;
102 border: none;
103 background: transparent;
104 color: var(--vp-c-text-3);
105 cursor: pointer;
106 opacity: 0.7;
107 transition: color 0.15s;
108}
109
110.history-clear-all:hover {
111 color: var(--vp-c-text-1);
112 opacity: 1;
113}
114
115.history-items {
116 display: flex;
117 flex-direction: column;
118 list-style: none;
119 margin: 0;
120 padding: 0;
121}
122
123.history-item {
124 display: flex;
125 align-items: center;
126 gap: 8px;
127 padding: 8px 12px;
128 cursor: pointer;
129 border-radius: 4px;
130 transition: background-color 0.15s;
131}
132
133.history-item:hover {
134 background: var(--vp-c-default-soft);
135}
136
137.history-main {
138 flex: 1;
139 min-width: 0;
140 display: flex;
141 align-items: center;
142 gap: 6px;
143 overflow: hidden;
144}
145
146.history-query {
147 flex-shrink: 0;
148 font-size: 0.9rem;
149 color: var(--vp-c-text-1);
150 white-space: nowrap;
151}
152
153.history-arrow {
154 flex-shrink: 0;
155 opacity: 0.5;
156 color: var(--vp-c-text-3);
157}
158
159.history-path-seg {
160 min-width: 0;
161 overflow: hidden;
162 text-overflow: ellipsis;
163 white-space: nowrap;
164 font-size: 0.78rem;
165 font-weight: 500;
166 color: var(--vp-c-text-3);
167}
168
169.history-path-sep {
170 flex-shrink: 0;
171 font-size: 0.78rem;
172 color: var(--vp-c-text-3);
173}
174
175.history-path-end {
176 flex-shrink: 0;
177 white-space: nowrap;
178 font-size: 0.78rem;
179 font-weight: 500;
180 color: var(--vp-c-text-3);
181}
182
183.history-path-only {
184 flex-shrink: 1;
185 min-width: 0;
186 overflow: hidden;
187 text-overflow: ellipsis;
188}
189
190.history-mode-icon {
191 flex-shrink: 0;
192 color: var(--vp-c-text-3);
193 opacity: 0.7;
194}
195
196.history-remove {
197 display: flex;
198 align-items: center;
199 justify-content: center;
200 flex-shrink: 0;
201 padding: 0;
202 border: none;
203 background: transparent;
204 color: var(--vp-c-text-3);
205 cursor: pointer;
206 opacity: 0.7;
207 transition: color 0.15s;
208}
209
210.history-remove:hover {
211 color: var(--vp-c-text-1);
212 opacity: 1;
213}
214</style>