-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlist.js
76 lines (68 loc) · 1.58 KB
/
list.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
// An example element that can gets used by all the other examples
module.exports = List
var BaseElement = require('../index.js')
var attachCSS = require('attach-css')
function List (el) {
BaseElement.call(this, el)
this.className = 'list'
}
List.prototype = Object.create(BaseElement.prototype)
List.prototype.render = function (items) {
var self = this
// Create li upon click just lets us know it was clicked
items = items.map(function (item) {
return self.html('li', {
onclick: function (e) {
self.send('clicked', e.target)
}
}, item)
})
// Add button that adds new li's to list
items.unshift(this.html('li', this.html('button', {
onclick: function (e) {
self.send('added')
}
}, ['add item'])))
return this.afterRender(this.html('ul', this, items))
}
// Localized CSS can be returned using attachCSS()
List.prototype.css = function () {
// Can be a string, brfs a style.css, or css preprocessor
return attachCSS(`
* {
font-family: Helvetica, sans-serif;
}
ul {
margin: 0;
padding: 0;
}
ul li {
list-style: none;
border-bottom: 1px solid #ddd;
padding: .3em 0;
}
ul li:hover {
background-color: #eee;
transition: .5s;
padding-left: .5em;
cursor: pointer;
}
li:first-child {
padding: .3em;
border-bottom: 1px solid #333;
text-align: right;
}
button {
border: none;
padding: .3em .5em;
background-color: #00bcd4;
color: white;
font-size: 1.2em;
cursor: pointer;
}
button:hover {
padding: .3em 1em;
transition: .5s;
}
`, this.vtree)
}