Skip to content

Commit 1bf0041

Browse files
committed
Added a Search Box
1 parent 93b58d2 commit 1bf0041

File tree

7 files changed

+123
-6
lines changed

7 files changed

+123
-6
lines changed

src/App.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.App {
2+
text-align: center;
3+
}
4+
5+
.App-body {
6+
display: flex;
7+
max-width: 1200px;
8+
padding: 1rem 2rem 4rem 2rem;
9+
margin: auto;
10+
}

src/App.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import React, { Component } from "react";
2+
23
import "./App.css";
34

5+
import Header from "./components/Header";
6+
47
class App extends Component {
58
render() {
69
return (
710
<div className="App">
8-
<header className="App-header">
9-
<h1 className="App-title">Welcome to React</h1>
10-
</header>
11-
<p className="App-intro">
12-
To get started, edit <code>src/App.js</code> and save to reload.
13-
</p>
11+
<div className="App-body">
12+
<Header />
13+
</div>
1414
</div>
1515
);
1616
}

src/components/Header.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.Header {
2+
display: flex;
3+
width: 100%;
4+
align-items: center;
5+
height: 50px;
6+
}
7+
8+
.Header-label {
9+
font-size: 20px;
10+
margin-right: 10px;
11+
}

src/components/Header.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from "react";
2+
import "./Header.css";
3+
4+
import SearchBox from "../containers/SearchBox";
5+
6+
export default function Header() {
7+
return (
8+
<div className="Header">
9+
<label className="Header-label" htmlFor="search">
10+
Search
11+
</label>
12+
<SearchBox />
13+
</div>
14+
);
15+
}

src/components/SearchBox.css

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.SearchBox {
2+
display: flex;
3+
}
4+
5+
.SearchBox-input {
6+
/* reset */
7+
background-image: none;
8+
background-color: transparent;
9+
-webkit-box-shadow: none;
10+
-moz-box-shadow: none;
11+
box-shadow: none;
12+
border: none;
13+
14+
font-size: 16px;
15+
min-width: 400px;
16+
height: 30px;
17+
padding: 0 6px;
18+
border: 1px solid darkgray;
19+
border-bottom-left-radius: 2px;
20+
border-top-left-radius: 2px;
21+
}
22+
23+
.SearchBox-button {
24+
/* reset */
25+
border: none;
26+
margin: 0;
27+
padding: 0;
28+
width: auto;
29+
overflow: visible;
30+
background: transparent;
31+
color: inherit;
32+
font: inherit;
33+
line-height: normal;
34+
-webkit-font-smoothing: inherit;
35+
-moz-osx-font-smoothing: inherit;
36+
-webkit-appearance: none;
37+
38+
border-bottom-right-radius: 2px;
39+
border-top-right-radius: 2px;
40+
border: 1px solid darkgray;
41+
border-left: none;
42+
padding: 0 5px;
43+
cursor: pointer;
44+
}

src/components/SearchBox.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from "react";
2+
import "./SearchBox.css";
3+
4+
export default function SearchBox({ value, onChange }) {
5+
return (
6+
<form className="SearchBox">
7+
<input
8+
className="SearchBox-input"
9+
type="text"
10+
value={value}
11+
onChange={onChange}
12+
/>
13+
<button className="SearchBox-button">GO</button>
14+
</form>
15+
);
16+
}

src/containers/SearchBox.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React, { Component } from "react";
2+
3+
import SearchBox from "../components/SearchBox";
4+
5+
class App extends Component {
6+
state = {
7+
value: "cat"
8+
};
9+
10+
render() {
11+
return <SearchBox value={this.state.value} onChange={this.handleChange} />;
12+
}
13+
14+
handleChange = e => {
15+
this.setState({
16+
value: e.currentTarget.value
17+
});
18+
};
19+
}
20+
21+
export default App;

0 commit comments

Comments
 (0)