hyper/lib/components/searchBox.tsx

80 lines
2 KiB
TypeScript
Raw Normal View History

import React from 'react';
2020-03-18 07:26:46 -08:00
import {SearchBoxProps} from '../hyper';
2020-03-18 07:26:46 -08:00
const searchBoxStyling: React.CSSProperties = {
float: 'right',
height: '28px',
backgroundColor: 'white',
position: 'absolute',
right: '10px',
top: '25px',
width: '224px',
2020-03-18 07:26:46 -08:00
zIndex: 9999
};
const enterKey = 13;
2020-03-18 07:26:46 -08:00
export default class SearchBox extends React.PureComponent<SearchBoxProps> {
searchTerm: string;
constructor(props: SearchBoxProps) {
super(props);
this.searchTerm = '';
}
2020-03-18 07:26:46 -08:00
handleChange = (event: React.KeyboardEvent<HTMLInputElement>) => {
this.searchTerm = event.currentTarget.value;
if (event.keyCode === enterKey) {
2020-03-18 07:26:46 -08:00
this.props.search(event.currentTarget.value);
}
2019-11-25 07:16:00 -09:00
};
render() {
return (
<div style={searchBoxStyling}>
<input type="text" className="search-box" onKeyUp={this.handleChange} ref={input => input && input.focus()} />
<span className="search-button" onClick={() => this.props.prev(this.searchTerm)}>
{' '}
&#x2190;{' '}
</span>
<span className="search-button" onClick={() => this.props.next(this.searchTerm)}>
{' '}
&#x2192;{' '}
</span>
<span className="search-button" onClick={() => this.props.close()}>
{' '}
x{' '}
</span>
<style jsx>
{`
.search-box {
font-size: 18px;
padding: 6px;
width: 145px;
border: none;
}
.search-box:focus {
outline: none;
}
.search-button {
background-color: #ffffff;
color: black;
padding: 7px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
transition-duration: 0.4s;
cursor: pointer;
}
.search-button:hover {
background-color: #e7e7e7;
}
`}
</style>
</div>
);
}
}