updated a couple form components to work with carbon w/ burnettk cullerton

This commit is contained in:
jasquat 2022-11-16 14:46:04 -05:00
parent b9c98a9760
commit e2a2e42712
5 changed files with 42 additions and 35 deletions

View File

@ -165,11 +165,7 @@ export default function ProcessGroupForm({
}; };
const formButtons = () => { const formButtons = () => {
const buttons = [ const buttons = [<Button type="submit">Submit</Button>];
<Button kind="secondary" type="submit">
Submit
</Button>,
];
if (mode === 'edit') { if (mode === 'edit') {
buttons.push( buttons.push(
<ButtonWithConfirmation <ButtonWithConfirmation

View File

@ -1,5 +1,6 @@
import React from 'react'; import React from 'react';
import TextField, { TextFieldProps } from '@mui/material/TextField'; // @ts-ignore
import { TextInput } from '@carbon/react';
import { getInputProps, WidgetProps } from '@rjsf/utils'; import { getInputProps, WidgetProps } from '@rjsf/utils';
function BaseInputTemplate({ function BaseInputTemplate({
@ -19,10 +20,9 @@ function BaseInputTemplate({
schema, schema,
uiSchema, uiSchema,
rawErrors = [], rawErrors = [],
formContext,
registry, registry,
...textFieldProps }: // ...textFieldProps
}: WidgetProps) { WidgetProps) {
const inputProps = getInputProps(schema, type, options); const inputProps = getInputProps(schema, type, options);
// Now we need to pull out the step, min, max into an inner `inputProps` for material-ui // Now we need to pull out the step, min, max into an inner `inputProps` for material-ui
const { step, min, max, ...rest } = inputProps; const { step, min, max, ...rest } = inputProps;
@ -35,13 +35,18 @@ function BaseInputTemplate({
}, },
...rest, ...rest,
}; };
const _onChange = ({ const localOnChange = ({
// eslint-disable-next-line no-shadow
target: { value }, target: { value },
}: React.ChangeEvent<HTMLInputElement>) => }: React.ChangeEvent<HTMLInputElement>) => {
onChange(value === '' ? options.emptyValue : value); onChange(value === '' ? options.emptyValue : value);
const _onBlur = ({ target: { value } }: React.FocusEvent<HTMLInputElement>) => };
onBlur(id, value); const localOnBlur = ({
const _onFocus = ({ // eslint-disable-next-line no-shadow
target: { value },
}: React.FocusEvent<HTMLInputElement>) => onBlur(id, value);
const localOnFocus = ({
// eslint-disable-next-line no-shadow
target: { value }, target: { value },
}: React.FocusEvent<HTMLInputElement>) => onFocus(id, value); }: React.FocusEvent<HTMLInputElement>) => onFocus(id, value);
@ -50,7 +55,7 @@ function BaseInputTemplate({
return ( return (
<> <>
<TextField <TextInput
id={id} id={id}
name={id} name={id}
placeholder={placeholder} placeholder={placeholder}
@ -58,19 +63,20 @@ function BaseInputTemplate({
autoFocus={autofocus} autoFocus={autofocus}
required={required} required={required}
disabled={disabled || readonly} disabled={disabled || readonly}
{...otherProps}
value={value || value === 0 ? value : ''} value={value || value === 0 ? value : ''}
error={rawErrors.length > 0} error={rawErrors.length > 0}
onChange={_onChange} onChange={localOnChange}
onBlur={_onBlur} onBlur={localOnBlur}
onFocus={_onFocus} onFocus={localOnFocus}
{...(textFieldProps as TextFieldProps)} // eslint-disable-next-line react/jsx-props-no-spreading
{...otherProps}
/> />
{schema.examples && ( {schema.examples && (
<datalist id={`examples_${id}`}> <datalist id={`examples_${id}`}>
{(schema.examples as string[]) {(schema.examples as string[])
.concat(schema.default ? ([schema.default] as string[]) : []) .concat(schema.default ? ([schema.default] as string[]) : [])
.map((example: any) => { .map((example: any) => {
// eslint-disable-next-line jsx-a11y/control-has-associated-label
return <option key={example} value={example} />; return <option key={example} value={example} />;
})} })}
</datalist> </datalist>

View File

@ -1,29 +1,30 @@
import React from 'react'; import React from 'react';
import Box from '@mui/material/Box'; // import Box from '@mui/material/Box';
import Button from '@mui/material/Button'; // @ts-ignore
import { Button } from '@carbon/react';
import { SubmitButtonProps, getSubmitButtonOptions } from '@rjsf/utils'; import { SubmitButtonProps, getSubmitButtonOptions } from '@rjsf/utils';
const SubmitButton: React.ComponentType<SubmitButtonProps> = (props) => { // const SubmitButton: React.ComponentType<SubmitButtonProps> = (props) => {
function SubmitButton(props: SubmitButtonProps) {
const { uiSchema } = props;
const { const {
submitText, submitText,
norender, norender,
props: submitButtonProps, props: submitButtonProps,
} = getSubmitButtonOptions(props.uiSchema); } = getSubmitButtonOptions(uiSchema);
if (norender) { if (norender) {
return null; return null;
} }
return ( return (
<Box marginTop={3}>
<Button <Button
className="react-json-schema-form-submit-button"
type="submit" type="submit"
variant="contained" // eslint-disable-next-line react/jsx-props-no-spreading
color="primary"
{...submitButtonProps} {...submitButtonProps}
> >
{submitText} {submitText}
</Button> </Button>
</Box>
); );
}; }
export default SubmitButton; export default SubmitButton;

View File

@ -0,0 +1,3 @@
button.react-json-schema-form-submit-button {
margin-top: 1.5em;
}

View File

@ -1,4 +1,5 @@
import MuiForm from './MuiForm/MuiForm'; import MuiForm from './MuiForm/MuiForm';
import './index.css';
export { default as Form } from './MuiForm'; export { default as Form } from './MuiForm';
export { default as Templates } from './Templates'; export { default as Templates } from './Templates';