aboutsummaryrefslogtreecommitdiff
path: root/src/views/nodes/FieldView.tsx
blob: 1c416408908884e3c30e1e71486fe9d00e18334f (plain)
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
import React = require("react")
import { DocumentFieldViewProps } from "./DocumentView";
import { observer } from "mobx-react";
import { computed } from "mobx";
import { Field, Opt } from "../../fields/Field";
import { TextField } from "../../fields/TextField";
import { NumberField } from "../../fields/NumberField";

@observer
export class FieldView extends React.Component<DocumentFieldViewProps> {
    @computed
    get field(): Opt<Field> {
        const { doc, fieldKey } = this.props;
        return doc.GetField(fieldKey);
    }
    render() {
        const field = this.field;
        if (!field) {
            return <p>{'<null>'}</p>
        }
        if (field instanceof TextField) {
            return <p>{field.Data}</p>
        }
        else if (field instanceof NumberField) {
            return <p>{field.Data}</p>
        } else {
            return <p>{field.GetValue}</p>
        }
    }

}