-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcategories-element.html
86 lines (73 loc) · 2.52 KB
/
categories-element.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
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="category-element.html">
<!--
A custom element that encapsulate categories container.
-->
<dom-module id="categories-element">
<template>
<style>
:host {
display: block;
}
.categories-container {
width: 100%;
background-color: #f5f5f5;
margin-top: 1px;
padding-bottom: 5px;
position: relative;
}
category-element {
display: inline-block;
vertical-align: -webkit-baseline-middle;
}
</style>
<div class="categories-container">
<template is="dom-repeat" items="{{items}}">
<category-element id="category" disabled="{{item.hidden}}" on-click="_clickOnCategory" label="{{item.label}}" color="{{item.color}}"></category-element>
</template>
</div>
</template>
<script>
/**
* @customElement
* @polymer
* @extends HTMLElement
*/
class CategoriesElement extends Polymer.Element {
static get is() { return 'categories-element'; }
static get properties() {
return {
/**
* list of category
**/
items: Array
}
}
ready() {
super.ready();
}
/**
* Fired when a category is clicked
*
*/
_clickOnCategory(e) {
let selectedCategory = Polymer.dom(e).localTarget,
disabledValue = selectedCategory.disabled,
categoryLabel = selectedCategory.label;
if (disabledValue) {
selectedCategory.setAttribute("disabled", "false");
selectedCategory.removeAttribute("disabled");
} else {
selectedCategory.setAttribute("disabled", "true");
}
// Fire event to inform that a category has been clicked.
let detail = {
disabled: !disabledValue,
category: e.model.item
}
this.dispatchEvent(new CustomEvent('category-click', { detail }));
}
}
window.customElements.define(CategoriesElement.is, CategoriesElement);
</script>
</dom-module>