Repository navigation
Expand file tree
/
Copy pathInlineDoc.tsx
More file actions
46 lines (44 loc) · 1.76 KB
/
Copy pathInlineDoc.tsx
File metadata and controls
46 lines (44 loc) · 1.76 KB
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
import React from "react";
import { Pre } from "@blueprintjs/core";
import { Doc } from "./Doc";
import { Id } from "./Data";
/** Render a {@link Doc} with the same newlines as the final result. */
export const InlineDocComponent: React.FC<{
doc: Doc,
statingColumn: number,
className: string,
highlightedLevelId?: Id
}> = ({doc, statingColumn, className, highlightedLevelId}) => {
function renderDoc(doc: Doc) {
switch (doc.type) {
case "break":
// TODO add breakToken in here
if (doc.breakState.broken) {
return <span key={doc.id} className={"doc doc-break taken highlight"}>
<br/>{' '.repeat(doc.breakState.newIndent)}
</span>;
} else {
return <span key={doc.id} className={"doc doc-break highlight"}>{doc.flat}</span>
}
case "level":
// TODO other information about the doc
return <span key={doc.id}
className={`doc doc-level ${doc.id === highlightedLevelId ? "referenced" : ""}`}>
{doc.docs.map(renderDoc)}
</span>;
case "comment":
// TODO maybe display original on hover?
return <span key={doc.id} className={"doc doc-comment highlight"}>{doc.text}</span>;
case "space":
return <span key={doc.id} className={"doc doc-space highlight"}> </span>;
case "token":
return <span key={doc.id} className={"doc-token highlight"}>{doc.flat}</span>;
}
}
return (
<Pre className={className}>
{' '.repeat(statingColumn)}
{renderDoc(doc)}
</Pre>
);
};