2018-05-24 12:38:21 +00:00
|
|
|
import withColours from 'Components/withColours'
|
2018-01-30 14:52:25 +00:00
|
|
|
import React, { Component } from 'react'
|
2018-03-29 13:53:52 +00:00
|
|
|
import { Trans, translate } from 'react-i18next'
|
2018-03-29 13:11:22 +00:00
|
|
|
import { connect } from 'react-redux'
|
2018-01-30 14:52:25 +00:00
|
|
|
import Overlay from './Overlay'
|
2018-05-24 12:38:21 +00:00
|
|
|
import './SearchButton.css'
|
2018-01-30 14:52:25 +00:00
|
|
|
import { SearchBar } from './pages/RulesList'
|
|
|
|
|
2018-05-24 12:38:21 +00:00
|
|
|
@connect(state => ({
|
|
|
|
flatRules: state.flatRules
|
|
|
|
}))
|
2018-01-30 14:52:25 +00:00
|
|
|
@withColours
|
2018-03-29 13:53:52 +00:00
|
|
|
@translate()
|
2018-01-30 14:52:25 +00:00
|
|
|
export default class SearchButton extends Component {
|
2018-01-30 15:15:38 +00:00
|
|
|
componentDidMount() {
|
|
|
|
// removeEventListener will need the exact same function instance
|
|
|
|
this.boundHandleKeyDown = this.handleKeyDown.bind(this)
|
|
|
|
|
|
|
|
window.addEventListener('keydown', this.boundHandleKeyDown)
|
|
|
|
}
|
|
|
|
handleKeyDown(e) {
|
|
|
|
if (!(e.ctrlKey && e.key === 'p')) return
|
|
|
|
this.setState({ visible: true })
|
|
|
|
e.preventDefault()
|
|
|
|
e.stopPropagation()
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
|
|
window.removeEventListener('keydown', this.boundHandleKeyDown)
|
|
|
|
}
|
2018-01-30 14:52:25 +00:00
|
|
|
state = {
|
|
|
|
visible: false
|
|
|
|
}
|
2018-01-30 15:15:38 +00:00
|
|
|
close = () => this.setState({ visible: false })
|
2018-01-30 14:52:25 +00:00
|
|
|
render() {
|
2018-03-29 13:11:22 +00:00
|
|
|
let { flatRules } = this.props
|
2018-01-30 14:52:25 +00:00
|
|
|
return (
|
|
|
|
<div id="searchButton">
|
|
|
|
{this.state.visible ? (
|
2018-05-24 12:38:21 +00:00
|
|
|
<Overlay onClose={this.close}>
|
|
|
|
<h2>
|
|
|
|
<Trans>Chercher une règle</Trans>
|
|
|
|
</h2>
|
|
|
|
<SearchBar
|
|
|
|
showDefaultList={false}
|
|
|
|
finally={this.close}
|
|
|
|
rules={flatRules}
|
|
|
|
/>
|
2018-01-30 14:52:25 +00:00
|
|
|
</Overlay>
|
|
|
|
) : (
|
2018-03-29 09:14:00 +00:00
|
|
|
<button
|
|
|
|
onClick={() => this.setState({ visible: true })}
|
2018-05-24 12:38:21 +00:00
|
|
|
style={{ color: this.props.colours.colour }}>
|
2018-06-12 10:21:36 +00:00
|
|
|
<i
|
|
|
|
className="fa fa-search"
|
|
|
|
aria-hidden="true"
|
|
|
|
style={{ marginRight: '0.4em' }}
|
|
|
|
/>
|
2018-05-24 12:38:21 +00:00
|
|
|
<span>
|
|
|
|
<Trans>Recherche</Trans>
|
|
|
|
</span>
|
2018-01-30 14:52:25 +00:00
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|