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';
9 TextField as MaterialTextField,
14 } from '@material-ui/core';
15 import RichTextEditor from 'react-rte';
16 import Margin = PropTypes.Margin;
18 type CssRules = 'textField' | 'rte';
20 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
22 marginBottom: theme.spacing.unit * 3
27 textDecoration: 'none',
28 color: theme.palette.primary.main,
31 textDecoration: 'underline'
37 type TextFieldProps = WrappedFieldProps & WithStyles<CssRules>;
39 export const TextField = withStyles(styles)((props: TextFieldProps & {
40 label?: string, autoFocus?: boolean, required?: boolean, select?: boolean, disabled?: boolean, children: React.ReactNode, margin?: Margin, placeholder?: string,
41 helperText?: string, type?: string,
44 helperText={(props.meta.touched && props.meta.error) || props.helperText}
45 className={props.classes.textField}
47 disabled={props.disabled || props.meta.submitting}
48 error={props.meta.touched && !!props.meta.error}
50 autoFocus={props.autoFocus}
52 required={props.required}
54 children={props.children}
56 placeholder={props.placeholder}
62 interface RichEditorTextFieldData {
66 type RichEditorTextFieldProps = RichEditorTextFieldData & TextFieldProps;
68 export const RichEditorTextField = withStyles(styles)(
69 class RichEditorTextField extends React.Component<RichEditorTextFieldProps> {
71 value: RichTextEditor.createValueFromString(this.props.input.value, 'html')
74 onChange = (value: any) => {
75 this.setState({ value });
76 this.props.input.onChange(value.toString('html'));
80 return <RichTextEditor
81 className={this.props.classes.rte}
82 value={this.state.value}
83 onChange={this.onChange}
84 placeholder={this.props.label} />;
89 export const DateTextField = withStyles(styles)
90 ((props: TextFieldProps) =>
93 disabled={props.meta.submitting}
94 helperText={props.meta.error}
95 error={!!props.meta.error}
100 name={props.input.name}
101 onChange={props.input.onChange}
102 value={props.input.value}