-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathks-search.js
131 lines (119 loc) · 3.76 KB
/
ks-search.js
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
import {html, PolymerElement} from '@polymer/polymer/polymer-element';
import {DomIf as DomIf} from '@polymer/polymer/lib/elements/dom-if';
import 'polymer3-granite-bootstrap/granite-bootstrap-min';
import './assets/js/font-awesome/font-awesome';
import './assets/js/corporate-ui/corporate-ui-vendors'
import './assets/js/corporate-ui/corporate-ui';
import './ks-shared-styles';
/**
* `ks-search`
* ks search
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class KsSearch extends PolymerElement {
static get template() {
return html`
<style include="granite-bootstrap-min"></style>
<style include="font-awesome"></style>
<style include="corporate-ui">
/* shadow DOM styles go here */
:host {
display: block;
}
.clear-input {
cursor: pointer;
}
.form-control {
padding: 10px 12px;
height: 42px;
}
.form-control:focus {
background-color: #fff;
}
.input-icon {
z-index: 10;
}
</style>
<div class="form-group sc-search">
<div class="input-group">
<input id="ksSearch" value="{{value::input}}" class="form-control"
type="text" on-focus="toggleIcon" on-input="toggleIcon"
placeholder="{{placeholder::input}}"/>
<div class="input-icon">
<template is="dom-if" if="[[showClearIcon]]">
<span on-click="clearInput" class="clear-input">
<i class="fal fa-times"></i>
</span>
</template>
<template is="dom-if" if="[[!showClearIcon]]">
<i class="fal fa-filter"></i>
</template>
</div>
</div>
</div>
<!-- <div style="background-color: gray"> Value received in <span style="font-style: normal">ks-search</span> the custom element : [[value]]</div>-->
`;
}
constructor() {
super();
}
static get properties() {
return {
showClearIcon: {
type: Boolean,
value: false
},
value: {
type: String,
notify: true
},
iconClass: {
type: String
},
onClear: {
type: Object
},
clear: {
type: Object
},
reloadOnClear: {
type: String,
reflectToAttribute: true
}
};
}
ready() {
super.ready();
// let placeholder = 'Scs_Core.Filtrera';
// if (this.iconClass === 'fa-search') {
// placeholder = 'Scs_Core.Sök';
// }
// this.$.ksSearch.setAttribute('placeholder', placeholder);
this.toggleIcon();
}
clearInput() {
const clearCallback = this.clear || this.onClear;
this.$.ksSearch.value = '';
//this.trigger('input');
this.set('value', this.$.ksSearch.value);
if (typeof clearCallback === 'function') {
clearCallback();
}
if (this.reloadOnClear) {
window.location.reload(true);
}
this.toggleIcon();
// Sample trigger custom event
this.customEv();
}
toggleIcon() {
this.showClearIcon = this.$.ksSearch.value.length > 0;
}
customEv() {
this.dispatchEvent(new CustomEvent('custom-ev', {detail: { data: 'Trigger event from custom element' }}));
}
}
customElements.define('ks-search', KsSearch);