aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/EditableView.tsx
diff options
context:
space:
mode:
authorMonika Hedman <monika_hedman@brown.edu>2019-02-12 16:26:22 -0500
committerMonika Hedman <monika_hedman@brown.edu>2019-02-12 16:26:22 -0500
commit05a710e2a541a07347d1626489a1811874126c79 (patch)
treefeb751e46036d2104bb81c5bcc4e4ab0b6336c08 /src/client/views/EditableView.tsx
parent6445930e05e8eb81a36930615926712986bc1a9d (diff)
parent7a93f60c9529e5d175e617fc7c07145a9b33e572 (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into hedmanLocal
Diffstat (limited to 'src/client/views/EditableView.tsx')
-rw-r--r--src/client/views/EditableView.tsx39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/client/views/EditableView.tsx b/src/client/views/EditableView.tsx
new file mode 100644
index 000000000..2e784d3f9
--- /dev/null
+++ b/src/client/views/EditableView.tsx
@@ -0,0 +1,39 @@
+import React = require('react')
+import { observer } from 'mobx-react';
+import { observable, action } from 'mobx';
+
+export interface EditableProps {
+ GetValue(): string;
+ SetValue(value: string): boolean;
+ contents: any;
+}
+
+@observer
+export class EditableView extends React.Component<EditableProps> {
+ @observable
+ editing: boolean = false;
+
+ @action
+ onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
+ if (e.key == "Enter" && !e.ctrlKey) {
+ this.props.SetValue(e.currentTarget.value);
+ this.editing = false;
+ } else if (e.key == "Escape") {
+ this.editing = false;
+ }
+ }
+
+ render() {
+ if (this.editing) {
+ return <input defaultValue={this.props.GetValue()} onKeyDown={this.onKeyDown} autoFocus onBlur={action(() => this.editing = false)}
+ style={{ width: "100%" }}></input>
+ } else {
+ return (
+ <div>
+ {this.props.contents}
+ <button onClick={action(() => this.editing = true)}>Edit</button>
+ </div>
+ )
+ }
+ }
+} \ No newline at end of file