1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { WrappedFieldProps } from 'redux-form';
7 import { ArvadosTheme } from '~/common/custom-theme';
8 import { TextField as MaterialTextField, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
9 import RichTextEditor from 'react-rte';
11 type CssRules = 'textField';
13 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
15 marginBottom: theme.spacing.unit * 3
19 type TextFieldProps = WrappedFieldProps & WithStyles<CssRules>;
21 export const TextField = withStyles(styles)((props: TextFieldProps & {
22 label?: string, autoFocus?: boolean, required?: boolean, select?: boolean, children: React.ReactNode
25 helperText={props.meta.touched && props.meta.error}
26 className={props.classes.textField}
28 disabled={props.meta.submitting}
29 error={props.meta.touched && !!props.meta.error}
31 autoFocus={props.autoFocus}
33 required={props.required}
35 children={props.children}
40 interface RichEditorTextFieldData {
44 type RichEditorTextFieldProps = RichEditorTextFieldData & TextFieldProps;
46 export const RichEditorTextField = withStyles(styles)(
47 class RichEditorTextField extends React.Component<RichEditorTextFieldProps> {
49 value: RichTextEditor.createValueFromString(this.props.input.value, 'html')
52 onChange = (value: any) => {
53 this.setState({ value });
54 this.props.input.onChange(value.toString('html'));
58 return <RichTextEditor
59 value={this.state.value}
60 onChange={this.onChange}
61 placeholder={this.props.label} />;
66 export const DateTextField = withStyles(styles)
67 ((props: TextFieldProps) =>
70 disabled={props.meta.submitting}
71 helperText={props.meta.error}
72 error={!!props.meta.error}
77 name={props.input.name}
78 onChange={props.input.onChange}
79 value={props.input.value}