Skip to content

Commit 7c0eb7f

Browse files
added searchbar
1 parent 6b1c295 commit 7c0eb7f

File tree

4 files changed

+164
-4
lines changed

4 files changed

+164
-4
lines changed

package-lock.json

Lines changed: 136 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"react-bootstrap": "^1.0.1",
1212
"react-dom": "^16.13.1",
1313
"react-scripts": "3.4.1",
14+
"react-select": "^3.1.0",
1415
"sweetalert2": "^9.10.13"
1516
},
1617
"scripts": {

src/App.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
white-space: pre-wrap
2525
}
2626

27+
.searchInput{
28+
width: 80%;
29+
margin: 20px auto;
30+
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
31+
}
32+
2733

2834
@media only screen and (min-width: 800px) {
2935
.cardList{
@@ -42,4 +48,11 @@
4248
hyphens: auto;
4349
white-space: pre-wrap
4450
}
51+
52+
.searchInput{
53+
width: 50%;
54+
margin: 20px auto;
55+
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
56+
}
57+
4558
}

src/App.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import './App.css';
3-
import {Navbar,Nav,Button,Card, ButtonGroup} from 'react-bootstrap';
3+
import {Navbar,Nav,Button,Card, ButtonGroup, Form, FormControl} from 'react-bootstrap';
44
import CreateModal from './createModal'
55
import ShowModal from './ShowModal';
66
import Swal from 'sweetalert2'
@@ -9,11 +9,13 @@ class App extends React.Component{
99
state = {
1010
modalShow:false,
1111
notes:[],
12+
notesToDisplay:[],
1213
modal2Show : false,
1314
modalType :'',
1415
id:'',
1516
title:'',
16-
body:''
17+
body:'',
18+
searchString:''
1719
}
1820

1921
submitNote = (data) =>{
@@ -68,7 +70,11 @@ class App extends React.Component{
6870
'Record is Updated',
6971
'success'
7072
)
71-
}
73+
}
74+
75+
searchItem = () => {
76+
77+
}
7278

7379

7480
render(){
@@ -79,6 +85,10 @@ class App extends React.Component{
7985
<Nav.Link onClick={() => this.setState({modalShow:true, modalType:''})} style={{color:'white',textDecoration:'none',position:'absolute',right:0,fontSize:'20px'}}><i className="fa fa-plus"></i></Nav.Link>
8086
</Navbar>
8187

88+
<Form className='searchInput'>
89+
<FormControl type="text" value={this.state.searchString} onChange={(e) => this.setState({searchString:e.target.value})} placeholder="Filter by title..." className="mr-sm-2" />
90+
</Form>
91+
8292
<CreateModal
8393
className='modal-content'
8494
show={this.state.modalShow}
@@ -98,7 +108,7 @@ class App extends React.Component{
98108

99109
<div style={{width:'90%',margin:'auto'}}>
100110
<div className='cardList'>
101-
{this.state.notes.map( (content)=>(
111+
{this.state.notes.filter(note => note.title.includes(this.state.searchString)).map( content => (
102112
<Card key={content.id} style={{ marginTop:'20px',width: '18rem',boxShadow:'0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)',borderRadius:'0.7rem'}}>
103113
<Card.Body>
104114
<Card.Title style={{display:'flex',justifyContent:'space-between'}}>

0 commit comments

Comments
 (0)