forked from fluxio/io-value
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathio-boolean-icon.html
98 lines (94 loc) · 2.67 KB
/
io-boolean-icon.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
<!--
I/O element for boolean data type. Displays value as core-icon.
<io-boolean-icon value="true" trueicon="done" falseicon="clear"></io-boolean-icon>
__Note__: When element is focused, pressing enter/spacebar will toggle the value.
@element io-boolean-icon
@extends io-base
@homepage https://github.com/arodic/io-value
@demo http://akirodic.com/components/io-value/demo.html
@blurb I/O element for boolean data type. Displays value as core-icon.
@status alpha
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../core-icons/core-icons.html">
<link rel="import" href="_io-base.html">
<polymer-element name="io-boolean-icon" extends="io-base">
<template>
<link rel="stylesheet" href="_io-base.css" shim-shadowdom>
<style type="text/css" shim-shadowdom>
:host(:not([disabled])) > .io-editor {
cursor: pointer;
}
:host > .io-editor {
width: 1em;
height: 1em;
}
</style>
<content></content>
<core-icon id="value" class="io-editor" tabindex="0" icon="{{value ? trueicon : falseicon}}"></core-icon>
</template>
<script>
Polymer({
publish: {
/**
* Element value.
*
* @attribute value
* @default false
*/
value: false,
/**
* Icon to display when value is true.
* See Polymer core-icon for more information.
*
* @attribute trueicon
* @type string
* @default 'done'
*/
trueicon: 'done',
/**
* Icon to display when value is false.
* See Polymer core-icon for more information.
*
* @attribute falseicon
* @type string
* @default 'clear'
*/
falseicon: 'clear'
},
eventDelegates: {
'keydown': 'keydownAction',
'down': 'downAction',
'tap': 'tapAction'
},
downAction: function(event) {
// prevent focus but let currently focused blur
event.preventDefault();
document.activeElement.blur();
},
tapAction: function(event) {
if (this.disabled) return;
if (event.path[0] == this.$.value) {
this.toggle();
}
},
keydownAction: function(event) {
if (this.disabled) return;
if (event.path[0] == this.$.value) {
if (event.which == 13 || event.which == 32) {
event.preventDefault(); // prevent blur
this.toggle();
}
}
},
/**
* Toggles the value.
*
* @method toggle
*/
toggle: function() {
this.setValue(!this.value);
}
});
</script>
</polymer-element>