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
// https://api.val.town/v1/express/liamdanielduffy.reactTodoListWebsite
export const REACT_TODO_LIST_CONTENTS = {
body: `<div id="root"></div>
<script>
const e = React.createElement;
class TodoList extends React.Component {
constructor(props) {
super(props);
this.state = { items: [], text: '' };
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
render() {
return e('div', {
id: 'todoContainer'
}, [
e('h3', {}, 'TODO'),
e('ul', {}, this.state.items.map((item, i) =>
e('li', {key: i}, [
e('input', { type: 'checkbox', id: 'item' + i, name: 'item' + i }),
e('label', { htmlFor: 'item' + i }, item)
])
)),
e('form', {onSubmit: this.handleSubmit}, [
e('input', {
id: 'new-todo',
onChange: this.handleChange,
value: this.state.text,
}),
e('button', {}, 'Add Todo #' + (this.state.items.length + 1)),
]),
]);
}
handleChange(e) {
this.setState({ text: e.target.value });
}
handleSubmit(e) {
e.preventDefault();
if (this.state.text.length === 0) {
return;
}
const newItem = this.state.text;
this.setState(state => ({
items: state.items.concat(newItem),
text: ''
}));
}
}
ReactDOM.render(
e(TodoList),
document.getElementById('root')
);
</script>`,
styles: `body {
background-image: url('https://cdn.discordapp.com/attachments/1045735023359295588/1113826974264209569/bg.png');
background-size: cover;
}
li {
list-style-type: none;
}
#todoContainer {
background-color: white;
padding: 8px;
border-radius: 4px;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.19), 0 6px 6px rgba(0, 0, 0, 0.23);
}
h3 {
text-align: center;
}
#root {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
}
form {
display: flex;
gap: 10px;
}
button {
display: inline-block;
font-size: 16px;
padding: 6px 12px;
color: #fff;
background-color: #007BFF;
border: none;
border-radius: 4px;
text-align: center;
text-decoration: none;
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
February 25, 2024