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';
8 import { CustomStyleRulesCallback } from 'common/custom-theme';
9 import { TextField as MaterialTextField, FormControlOwnProps } from '@mui/material';
10 import { WithStyles } from '@mui/styles';
11 import withStyles from '@mui/styles/withStyles';
12 import RichTextEditor from 'react-rte';
14 type CssRules = 'textField' | 'rte';
16 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
18 marginBottom: theme.spacing(1)
23 textDecoration: 'none',
24 color: theme.palette.primary.main,
27 textDecoration: 'underline'
33 type TextFieldProps = WrappedFieldProps & WithStyles<CssRules>;
35 export const TextField = withStyles(styles)((props: TextFieldProps & {
36 label?: string, autoFocus?: boolean, required?: boolean, select?: boolean, disabled?: boolean, children: React.ReactNode, margin?: FormControlOwnProps["margin"], placeholder?: string,
37 helperText?: string, type?: string,
41 helperText={(props.meta.touched && props.meta.error) || props.helperText}
42 className={props.classes.textField}
44 disabled={props.disabled || props.meta.submitting}
45 error={props.meta.touched && !!props.meta.error}
47 autoFocus={props.autoFocus}
49 required={props.required}
51 children={props.children}
53 placeholder={props.placeholder}
58 interface RichEditorTextFieldData {
62 type RichEditorTextFieldProps = RichEditorTextFieldData & TextFieldProps;
64 export const RichEditorTextField = withStyles(styles)(
65 class RichEditorTextField extends React.Component<RichEditorTextFieldProps> {
67 value: RichTextEditor.createValueFromString(this.props.input.value, 'html')
70 onChange = (value: any) => {
71 this.setState({ value });
72 this.props.input.onChange(
73 !!value.getEditorState().getCurrentContent().getPlainText().trim()
74 ? 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) =>
94 disabled={props.meta.submitting}
95 helperText={props.meta.error}
96 error={!!props.meta.error}
101 name={props.input.name}
102 onChange={props.input.onChange}
103 value={props.input.value} />