forked from IgorRubinovich/ir-select
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathir-select-item.html
More file actions
138 lines (121 loc) · 3.13 KB
/
ir-select-item.html
File metadata and controls
138 lines (121 loc) · 3.13 KB
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
<!--
@license
Copyright (c) 2015 Igor Rubinovich <igor.rubinovich@gmail.com>. All rights reserved.
This code may only be used under the MIT license found at http://opensource.org/licenses/MIT
-->
<!--
# ir-select-item
# Single item elements for ir-select
Part of ir-select, tagging-style multiselect box for Polymer 1.0
-->
<dom-module id="ir-select-item">
<template>
<style>
:host {
margin : 0;
padding : 0
transition : all 1s;
}
@media (max-width: 600px) {
h1.paper-font-display1 {
font-size: 24px;
}
}
iron-icon {
width : 15px;
height : 15px;
color : #555;
transition : all .1s;
border-radius : 15px;
}
iron-icon:hover {
color : #333;
}
.ir-select-item-default {
border : 1px inset #eee;
margin-right : 3px;
transition : all .05s;
display : inline-block;
padding : 4px 8px;
background: #fff;
}
.ir-select-item-focus {
border : 1px solid #aaa;
transform : translate(-1px,-1px);
box-shadow : 0px 0px 1px #aaa;
}
:host .remove
{
transition : .3s;
transform-origin : 0% 50%;
transform : scaleX(0);
alpha : .7;
}
</style>
<span id="container" class="ir-select-item-default">
<slot></slot>
<iron-icon id="close" on-click="close" icon='cancel'></iron-icon>
</span>
</template>
</dom-module>
<script>
(function () {
Polymer({
is : 'ir-select-item',
properties : {
/** value of the item */
value: { type : String, value : '', notify : true },
/** label of the item */
label: { type : String, value : '', notify : true, observer : "_labelChanged" },
},
/*
Fired when close is called or the close icon is clicked.
@event item-close
*/
/*
Fired when ir-select-item is attached to DOM.
@event item-attached
*/
/** Close the label - only fires the item-close event */
close : function close()
{
this.blur();
this.$.container.classList.add('remove');
Polymer.dom.flush();
this.fire('item-close', this);
},
_labelChanged : function() {
Polymer.dom(this).innerHTML = this.label;
//console.log('setting label', this.label);
},
/**
* Get object representation of the item.
* @param {string} labelPath object path to label, defaults to 'label'.
* @param {string} valuePath object path to value, defaults to 'value'.
* @return {Object} item label and value at labelPath and valuePath respectively
*/
toObject: function (labelPath, valuePath) {
var res = {};
this.set(labelPath || 'label', this.label, res);
this.set(valuePath || 'value', this.value, res);
return res;
},
/** Adds `ir-select-item-focus` class to the element. */
focus: function() {
this.$.container.classList.add('ir-select-item-focus');
Polymer.dom.flush();
},
/** Removes `ir-select-item-focus` class from the element. */
blur: function() {
this.$.container.classList.remove('ir-select-item-focus')
},
ready : function() {
var content = Polymer.dom(this.root).querySelector('content');
var preset = Polymer.dom(content).getDistributedNodes()[0];
if(preset && !this.label)
this.label = preset.textContent;
this.fire('item-attached', this, { cancelable : true });
}
});
})();
</script>