-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathLyricsPorthole.js
76 lines (67 loc) · 1.74 KB
/
LyricsPorthole.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
import React, { Component } from 'react';
import './LyricsPorthole.css';
class LyricsPorthole extends Component {
renderContext(dir, ax) {
const ctx = 10;
var diag = this.props.focal;
var start = (ax === 'x' ?
(dir === -1 ? diag.x0 : diag.x1)
:
(dir === -1 ? diag.y0 : diag.y1)
);
start += dir;
var end = start + (dir * ctx);
var txt = this.props.verse.textInRange(
Math.min(start, end),
Math.max(start, end)
);
var paras = [];
if (dir === 1 && txt.length && txt[0].startsWith('...')) {
paras = [<p className="continuation" key="c">{txt[0]}</p>];
paras = paras.concat(this.parify(txt.slice(1)));
} else {
paras = this.parify(txt);
}
return (
<div>
{paras}
</div>
);
}
parify = (txts) => {
return txts.map((t, i) => (<p key={i}>{t}</p>));
}
render() {
var diag = this.props.focal;
if (!diag) {
return <div className="porthole" />;
}
var inner;
inner = this.props.verse.diagText(diag);
inner = this.parify(inner);
return (
<div className="porthole">
<div className="row">
<div className="col-xs-6">
<b>x:</b>{this.renderContext(-1, 'x')}
</div>
<div className="col-xs-6">
<b>y:</b>{this.renderContext(-1, 'y')}
</div>
</div>
<div className="row matchText">
{inner}
</div>
<div className="row">
<div className="col-xs-6">
{this.renderContext(1, 'x')}
</div>
<div className="col-xs-6">
{this.renderContext(1, 'y')}
</div>
</div>
</div>
);
}
}
export default LyricsPorthole;