-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathindex.html
443 lines (411 loc) · 14.1 KB
/
index.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
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>React Rating</title>
<!-- Font Awesome CSS -->
<link rel="stylesheet" href="node_modules/font-awesome/css/font-awesome.css">
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css">
<!-- Prism -->
<link rel="stylesheet" href="node_modules/prismjs/themes/prism.css">
<script src="node_modules/prismjs/prism.js"></script>
<script src="node_modules/prismjs/components/prism-jsx.min.js"></script>
<!-- Babel -->
<script src="node_modules/@babel/standalone/babel.min.js"></script>
<!-- React -->
<script src="node_modules/react/umd/react.development.js"></script>
<!-- ReactDOM -->
<script src="node_modules/react-dom/umd/react-dom.development.js"></script>
<!-- React Rating component -->
<script src="lib/react-rating.umd.js"></script>
<!-- SVG icons generated with https://icomoon.io/app/ -->
<svg id="svg-source" style="display: none;" version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs>
<symbol id="icon-star-empty" viewBox="0 0 1024 1024">
<title>star-empty</title>
<path class="path1" d="M1024 397.050l-353.78-51.408-158.22-320.582-158.216 320.582-353.784 51.408 256 249.538-60.432 352.352 316.432-166.358 316.432 166.358-60.434-352.352 256.002-249.538zM512 753.498l-223.462 117.48 42.676-248.83-180.786-176.222 249.84-36.304 111.732-226.396 111.736 226.396 249.836 36.304-180.788 176.222 42.678 248.83-223.462-117.48z"></path>
</symbol>
<symbol id="icon-star-full" viewBox="0 0 1024 1024">
<title>star-full</title>
<path class="path1" d="M1024 397.050l-353.78-51.408-158.22-320.582-158.216 320.582-353.784 51.408 256 249.538-60.432 352.352 316.432-166.358 316.432 166.358-60.434-352.352 256.002-249.538z"></path>
</symbol>
</defs>
</svg>
<style type="text/css">
.low {
color: red;
}
.medium {
color: orange;
}
.high {
color: green;
}
.icon {
width: 26px;
height: 26px;
}
.icon-text {
display: inline-block;
width: 26px;
font-size: 2em;
background-color: white;
}
</style>
</head>
<body>
<h3>Default rating</h3>
<div class="rating" id="rating-default"></div>
<h3>Reset rating</h3>
<div class="rating" id="rating-reset"></div>
<h3>Readonly rating</h3>
<div class="rating" id="rating-default-readonly"></div>
<h3>Readonly fractional rating</h3>
<div class="rating" id="rating-default-readonly-fractional"></div>
<h3>React svg element rating</h3>
<div class="rating" id="rating-svg"></div>
<h3>React span element rating</h3>
<div class="rating" id="rating-span"></div>
<h3>React img element rating</h3>
<div class="rating" id="rating-img"></div>
<h3>Fontawesome Five Star rating</h3>
<div class="rating" id="rating-fontawesome-star"></div>
<h3>Fontawesome Thumbs Up/Down rating (showcases background icon hiding)</h3>
<div class="rating" id="rating-fontawesome-thumbs"></div>
<h3>Bootstrap Five Heart rating</h3>
<div class="rating" id="rating-bootstrap-heart"></div>
<h3>Fractional rating</h3>
<div class="rating" id="rating-fractional"></div>
<h3>Alert when rate changes</h3>
<div class="rating" id="rating-default-change"></div>
<h3>Update a label when rate moves</h3>
<span class="rating" id="rating-default-onrate"></span>
<span class="label label-default" id="label-onrate"></span>
<h3>Update a label when rate moves "quietly"</h3>
<span class="rating" id="rating-quiet-onrate"></span>
<span class="label label-default" id="label-quiet-onrate"></span>
<h3>Colored rating</h3>
<span class="rating" id="rating-colored"></span>
<h3>Mixed symbols</h3>
<div class="rating" id="rating-mixed"></div>
<h3>Custom each symbol</h3>
<div class="rating" id="rating-custom"></div>
<h3>1 to 10 rating</h3>
<div class="rating" id="rating-default-1-to-10"></div>
<h3>5 to 10 rating</h3>
<div class="rating" id="rating-default-5-to-10"></div>
<h3>1 to 10 with step 2 (odd numbers)</h3>
<div class="rating" id="rating-default-1-to-10-step-2"></div>
<h3>10 to 1 with step -2 (odd numbers between [1..10] inverted order)</h3>
<div class="rating" id="rating-default-10-to-1-step--2"></div>
<h3>Rating with placeholder</h3>
<div class="rating" id="rating-placeholder"></div>
<script type="text/babel">
const Rating = ReactRating;
const insertCode = function (code, elementId) {
document
.getElementById(elementId)
.insertAdjacentHTML('afterend',
'<pre><code>' +
Prism.highlight(code, Prism.languages.jsx) +
'</code></pre>'
);
};
// ResetRating
class ResetRating extends React.Component {
constructor(props) {
super(props);
this.state = {value: 0};
this.handleClick = this.handleClick.bind(this);
}
handleClick(event) {
this.setState({value: undefined});
}
render() {
return (
<div>
<Rating {...this.props} initialRating={this.state.value} />
<button onClick={this.handleClick}>Reset</button>
</div>
);
}
}
ReactDOM.render(
<Rating />
, document.getElementById('rating-default'));
insertCode('<Rating />', 'rating-default');
ReactDOM.render(
<ResetRating placeholderRating={3} />
, document.getElementById('rating-reset'));
insertCode(
`
class ResetRating extends React.Component {
constructor(props) {
super(props);
this.state = {value: 0};
this.handleClick = this.handleClick.bind(this);
}
handleClick(event) {
this.setState({value: undefined});
}
render() {
return (
<div>
<Rating {...this.props} initialRating={this.state.value} />
<button onClick={this.handleClick}>Reset</button>
</div>
);
}
}
<ResetRating placeholderRating={3} />
`, 'rating-reset');
ReactDOM.render(
<Rating
initialRating={3}
readonly
/>
, document.getElementById('rating-default-readonly'));
insertCode(
`<Rating
initialRating={3}
readonly
/>`, 'rating-default-readonly');
ReactDOM.render(
<Rating
initialRating={2.5}
readonly
/>
, document.getElementById('rating-default-readonly-fractional'));
insertCode(
`<Rating
initialRating={2.5}
readonly
/>`, 'rating-default-readonly-fractional');
const SVGIcon = (props) =>
<svg className={props.className} pointerEvents="none">
<use xlinkHref={props.href} />
</svg>;
ReactDOM.render(
<Rating
emptySymbol={<SVGIcon href="#icon-star-empty" className="icon" />}
fullSymbol={<SVGIcon href="#icon-star-full" className="icon" />}
/>
, document.getElementById('rating-svg'));
insertCode(
`const SVGIcon = (props) =>
<svg className={props.className} pointerEvents="none">
<use xlinkHref={props.href} />
</svg>;
<Rating
emptySymbol={<SVGIcon href="#icon-star-empty" className="icon" />}
fullSymbol={<SVGIcon href="#icon-star-full" className="icon" />}
/>`, 'rating-svg');
ReactDOM.render(
<Rating
emptySymbol={<span className="icon-text">-</span>}
fullSymbol={[1,2,3,4,5].map(n => <span className="icon-text">{n}</span>)}
/>
, document.getElementById('rating-span'));
insertCode(
`<Rating
emptySymbol={<span className="icon-text">-</span>}
fullSymbol={[1,2,3,4,5].map(n => <span className="icon-text">{n}</span>)}
/>`, 'rating-span');
ReactDOM.render(
<Rating
emptySymbol={<img src="assets/images/star-empty.png" className="icon" />}
fullSymbol={<img src="assets/images/star-full.png" className="icon" />}
/>
, document.getElementById('rating-img'));
insertCode(
`<Rating
emptySymbol={<img src="assets/images/star-empty.png" className="icon" />}
fullSymbol={<img src="assets/images/star-full.png" className="icon" />}
/>`, 'rating-img');
ReactDOM.render(
<Rating
emptySymbol="fa fa-star-o fa-2x"
fullSymbol="fa fa-star fa-2x"
/>
, document.getElementById('rating-fontawesome-star'));
insertCode(
`<Rating
emptySymbol="fa fa-star-o fa-2x"
fullSymbol="fa fa-star fa-2x"
/>`, 'rating-fontawesome-star');
ReactDOM.render(
<Rating
emptySymbol="fa fa-thumbs-down fa-2x"
fullSymbol="fa fa-thumbs-up fa-2x"
/>
, document.getElementById('rating-fontawesome-thumbs'));
insertCode(
`<Rating
emptySymbol="fa fa-thumbs-down fa-2x"
fullSymbol="fa fa-thumbs-up fa-2x"
/>`, 'rating-fontawesome-thumbs');
ReactDOM.render(
<Rating
emptySymbol="glyphicon glyphicon-heart-empty"
fullSymbol="glyphicon glyphicon-heart"
/>
, document.getElementById('rating-bootstrap-heart'));
insertCode(
`<Rating
emptySymbol="glyphicon glyphicon-heart-empty"
fullSymbol="glyphicon glyphicon-heart"
/>`, 'rating-bootstrap-heart');
ReactDOM.render(
<Rating
emptySymbol="fa fa-star-o fa-2x"
fullSymbol="fa fa-star fa-2x"
fractions={2}
/>
, document.getElementById('rating-fractional'));
insertCode(
`<Rating
emptySymbol="fa fa-star-o fa-2x"
fullSymbol="fa fa-star fa-2x"
fractions={2}
/>`, 'rating-fractional');
ReactDOM.render(
<Rating
onChange={(rate) => alert(rate)}
/>
, document.getElementById('rating-default-change'));
insertCode(
`<Rating
onChange={(rate) => alert(rate)}
/>`, 'rating-default-change');
ReactDOM.render(
<Rating
onHover={(rate) => document.getElementById('label-onrate').innerHTML = rate || ''}
/>
, document.getElementById('rating-default-onrate'));
insertCode(
`<Rating
onHover={(rate) => document.getElementById('label-onrate').innerHTML = rate || ''}
/>`, 'label-onrate');
ReactDOM.render(
<Rating
quiet
onHover={(rate) => document.getElementById('label-quiet-onrate').innerHTML = rate || ''}
/>
, document.getElementById('rating-quiet-onrate'));
insertCode(
`<Rating
quiet
onHover={(rate) => document.getElementById('label-quiet-onrate').innerHTML = rate || ''}
/>`, 'label-quiet-onrate');
ReactDOM.render(
<Rating
stop={10}
/>
, document.getElementById('rating-default-1-to-10'));
insertCode(
`<Rating
stop={10}
/>`, 'rating-default-1-to-10');
ReactDOM.render(
<Rating
start={4}
stop={10}
/>
, document.getElementById('rating-default-5-to-10'));
insertCode(
`<Rating
start={4}
stop={10}
/>`, 'rating-default-5-to-10');
ReactDOM.render(
<Rating
stop={10}
step={2}
/>
, document.getElementById('rating-default-1-to-10-step-2'));
insertCode(
`<Rating
stop={10}
step={2}
/>`, 'rating-default-1-to-10-step-2');
ReactDOM.render(
<Rating
start={11}
stop={1}
step={-2}
/>
, document.getElementById('rating-default-10-to-1-step--2'));
insertCode(
`<Rating
start={11}
stop={1}
step={-2}
/>`, 'rating-default-10-to-1-step--2');
// Mixing symbols.
ReactDOM.render(
<Rating
emptySymbol={['fa fa-star-o fa-2x', 'fa fa-heart-o fa-2x']}
fullSymbol={['fa fa-star fa-2x', 'fa fa-heart fa-2x']}
/>
, document.getElementById('rating-mixed'));
insertCode(
`<Rating
emptySymbol={['fa fa-star-o fa-2x', 'fa fa-heart-o fa-2x']}
fullSymbol={['fa fa-star fa-2x', 'fa fa-heart fa-2x']}
/>`, 'rating-mixed');
ReactDOM.render(
<Rating
stop={6}
emptySymbol={['fa fa-star-o fa-2x low', 'fa fa-star-o fa-2x low',
'fa fa-star-o fa-2x medium', 'fa fa-star-o fa-2x medium',
'fa fa-star-o fa-2x high', 'fa fa-star-o fa-2x high']}
fullSymbol={['fa fa-star fa-2x low', 'fa fa-star fa-2x low',
'fa fa-star fa-2x medium', 'fa fa-star fa-2x medium',
'fa fa-star fa-2x high', 'fa fa-star fa-2x high']}
/>
, document.getElementById('rating-colored'));
insertCode(
`<Rating
stop={6}
emptySymbol={['fa fa-star-o fa-2x low', 'fa fa-star-o fa-2x low',
'fa fa-star-o fa-2x medium', 'fa fa-star-o fa-2x medium',
'fa fa-star-o fa-2x high', 'fa fa-star-o fa-2x high']}
fullSymbol={['fa fa-star fa-2x low', 'fa fa-star fa-2x low',
'fa fa-star fa-2x medium', 'fa fa-star fa-2x medium',
'fa fa-star fa-2x high', 'fa fa-star fa-2x high']}
/>`, 'rating-colored');
ReactDOM.render(
<Rating
stop={4}
emptySymbol="fa fa-battery-empty fa-2x"
fullSymbol={['fa fa-battery-1 fa-2x', 'fa fa-battery-2 fa-2x',
'fa fa-battery-3 fa-2x', 'fa fa-battery-4 fa-2x']}
/>
, document.getElementById('rating-custom'));
insertCode(
`<Rating
stop={4}
emptySymbol="fa fa-battery-empty fa-2x"
fullSymbol={['fa fa-battery-1 fa-2x', 'fa fa-battery-2 fa-2x',
'fa fa-battery-3 fa-2x', 'fa fa-battery-4 fa-2x']}
/>`, 'rating-custom');
ReactDOM.render(
<Rating
placeholderRating={3.5}
emptySymbol={<img src="assets/images/star-grey.png" className="icon" />}
placeholderSymbol={<img src="assets/images/star-red.png" className="icon" />}
fullSymbol={<img src="assets/images/star-yellow.png" className="icon" />}
/>
, document.getElementById('rating-placeholder'));
insertCode(
`<Rating
placeholderRating={3.5}
emptySymbol={<img src="assets/images/star-grey.png" className="icon" />}
placeholderSymbol={<img src="assets/images/star-red.png" className="icon" />}
fullSymbol={<img src="assets/images/star-yellow.png" className="icon" />}
/>`, 'rating-placeholder');
</script>
</body>
</html>