11import React from 'react' ;
2- import { Dropdown , Icon , Input } from 'semantic-ui-react' ;
2+ import { Dropdown , Icon , Input , Checkbox } from 'semantic-ui-react' ;
3+
4+ // http://githut.info/
5+ const topProgramLan = [
6+ { id : '22,106' , language : 'JavaScript, CoffeeScript' } ,
7+ { id : '133,135' , language : 'CSS' } ,
8+ { id : '3,39' , language : 'HTML' } ,
9+ { id : 137 , language : 'Swift' } ,
10+ { id : 35 , language : 'Objective-C' } ,
11+ { id : 23 , language : 'Java' } ,
12+ { id : 19 , language : 'Python' } ,
13+ { id : 24 , language : 'PHP' } ,
14+ { id : 32 , language : 'Ruby' } ,
15+ { id : 28 , language : 'C' } ,
16+ { id : 16 , language : 'C++' } ,
17+ { id : 6 , language : 'C#' } ,
18+ { id : 55 , language : 'Go' } ,
19+ { id : 51 , language : 'Perl' } ,
20+ { id : '104,109' , language : 'Clojure, ClojureScript' } ,
21+ { id : 40 , language : 'Haskell' } ,
22+ { id : 54 , language : 'Lua' } ,
23+ { id : 20 , language : 'Matlab' } ,
24+ { id : 144 , language : 'R' } ,
25+ { id : 47 , language : 'Scala' } ,
26+ { id : '69,78,146' , language : 'Shell' } ,
27+ { id : 29 , language : 'Lisp' } ,
28+ { id : 42 , language : 'ActionScript' }
29+ ] ;
30+
31+
332
433export default class SearchBar extends React . Component {
534 input = React . createRef ( ) ;
@@ -8,7 +37,7 @@ export default class SearchBar extends React.Component {
837 constructor ( props ) {
938 super ( props ) ;
1039 this . state = {
11- lang : null ,
40+ lang : [ ] ,
1241 prevProps : props ,
1342 inputSize : 'huge'
1443 }
@@ -17,7 +46,9 @@ export default class SearchBar extends React.Component {
1746
1847 static getDerivedStateFromProps ( nextProps , prevState ) {
1948 // avoid calculating expensive derived data
20- if ( prevState . prevProps === nextProps ) { return null }
49+ if ( prevState . prevProps === nextProps ) {
50+ return null
51+ }
2152 let newState = {
2253 prevProps : nextProps // prevProps memoization
2354 }
@@ -40,7 +71,34 @@ export default class SearchBar extends React.Component {
4071 this . props . onSearch ( this . input . current . inputRef . value , this . state . lang ) ;
4172 }
4273
43- handleTypeChange = ( e , { value } ) => this . setState ( { type : value } ) ;
74+ handleRestLang = ( ) => {
75+ this . setState ( { lang : [ ] } )
76+ }
77+
78+ handleSelectLang = id => {
79+ this . setState ( { lang : this . state . lang . concat ( id ) } )
80+ }
81+
82+ handleDeselectLang = id => {
83+ let lang = this . state . lang ;
84+ lang . splice ( this . state . lang . indexOf ( id ) , 1 ) ;
85+ this . setState ( { lang : lang } )
86+ }
87+
88+ handleToggleSelectLang = id => {
89+ this . state . lang . indexOf ( id ) === - 1 ? this . handleSelectLang ( id ) : this . handleDeselectLang ( id ) ;
90+ }
91+
92+ renderItems ( ) {
93+ return topProgramLan . map ( key => {
94+ const active = this . state . lang . indexOf ( key . id ) !== - 1 ;
95+ return < Dropdown . Item key = { key . id }
96+ active = { active }
97+ onClick = { ( ) => this . handleToggleSelectLang ( key . id ) } >
98+ < Icon name = { active ? 'check circle outline' : 'circle outline' } /> { key . language }
99+ </ Dropdown . Item > ;
100+ } )
101+ }
44102
45103 render ( ) {
46104 return (
@@ -49,30 +107,22 @@ export default class SearchBar extends React.Component {
49107 Search over GitHub, Bitbucket, GitLab to find real-world usage variable names
50108 </ div >
51109 < Input ref = { this . input }
52- className = { `search-bar__input${ this . props . variableList . length ? ' search-bar__input--dark' :'' } ` }
110+ className = { `search-bar__input${ this . props . variableList . length ? ' search-bar__input--dark' : '' } ` }
53111 icon fluid placeholder = { this . props . placeholder } size = { this . state . inputSize } >
54112 < Dropdown text = '' icon = 'filter' className = 'search-bar__dropdown' >
55113 < Dropdown . Menu >
56- < Dropdown . Item icon = 'undo' text = 'All 90 Languages (Reset)' />
114+ < Dropdown . Item icon = 'undo' text = 'All 90 Languages (Reset)' onClick = { this . handleRestLang } />
57115 < Dropdown . Menu scrolling >
58- < Dropdown . Item text = 'Open...' description = 'ctrl + o' />
59- < Dropdown . Item text = 'Save as...' description = 'ctrl + s' />
60- < Dropdown . Item text = 'Rename' description = 'ctrl + r' />
61- < Dropdown . Item text = 'Make a copy' />
62- < Dropdown . Item icon = 'folder' text = 'Move to folder' />
63- < Dropdown . Item icon = 'trash' text = 'Move to trash' />
64- < Dropdown . Item icon = 'trash' text = 'Move to trash' />
65- < Dropdown . Item icon = 'trash' text = 'Move to trash' />
66- < Dropdown . Item icon = 'trash' text = 'Move to trash' />
67- < Dropdown . Item icon = 'trash' text = 'Move to trash' />
68- < Dropdown . Item icon = 'trash' text = 'Move to trash' />
69- < Dropdown . Item icon = 'trash' text = 'Move to trash' />
116+ { this . renderItems ( ) }
70117 </ Dropdown . Menu >
71118 </ Dropdown . Menu >
72119 </ Dropdown >
73120 < input defaultValue = { this . props . searchValue }
74- onKeyPress = { e => { e . key === 'Enter' && this . handleSearch ( ) } } />
75- < Icon name = 'search' link onClick = { ( ) => this . handleSearch ( ) } />
121+ onKeyPress = { e => {
122+ e . key === 'Enter' && this . handleSearch ( )
123+ } } />
124+ < Icon name = { this . props . variableList . length ? 'search plus' : 'search' }
125+ link onClick = { ( ) => this . handleSearch ( ) } />
76126 </ Input >
77127 < div className = 'search-bar__helper' >
78128 </ div >
0 commit comments