mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-01-18 14:12:44 +00:00
replace fieldTemplate with unthemed core version and remove labels since that is handled in there
This commit is contained in:
parent
4aaf05d935
commit
035588120b
@ -107,7 +107,6 @@ export default function BaseInputTemplate<
|
|||||||
id={id}
|
id={id}
|
||||||
name={id}
|
name={id}
|
||||||
className="input"
|
className="input"
|
||||||
labelText={labelToUse}
|
|
||||||
helperText={helperText}
|
helperText={helperText}
|
||||||
invalid={invalid}
|
invalid={invalid}
|
||||||
invalidText={errorMessageForField}
|
invalidText={errorMessageForField}
|
||||||
|
@ -1,66 +1,57 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import FormControl from '@mui/material/FormControl';
|
import {
|
||||||
import Typography from '@mui/material/Typography';
|
FieldTemplateProps,
|
||||||
import { FieldTemplateProps, getTemplate, getUiOptions } from '@rjsf/utils';
|
FormContextType,
|
||||||
|
RJSFSchema,
|
||||||
|
StrictRJSFSchema,
|
||||||
|
getTemplate,
|
||||||
|
getUiOptions,
|
||||||
|
} from '@rjsf/utils';
|
||||||
|
|
||||||
function FieldTemplate({
|
import Label from './Label';
|
||||||
|
|
||||||
|
/** The `FieldTemplate` component is the template used by `SchemaField` to render any field. It renders the field
|
||||||
|
* content, (label, description, children, errors and help) inside of a `WrapIfAdditional` component.
|
||||||
|
*
|
||||||
|
* @param props - The `FieldTemplateProps` for this component
|
||||||
|
*/
|
||||||
|
export default function FieldTemplate<
|
||||||
|
T = any,
|
||||||
|
S extends StrictRJSFSchema = RJSFSchema,
|
||||||
|
F extends FormContextType = any
|
||||||
|
>(props: FieldTemplateProps<T, S, F>) {
|
||||||
|
const {
|
||||||
id,
|
id,
|
||||||
children,
|
|
||||||
classNames,
|
|
||||||
disabled,
|
|
||||||
displayLabel,
|
|
||||||
hidden,
|
|
||||||
label,
|
label,
|
||||||
onDropPropertyClick,
|
children,
|
||||||
onKeyChange,
|
|
||||||
readonly,
|
|
||||||
required,
|
|
||||||
rawErrors = [],
|
|
||||||
errors,
|
errors,
|
||||||
help,
|
help,
|
||||||
rawDescription,
|
description,
|
||||||
schema,
|
hidden,
|
||||||
|
required,
|
||||||
|
displayLabel,
|
||||||
|
registry,
|
||||||
uiSchema,
|
uiSchema,
|
||||||
registry,
|
} = props;
|
||||||
}: FieldTemplateProps) {
|
|
||||||
const uiOptions = getUiOptions(uiSchema);
|
const uiOptions = getUiOptions(uiSchema);
|
||||||
const WrapIfAdditionalTemplate = getTemplate<'WrapIfAdditionalTemplate'>(
|
const WrapIfAdditionalTemplate = getTemplate<
|
||||||
'WrapIfAdditionalTemplate',
|
'WrapIfAdditionalTemplate',
|
||||||
registry,
|
T,
|
||||||
uiOptions
|
S,
|
||||||
);
|
F
|
||||||
|
>('WrapIfAdditionalTemplate', registry, uiOptions);
|
||||||
if (hidden) {
|
if (hidden) {
|
||||||
return <div style={{ display: 'none' }}>{children}</div>;
|
return <div className="hidden">{children}</div>;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div className="rjsf-field">
|
<div className="rjsf-field">
|
||||||
<WrapIfAdditionalTemplate
|
<WrapIfAdditionalTemplate {...props}>
|
||||||
classNames={classNames}
|
{displayLabel && <Label label={label} required={required} id={id} />}
|
||||||
disabled={disabled}
|
{displayLabel && description ? description : null}
|
||||||
id={id}
|
|
||||||
label={label}
|
|
||||||
onDropPropertyClick={onDropPropertyClick}
|
|
||||||
onKeyChange={onKeyChange}
|
|
||||||
readonly={readonly}
|
|
||||||
required={required}
|
|
||||||
schema={schema}
|
|
||||||
uiSchema={uiSchema}
|
|
||||||
registry={registry}
|
|
||||||
>
|
|
||||||
<FormControl fullWidth error={!!rawErrors.length} required={required}>
|
|
||||||
{children}
|
{children}
|
||||||
{displayLabel && rawDescription ? (
|
|
||||||
<Typography variant="caption" color="textSecondary">
|
|
||||||
{rawDescription}
|
|
||||||
</Typography>
|
|
||||||
) : null}
|
|
||||||
{errors}
|
{errors}
|
||||||
{help}
|
{help}
|
||||||
</FormControl>
|
|
||||||
</WrapIfAdditionalTemplate>
|
</WrapIfAdditionalTemplate>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default FieldTemplate;
|
|
||||||
|
@ -53,7 +53,8 @@ function SelectWidget({
|
|||||||
let errorMessageForField = null;
|
let errorMessageForField = null;
|
||||||
if (rawErrors && rawErrors.length > 0) {
|
if (rawErrors && rawErrors.length > 0) {
|
||||||
invalid = true;
|
invalid = true;
|
||||||
errorMessageForField = `${labelToUse.replace(/\*$/, '')} ${rawErrors[0]}`;
|
// errorMessageForField = `${labelToUse.replace(/\*$/, '')} ${rawErrors[0]}`;
|
||||||
|
errorMessageForField = rawErrors[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// maybe use placeholder somehow. it was previously jammed into the helperText field,
|
// maybe use placeholder somehow. it was previously jammed into the helperText field,
|
||||||
@ -63,7 +64,7 @@ function SelectWidget({
|
|||||||
<Select
|
<Select
|
||||||
id={id}
|
id={id}
|
||||||
name={id}
|
name={id}
|
||||||
labelText={labelToUse}
|
labelText=""
|
||||||
select
|
select
|
||||||
helperText={helperText}
|
helperText={helperText}
|
||||||
value={typeof value === 'undefined' ? emptyValue : value}
|
value={typeof value === 'undefined' ? emptyValue : value}
|
||||||
|
@ -65,7 +65,7 @@ function TextareaWidget<
|
|||||||
let errorMessageForField = null;
|
let errorMessageForField = null;
|
||||||
if (rawErrors && rawErrors.length > 0) {
|
if (rawErrors && rawErrors.length > 0) {
|
||||||
invalid = true;
|
invalid = true;
|
||||||
errorMessageForField = `${labelToUse.replace(/\*$/, '')} ${rawErrors[0]}`;
|
errorMessageForField = rawErrors[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user