Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(all): replace defaultProps with inline function defaults #1440

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/ant-component-mapper/src/date-picker/date-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { validationError } from '../validation-error/validation-error';
import { useFieldApi } from '@data-driven-forms/react-form-renderer';
import FormGroup from '../form-group';

const DatePicker = (props) => {
const { input, isReadOnly, isDisabled, placeholder, isRequired, label, helperText, description, validateOnMount, meta, FormItemProps, ...rest } =
const DatePicker = ({ placeholder = 'Select date', ...props }) => {
const { input, isReadOnly, isDisabled, isRequired, label, helperText, description, validateOnMount, meta, FormItemProps, ...rest } =
useFieldApi(props);
const invalid = validationError(meta, validateOnMount);

Expand Down Expand Up @@ -50,8 +50,4 @@ DatePicker.propTypes = {
FormItemProps: PropTypes.object,
};

DatePicker.defaultProps = {
placeholder: 'Select date',
};

export default DatePicker;
60 changes: 19 additions & 41 deletions packages/ant-component-mapper/src/field-array/field-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,32 +103,32 @@
fields: formFields,
defaultItem,
meta,
minItems,
maxItems,
noItemsMessage,
minItems = 0,
maxItems = Infinity,
noItemsMessage = 'No items added',
FormFieldGridProps,
FormControlProps,
buttonLabels,
validateOnMount,
isRequired,
helperText,
// customization props
FormItemProps,
ArrayItemProps,
FieldsContainerProps,
RemoveContainerProps,
RemoveButtonProps,
FieldArrayRowProps,
FieldArrayRowCol,
FieldArrayHeaderProps,
FieldArrayLabelProps,
FieldArrayButtonsProps,
UndoButtonProps,
RedoButtonProps,
AddButtonProps,
FieldArrayDescriptionProps,
NoItemsMessageProps,
ErrorMessageProps,
FormItemProps = {},
ArrayItemProps = {},
FieldsContainerProps = {},
RemoveContainerProps = {},
RemoveButtonProps = {},

Check warning on line 120 in packages/ant-component-mapper/src/field-array/field-array.js

View check run for this annotation

Codecov / codecov/patch

packages/ant-component-mapper/src/field-array/field-array.js#L120

Added line #L120 was not covered by tests
FieldArrayRowProps = {},
FieldArrayRowCol = {},
FieldArrayHeaderProps = {},
FieldArrayLabelProps = {},
FieldArrayButtonsProps = {},
UndoButtonProps = {},
RedoButtonProps = {},
AddButtonProps = {},

Check warning on line 128 in packages/ant-component-mapper/src/field-array/field-array.js

View check run for this annotation

Codecov / codecov/patch

packages/ant-component-mapper/src/field-array/field-array.js#L128

Added line #L128 was not covered by tests
FieldArrayDescriptionProps = {},
NoItemsMessageProps = {},
ErrorMessageProps = {},
...rest
} = useFieldApi(props);
const [state, dispatch] = useReducer(reducer, initialState);
Expand Down Expand Up @@ -275,26 +275,4 @@
ErrorMessageProps: PropTypes.object,
};

DynamicArray.defaultProps = {
maxItems: Infinity,
minItems: 0,
noItemsMessage: 'No items added',
FormItemProps: {},
ArrayItemProps: {},
FieldsContainerProps: {},
RemoveContainerProps: {},
RemoveButtonProps: {},
FieldArrayRowProps: {},
FieldArrayRowCol: {},
FieldArrayHeaderProps: {},
FieldArrayLabelProps: {},
FieldArrayButtonsProps: {},
UndoButtonProps: {},
RedoButtonProps: {},
AddButtonProps: {},
FieldArrayDescriptionProps: {},
NoItemsMessageProps: {},
ErrorMessageProps: {},
};

export default DynamicArray;
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { childrenPropTypes } from '@data-driven-forms/common/prop-types-template

const { Title, Paragraph } = Typography;

const Form = ({ children, onSubmit, ...props }) => (
<AntForm onFinish={onSubmit} {...props}>
const Form = ({ children, onSubmit, layout = 'vertical', ...props }) => (
<AntForm onFinish={onSubmit} layout={layout} {...props}>
{children}
</AntForm>
);
Expand All @@ -18,10 +18,6 @@ Form.propTypes = {
children: childrenPropTypes,
};

Form.defaultProps = {
layout: 'vertical',
};

const Description = ({ children, ...props }) => (
<Typography {...props}>
<Paragraph>{children}</Paragraph>
Expand Down
26 changes: 17 additions & 9 deletions packages/ant-component-mapper/src/radio/radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,23 @@
};

const Radio = ({ name, component, ...props }) => {
const { options, isDisabled, label, isRequired, helperText, description, isReadOnly, meta, validateOnMount, FormItemProps, input, ...rest } =
useFieldApi({
...props,
name,
});
const {
options = [],

Check warning on line 21 in packages/ant-component-mapper/src/radio/radio.js

View check run for this annotation

Codecov / codecov/patch

packages/ant-component-mapper/src/radio/radio.js#L21

Added line #L21 was not covered by tests
isDisabled,
label,
isRequired,
helperText,
description,
isReadOnly,
meta,
validateOnMount,
FormItemProps,
input,
...rest
} = useFieldApi({
...props,
name,
});

return (
<FormGroup
Expand Down Expand Up @@ -58,8 +70,4 @@
component: PropTypes.string,
};

Radio.defaultProps = {
options: [],
};

export default Radio;
20 changes: 14 additions & 6 deletions packages/ant-component-mapper/src/time-picker/time-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@ import { useFieldApi } from '@data-driven-forms/react-form-renderer';
import FormGroup from '../form-group';

const TimePicker = (props) => {
const { input, isReadOnly, isDisabled, placeholder, isRequired, label, helperText, description, validateOnMount, meta, FormItemProps, ...rest } =
useFieldApi(props);
const {
input,
isReadOnly,
isDisabled,
placeholder = 'Select date',
isRequired,
label,
helperText,
description,
validateOnMount,
meta,
FormItemProps,
...rest
} = useFieldApi(props);
const invalid = validationError(meta, validateOnMount);

return (
Expand Down Expand Up @@ -52,8 +64,4 @@ TimePicker.propTypes = {
FormItemProps: PropTypes.object,
};

TimePicker.defaultProps = {
placeholder: 'Select date',
};

export default TimePicker;
6 changes: 1 addition & 5 deletions packages/ant-component-mapper/src/wizard/wizard-step.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import WizardStepButtons from './step-buttons';

import './wizard-step.css';

const WizardStep = ({ fields, formOptions, WizardStepProps, ...rest }) => (
const WizardStep = ({ fields = [], formOptions, WizardStepProps, ...rest }) => (
<Fragment>
<div className="ddorg__ant-component-mapper_wizard-step" {...WizardStepProps}>
{fields.map((item) => formOptions.renderForm([item], formOptions))}
Expand All @@ -22,8 +22,4 @@ WizardStep.propTypes = {
WizardStepProps: PropTypes.object,
};

WizardStep.defaultProps = {
fields: [],
};

export default WizardStep;
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ import { DatePicker as BDatePicker } from '@blueprintjs/datetime';
import FormGroupWrapper from '../form-group/form-group';
import propsCatcher from '../props-catcher/props-catcher';

const DatePicker = ({ input, disabled, placeholder, valueRenderer, PopoverProps, ButtonProps, ...props }) => (
const DatePicker = ({
input,
disabled,
placeholder = 'Select date...',
valueRenderer = (value) => value.toString(),
PopoverProps,
ButtonProps,
...props
}) => (
<Popover disabled={disabled} {...PopoverProps}>
<Button text={input.value ? valueRenderer(input.value) : placeholder} disabled={disabled} {...ButtonProps} />
<BDatePicker id={input.name} {...propsCatcher(props)} {...input} value={input.value || null} />
</Popover>
);

DatePicker.defaultProps = {
placeholder: 'Select date...',
valueRenderer: (value) => value.toString(),
};

DatePicker.propTypes = {
input: PropTypes.object,
disabled: PropTypes.bool,
Expand Down
Loading
Loading