[reference] Add filter input, add counts

This commit is contained in:
Lea Verou
2024-12-02 19:37:29 -05:00
parent 8b1fc9a18f
commit 8c804957fa
2 changed files with 34 additions and 1 deletions

View File

@@ -39,6 +39,7 @@ export default function (eleventyConfig) {
// With Prettier 3, this means a leading pipe will exist be present when the line wraps.
return typeof content === 'string' ? content.replace(/^(\s|\|)/g, '').replace(/(\s|\|)$/g, '') : content;
});
eleventyConfig.addFilter('keys', obj => Object.keys(obj));
// Shortcodes - {% shortCode arg1, arg2 %}
eleventyConfig.addShortcode('cdnUrl', location => {

View File

@@ -9,8 +9,40 @@ table code {
}
</style>
<wa-input type=search label="Filter by name:" clearable id="name_search"></wa-input>
<script>
name_search.addEventListener("wa-input", e => {
let value = e.target.value;
if (value) {
for (let th of document.querySelectorAll("table tbody th:first-child")) {
let tr = th.parentNode;
tr.toggleAttribute("hidden", !th.textContent.includes(value));
}
}
else {
for (let tr of document.querySelectorAll("table tbody tr[hidden]")) {
tr.removeAttribute("hidden");
}
}
// Update heading counts
for (let h2 of document.querySelectorAll("h2:has(+ table)")) {
let count = h2.querySelector(".count");
if (!count) continue;
let table = h2.nextElementSibling;
let visibleRows = table.querySelectorAll("tbody tr:not([hidden])").length;
count.textContent = visibleRows;
}
});
</script>
{% for type, all in componentsBy -%}
<h2>All {{ "CSS custom properties" if type == "cssProperty" else ("CSS parts" if type == "cssPart" else (type | title) + "s") }}</h2>
{% set typeTitle = "CSS custom properties" if type == "cssProperty" else ("CSS parts" if type == "cssPart" else (type | title) + "s") %}
<h2 id="{{ typeTitle | slugify }}">
All <span class="count">{{ (all | keys).length }}</span>
{{ typeTitle }}
</h2>
<table>
<thead>