GitHub Primer
JS behaviour
Filter Bar
Query-syntax search (is:pr is:open label:bug) with Label/Sort/State dropdowns. GitHub's search power dressed as one quiet gray input.
Real scenarios
The component as it is used in a product — not a specimen grid.
A query, not a form
The menus never open a modal — they edit tokens inside the quiet gray input, and the list below obeys instantly. Press «/» anywhere to jump into the box.
Its quiet cousin: the FilterList
The same power as plain links with CounterLabels — the selected one goes bold with the accent counter, no input required.
Important props
| Prop | Type | Default | What it does |
|---|---|---|---|
| query | input | 'monospace-ish' | The quiet gray input with a search glyph; the query edits as raw text. |
| menu | dropdown | 'Label · Sort · State' | Three menu buttons; picking an option swaps in its query token. |
| count | result line | '«n»' | The result line under the bar speaks the live count. |
| shortcut | key | '/' | The '/' key jumps focus into search — the GitHub habit. |
Snippet
<div class="prf-bar">
<span class="prf-glyph"><svg>…</svg></span>
<input class="prf-input" value="is:pr is:open label:bug" spellcheck="false">
<details class="prf-menu">
<summary>Label</summary>
<div class="prf-list">…options…</div>
</details>
</div>
<style>
.prf-bar { display: flex; align-items: center; gap: 8px; block-size: 32px;
padding-inline: 8px; border: 1px solid #d1d9e0; border-radius: 6px; }
.prf-input { flex: 1; min-inline-size: 0; border: 0; background: transparent;
font: 400 14px ui-monospace, monospace; color: #1f2328; }
.prf-menu[open] .prf-list { display: grid; }
</style>
// resources/js/Pages/Pulls/Index.tsx — the query string syncs to
// URL params so every filtered view is a shareable link.
import { Head, router, usePage } from '@inertiajs/react';
import FilterBar from '@/components/primer/FilterBar';
export default function PullsIndex() {
const { q } = usePage().props; // current query from the backend
return (
<>
<Head title="Pull requests" />
{/* onQueryChange={(next) => router.get('/pulls', { q: next })} */}
<FilterBar initialQuery={q} />
</>
);
}
import { useState } from 'react';
import '@nabuxai/ui-core/css';
const PRS = [
{ n: 415, state: 'open', title: 'PDF export stalls on 50-page reports', label: 'bug' },
{ n: 409, state: 'open', title: 'Refresh the report empty-state art', label: 'design' },
{ n: 402, state: 'merged', title: 'Queue the heavy renders off-request', label: 'enhancement' },
];
export default function FilterBar({ initialQuery = 'is:open label:bug' }: { initialQuery?: string }) {
const [q, setQ] = useState(initialQuery);
const tokens = {
open: /(^|\s)is:open(\s|$)/.test(q),
label: q.match(/label:(\S+)/)?.[1] ?? null,
};
const setToken = (key: string, v: string) =>
setQ((prev) =>
new RegExp(`${key}:\\S+`).test(prev)
? prev.replace(new RegExp(`${key}:\\S+`), `${key}:${v}`)
: `${prev} ${key}:${v}`.trim(),
);
const rows = PRS.filter(
(r) => (!tokens.open || r.state === 'open') && (!tokens.label || r.label === tokens.label),
);
return (
<div className="prf-panel">
<div className="prf-line">
<span className="prf-glyph" aria-hidden>⌕</span>
<input
className="prf-input" value={q} onChange={(e) => setQ(e.target.value)}
spellCheck={false} aria-label="Search pull requests"
/>
{['bug', 'design', 'enhancement'].map((l) => (
<button key={l} onClick={() => setToken('label', l)}>label:{l}</button>
))}
</div>
<p className="prf-result"><b>{rows.length}</b> pull requests match this query</p>
{rows.map((r) => (
<a className="prf-row" href="#" key={r.n}><b>{r.title}</b> <small>#{r.n}</small></a>
))}
<style>{`
.prf-line { display: flex; align-items: center; gap: 8px; block-size: 32px; padding-inline: 8px;
border: 1px solid #d1d9e0; border-radius: 6px; }
.prf-input { flex: 1; min-inline-size: 0; border: 0; background: transparent;
font: 400 14px ui-monospace, monospace; color: #1f2328; }
`}</style>
</div>
);
}
<!-- FilterBar.vue -->
<script setup lang="ts">
import { ref, computed } from 'vue';
import '@nabuxai/ui-core/css';
const PRS = [
{ n: 415, state: 'open', title: 'PDF export stalls on 50-page reports', label: 'bug' },
{ n: 409, state: 'open', title: 'Refresh the report empty-state art', label: 'design' },
{ n: 402, state: 'merged', title: 'Queue the heavy renders off-request', label: 'enhancement' },
];
const q = ref('is:open label:bug');
const rows = computed(() => {
const open = /(^|\s)is:open(\s|$)/.test(q.value);
const label = q.value.match(/label:(\S+)/)?.[1] ?? null;
return PRS.filter((r) => (!open || r.state === 'open') && (!label || r.label === label));
});
const setToken = (key: string, v: string) => {
const re = new RegExp(`${key}:\\S+`);
q.value = re.test(q.value) ? q.value.replace(re, `${key}:${v}`) : `${q.value} ${key}:${v}`.trim();
};
</script>
<template>
<div class="prf-panel">
<div class="prf-line">
<span class="prf-glyph" aria-hidden="true">⌕</span>
<input v-model="q" class="prf-input" spellcheck="false" aria-label="Search pull requests" />
<button v-for="l in ['bug', 'design', 'enhancement']" :key="l" @click="setToken('label', l)">label:{{ l }}</button>
</div>
<p class="prf-result"><b>{{ rows.length }}</b> pull requests match this query</p>
<a v-for="r in rows" :key="r.n" class="prf-row" href="#"><b>{{ r.title }}</b> <small>#{{ r.n }}</small></a>
</div>
</template>
<style scoped>
.prf-line { display: flex; align-items: center; gap: 8px; block-size: 32px; padding-inline: 8px;
border: 1px solid #d1d9e0; border-radius: 6px; }
.prf-input { flex: 1; min-inline-size: 0; border: 0; background: transparent;
font: 400 14px ui-monospace, monospace; color: #1f2328; }
</style>
<!-- FilterBar.svelte -->
<script lang="ts">
import '@nabuxai/ui-core/css';
const PRS = [
{ n: 415, state: 'open', title: 'PDF export stalls on 50-page reports', label: 'bug' },
{ n: 409, state: 'open', title: 'Refresh the report empty-state art', label: 'design' },
{ n: 402, state: 'merged', title: 'Queue the heavy renders off-request', label: 'enhancement' },
];
let q = $state('is:open label:bug');
const rows = $derived.by(() => {
const open = /(^|\s)is:open(\s|$)/.test(q);
const label = q.match(/label:(\S+)/)?.[1] ?? null;
return PRS.filter((r) => (!open || r.state === 'open') && (!label || r.label === label));
});
const setToken = (key: string, v: string) => {
const re = new RegExp(`${key}:\\S+`);
q = re.test(q) ? q.replace(re, `${key}:${v}`) : `${q} ${key}:${v}`.trim();
};
</script>
<div class="prf-panel">
<div class="prf-line">
<span class="prf-glyph" aria-hidden="true">⌕</span>
<input bind:value={q} class="prf-input" spellcheck="false" aria-label="Search pull requests" />
{#each ['bug', 'design', 'enhancement'] as l (l)}<button onclick={() => setToken('label', l)}>label:{l}</button>{/each}
</div>
<p class="prf-result"><b>{rows.length}</b> pull requests match this query</p>
{#each rows as r (r.n)}<a class="prf-row" href="#/pulls/{r.n}"><b>{r.title}</b> <small>#{r.n}</small></a>{/each}
</div>
<style>
.prf-line { display: flex; align-items: center; gap: 8px; block-size: 32px; padding-inline: 8px;
border: 1px solid #d1d9e0; border-radius: 6px; }
.prf-input { flex: 1; min-inline-size: 0; border: 0; background: transparent;
font: 400 14px ui-monospace, monospace; color: #1f2328; }
</style>