Skip to content

Commit 05c7791

Browse files
committed
feat: input hints
On click the hint will update the input value and trigger a request.
1 parent 1e8094e commit 05c7791

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/components/ApiExplorer.astro

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,13 @@ import { Aside, Icon } from '@astrojs/starlight/components'
6464
<h2 id="try-it-now" class="text-center mb-10">Try it now!</h2>
6565

6666
<Aside type="tip" title="Need a hint?">
67-
Try <code>pokemon/ditto</code>, <code>pokemon-species/aegislash</code>, <code>type/3</code>,
68-
<code>ability/battle-armor</code>, or <code>pokemon?limit=100000&offset=0</code>. Read the <a href="./v2/openapi/"
67+
Try
68+
<a class="input-hints cursor-pointer" href="#try-it-now"><code>pokemon/ditto</code></a>,
69+
<a class="input-hints cursor-pointer" href="#try-it-now"><code>pokemon-species/aegislash</code></a>,
70+
<a class="input-hints cursor-pointer" href="#try-it-now"><code>type/3</code></a>,
71+
<a class="input-hints cursor-pointer" href="#try-it-now"><code>ability/battle-armor</code></a>, or
72+
<a class="input-hints cursor-pointer" href="#try-it-now"><code>pokemon?limit=100000&offset=0</code></a>. Read the <a
73+
href="./v2/openapi/"
6974
>OpenAPI docs</a> for more options.
7075
</Aside>
7176

@@ -256,4 +261,14 @@ import { Aside, Icon } from '@astrojs/starlight/components'
256261
pokeapiPathInput.disabled = false
257262
pokeapiPathInput.scrollIntoView({ behavior: 'smooth', block: 'start' })
258263
}
264+
265+
const inputHints = document.querySelectorAll('.input-hints code')
266+
inputHints.forEach((inputHint) => {
267+
console.log(inputHint.innerText)
268+
269+
inputHint.addEventListener('click', function () {
270+
pokeapiPathInput.value = inputHint.innerText
271+
sendRequest()
272+
})
273+
})
259274
</script>

0 commit comments

Comments
 (0)