diff --git a/src/components/management/SearchBox.jsx b/src/components/management/SearchBox.jsx deleted file mode 100644 index b99d2d3..0000000 --- a/src/components/management/SearchBox.jsx +++ /dev/null @@ -1,230 +0,0 @@ -import Inferno from 'inferno'; -import Component from 'inferno-component'; - -import Helper from '../../Helper'; - -import dictionary from '../../managers/DictionaryData'; - -export class SearchBox extends Component { - constructor (props) { - super(props); - - this.state = { - searchingIn: 'name' - , searchTerm: '' - , filteredPartsOfSpeech: [] - , showHeader: false - , showAdvanced: false - }; - } - - componentDidUpdate(prevProps, prevState) { - if (this.state.showHeader && this.searchBox) { - this.searchBox.focus(); - } - } - - search () { - const {searchingIn, searchTerm, filteredPartsOfSpeech} = this.state; - const searchConfig = { - searchingIn - , searchTerm - , filteredPartsOfSpeech - }; - - this.props.search(searchConfig); - } - - displaySearchHeader () { - if (this.state.showHeader) { - return ( -
-
-
this.hideHeader()} /> - -
-
-
- -
-
-

- - - -

-

- { - this.searchBox = input; - }} - value={this.state.searchTerm} - onChange={event => { - console.log(event); - this.setState({ searchTerm: event.target.value }); - }} /> -

-
- - {this.showFilterOptions()} - -
- - -
-
-
-
-
- ); - } - } - - showFilterOptions () { - if (dictionary.partsOfSpeech.length > 0) { - const searchMethodSectionJSX = this.state.searchingIn !== 'details' - ? ( -
-
- -
-
-
-

- - - -

-
-
-

- - Contains:  - Search term is anywhere within the {this.state.searchingIn.capitalize()} - - - Starts With:  - The {this.state.searchingIn.capitalize()} begins with the search term - - - Exact:  - Search term matches the {this.state.searchingIn.capitalize()} exactly - -

-
-
-
- ) - : null; - - const filterSectionJSX = ( -
-
- -
-
-
- {dictionary.partsOfSpeech.map((partOfSpeech) => { - return ( -

- -

- ); - })} -
-
-
- ); - - const advancedSectionJSX = ( -
-
- {searchMethodSectionJSX} - {filterSectionJSX} -
-
- ); - - return ( -
-
-
-

- this.setState({showAdvanced: !this.state.showAdvanced})}> - Advanced - -

-
-
- {this.state.showAdvanced ? advancedSectionJSX : null} -
- ); - } - } - - showHeader () { - this.setState({ - showHeader: true - }); - } - - hideHeader () { - this.setState({ - showHeader: false - }); - } - - render () { - return ( -
-
-

- this.showHeader()} /> -

-

- this.showHeader()}> - Search - -

-
- - this.showHeader()}> - S - - - {this.displaySearchHeader()} -
- ); - } -} diff --git a/src/components/management/SearchBox/SearchMethod.js b/src/components/management/SearchBox/SearchMethod.js new file mode 100644 index 0000000..262e7ce --- /dev/null +++ b/src/components/management/SearchBox/SearchMethod.js @@ -0,0 +1,6 @@ +export default { + contains: 'contains', + startsWith: 'start', + endsWith: 'end', + isExactly: 'exact', +}; \ No newline at end of file diff --git a/src/components/management/SearchBox/index.jsx b/src/components/management/SearchBox/index.jsx new file mode 100644 index 0000000..9715230 --- /dev/null +++ b/src/components/management/SearchBox/index.jsx @@ -0,0 +1,273 @@ +import Inferno from 'inferno'; +import Component from 'inferno-component'; + +import Helper from '../../../Helper'; + +import dictionary from '../../../managers/DictionaryData'; + +import METHOD from './SearchMethod.js'; + +export class SearchBox extends Component { + constructor (props) { + super(props); + + this.state = { + searchingIn: 'name', + searchMethod: METHOD.contains, + searchTerm: '', + filteredPartsOfSpeech: [], + showHeader: false, + showAdvanced: false, + }; + } + + componentDidUpdate(prevProps, prevState) { + if (this.state.showHeader && this.searchBox) { + this.searchBox.focus(); + } + } + + search () { + const {searchingIn, searchMethod, searchTerm, filteredPartsOfSpeech} = this.state; + const searchConfig = { + searchingIn, + searchMethod, + searchTerm, + filteredPartsOfSpeech, + }; + + this.props.search(searchConfig); + } + + displaySearchHeader () { + if (this.state.showHeader) { + return ( +
+
+
+ +
+
+
+ +
+
+

+ + + +

+

+ { + this.searchBox = input; + }} + value={ this.state.searchTerm } + onChange={event => { + console.log(event); + this.setState({ searchTerm: event.target.value }); + }} /> +

+
+ + { this.showFilterOptions() } + +
+ + +
+
+
+
+
+ ); + } + } + + showFilterOptions () { + if (this.props.partsOfSpeech.length > 0) { + const searchMethodSectionJSX = this.state.searchingIn !== 'details' + ? ( +
+
+ +
+
+
+

+ + + + +

+
+
+
+ ) + : null; + + const filterSectionJSX = ( +
+
+ +
+
+
+ { + this.props.partsOfSpeech.map(partOfSpeech => { + return ( +

+ +

+ ); + }) + } +
+
+
+ ); + + const advancedSectionJSX = ( +
+
+ { searchMethodSectionJSX } + { filterSectionJSX } +
+
+ ); + + return ( +
+
+
+

+ this.setState({ showAdvanced: !this.state.showAdvanced }) }> + Advanced + +

+
+
+ { this.state.showAdvanced ? advancedSectionJSX : null } +
+ ); + } + } + + showHeader () { + this.setState({ + showHeader: true + }); + } + + hideHeader () { + this.setState({ + showHeader: false + }); + } + + render () { + return ( +
+
+

+ +

+

+ + Search + +

+
+ + + S + + + { this.displaySearchHeader() } +
+ ); + } +} diff --git a/src/components/structure/Header.jsx b/src/components/structure/Header.jsx index 154ad3b..0489eeb 100644 --- a/src/components/structure/Header.jsx +++ b/src/components/structure/Header.jsx @@ -8,7 +8,7 @@ export class Header extends Component { super(props); this.state = { - displayNavMenu: false + displayNavMenu: false, } } @@ -17,14 +17,15 @@ export class Header extends Component {