-
Notifications
You must be signed in to change notification settings - Fork 6
/
mist-check.js
126 lines (112 loc) · 2.79 KB
/
mist-check.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
import '@polymer/polymer/polymer-legacy.js';
import '@polymer/iron-icon/iron-icon.js';
import { Polymer } from '@polymer/polymer/lib/legacy/polymer-fn.js';
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
Polymer({
_template: html`
<style>
:host {
display: inline-block;
min-width: 36px;
color: inherit;
}
:host([selected]) .check {
transform: rotate3d(0, 1, 0, 180deg);
}
:host([selected]) iron-icon {
display: none;
}
:host([selected]) iron-icon#check {
display: flex;
transform: rotate3d(0, 1, 0, -180deg) scale(1);
opacity: 1;
}
:host([selected]) .unchecked {
opacity: 0;
}
.check {
border-radius: 50%;
width: 32px;
height: 32px;
transition: transform 350ms ease-in-out;
background-color: rgba(158, 158, 158, 0.13);
color: inherit;
will-change: transform;
cursor: pointer;
box-sizing: border-box;
text-align: center;
font-size: 13px;
line-height: 30px;
}
.unchecked {
border-radius: inherit;
width: 100%;
height: 100%;
transition: opacity 200ms ease-in-out 100ms;
will-change: opacity;
text-transform: uppercase;
}
iron-icon#check {
transition: transform 300ms ease-in-out 100ms;
will-change: opacity;
transform: rotate3d(0, 1, 0, -180deg) scale(0);
position: absolute;
top: 0;
left: 0;
padding: 4px;
opacity: 0;
color: inherit;
}
.check img {
width: 24px;
height: 24px;
}
:host[disabled] {
display: inline-block;
opacity: 0;
}
.layout.horizontal {
display: flex;
flex-direction: row;
}
.center-center {
align-items: center;
justify-content: center;
}
</style>
<div class="check">
<span class="unchecked layout horizontal center-center">
<slot></slot>
<template is="dom-if" if="[[_hasSlash(icon)]]" restamp>
<img src="[[icon]]" />
</template>
<template is="dom-if" if="[[!_hasSlash(icon)]]" restamp>
<iron-icon icon="[[icon]]"></iron-icon>
</template>
</span>
<iron-icon icon="check" id="check"></iron-icon>
</div>
`,
is: 'mist-check',
properties: {
item: {
type: Object,
},
selected: {
type: Boolean,
reflectToAttribute: true,
value: false,
notify: true,
},
},
listeners: {
click: 'toggle',
},
toggle: function (e) {
e.stopImmediatePropagation();
this.set('selected', !this.selected);
},
_hasSlash(icon) {
return icon.indexOf('/') != -1;
},
});