@@ -44,6 +44,25 @@ export function renderHomeHtml(pluginsData: PluginsData) {
4444 }, 1600);
4545 });
4646 }
47+
48+ // live filter
49+ const search = document.getElementById("plugin-search");
50+ if (search != null) {
51+ const rows = document.getElementsByClassName("plugin-row");
52+ const table = document.getElementsByClassName("plugin-table")[0];
53+ const noMatches = document.getElementById("no-matches");
54+ search.addEventListener("input", () => {
55+ const query = search.value.trim().toLowerCase();
56+ let visible = 0;
57+ for (const row of rows) {
58+ const match = query === "" || (row.dataset.search || "").indexOf(query) !== -1;
59+ row.hidden = !match;
60+ if (match) visible++;
61+ }
62+ if (table != null) table.hidden = visible === 0;
63+ if (noMatches != null) noMatches.hidden = visible !== 0;
64+ });
65+ }
4766 });
4867 </script>
4968 </head>
@@ -58,9 +77,19 @@ function renderPage(pluginsData: PluginsData) {
5877 return (
5978 < main class = "page" >
6079 < div class = "topbar" >
80+ < input
81+ type = "search"
82+ id = "plugin-search"
83+ class = "plugin-search"
84+ placeholder = "Filter plugins…"
85+ aria-label = "Filter plugins"
86+ autocomplete = "off"
87+ spellcheck = { false }
88+ />
6189 < a class = "docs-link" href = "https://dprint.dev/plugins" > dprint plugin docs < span > ↗</ span > </ a >
6290 </ div >
6391 { renderPlugins ( pluginsData ) }
92+ < div id = "no-matches" class = "no-matches" hidden > No plugins match your filter.</ div >
6493 { renderCommands ( ) }
6594 </ main >
6695 ) ;
@@ -103,7 +132,7 @@ function renderPlugins(data: PluginsData) {
103132
104133function renderPlugin ( plugin : PluginData ) {
105134 return (
106- < div class = "plugin-row" role = "row" key = { plugin . name } >
135+ < div class = "plugin-row" role = "row" key = { plugin . name } data-search = { ` ${ plugin . name } ${ plugin . url } ` . toLowerCase ( ) } >
107136 < div class = "col-name" role = "cell" >
108137 < span class = "swatch" > </ span >
109138 < span class = "name-text" > { plugin . name } </ span >
0 commit comments