-
Notifications
You must be signed in to change notification settings - Fork 108
/
app-main.riot
95 lines (90 loc) · 2.15 KB
/
app-main.riot
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
<app-main>
<article>
<!-- subroutes blocks -->
<route path="#/first(.*)">
<ul>
<li each={ item in state.data }>
<a href="#/first/{ item.id }">{ item.title }</a>
</li>
</ul>
</route>
<main>
<!-- main content -->
<route each={ page in state.mainPages } path={page.path}>
<h1>{ page.title }</h1>
<p>{ page.body }</p>
</route>
<!-- subroutes contents -->
<route path="#/first/:id">
<h1>{getSubPageDataById(route).title}</h1>
<p>{getSubPageDataById(route).body}</p>
</route>
</main>
</article>
<script>
export default {
state: {
data: [
{ id: 'apple', title: 'Apple', body: "The world biggest fruit company." },
{ id: 'orange', title: 'Orange', body: "I don't have the word for it..." }
],
mainPages: [{
path: '(#)?',
title: "Home of the great app",
body: "Timeline or dashboard as you like!"
}, {
path: '#/first',
title: "First feature of your app",
body: "It could be a list of something for example."
},{
path: '#/second',
title: "Second feature of your app",
body: "It could be a config page for example."
}]
},
getSubPageDataById(route) {
const {id} = route.params
return this.state.data.find(data => data.id === id)
}
}
</script>
<style>
:host {
display: block;
font-family: sans-serif;
margin-right: 0;
margin-bottom: 130px;
margin-left: 50px;
padding: 1em;
text-align: center;
color: #666;
}
ul {
padding: 10px;
list-style: none;
}
li {
display: inline-block;
margin: 5px;
}
a {
display: block;
background: #f7f7f7;
text-decoration: none;
width: 150px;
height: 150px;
line-height: 150px;
color: inherit;
}
a:hover {
background: #eee;
color: #000;
}
@media (min-width: 480px) {
:scope {
margin-right: 200px;
margin-bottom: 0;
}
}
</style>
</app-main>