Skip to content

Commit 351d5e7

Browse files
committed
filter for api index
1 parent f2e7dff commit 351d5e7

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

src/api/index.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ page: true
55

66
<script setup>
77
import apiIndex from './index.json'
8+
import { ref, computed } from 'vue'
9+
10+
const query = ref('')
11+
12+
const filtered = computed(() => {
13+
const q = query.value
14+
return apiIndex.map(section => {
15+
const items = section.items.map(({ text, link, headers }) => {
16+
headers = headers.filter(h => {
17+
return h.toLowerCase().includes(q.toLowerCase())
18+
})
19+
return headers.length ? { text, link, headers } : null
20+
}).filter(i => i)
21+
return items.length ? { text: section.text, items } : null
22+
}).filter(i => i)
23+
})
824

925
// same as vitepress' slugify logic
1026
function slugify(text) {
@@ -23,9 +39,12 @@ function slugify(text) {
2339
</script>
2440

2541
<div id="api-index">
26-
<h1>API Reference</h1>
42+
<div class="header">
43+
<h1>API Reference</h1>
44+
<input class="api-filter" placeholder="Filter" v-model="query">
45+
</div>
2746

28-
<div v-for="section of apiIndex" class="api-section">
47+
<div v-for="section of filtered" class="api-section">
2948
<h2>{{ section.text }}</h2>
3049
<div class="api-groups">
3150
<div v-for="item of section.items" class="api-group">
@@ -66,7 +85,7 @@ h1 {
6685
h2 {
6786
font-size: 24px;
6887
color: var(--vt-c-text-1);
69-
margin: 64px 0 36px;
88+
margin: 36px 0;
7089
transition: color 0.5s;
7190
padding-top: 36px;
7291
border-top: 1px solid var(--vt-c-divider-light);
@@ -80,6 +99,10 @@ h3 {
8099
transition: color 0.5s;
81100
}
82101

102+
.api-section {
103+
margin-bottom: 64px;
104+
}
105+
83106
.api-groups a {
84107
font-size: 15px;
85108
font-weight: 500;
@@ -106,12 +129,29 @@ h3 {
106129
transition: background-color 0.5s;
107130
}
108131

132+
.header {
133+
display: flex;
134+
align-items: center;
135+
justify-content: space-between;
136+
}
137+
138+
.api-filter {
139+
border: 1px solid var(--vt-c-divider);
140+
border-radius: 8px;
141+
padding: 6px 12px;
142+
}
143+
144+
.api-filter:focus {
145+
border-color: var(--vt-c-green-light);
146+
}
147+
109148
@media (max-width: 768px) {
110149
#api-index {
111150
padding: 42px 24px;
112151
}
113152
h1 {
114153
font-size: 32px;
154+
margin-bottom: 24px;
115155
}
116156
h2 {
117157
font-size: 22px;
@@ -121,6 +161,9 @@ h3 {
121161
.api-groups a {
122162
font-size: 14px;
123163
}
164+
.header {
165+
display: block;
166+
}
124167
}
125168

126169
@media (min-width: 768px) {

0 commit comments

Comments
 (0)