|
| 1 | +import IDocumentation from "../../../lib/interfaces/IDocumentation"; |
1 | 2 | import navigationButton from "./navigationButton"; |
| 3 | +import registryButton from "./registryButton"; |
2 | 4 |
|
3 | 5 | const searchInput = ( |
4 | 6 | searchValue: string, |
5 | 7 | searchMode: boolean, |
6 | | - documentationLength: number, |
7 | | - searchDocumentationLength: number |
| 8 | + documentations: IDocumentation[], |
| 9 | + searchDocumentations: IDocumentation[], |
| 10 | + hideRegistries: ("npm" | "packagist")[] |
8 | 11 | ) => { |
9 | 12 | const subtitle = searchMode |
10 | | - ? searchDocumentationLength + " documentation(s) found" |
11 | | - : documentationLength + " documentation(s) installed"; |
| 13 | + ? searchDocumentations.length + " documentation(s) found" |
| 14 | + : documentations.length + " documentation(s) loaded"; |
| 15 | + |
| 16 | + const npm = searchMode |
| 17 | + ? searchDocumentations.filter( |
| 18 | + (documentation) => documentation.registry === "npm" |
| 19 | + ).length |
| 20 | + : documentations.filter((documentation) => documentation.registry === "npm") |
| 21 | + .length; |
| 22 | + |
| 23 | + const packagist = searchMode |
| 24 | + ? searchDocumentations.filter( |
| 25 | + (documentation) => documentation.registry === "packagist" |
| 26 | + ).length |
| 27 | + : documentations.filter( |
| 28 | + (documentation) => documentation.registry === "packagist" |
| 29 | + ).length; |
12 | 30 |
|
13 | 31 | return `<div class="flex w-full gap-2"> |
14 | | - ${navigationButton(searchMode, searchDocumentationLength)} |
15 | | - <input id="search-package-input" type="text" placeholder="Search documentations..." class="w-full appearance-none rounded-md p-4 leading-tight ring-1 ring-inset focus:outline-none focus:ring-sky-500" value="${searchValue}" /> |
| 32 | + ${navigationButton(searchMode, searchDocumentations.length)} |
| 33 | + <input id="search-package-input" type="text" placeholder="Search documentations..." class="w-full appearance-none rounded-md p-4 leading-tight ring-1 ring-inset focus:outline-none focus:ring-sky-500" value="${searchValue}" /> |
16 | 34 | <div id="search-package-button" class="flex items-center justify-center gap-2 rounded bg-sky-500 px-3 py-2 text-slate-50 hover:cursor-pointer hover:bg-sky-400"> |
17 | 35 | <div class="codicon codicon-search" aria-label="search"></div> |
18 | 36 | </div> |
19 | 37 | </div> |
20 | | - <p id="documentation-found-length" class="italic">${subtitle}</p>`; |
| 38 | + <div id="subtitle" class="flex items-center gap-4"> |
| 39 | + <p class="italic">${subtitle}</p> |
| 40 | + <div class="flex gap-3"> |
| 41 | + ${registryButton(hideRegistries, "npm", npm)} |
| 42 | + ${registryButton(hideRegistries, "packagist", packagist)} |
| 43 | + </div> |
| 44 | + </div>`; |
21 | 45 | }; |
22 | 46 |
|
23 | 47 | export default searchInput; |
0 commit comments