diff --git a/src/tailwindcss/src/search-documentation.tsx b/src/tailwindcss/src/search-documentation.tsx index ae34d05..955bea2 100644 --- a/src/tailwindcss/src/search-documentation.tsx +++ b/src/tailwindcss/src/search-documentation.tsx @@ -1,10 +1,12 @@ import { List } from "@project-gauntlet/api/components"; -import React, { ReactElement } from "react"; +import React, { ReactElement, useState } from "react"; import documentation from "./documentation/tailwind-css"; import { Clipboard } from "@project-gauntlet/api/helpers"; //import { open } from "@opensrc/deno-open"; # pending a fix for https://github.com/project-gauntlet/gauntlet/issues/28 export default function SearchDocumentation(): ReactElement { + const [searchText, setSearchText] = useState(""); + const onClick = async (url: string) => { //await open(url); await Clipboard.writeText(url); @@ -23,18 +25,39 @@ export default function SearchDocumentation(): ReactElement { // // } > - {Object.entries(documentation).map(([section, items]) => ( - - {items.map((item) => ( - onClick(item.url)} - /> + + {searchText + ? // eslint-disable-next-line @typescript-eslint/no-unused-vars + Object.entries(documentation).map(([_section, items]) => + items + .filter((item: { title: string; url: string }) => + item.title.toLowerCase().includes(searchText.toLowerCase()), + ) + .map((item: { title: string; url: string }) => ( + onClick(item.url)} + /> + )), + ) + : Object.entries(documentation).map(([section, items]) => ( + + {items.map((item) => ( + onClick(item.url)} + /> + ))} + ))} - - ))} ); }