-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstats-box.ts
More file actions
84 lines (76 loc) · 1.74 KB
/
stats-box.ts
File metadata and controls
84 lines (76 loc) · 1.74 KB
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
import { LitElement, customElement, property, css } from 'lit-element'
import { html } from 'lit-html'
@customElement('stats-box')
export class StatsBox extends LitElement {
@property({ type: Array })
stats
@property({ type: Array })
universities
private get max () {
return this.stats[0].count
}
static styles = css`
* {
box-sizing: border-box;
}
#stats {
padding: 0 1.5rem;
}
.stat {
margin-bottom: 1.25rem;
}
a {
text-decoration: none;
display: flex;
padding-bottom: 0.5rem;
font-weight: 500;
}
.name {
font-size: 1.15rem;
color: var(--highlight-color);
flex: 1;
}
.decorated {
text-decoration: underline;
}
.name .count {
font-size: 0.95rem;
color: black;
width: 1rem;
}
.arrow {
margin-right: -0.75rem;
}
.bar {
height: 1.25rem;
}
.university {
background-color: var(--university-color);
}
`
private linkTo (university) {
return `/${university.domains[0]}`
}
private resultBar (stat) {
const university = this.universities.find(uni => uni.domains.includes(stat.code))
return html`
<div class="stat">
<a href=${this.linkTo(university)}>
<div class="name">
<span class="decorated">${university.name}</span>
<span class="count">${stat.count} vote${stat.count === 1 ? '' : 's'}</span>
</div>
<div class="arrow">〉</div>
</a>
<div class="bar university" style="width: ${(stat.count / this.max) * 100}%"></div>
</div>
`
}
render () {
return html`
<div id="stats">
${this.stats.map(uni => this.resultBar(uni))}
</div>
`
}
}