1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { WrappedFieldProps } from 'redux-form';
7 import { ArvadosTheme } from 'common/custom-theme';
9 TextField as MaterialTextField,
14 } from '@material-ui/core';
15 import RichTextEditor from 'react-rte';
17 type CssRules = 'textField' | 'rte';
19 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
21 marginBottom: theme.spacing.unit
26 textDecoration: 'none',
27 color: theme.palette.primary.main,
30 textDecoration: 'underline'
36 type TextFieldProps = WrappedFieldProps & WithStyles<CssRules>;
38 export const TextField = withStyles(styles)((props: TextFieldProps & {
39 label?: string, autoFocus?: boolean, required?: boolean, select?: boolean, disabled?: boolean, children: React.ReactNode, margin?: PropTypes.Margin, placeholder?: string,
40 helperText?: string, type?: string,
43 helperText={(props.meta.touched && props.meta.error) || props.helperText}
44 className={props.classes.textField}
46 disabled={props.disabled || props.meta.submitting}
47 error={props.meta.touched && !!props.meta.error}
49 autoFocus={props.autoFocus}
51 required={props.required}
53 children={props.children}
55 placeholder={props.placeholder}
61 interface RichEditorTextFieldData {
65 type RichEditorTextFieldProps = RichEditorTextFieldData & TextFieldProps;
67 export const RichEditorTextField = withStyles(styles)(
68 class RichEditorTextField extends React.Component<RichEditorTextFieldProps> {
70 value: RichTextEditor.createValueFromString(this.props.input.value, 'html')
73 onChange = (value: any) => {
74 this.setState({ value });
75 this.props.input.onChange(
76 !!value.getEditorState().getCurrentContent().getPlainText().trim()
77 ? value.toString('html')
83 return <RichTextEditor
84 className={this.props.classes.rte}
85 value={this.state.value}
86 onChange={this.onChange}
87 placeholder={this.props.label} />;
92 export const DateTextField = withStyles(styles)
93 ((props: TextFieldProps) =>
96 disabled={props.meta.submitting}
97 helperText={props.meta.error}
98 error={!!props.meta.error}
103 name={props.input.name}
104 onChange={props.input.onChange}
105 value={props.input.value}