Skip to content

Commit d836a34

Browse files
committed
Complete 08. Hidden Search Bar
1 parent 9fad31d commit d836a34

File tree

6 files changed

+91
-15
lines changed

6 files changed

+91
-15
lines changed

08. Hidden-Search-Bar/README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +0,0 @@
1-
# React + Vite
2-
3-
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4-
5-
Currently, two official plugins are available:
6-
7-
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8-
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9-
10-
## Expanding the ESLint configuration
11-
12-
If you are developing a production application, we recommend using TypeScript and enable type-aware lint rules. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.

08. Hidden-Search-Bar/package-lock.json

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

08. Hidden-Search-Bar/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
},
1212
"dependencies": {
1313
"react": "^19.0.0",
14-
"react-dom": "^19.0.0"
14+
"react-dom": "^19.0.0",
15+
"react-icons": "^5.5.0"
1516
},
1617
"devDependencies": {
1718
"@eslint/js": "^9.21.0",

08. Hidden-Search-Bar/src/App.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
rfce
1+
import React from "react";
2+
import HiddenSearchBar from "./HiddenSearchBar";
3+
4+
function App() {
5+
return (
6+
<div>
7+
<HiddenSearchBar />
8+
</div>
9+
);
10+
}
11+
12+
export default App;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React, { useState } from "react";
2+
import { FaSearch } from "react-icons/fa";
3+
4+
function HiddenSearchBar() {
5+
const [showInput, setShowInput] = useState(false);
6+
const [bgColor, setBgColor] = useState("white");
7+
8+
const handleClick = (e) => {
9+
setBgColor("#1a1a1a");
10+
11+
if (e.target.className === "container") {
12+
setShowInput(false);
13+
setBgColor("#fff");
14+
}
15+
};
16+
17+
return (
18+
<section
19+
className="container"
20+
style={{ backgroundColor: bgColor }}
21+
onClick={handleClick}
22+
>
23+
{showInput ? (
24+
<input type="text" placeholder="Search..." />
25+
) : (
26+
<FaSearch onClick={() => setShowInput(true)} />
27+
)}
28+
</section>
29+
);
30+
}
31+
32+
export default HiddenSearchBar;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
* {
3+
margin: 0;
4+
padding: 0;
5+
box-sizing: border-box;
6+
}
7+
8+
section {
9+
height: 100vh;
10+
display: flex;
11+
flex-direction: column;
12+
justify-content: center;
13+
align-items: center;
14+
transition: 0.7s ease;
15+
}
16+
17+
button {
18+
position: absolute;
19+
top: 20px;
20+
right: 20px;
21+
padding: 10px 20px;
22+
background: transparent;
23+
cursor: pointer;
24+
}
25+
26+
input {
27+
padding: 13px 12px;
28+
background: transparent;
29+
outline: none;
30+
border: 1px solid #fff;
31+
color: #fff;
32+
border-radius: 2px;
33+
box-shadow: 2px 2px 2px 1px rgb(35, 35, 35);
34+
}

0 commit comments

Comments
 (0)