|
| 1 | +"use client"; |
| 2 | + |
| 3 | +import { useState } from "react"; |
1 | 4 | import type { NextPage } from "next"; |
2 | 5 | import NameLink from "@azure-fundamentals/components/NameLink"; |
3 | 6 | import exams from "@azure-fundamentals/lib/exams.json"; |
4 | 7 |
|
5 | 8 | const Home: NextPage = () => { |
| 9 | + const [searchTerm, setSearchTerm] = useState(""); |
| 10 | + |
| 11 | + const handleSearchChange = (event: React.ChangeEvent<HTMLInputElement>) => { |
| 12 | + setSearchTerm(event.target.value); |
| 13 | + }; |
| 14 | + |
| 15 | + const filteredExams = exams.filter((exam) => |
| 16 | + exam.name.toLowerCase().includes(searchTerm.toLowerCase()), |
| 17 | + ); |
| 18 | + |
6 | 19 | return ( |
7 | 20 | <div className="mx-auto mb-6 w-full lg:w-[70vw] 2xl:w-[45%] text-center"> |
8 | | - <h2 className="text-white text-5xl text-leading font-bold uppercase md:mt-14"> |
| 21 | + <h2 className="text-white text-5xl font-bold uppercase md:mt-14"> |
9 | 22 | Welcome! |
10 | 23 | </h2> |
11 | 24 | <p className="text-white text-lg mt-4 mb-14 px-5 leading-6"> |
12 | | - Select an exam from the list bellow. |
| 25 | + Select an exam from the list below. |
13 | 26 | </p> |
| 27 | + <input |
| 28 | + type="text" |
| 29 | + value={searchTerm} |
| 30 | + onChange={handleSearchChange} |
| 31 | + placeholder="Search exams" |
| 32 | + className="mb-5 px-4 py-2 border border-gray-300 rounded-md w-3/4 lg:w-1/2" |
| 33 | + /> |
14 | 34 | <div className="grid grid-cols-1 sm:grid-cols-2 gap-x-10 gap-y-5 mx-5 lg:mx-0"> |
15 | | - {exams.map((exam) => { |
16 | | - return ( |
17 | | - <NameLink |
18 | | - key={exam.name} |
19 | | - href={{ |
20 | | - pathname: "/modes", |
21 | | - query: { url: exam.url, name: exam.name }, |
22 | | - }} |
23 | | - heading={exam.name} |
24 | | - paragraph={exam.subtitle} |
25 | | - wrapperClassNames="hover:bg-[#C7D2E2]" |
26 | | - headingClassNames="group-hover:from-[#fff] group-hover:to-[#fff]" |
27 | | - /> |
28 | | - ); |
29 | | - })} |
| 35 | + {filteredExams.map((exam) => ( |
| 36 | + <NameLink |
| 37 | + key={exam.name} |
| 38 | + href={{ |
| 39 | + pathname: "/modes", |
| 40 | + query: { url: exam.url, name: exam.name }, |
| 41 | + }} |
| 42 | + heading={exam.name} |
| 43 | + paragraph={exam.subtitle} |
| 44 | + wrapperClassNames="hover:bg-[#C7D2E2]" |
| 45 | + headingClassNames="group-hover:from-[#fff] group-hover:to-[#fff]" |
| 46 | + /> |
| 47 | + ))} |
30 | 48 | </div> |
31 | 49 | </div> |
32 | 50 | ); |
|
0 commit comments