-
Notifications
You must be signed in to change notification settings - Fork 3
/
polymate-view.html
102 lines (96 loc) · 2.61 KB
/
polymate-view.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
<link rel="import" href="../polymer/polymer-element.html">
<link rel="import" href="../paper-icon-button/paper-icon-button.html">
<link rel="import" href="./polymate-behavior.html">
<link rel="import" href="./polymate-demo-controllers.html">
<dom-module id="polymate-view">
<template>
<style>
:host {
display: inline-block;
width: var(--polymate-view-width, 1em);
height: var(--polymate-view-height, 1em);
min-height: auto;
margin: 0 auto;
}
</style>
<template is="dom-if" if="[[showControllers]]">
<polymate-demo-controllers id="controllers" anim="[[anim]]" options="{{options}}"></polymate-demo-controllers>
</template>
<div id="polymate"></div>
</template>
<script>
/**
* `polymate-view`
* lottie view component for polymer
*
* @customElement
* @polymer
* @demo demo/index.html
*/
class PolymateView extends PolymateBehavior(Polymer.Element) {
static get is() { return 'polymate-view'; }
static get properties() {
return {
/**
* @desc animation object
* @type {Object}
*/
anim: {
type: Object,
notify: true
},
/**
* @desc animation's options
* @type {Object}
*/
options: {
type: Object,
value: {}
},
/**
* @desc path
* @type {String}
*/
path: String,
/**
* @desc autoplay
* @type {Boolean}
*/
autoplay: Boolean,
/**
* @desc loop
* @type {Boolean}
*/
loop: Boolean,
/**
* @desc enable demo controllers
* @type {Boolean}
*/
showControllers: {
type: Boolean,
value: false
}
};
}
static get observers() {
return [
'_reloadAnimation(options.*)'
]
}
/**
* @desc reinitialize if options are updated
* @param {Object} options
* @return {Object} anim
*/
_reloadAnimation(options) {
if (this.anim) this.anim.destroy();
let newOptions = options.value ? options.value : {};
if (this.path) newOptions.path = this.path;
if (this.autoplay) newOptions.autoplay = this.autoplay;
if (this.loop) newOptions.loop = this.loop;
this.anim = this.initializeLottie(newOptions);
}
}
window.customElements.define(PolymateView.is, PolymateView);
</script>
</dom-module>