-
Notifications
You must be signed in to change notification settings - Fork 29
/
paper-search-bar.html
199 lines (174 loc) · 4.47 KB
/
paper-search-bar.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
<!doctype html>
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-a11y-keys-behavior/iron-a11y-keys-behavior.html">
<link rel="import" href="../iron-icon/iron-icon.html">
<link rel="import" href="../iron-icons/iron-icons.html">
<link rel="import" href="../iron-icons/image-icons.html">
<link rel="import" href="../iron-input/iron-input.html">
<link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../paper-badge/paper-badge.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="../paper-styles/default-theme.html">
<!--
Bar in which the user can enter search terms and filter
@demo demo/paper-search-bar.html
-->
<dom-module id="paper-search-bar">
<template>
<style>
:host {
display: block;
}
.horizontal-holder {
background: var(--background-color, white);
display: block;
padding: 0 16px;
@apply --layout-horizontal;
@apply --layout-center-center;
height: var(--paper-search-bar-height, 48px); /* To resolve `min-height` bug on IE 11 */
box-sizing: border-box;
}
iron-input {
@apply --layout-flex;
@apply --layout-vertical;
height: 100%; /* To resolve `min-height` bug on IE 11 */
}
.icon {
color: var(--disabled-text-color);
@apply --icon-styles;
}
#input {
@apply --layout-flex;
margin: 0 10px;
padding: 16px 0;
cursor: text;
background: transparent;
color: inherit;
@apply --input-styles;
border: 0;
outline: 0;
}
#input::-ms-clear {
display: none;
}
#input[disabled] {
@apply --disabled-input-styles;
}
.badge {
--paper-badge-background: var(--paper-red-500);
--paper-badge-opacity: 1;
--paper-badge-width: 18px;
--paper-badge-height: 18px;
--paper-badge-margin-left: -5px;
--paper-badge-margin-bottom: -25px;
}
.badge[invisible] {
visibility: hidden;
}
</style>
<div class="horizontal-holder">
<iron-icon icon="[[icon]]" class="icon"></iron-icon>
<iron-input bind-value="{{query}}">
<!-- Define is="iron-input" for backwards compatibility with Polymer 1.x -->
<input id="input" is="iron-input" placeholder="[[placeholder]]" value="{{value::input}}"></input>
</iron-input>
<template is="dom-if" if="{{query}}">
<paper-icon-button icon="clear" on-tap="_clear" class="icon"></paper-icon-button>
</template>
<template is="dom-if" if="{{!hideFilterButton}}">
<template is="dom-if" if="{{!disableFilterButton}}">
<paper-icon-button id="filter" icon="image:tune" on-tap="_filter" class="icon"></paper-icon-button>
</template>
<paper-badge for="filter" label="[[nrSelectedFilters]]" class="badge" invisible$="[[!nrSelectedFilters]]"></paper-badge>
</template>
</div>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'paper-search-bar',
/**
* Fired when the user requests to open the filtering dialog
*
* @event paper-search-filter
*/
/**
* Fired when the user requests to search for a query
*
* @event paper-search-search
*/
/**
* Fired when the user taps the clear icon
*
* @event paper-search-clear
*/
properties: {
/**
* Text for which the user is searching
*/
query: {
type: String,
notify: true,
value: ''
},
/**
* Whether to hide the Filter button. Set attribute "hide-filter-button" to do so.
*/
hideFilterButton: {
type: Boolean,
value: false
},
/**
* Whether to disable the Filter button. Set attribute "disable-filter-button" to do so.
*/
disableFilterButton: {
type: Boolean,
value: false
},
/**
* Number of filters the user has been selected (shown in the badge) (optional)
*/
nrSelectedFilters: {
type: Number,
value: 0
},
/**
* Icon shown in the search background
*/
icon: {
type: String,
value: 'search'
},
/**
* Text shown in the search box if the user didn't enter any query
*/
placeholder: {
type: String,
value: 'Search'
},
},
behaviors: [
Polymer.IronA11yKeysBehavior
],
keyBindings: {
'enter': '_search'
},
focus: function() {
this.$.input.focus();
},
// Private methods
_filter: function(e) {
this.fire('paper-search-filter');
},
_clear: function() {
this.query = "";
this.$.input.focus();
this.fire('paper-search-clear');
},
_search: function() {
this.fire('paper-search-search');
}
});
})();
</script>