-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsearch-strategy.html
224 lines (188 loc) · 4.64 KB
/
search-strategy.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!--
A Polymer Element showing search strategy.
### Example
```html
<search-strategy
free-text-search-fields="[[freeTextSearchFields]]"
selected-field="{{selectedField}}">
</search-strategy>
```
-->
<dom-module id="search-strategy">
<template>
<style>
:host {
display: flex;
}
#search_strategy {
font-size: 14px;
height: 16px;
line-height: 16px;
}
.category_item span {
display: inline-block;
text-transform: capitalize;
}
.category_item {
cursor: pointer;
display: inline-block;
margin-right: 5px;
}
.category_item:hover span {
text-decoration: underline;
}
iron-icon {
float: left;
height: 16px;
width: 16px;
min-height: 16px;
min-width: 16px;
margin-right: 5px;
}
iron-icon.amber {
color: var(--paper-amber-600);
}
iron-icon.black {
color: #111;
}
iron-icon.blue {
color: var(--paper-blue-600);
}
iron-icon.blue-grey {
color: var(--paper-blue-grey-600);
}
iron-icon.brown {
color: var(--paper-brown-600);
}
iron-icon.cyan {
color: var(--paper-cyan-600);
}
iron-icon.deep-orange {
color: var(--paper-deep-orange-600);
}
iron-icon.deep-purple {
color: var(--paper-deep-purple-600);
}
iron-icon.green {
color: var(--paper-green-600);
}
iron-icon.grey {
color: var(--paper-grey-600);
}
iron-icon.indigo {
color: var(--paper-indigo-600);
}
iron-icon.light-blue {
color: var(--paper-light-blue-600);
}
iron-icon.light-green {
color: var(--paper-light-green-600);
}
iron-icon.lime {
color: var(--paper-lime-600);
}
iron-icon.orange {
color: var(--paper-orange-600);
}
iron-icon.pink {
color: var(--paper-pink-600);
}
iron-icon.purple {
color: var(--paper-purple-600);
}
iron-icon.red {
color: var(--paper-red-600);
}
iron-icon.teal {
color: var(--paper-teal-600);
}
iron-icon.white {
color: #fff;
}
iron-icon.yellow {
color: var(--paper-yellow-600);
}
</style>
<div id="search_strategy">
<em class="suggestions">Suggestions</em>
<template is="dom-repeat" id="categoryList" items="{{categories}}">
<span id$="category_[[item]]" class="category_item" on-click="_selection">
<iron-icon class$=[[item.fieldStyle]] icon$="[[item.fieldIcon]]"></iron-icon>
<span>{{item.fieldTitle}}</span>
</span>
</template>
<array-selector id="selector" items="{{categories}}" selected="{{selectedField}}" toggle></array-selector>
</div>
</template>
<script>
class SearchStrategy extends Polymer.Element {
// constructor
constructor() {
super();
}
// returns the name of the component
static get is() { return 'search-strategy'; }
// defines the component's properties
static get properties() {
return {
/**
* (Required)
*
* List of search fields objects for the free text search each containing {String} key, {String} title, and optionally {String} type.
*
* @type {Array}
*/
freeTextSearchFields: {
type: Array
},
/**
* (Required | Output)
*
* Selected field
*
* @type {String}
*/
selectedField: {
type: String,
notify: true,
reflectToAttribute: true,
},
/**
* (Output)
*
* All candidate fields from free text search fields
*
* @type {Array}
*/
categories: {
type: Array,
computed: '_generateCategories()',
},
};
}
/**
* Set selected field chosen by user.
*
* @param {Object} event
*
*/
_selection(e) {
this.$.selector.select(e.model.item);
}
/**
* Generate all free text search fields
*
*/
_generateCategories() {
return this.freeTextSearchFields.map(function(val) {
return {
fieldTitle: val.title,
fieldIcon: val.icon,
fieldStyle: val.color
};
});
}
}
window.customElements.define(SearchStrategy.is, SearchStrategy);
</script>
</dom-module>