|
| 1 | +import React, { PropTypes } from 'react' |
| 2 | +import CSSModules from 'browser/lib/CSSModules' |
| 3 | +import styles from './TopBar.styl' |
| 4 | +import activityRecord from 'browser/lib/activityRecord' |
| 5 | + |
| 6 | +const OSX = window.process.platform === 'darwin' |
| 7 | + |
| 8 | +class TopBar extends React.Component { |
| 9 | + constructor (props) { |
| 10 | + super(props) |
| 11 | + |
| 12 | + this.state = { |
| 13 | + search: '' |
| 14 | + } |
| 15 | + } |
| 16 | + |
| 17 | + isInputFocused () { |
| 18 | + return document.activeElement === this.refs.searchInput |
| 19 | + } |
| 20 | + |
| 21 | + escape () { |
| 22 | + } |
| 23 | + |
| 24 | + focusInput () { |
| 25 | + this.searchInput.focus() |
| 26 | + } |
| 27 | + |
| 28 | + blurInput () { |
| 29 | + this.searchInput.blur() |
| 30 | + } |
| 31 | + |
| 32 | + handleSearchChange (e) { |
| 33 | + } |
| 34 | + |
| 35 | + handleSearchClearButton (e) { |
| 36 | + this.searchInput.value = '' |
| 37 | + this.focusInput() |
| 38 | + } |
| 39 | + |
| 40 | + handleNewPostButtonClick (e) { |
| 41 | + activityRecord.emit('ARTICLE_CREATE') |
| 42 | + } |
| 43 | + |
| 44 | + handleTutorialButtonClick (e) { |
| 45 | + } |
| 46 | + |
| 47 | + handleLinksButton (e) { |
| 48 | + |
| 49 | + } |
| 50 | + |
| 51 | + render () { |
| 52 | + let { config } = this.props |
| 53 | + return ( |
| 54 | + <div className='TopBar' |
| 55 | + styleName={config.isSideNavFolded ? 'root--expanded' : 'root'} |
| 56 | + > |
| 57 | + <div styleName='left'> |
| 58 | + <div styleName='left-search'> |
| 59 | + <i styleName='left-search-icon' className='fa fa-search fa-fw'/> |
| 60 | + <input styleName='left-search-input' |
| 61 | + ref='searchInput' |
| 62 | + onFocus={(e) => this.handleSearchChange(e)} |
| 63 | + onBlur={(e) => this.handleSearchChange(e)} |
| 64 | + value={this.state.search} |
| 65 | + onChange={(e) => this.handleSearchChange(e)} |
| 66 | + placeholder='Search' |
| 67 | + type='text' |
| 68 | + /> |
| 69 | + {this.state.search > 0 && |
| 70 | + <button styleName='left-search-clearButton' |
| 71 | + onClick={(e) => this.handleSearchClearButton(e)} |
| 72 | + > |
| 73 | + <i className='fa fa-times'/> |
| 74 | + </button> |
| 75 | + } |
| 76 | + </div> |
| 77 | + |
| 78 | + <div styleName='left-control'> |
| 79 | + <button styleName='left-control-newPostButton' |
| 80 | + onClick={(e) => this.handleNewPostButtonClick(e)}> |
| 81 | + <i className='fa fa-plus'/> |
| 82 | + <span styleName='left-control-newPostButton-tooltip'> |
| 83 | + New Post ({OSX ? '⌘' : '^'} + n) |
| 84 | + </span> |
| 85 | + </button> |
| 86 | + </div> |
| 87 | + </div> |
| 88 | + |
| 89 | + <div styleName='right'> |
| 90 | + <button styleName='right-helpButton' |
| 91 | + onClick={(e) => this.handleTutorialButtonClick(e)} |
| 92 | + disabled |
| 93 | + > |
| 94 | + ?<span styleName='left-control-newPostButton-tooltip'>How to use</span> |
| 95 | + </button> |
| 96 | + <button styleName='right-linksButton' |
| 97 | + onClick={(e) => this.handleLinksButton(e)} |
| 98 | + > |
| 99 | + <img src='../resources/app.png' width='44' height='44'/> |
| 100 | + </button> |
| 101 | + </div> |
| 102 | + </div> |
| 103 | + ) |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +TopBar.propTypes = { |
| 108 | + dispatch: PropTypes.func, |
| 109 | + config: PropTypes.shape({ |
| 110 | + isSideNavFolded: PropTypes.bool |
| 111 | + }) |
| 112 | +} |
| 113 | + |
| 114 | +export default CSSModules(TopBar, styles) |
0 commit comments