-
Notifications
You must be signed in to change notification settings - Fork 4
/
vellum-stat.js
76 lines (64 loc) · 1.43 KB
/
vellum-stat.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
import { LitElement, html, css } from 'lit-element'
class Stat extends LitElement {
static get styles() {
return css`
.stat-name {
font-weight: bold;
}
p {
margin-top: 1pt;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
padding-left: 1em;
text-indent: -1em;
}
:host(.trait) p,
:host(.action) p {
margin-top: 0;
margin-bottom: 1em;
margin-left: 0;
margin-right: 0;
padding-left: 0;
text-indent: 0;
}
:host(.table-row) p {
padding-left: 0;
text-indent: 1em;
}
:host(.trait) .stat-name,
:host(.action) .stat-name {
font-style: italic;
}`
}
static get properties() {
return {
name: String,
values: {
type: String,
hasChanged(newVal, oldVal) {
return newVal !== oldVal
}
}
}
}
render() {
return html`<p>
<span class="stat-name">${this.name}</span>
<span class="stat-values">${this.renderValues()}</span>
</p>`
}
renderValues() {
if (Array.isArray(this.values)) {
return this.values.join(', ')
}
// TODO replace this try...catch block that could hide important error messages
try {
return JSON.parse(this.values).join(', ')
} catch (error) {
if (this.values) return this.values
else return html`<slot></slot>`
}
}
}
customElements.define('vellum-stat', Stat)