-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcube-action.js
104 lines (87 loc) · 2.38 KB
/
cube-action.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
import {PolymerElement, html} from '@polymer/polymer/polymer-element.js';
import '@polymer/paper-ripple/paper-ripple.js';
import '@kubex/cube-icon/cube-icon.js';
/**
An element providing a solution to no problem in particular.
Example:
<cube-action icon="iron:icons:star"></cube-action>
@demo demo/index.html
*/
class CubeAction extends PolymerElement {
static get is() {return 'cube-action';}
static get template()
{
return html`<style>
:host {
position: relative;
background: transparent;
-webkit-tap-highlight-color: transparent;
outline: none;
-moz-user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
user-select: none;
cursor: pointer;
z-index: 0;
box-sizing: content-box;
display: inline-flex;
align-items: center;
font-size: calc(var(--cube-icon-size, 24px) * 0.6);
padding: 5px;
@apply --cube-action-style;
}
:host([same-font]) {
font-size: var(--cube-icon-size, 24px);
}
:host:hover {
@apply --cube-action-hover-style;
}
paper-ripple {
color: var(--paper-button-ink-color);
}
#container {
display: flex;
align-items: center;
}
#slottedContent {
display: inline-flex;
align-items: center;
}
</style>
<div id="container">
<template strip-whitespace="" is="dom-if" if="[[_showIcon(icon,src)]]">
<cube-icon icon="[[icon]]" src="[[src]]" size="[[size]]"></cube-icon>
</template>
<div id="slottedContent">
<slot></slot>
</div>
</div>
<paper-ripple center="[[rippleCenter]]" class$="[[_rippleCircle(rippleCircle)]]"></paper-ripple>`;
}
static get properties()
{
return {
icon: {type: String, notify: true, reflectToAttribute: true},
src: {type: String, notify: true, reflectToAttribute: true},
size: {type: Number, notify: true, observer: '_styleChanged'},
rippleCenter: {type: Boolean},
rippleCircle: {type: Boolean}
};
}
_showIcon(icon, src)
{
return icon || src;
}
_styleChanged()
{
if(this.size)
{
this.updateStyles({'--cube-icon-size': this.size + 'px'});
}
}
_rippleCircle(rippleCircle)
{
return rippleCircle ? 'circle' : '';
}
}
customElements.define(CubeAction.is, CubeAction);