@@ -2,60 +2,69 @@ import React, { Component } from 'react';
22import EmojiList from './emojiList.json' ;
33import './App.css' ;
44import Navbar from './Components/Navbar'
5+
56class App extends Component {
67 constructor ( props ) {
78 super ( props ) ;
89 this . state = {
910 emojiList : EmojiList ,
1011 inputValue : "" ,
11- title : ""
12+ copiedEmoji : null
1213 }
1314 this . searchEmoji = this . searchEmoji . bind ( this ) ;
1415 this . copyToClipboard = this . copyToClipboard . bind ( this ) ;
1516 }
17+
1618 searchEmoji = ( e ) => {
17- this . setState ( { inputValue : e . target . value } )
19+ const inputValue = e . target . value . trim ( ) ;
20+ this . setState ( { inputValue } ) ;
1821 }
19- copyToClipboard = ( title , symbol ) => {
22+
23+ copyToClipboard = ( symbol ) => {
2024 navigator . clipboard . writeText ( symbol ) ;
21- this . setState ( { title : title } )
25+ this . setState ( { copiedEmoji : symbol } ) ;
2226 setTimeout ( ( ) => {
23- this . setState ( { title : "" } )
24- } , 4000 )
27+ this . setState ( { copiedEmoji : null } ) ;
28+ } , 4000 ) ;
2529 }
30+
2631 render ( ) {
27- return ( < React . Fragment >
28- < Navbar />
29- < div className = "container " >
30- < h1 className = "heading pb-5" > 🦄 Emoji Search App</ h1 >
31- < div className = "col-md-6 mb-4 mx-auto" >
32- < div className = "input-group md-form form-sm form-2 pl-0" >
33- < div className = "input-group-append" >
34- < span className = "input-group-text amber lighten-3" id = "basic-text1" > < i className = "fa fa-search text-grey"
35- aria-hidden = "true" > </ i > </ span >
32+ return (
33+ < React . Fragment >
34+ < Navbar />
35+ < div className = "container " >
36+ < h1 className = "heading pb-5" > 🦄 Emoji Search App</ h1 >
37+ < div className = "col-md-6 mb-4 mx-auto" >
38+ < div className = "input-group md-form form-sm form-2 pl-0" >
39+ < div className = "input-group-append" >
40+ < span className = "input-group-text amber lighten-3" id = "basic-text1" > < i className = "fa fa-search text-grey"
41+ aria-hidden = "true" > </ i > </ span >
42+ </ div >
43+ < input className = "form-control my-0 py-1 " onChange = { ( e ) => { this . searchEmoji ( e ) } } type = "text" placeholder = "Search for an emoji" aria-label = "Search" > </ input >
3644 </ div >
37- < input className = "form-control my-0 py-1 " onChange = { ( e ) => { this . searchEmoji ( e ) } } type = "text" placeholder = "Search for an emoji" aria-label = "Search" > </ input >
45+ </ div >
46+ < div className = "row mx-auto " >
47+ {
48+ this . state . emojiList . filter ( value => {
49+ return value . keywords . some ( keyword => keyword . toLowerCase ( ) . includes ( this . state . inputValue . toLowerCase ( ) ) )
50+ } ) . map ( el => {
51+ return (
52+ < div className = "card emojiCard m-3 card-columns mx-auto d-flex justify-content-center " data-toggle = "tooltip" data-placement = "bottom" title = "Click here to Copy" onClick = { ( ) => this . copyToClipboard ( el . symbol ) } >
53+ < div className = "emoji" >
54+ < span className = "emoji" >
55+ { el . symbol }
56+ </ span >
57+ { this . state . copiedEmoji === el . symbol && < p className = "fade-in " > Copied!</ p > }
58+ </ div >
59+ </ div >
60+ )
61+ } )
62+ }
3863 </ div >
3964 </ div >
40- < div className = "row mx-auto " >
41- {
42- this . state . emojiList . filter ( value => {
43- return value . keywords . toLowerCase ( ) . includes ( this . state . inputValue . toLowerCase ( ) )
44- } ) . map ( el => {
45- return < div className = "card emojiCard m-3 card-columns mx-auto d-flex justify-content-center " data-toggle = "tooltip" data-placement = "bottom" title = "Click here to Copy" onClick = { ( ) => this . copyToClipboard ( el . title , el . symbol ) } >
46- < div className = "emoji" >
47- < span className = "emoji" ref = { ( copyEmoji ) => this . copyEmoji = copyEmoji } >
48- { el . symbol }
49- </ span >
50- { this . state . title === el . title && < p className = "fade-in " > Copied!</ p > }
51- </ div >
52- </ div >
53- } )
54- }
55- </ div >
56- </ div >
57- </ React . Fragment >
65+ </ React . Fragment >
5866 ) ;
5967 }
6068}
61- export default App ;
69+
70+ export default App ;
0 commit comments