-
Notifications
You must be signed in to change notification settings - Fork 4
/
guide.js
221 lines (195 loc) · 6.83 KB
/
guide.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
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
import XElement from './x-element.js';
import Highlight from './highlight.js';
import Color from './modules/color.js';
export default class XGuide extends XElement {
title = 'Guide';
text = 'Hello World';
checked = true;
radioOne = undefined;
radioTwo = undefined;
color = Color();
colorChange () { this.color = Color(); }
active = true;
lightblue = active => active ? 'lightblue' : '';
classToggle () { this.active = !this.active; }
value = { text: 'hello world' };
fruit = 'Orange';
fruits = [ 'Apple', 'Orange', 'Tomato' ];
plant = undefined;
cars = [];
form = '';
agree = true;
disabled = false;
lastName = 'bond';
firstName = 'james';
favoriteNumber = undefined;
submit (form) {
this.form = JSON.stringify(form, null, '\t');
console.log(form);
console.log(this);
}
highlight (query) {
return Highlight(this.querySelector(query).innerHTML, 'html')
.replace(/{{/g, '{‌{').replace(/}}/g, '}‌}').replace(/^(\t{4}|\s{16})/mg, '').slice(1);
}
constructor () {
super();
this.shadowRoot.innerHTML = '<slot></slot>';
}
connectedCallback () {
if (this.innerHTML) return;
this.innerHTML = this.#html;
// document.body.style.opacity = 1;
}
#html = /*html*/`
<style>
.default {
border: solid 5px transparent;
}
.class-color {
border-color: var(--accent);
}
</style>
<section id="text">
<h3>Text Binder</h3>
<pre>
<code html="{{highlight('#text-demo')}}"></code>
<div id="text-demo">
<span>{{text}}</span>
</div>
</pre>
</section>
<section id="checked">
<h3>Checked Binder</h3>
<pre>
<code html="{{highlight('#checked-demo')}}"></code>
<div id="checked-demo">
<input type="checkbox" value="{{checked}}" checked="{{checked = $checked}}"> Checkbox {{checked ? 'checked' : ''}}
</div>
</pre>
<pre>
<code html="{{highlight('#radio-demo')}}"></code>
<div id="radio-demo">
<input type="radio" name="radio" value="one" checked="{{radioOne = $checked}}"> Radio One {{radioOne ? 'checked' : ''}}
<input type="radio" name="radio" value="two" checked="{{radioTwo = $checked}}"> Radio Two {{radioTwo ? 'checked' : ''}}
</div>
</pre>
</section>
<section id="style">
<h3>Style Binder</h3>
<pre>
<code html="{{highlight('#style-demo')}}"></code>
<div id="style-demo">
<span style="color: {{color}}">Look at my style</span>
<button onclick="{{colorChange()}}">Change Color</button>
</div>
</pre>
</section>
<section id="class">
<h3>Class Binder</h3>
<pre>
<code html="{{highlight('#class-demo')}}"></code>
<div id="class-demo">
<span class="default {{active ? 'class-color' : ''}}">Look at my class</span>
<button onclick="{{classToggle()}}">Toggle Active</button>
</div>
</pre>
</section>
<section id="value">
<h3>Value Binder</h3>
<pre>
<code html="{{highlight('#value-demo')}}"></code>
<div id="value-demo">
<input value="{{value.text = $value.toUpperCase()}}">
<input value="{{value.text = $value.toLowerCase()}}">
<span>{{value.text}}</span>
</div>
</pre>
</section>
<section id="each">
<h3>Each Binder</h3>
<pre>
<code html="{{highlight('#each-demo')}}"></code>
<div id="each-demo">
<div each="{{[ fruits, 'ff', 'key', 'index' ]}}">
<div id="{{ff}}">
<strong>Key: </strong>{{key}},
<strong>Index: </strong>{{index}},
<strong>Value: </strong>{{ff}}
</div>
</div>
</div>
</pre>
</section>
<section id="select">
<h3>Select Binder</h3>
<pre>
<code html="{{highlight('#plant-demo')}}"></code>
<div id="plant-demo">
<select value="{{plant = $value}}">
<option value="tree">Tree</option>
<option value="cactus">Cactus</option>
</select>
<span>{{plant}}</span>
</div>
</pre>
<pre>
<code html="{{highlight('#fruit-demo')}}"></code>
<div id="fruit-demo">
<select value="{{fruit = $value}}" each="{{[fruits, 'f']}}">
<option value="{{f}}">{{f}}</option>
</select>
<span>{{fruit}}</span>
</div>
</pre>
<pre>
<code html="{{highlight('#cars-demo')}}"></code>
<div id="cars-demo">
<select value="{{cars = $value}}" multiple>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="opel">Opel</option>
<option value="audi">Audi</option>
</select>
<span>{{cars}}</span>
</div>
</pre>
</section>
<section id="html">
<h3>HTML Binder</h3>
<pre>
<code html="{{highlight('#html-demo')}}"></code>
<div id="html-demo">
<div html="{{'<strong>Hyper Text Markup Language</strong>'}}"></div>
</div>
</pre>
</section>
<section id="submit">
<h3>Submit Binder</h3>
<br>
<form onsubmit="{{submit($form)}}" reset>
<div>{{firstName}}</div>
<input disabled="{{disabled}}" name="name.first" value="{{firstName = $value}}" placeholder="first name">
<div>{{lastName}}</div>
<input name="name.last" value="{{$value ?? lastName}}" placeholder="last name">
<br>
<br>
<input type="checkbox" name="agree" value="{{agree ? 'yes' : 'no'}}" checked="{{agree = $checked}}">Agree? {{agree ? 'yes': 'no'}}
<br>
<br>
<strong>Animal:</strong>
<input type="radio" name="animal" value="{{'dogs'}}" checked="{{$checked}}">Dogs
<input type="radio" name="animal" value="cats" checked="{{$checked}}">Cats
<br>
<br>
<div>{{favoriteNumber}}</div>
<input name="favoriteNumber" type="number" value="{{favoriteNumber = $value ?? NaN}}">
<br>
<br>
<input type="submit" value="submit">
</form>
<br>
<pre>{{form}}</pre>
</section>
`;
}