aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/KeywordBox.tsx
diff options
context:
space:
mode:
authorIEatChili <nanunguyen99@gmail.com>2024-06-18 14:33:47 -0400
committerIEatChili <nanunguyen99@gmail.com>2024-06-18 14:33:47 -0400
commit376ff1626b24cbac12b27ad072690424549f05c7 (patch)
tree1775455e91750eb05a2610faec123a49862ec0a0 /src/client/views/KeywordBox.tsx
parent8aee62b8623e23f6478960291857ee47f50f9aaf (diff)
feat: added view of labels on docs in freeform
Diffstat (limited to 'src/client/views/KeywordBox.tsx')
-rw-r--r--src/client/views/KeywordBox.tsx69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/client/views/KeywordBox.tsx b/src/client/views/KeywordBox.tsx
new file mode 100644
index 000000000..3faddeb64
--- /dev/null
+++ b/src/client/views/KeywordBox.tsx
@@ -0,0 +1,69 @@
+import { action, makeObservable } from 'mobx';
+import { observer } from 'mobx-react';
+import React from 'react';
+import { Doc } from '../../fields/Doc';
+import { DocData } from '../../fields/DocSymbols';
+import { List } from '../../fields/List';
+import { ObservableReactComponent } from './ObservableReactComponent';
+
+interface KeywordBoxProps {
+ _doc: Doc;
+ _isEditing: boolean;
+}
+
+@observer
+export class KeywordBox extends ObservableReactComponent<KeywordBoxProps> {
+ constructor(props: any) {
+ super(props);
+ makeObservable(this);
+ }
+
+ @action
+ setToEditing = () => {
+ this._props._isEditing = true;
+ };
+
+ @action
+ setToView = () => {
+ this._props._isEditing = false;
+ };
+
+ submitLabel = () => {};
+
+ onInputChange = () => {};
+
+ render() {
+ const keywordsList = this._props._doc![DocData].data_labels;
+ return (
+ <div className="keywords-container">
+ {(keywordsList as List<string>).map(label => {
+ return (
+ <div className="keyword" onClick={this.setToEditing}>
+ {label}
+ </div>
+ );
+ })}
+ {this._props._isEditing ? (
+ <div>
+ <input
+ defaultValue=""
+ autoComplete="off"
+ onChange={this.onInputChange}
+ onKeyDown={e => {
+ e.key === 'Enter' ? this.submitLabel() : null;
+ e.stopPropagation();
+ }}
+ type="text"
+ placeholder="Input keywords for document..."
+ aria-label="keyword-input"
+ className="keyword-input"
+ style={{ width: '100%', borderRadius: '5px' }}
+ />
+ </div>
+ ) : (
+ <div></div>
+ )}
+ </div>
+ );
+ }
+}