X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/c11055f2d6ce8385088bc221eab1175e31777ec0..e9d30481d8d57a0b906364ee115e136305b7ce79:/src/components/text-field/text-field.tsx

diff --git a/src/components/text-field/text-field.tsx b/src/components/text-field/text-field.tsx
index 1fe77ca6..dd864a93 100644
--- a/src/components/text-field/text-field.tsx
+++ b/src/components/text-field/text-field.tsx
@@ -6,6 +6,7 @@ import * as React from 'react';
 import { WrappedFieldProps } from 'redux-form';
 import { ArvadosTheme } from '~/common/custom-theme';
 import { TextField as MaterialTextField, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
+import RichTextEditor from 'react-rte';
 
 type CssRules = 'textField';
 
@@ -15,7 +16,9 @@ const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     },
 });
 
-export const TextField = withStyles(styles)((props: WrappedFieldProps & WithStyles<CssRules> & { label?: string }) =>
+type TextFieldProps = WrappedFieldProps & WithStyles<CssRules>;
+
+export const TextField = withStyles(styles)((props: TextFieldProps & { label?: string, autoFocus?: boolean, required?: boolean }) =>
     <MaterialTextField
         helperText={props.meta.touched && props.meta.error}
         className={props.classes.textField}
@@ -23,6 +26,52 @@ export const TextField = withStyles(styles)((props: WrappedFieldProps & WithStyl
         disabled={props.meta.submitting}
         error={props.meta.touched && !!props.meta.error}
         autoComplete='off'
+        autoFocus={props.autoFocus}
         fullWidth={true}
+        required={props.required}
         {...props.input}
     />);
+
+
+interface RichEditorTextFieldData {
+    label?: string;
+}
+
+type RichEditorTextFieldProps = RichEditorTextFieldData & TextFieldProps;
+
+export const RichEditorTextField = withStyles(styles)(
+    class RichEditorTextField extends React.Component<RichEditorTextFieldProps> {
+        state = {
+            value: RichTextEditor.createValueFromString(this.props.input.value, 'html')
+        };
+
+        onChange = (value: any) => {
+            this.setState({ value });
+            this.props.input.onChange(value.toString('html'));
+        }
+
+        render() {
+            return <RichTextEditor 
+                value={this.state.value}
+                onChange={this.onChange}
+                placeholder={this.props.label} />;
+        }
+    }
+);
+
+export const DateTextField = withStyles(styles)
+    ((props: TextFieldProps) => 
+        <MaterialTextField
+            type="date"
+            disabled={props.meta.submitting}
+            helperText={props.meta.error}
+            error={!!props.meta.error}
+            fullWidth={true}
+            InputLabelProps={{
+                shrink: true
+            }}
+            name={props.input.name}
+            onChange={props.input.onChange}
+            value={props.input.value}
+        />    
+    );
\ No newline at end of file
