-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtangy-list-item.js
107 lines (96 loc) · 2.49 KB
/
tangy-list-item.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
import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
import './util/html-element-props.js'
import '@polymer/paper-card/paper-card.js'
import './style/tangy-common-styles.js'
import './style/tangy-element-styles.js'
export class TangyListItem extends PolymerElement {
static get template () {
return html`
<style include="tangy-common-styles"></style>
<style include="tangy-element-styles"></style>
<style>
:host {
position: relative;
}
paper-card { width: 100%; }
paper-fab {
position: absolute;
top: -15px;
right: -15px;
--paper-fab-background: var(--accent-color);
--paper-fab-keyboard-focus-background: var(--accent-color);
}
</style>
<paper-card id="content">
<slot></slot>
</paper-card>
<paper-fab mini icon="close" id="remove" on-click="onRemoveClick"></paper-fab>
`
}
static get is () {
return 'tangy-list-item'
}
static get _props() {
return ['name','value','label','disabled','invalid','incomplete','hidden','correct']
}
static get properties () {
return {
name: {
type: String,
value: '',
reflectToAttribute: true
},
label: {
type: String,
value: '',
reflectToAttribute: true
},
disabled: {
type: Boolean,
value: false,
reflectToAttribute: true
},
invalid: {
type: Boolean,
value: false,
reflectToAttribute: true
},
incomplete: {
type: Boolean,
value: true,
reflectToAttribute: true
},
hidden: {
type: Boolean,
value: false,
reflectToAttribute: true
},
correct: {
type: Boolean,
value: false,
reflectToAttribute: true
}
}
}
connectedCallback () {
super.connectedCallback()
}
get value() {
if (this.shadowRoot && this.querySelectorAll('[name]').length > 0) {
this._value = [...this.querySelectorAll('[name]')].map(inputEl => inputEl.getProps())
}
return this._value ? this._value : []
}
set value(value) {
this._value = value
this._value.forEach(inputProps => this.querySelector(`[name=${inputProps.name}]`).setProps(inputProps))
}
validate() {
return [...this.querySelectorAll('[name]')]
.reduce((isValid, inputEl) => inputEl.validate() ? isValid : false, true)
}
onRemoveClick() {
this.remove()
}
}
window.customElements.define(TangyListItem.is, TangyListItem)