/
ui-preview.html
227 lines (189 loc) Β· 6.55 KB
/
ui-preview.html
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script src="../bundles/nano.dev.min.js"></script>
</head>
<body>
<style>
/* no overflow in this example */
html {
overflow: hidden;
}
body {
font-family: BlinkMacSystemFont, -apple-system, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans',
'Droid Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
margin: 0;
padding: 0;
background-color: black;
}
/* just the radius for the phone cover in this example */
.appBar_container {
border-top-left-radius: 18px;
border-top-right-radius: 18px;
}
/* TODO(yandeu): should be added to the lib! */
.appBar_container .toolbar_container .toolbar_left {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.appBar_container .toolbar_title {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
</style>
<div id="root"></div>
<script>
const { render, Link, jsx, UI, Component } = nanoJSX
const {
AppBar,
Button,
Dialog,
Fab,
Icon,
List,
ListItem,
Menu,
Navigation,
NavigationAction,
Sheet,
Snackbar,
Tab,
Tabs,
Toolbar
} = UI
// a reference to the Pages Component
let pagesRef
const Container = props => {
return jsx`<div style="min-height: calc(100vh - 64px); border-radius: 18px; background-color: white; padding: 24px 16px 16px;">${props.children}</div>`
}
const names = ['Tayla', 'Beau', 'Nella', 'Britany']
const Names = props => {
return jsx`
<${List}>
${names.map(name => {
return jsx`<${ListItem}>${name}</${ListItem}>`
})}
</${List}>`
}
const dialog = new Dialog()
const snackbar = new Snackbar()
const snacks = [
{
message: 'Hello Snack!',
actions: [{ name: 'Dismiss', color: this.defaultActionColor }],
autoHide: true,
consecutive: true,
offsetY: 56
},
{
message: 'Simple question? With custom colors!',
actions: [
{ name: 'Yes', color: '#7edeff' },
{ name: 'No', color: '#f261ff' }
],
autoHide: false,
consecutive: true,
offsetY: 56
},
{
message:
'A very very long text without any action. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eius',
actions: [],
autoHide: true,
consecutive: true,
offsetY: 56
}
]
const sheetLeft = jsx`<${Sheet} mode="left" title="menu" subtitle="(same list of names)">${Names}</${Sheet}>`
const sheetBottom = jsx`<${Sheet} mode="bottom" title="menu" subtitle="(same list of names)">${Names}</${Sheet}>`
const contextMenu = new Menu()
const dialogClickHandler = () => {
dialog.show(
{
title: 'Hello',
body: 'Some text.',
actions: [{ name: 'Action 1' }, { name: 'Action 2' }]
},
event => {
console.log(event)
}
)
}
class Pages extends Component {
render(page) {
const showHomePage = !page || page === 'home'
if (!showHomePage) {
return jsx`<h2>${page}</h2>`
}
if (showHomePage)
return jsx`
<div>
<!-- Listen for the click event -->
<h2 onClick="${() => console.log('click')}">List of names</h2>
<!-- Render the Names component -->
<${Names} />
<br />
<${Button} outlined icon="/dev/font-awesome/heart-solid.svg">Button (outlined + icon)</${Button}>
<br />
<!-- Use the built-in Link component -->
<!--
<${Link} prefetch="hover" href="https://geckosio.github.io/">
<${Button}>External Link (with prefetch)</${Button}>
</${Link}>
<br />
-->
<${Button} onClick=${() => dialogClickHandler()}>Open Dialog</${Button}>
<br />
<${Button} onClick=${() => Sheet.show(sheetBottom)}>Sheet Bottom</${Button}>
<br />
<${Button} onClick=${() => {
const rnd = Math.floor(Math.random() * 3)
snackbar.show(snacks[rnd])
}}>Snackbar</${Button}>
</div>`
}
}
const App = () => {
return jsx`
<${Container}>
<${AppBar}>
<${Toolbar} actionClick=${() => Sheet.show(sheetLeft)} menu title="Home Page">
<div class="toolbar_text">Text</div>
<${Icon}
onClick=${e => {
const { pageX: x, pageY: y } = e
contextMenu.open({ position: { x, y }, list: Names })
}}
class="toolbar_icon"
color="white"
src="/dev/font-awesome/ellipsis-v-solid.svg" />
<${Icon} class="toolbar_icon" color="white" src="/dev/font-awesome/heart-solid.svg" />
</${Toolbar}>
<${Tabs}>
<${Tab}>first</${Tab}>
<${Tab}>second</${Tab}>
<${Tab}>third</${Tab}>
</${Tabs}>
</${AppBar}>
<div style="padding: 16px 16px 64px; margin-top: 56px; margin-bottom: 56px;">
<!-- save the Pages reference in pagesRef -->
<${Pages} ref=${p => (pagesRef = p)}/>
</div>
<${Fab} offsetY=${72}><${Icon} src="/dev/font-awesome/home-solid.svg" color="white" size=${20} /></${Fab} />
<!-- call update on the Pages Component and pass the tab it to update/render -->
<${Navigation} onClick=${e => pagesRef.update(e.id)} >
<${NavigationAction} label="Home" icon="/dev/font-awesome/home-solid.svg" active=${true} />
<${NavigationAction} label="About" icon="/dev/font-awesome/user-solid.svg" active=${false} />
<${NavigationAction} label="Favorites" icon="/dev/font-awesome/heart-solid.svg" active=${false} />
</${Navigation}>
</${Container}>`
}
render(App, document.getElementById('root'))
</script>
</body>
</html>