|
1 | 1 | import * as React from 'react';
|
2 | 2 |
|
3 |
| -import styled from '../../styled-components'; |
4 |
| - |
5 | 3 | import { IMenuItem } from '../../services/MenuStore';
|
6 | 4 | import { SearchStore } from '../../services/SearchStore';
|
7 | 5 | import { MenuItem } from '../SideMenu/MenuItem';
|
8 |
| -import { MenuItemLabel } from '../SideMenu/styled.elements'; |
| 6 | + |
9 | 7 | import { MarkerService } from '../../services/MarkerService';
|
10 | 8 | import { SearchDocument } from '../../services/SearchWorker.worker';
|
11 | 9 |
|
12 |
| -const SearchInput = styled.input.attrs({ |
13 |
| - className: 'search-input', |
14 |
| -})` |
15 |
| - width: calc(100% - ${props => props.theme.spacingUnit * 2}px); |
16 |
| - box-sizing: border-box; |
17 |
| - margin: 0 ${props => props.theme.spacingUnit}px; |
18 |
| - padding: 5px 0 5px ${props => props.theme.spacingUnit}px; |
19 |
| - border: 0; |
20 |
| - border-bottom: 1px solid #e1e1e1; |
21 |
| - font-weight: bold; |
22 |
| - font-size: 13px; |
23 |
| - color: ${props => props.theme.colors.text}; |
24 |
| - background-color: transparent; |
25 |
| - outline: none; |
26 |
| -`; |
27 |
| - |
28 |
| -const SearchIcon = styled((props: any) => ( |
29 |
| - <svg |
30 |
| - className={props.className} |
31 |
| - version="1.1" |
32 |
| - viewBox="0 0 1000 1000" |
33 |
| - x="0px" |
34 |
| - xmlns="http://www.w3.org/2000/svg" |
35 |
| - y="0px" |
36 |
| - > |
37 |
| - <path d="M968.2,849.4L667.3,549c83.9-136.5,66.7-317.4-51.7-435.6C477.1-25,252.5-25,113.9,113.4c-138.5,138.3-138.5,362.6,0,501C219.2,730.1,413.2,743,547.6,666.5l301.9,301.4c43.6,43.6,76.9,14.9,104.2-12.4C981,928.3,1011.8,893,968.2,849.4z M524.5,522c-88.9,88.7-233,88.7-321.8,0c-88.9-88.7-88.9-232.6,0-321.3c88.9-88.7,233-88.7,321.8,0C613.4,289.4,613.4,433.3,524.5,522z" /> |
38 |
| - </svg> |
39 |
| -)).attrs({ |
40 |
| - className: 'search-icon', |
41 |
| -})` |
42 |
| - position: absolute; |
43 |
| - left: ${props => props.theme.spacingUnit}px; |
44 |
| - height: 1.8em; |
45 |
| - width: 0.9em; |
46 |
| -
|
47 |
| - path { |
48 |
| - fill: ${props => props.theme.colors.text}; |
49 |
| - } |
50 |
| -`; |
51 |
| - |
52 |
| -const SearchResultsBox = styled.div.attrs({ |
53 |
| - className: 'search-results', |
54 |
| -})` |
55 |
| - padding: ${props => props.theme.spacingUnit / 4}px 0; |
56 |
| - background-color: #ededed; |
57 |
| - min-height: 150px; |
58 |
| - max-height: 250px; |
59 |
| - border-top: 1px solid #e1e1e1; |
60 |
| - border-bottom: 1px solid #e1e1e1; |
61 |
| - margin-top: 10px; |
62 |
| - line-height: 1.4; |
63 |
| - font-size: 0.9em; |
64 |
| - overflow: auto; |
65 |
| -
|
66 |
| - ${MenuItemLabel} { |
67 |
| - padding-top: 6px; |
68 |
| - padding-bottom: 6px; |
69 |
| -
|
70 |
| - &:hover { |
71 |
| - background-color: #e1e1e1; |
72 |
| - } |
73 |
| -
|
74 |
| - > svg { |
75 |
| - display: none; |
76 |
| - } |
77 |
| - } |
78 |
| -`; |
| 10 | +import { ClearIcon, SearchIcon, SearchInput, SearchResultsBox } from './elements'; |
79 | 11 |
|
80 | 12 | export interface SearchBoxProps {
|
81 | 13 | search: SearchStore;
|
@@ -113,13 +45,13 @@ export class SearchBox extends React.PureComponent<SearchBoxProps, SearchBoxStat
|
113 | 45 | this.props.marker.unmark();
|
114 | 46 | }
|
115 | 47 |
|
116 |
| - clear() { |
| 48 | + clear = () => { |
117 | 49 | this.setState({
|
118 | 50 | results: [],
|
119 | 51 | term: '',
|
120 | 52 | });
|
121 | 53 | this.props.marker.unmark();
|
122 |
| - } |
| 54 | + }; |
123 | 55 |
|
124 | 56 | clearIfEsq = event => {
|
125 | 57 | if (event && event.keyCode === 27) {
|
@@ -163,6 +95,7 @@ export class SearchBox extends React.PureComponent<SearchBoxProps, SearchBoxStat
|
163 | 95 |
|
164 | 96 | return (
|
165 | 97 | <div>
|
| 98 | + {this.state.term && <ClearIcon onClick={this.clear}>×</ClearIcon>} |
166 | 99 | <SearchIcon />
|
167 | 100 | <SearchInput
|
168 | 101 | value={this.state.term}
|
|
0 commit comments