-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcategory-element.html
105 lines (90 loc) · 2.85 KB
/
category-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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<link rel="import" href="../polymer/polymer-element.html">
<!--
A custom element that encapsulate a scheduler's category.
-->
<dom-module id="category-element">
<template>
<style>
:host {
display: block;
cursor: pointer;
}
.category {
display: inline-block;
padding-left: 2px;
height: inherit;
text-align: center;
}
.category-shape {
height: 15px;
width: 15px;
border-radius: 50%;
display: inline-block;
vertical-align: top;
}
.disabled {
pointer-events: none !important;
cursor: none !important;
opacity: 0.3;
}
</style>
<div id="categoryContainer" class$="category {{disabledStyle()}}">
<div style$="background-color: {{color}};" class="category-shape"></div>
<div style="display:inline-block;">[[label]]</div>
</div>
</template>
<script>
/**
* @customElement
* @polymer
* @extends HTMLElement
*/
class CategoryElement extends Polymer.Element {
static get is() { return 'category-element'; }
static get properties() {
return {
label: String,
color: String,
disabled: {
type: Boolean,
value: false,
observer: '_disabledChange'
}
}
}
ready() {
super.ready();
this.addEventListener('click', e => this._clickListener(e));
}
/*
* Listens to click events on the host element.
*
*/
_clickListener(event) {
this.dispatchEvent(new CustomEvent('category-clicked', { detail: event }));
}
/*
* Returns the style of the host element
* based on the disabled property.
*
*/
disabledStyle() {
return this.disabled ? 'disabled' : '';
}
/**
* Observes disabled value change.
* Add /remove disabled class based on the newValue property
*
*/
_disabledChange(newValue, oldValue) {
if (newValue) {
this.$.categoryContainer.classList.add('disabled');
}
else {
this.$.categoryContainer.classList.remove('disabled');
}
}
}
window.customElements.define(CategoryElement.is, CategoryElement);
</script>
</dom-module>