-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathdemo.jsx
292 lines (282 loc) · 9.6 KB
/
demo.jsx
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
import React from 'react';
import ReactDOM from 'react-dom';
import Highlight from 'react-highlight';
import {RIEInput, RIEToggle, RIETextArea, RIENumber, RIETags, RIESelect} from '../src/index.js';
class Demo extends React.Component {
constructor(props){
super(props);
this.state = {
select : {id: "1", text: "broccoli"},
selectOptions : [
{id: "1", text: "broccoli"},
{id: "2", text: "arugula"},
{id: "3", text: "leek"},
{id: "4", text: "radish"},
{id: "5", text: "watercress"},
{id: "6", text: "dandelion"}
],
boolean : true,
number : 9000,
text : "Example text value",
textarea : `Multiline example
text value`,
date : Date.now(),
tags: new Set(["Bergen", "Asmara", "Göteborg", "Newcastle", "Seattle"]),
simulateXHR: false,
XHRDelay: 450,
highlight: false,
showSource: false,
isDisabled: false,
};
}
virtualServerCallback = (newState) => {
if (this.state.simulateXHR) {
window.setTimeout(function() {
this.changeState(newState);
}.bind(this), this.state.XHRDelay);
} else {
this.changeState(newState);
}
};
changeState = (newState) => {
this.setState(newState);
};
isStringAcceptable = (string) => {
return (string.length >= 1); // Minimum 4 letters long
};
isStringEvenNumber = (string) => {
var number = parseInt(string);
if (isNaN(number) || !isFinite(number)) return false;
return number % 2 == 0;
};
isValidXHRDelay = (text) => {
let number = parseInt(text);
if (isNaN(number)) return false;
return (0 < number) && (number < 50000);
};
formatInteger = (number) => {
return number.toString() + " feet";
};
formatMillisecondsAppend = (text) => {
return text + " ms";
};
render = () => {
let xhrDelaySwitch = (this.state.simulateXHR) ? <li>XHR delay: <RIENumber value={this.state.XHRDelay} change={this.changeState} validate={this.isValidXHRDelay} propName="XHRDelay" className="editable-pill" format={this.formatMillisecondsAppend} /></li> : null;
return <div>
<div className="menu">
<div className="fifty">
<h3>Application State</h3>
<ul>
<li><i>boolean:</i> {this.state.boolean.toString()}</li>
<li><i>text:</i> {this.state.text}</li>
<li><i>textarea:</i> {this.state.textarea.replace(new RegExp("\n", "g"), "\\n")}</li>
<li><i>number:</i> {this.state.number}</li>
<li><i>tags:</i> {[...this.state.tags].join(', ')}</li>
<li><i>select:</i> {JSON.stringify(this.state.select)}</li>
</ul>
</div>
<div className="fifty">
<h3>Options</h3>
<ul>
<li>Simulate XHR: <RIEToggle value={this.state.simulateXHR} change={this.changeState} propName="simulateXHR" textTrue="yes" textFalse="don't" className="editable-pill"/></li>
{xhrDelaySwitch}
<li>Highlight editable: <RIEToggle value={this.state.highlight} change={this.changeState} propName="highlight" textTrue="highlight" textFalse="don't" className="editable-pill" /></li>
<li><RIEToggle value={this.state.showSource} change={this.changeState} propName="showSource" textTrue="Source shown" textFalse="Source hidden" className="editable-pill"/></li>
<li><RIEToggle value={this.state.isDisabled} change={this.changeState} propName="isDisabled" textTrue="fields disabled" textFalse="fields not disabled" className="editable-pill" /></li>
</ul>
</div>
</div>
<div className="content">
<h3>Toggle</h3>
<div>
<span>Default: </span>
<RIEToggle
value={this.state.boolean}
className={this.state.highlight ? "editable" : ""}
change={this.virtualServerCallback}
classLoading="loading"
propName="boolean"
isDisabled={this.state.isDisabled} />
{this.state.showSource ? <Highlight className="jsx">
{`<RIEToggle
value={this.state.boolean}
className={this.state.highlight ? "editable" : ""}
change={this.virtualServerCallback}
classLoading="loading"
propName="boolean"
isDisabled={this.state.isDisabled} />`}
</Highlight> : null}
<br />
<span>Custom labels: </span>
<RIEToggle
value={this.state.boolean}
className={this.state.highlight ? "editable" : ""}
change={this.virtualServerCallback}
textTrue="activated"
textFalse="deactivated"
classLoading="loading"
propName="boolean"
isDisabled={this.state.isDisabled} />
{this.state.showSource ? <Highlight className="jsx">
{`<RIEToggle
value={this.state.boolean}
className={this.state.highlight ? "editable" : ""}
change={this.virtualServerCallback}
textTrue="activated"
textFalse="deactivated"
classLoading="loading"
propName="boolean"
isDisabled={this.state.isDisabled} />`}
</Highlight> : null}
</div>
<hr />
<h3>Input</h3>
<div>
<span>Default: </span>
<RIEInput
value={this.state.text}
change={this.virtualServerCallback}
propName="text"
className={this.state.highlight ? "editable" : ""}
classLoading="loading"
classInvalid="invalid"
isDisabled={this.state.isDisabled} />
{this.state.showSource ? <Highlight className="jsx">
{`<RIEInput
value={this.state.text}
change={this.virtualServerCallback}
propName="text"
className={this.state.highlight ? "editable" : ""}
validate={this.isStringAcceptable}
classLoading="loading"
classInvalid="invalid"
isDisabled={this.state.isDisabled} />`}
</Highlight> : null}
</div>
<hr />
<h3>Textarea</h3>
<div>
<p>Default: </p>
<RIETextArea
value={this.state.textarea}
change={this.virtualServerCallback}
propName="textarea"
className={this.state.highlight ? "editable" : ""}
validate={this.isStringAcceptable}
classLoading="loading"
classInvalid="invalid"
isDisabled={this.state.isDisabled} />
{this.state.showSource ? <Highlight className="jsx">
{`<RIETextArea
value={this.state.textarea}
change={this.virtualServerCallback}
propName="textarea"
className={this.state.highlight ? "editable" : ""}
validate={this.isStringAcceptable}
classLoading="loading"
classInvalid="invalid"
isDisabled={this.state.isDisabled} />`}
</Highlight> : null}
</div>
<hr />
<h3>Number</h3>
<div>
<span>Default: </span>
<RIENumber
value={this.state.number}
change={this.virtualServerCallback}
propName="number"
className={this.state.highlight ? "editable" : ""}
classLoading="loading"
classInvalid="invalid"
isDisabled={this.state.isDisabled} />
{this.state.showSource ? <Highlight className="jsx">
{`<RIENumber
value={this.state.number}
change={this.virtualServerCallback}
propName="number"
className={this.state.highlight ? "editable" : ""}
classLoading="loading"
classInvalid="invalid"
isDisabled={this.state.isDisabled} />`}
</Highlight> : null}
<br />
<span>Only even, custom formatter: </span>
<RIENumber
value={this.state.number}
change={this.virtualServerCallback}
propName="number"
format={this.formatInteger}
classLoading="loading"
className={this.state.highlight ? "editable" : ""}
validate={this.isStringEvenNumber}
classInvalid="invalid"
isDisabled={this.state.isDisabled} />
{this.state.showSource ? <Highlight className="jsx">
{`<RIENumber
value={this.state.number}
change={this.virtualServerCallback}
propName="number"
format={this.formatInteger}
classLoading="loading"
className={this.state.highlight ? "editable" : ""}
validate={this.isStringEvenNumber}
classInvalid="invalid"
isDisabled={this.state.isDisabled} />`}
</Highlight> : null}
</div>
<hr />
<h3>Tags</h3>
<div>
<span>Default: </span>
<RIETags
value={this.state.tags}
change={this.virtualServerCallback}
maxTags={10}
minTags={2}
propName="tags"
placeholder="New"
className={this.state.highlight ? "tags editable" : "tags"}
classLoading="loading"
isDisabled={this.state.isDisabled} />
{this.state.showSource ? <Highlight className="jsx">
{`<RIETags
value={this.state.tags}
change={this.virtualServerCallback}
maxTags={10}
minTags={2}
propName="tags"
placeholder="New"
className={this.state.highlight ? "tags editable" : "tags"}
classLoading="loading"
isDisabled={this.state.isDisabled} />`}
</Highlight> : null}
</div>
<hr />
<h3>Select</h3>
<div>
<span>Default: </span>
<RIESelect
value={this.state.select}
className={this.state.highlight ? "editable" : ""}
options={this.state.selectOptions}
change={this.virtualServerCallback}
classLoading="loading"
propName="select"
isDisabled={this.state.isDisabled} />
{this.state.showSource ? <Highlight className="jsx">
{`<RIESelect
value={this.state.select}
className={this.state.highlight ? "editable" : ""}
options={this.state.selectOptions}
change={this.virtualServerCallback}
classLoading="loading"
propName="select"
isDisabled={this.state.isDisabled} />`}
</Highlight> : null}
</div>
</div>
</div>;
};
}
ReactDOM.render(<Demo />, document.getElementById('app'));