Skip to content

Commit c219e53

Browse files
committed
fix(ANT): add types for components
1 parent a215ed6 commit c219e53

21 files changed

+374
-4
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { AnyObject } from "@data-driven-forms/react-form-renderer";
2+
import { ReactNode } from "react";
3+
import { FormGroupProps } from "./form-group";
4+
5+
import { CheckboxProps as AndCheckboxProps } from 'antd/es/checkbox/Checkbox';
6+
7+
export interface CheckboxOption extends AnyObject {
8+
value?: any;
9+
label: ReactNode;
10+
}
11+
12+
interface InternalCheckboxProps extends AndCheckboxProps {
13+
options?: CheckboxOption[];
14+
}
15+
16+
export type CheckboxProps = InternalCheckboxProps & FormGroupProps;
17+
18+
declare const Checkbox: React.ComponentType<CheckboxProps>;
19+
20+
export default Checkbox;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { ComponentTypes, ComponentMapper } from '@data-driven-forms/react-form-renderer';
2+
3+
interface Components {
4+
TextField: React.ComponentType;
5+
Textarea: React.ComponentType;
6+
Select: React.ComponentType;
7+
Checkbox: React.ComponentType;
8+
Radio: React.ComponentType;
9+
Switch: React.ComponentType;
10+
DatePicker: React.ComponentType;
11+
TimePicker: React.ComponentType;
12+
PlainText: React.ComponentType;
13+
SubForm: React.ComponentType;
14+
Wizard: React.ComponentType;
15+
DualListSelect: React.ComponentType;
16+
Slider: React.ComponentType;
17+
FueldArray: React.ComponentType;
18+
Tabs: React.ComponentType;
19+
}
20+
21+
interface componentMapper extends ComponentMapper {
22+
[ComponentTypes.TEXT_FIELD]: React.ComponentType;
23+
[ComponentTypes.TEXTAREA]: React.ComponentType;
24+
[ComponentTypes.SELECT]: React.ComponentType;
25+
[ComponentTypes.CHECKBOX]: React.ComponentType;
26+
[ComponentTypes.SUB_FORM]: React.ComponentType;
27+
[ComponentTypes.RADIO]: React.ComponentType;
28+
[ComponentTypes.TABS]: React.ComponentType;
29+
[ComponentTypes.DATE_PICKER]: React.ComponentType;
30+
[ComponentTypes.TIME_PICKER]: React.ComponentType;
31+
[ComponentTypes.SWITCH]: React.ComponentType;
32+
[ComponentTypes.PLAIN_TEXT]: React.ComponentType;
33+
[ComponentTypes.WIZARD]: React.ComponentType;
34+
[ComponentTypes.FIELD_ARRAY]: React.ComponentType;
35+
[ComponentTypes.DUAL_LIST_SELECT]: React.ComponentType;
36+
[ComponentTypes.SLIDER]: React.ComponentType;
37+
}
38+
39+
declare const componentMapper: componentMapper;
40+
41+
export const components: Components;
42+
43+
export default componentMapper;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { FormGroupProps } from "./form-group";
2+
3+
import { DatePickerProps as AntDatePickerProps } from 'antd/es/date-picker/index';
4+
5+
export type DatePickerProps = AntDatePickerProps & FormGroupProps;
6+
7+
declare const DatePicker: React.ComponentType<DatePickerProps>;
8+
9+
export default DatePicker;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { FormGroupProps } from "./form-group";
2+
import { AnyObject } from "@data-driven-forms/react-form-renderer";
3+
import { ReactNode } from "react";
4+
5+
import { TransferProps } from "antd/es/transfer";
6+
7+
export interface DualListSelectValue extends AnyObject {
8+
value: any;
9+
label: ReactNode;
10+
}
11+
12+
interface InternalDualListSelectProps extends TransferProps {
13+
options: DualListSelectValue[];
14+
}
15+
16+
export type DualListSelectProps = InternalDualListSelectProps & FormGroupProps;
17+
18+
declare const DualListSelect: React.ComponentType<DualListSelectProps>;
19+
20+
export default DualListSelect;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { FieldArrayField } from "@data-driven-forms/react-form-renderer";
2+
import { ReactNode } from "react";
3+
import { RowProps } from "antd/lib/row";
4+
import { ButtonProps } from "antd/es/button";
5+
import { TextProps } from "antd/lib/typography/Text";
6+
import { ColProps } from "antd/lib/col";
7+
import { TitleProps } from "antd/lib/typography/Title";
8+
import { SpaceProps } from "antd/lib/space";
9+
10+
export interface FieldArrayButtonLabels {
11+
add?: ReactNode;
12+
remove?: ReactNode;
13+
}
14+
15+
export interface FieldArrayProps {
16+
fields: FieldArrayField[];
17+
defaultItem?: any;
18+
minItems?: number;
19+
maxItems?: number;
20+
noItemsMessage?: ReactNode;
21+
buttonLabels?: FieldArrayButtonLabels;
22+
ArrayItemProps?: RowProps;
23+
FieldsContainerProps?: ColProps;
24+
RemoveContainerProps?: ColProps;
25+
RemoveButtonProps?: ButtonProps;
26+
FieldArrayRowProps?: RowProps;
27+
FieldArrayRowCol?: ColProps;
28+
FieldArrayHeaderProps?: RowProps;
29+
FieldArrayLabelProps?: TitleProps;
30+
FieldArrayButtonsProps?: SpaceProps;
31+
UndoButtonProps?: ButtonProps;
32+
RedoButtonProps?: ButtonProps;
33+
AddButtonProps?: ButtonProps;
34+
FieldArrayDescriptionProps?: TextProps;
35+
NoItemsMessageProps?: TextProps;
36+
ErrorMessageProps?: TextProps;
37+
}
38+
39+
declare const FieldArray: React.ComponentType<FieldArrayProps>;
40+
41+
export default FieldArray;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { UseFieldApiComponentConfig } from "@data-driven-forms/react-form-renderer";
2+
import { ReactNode } from "react";
3+
4+
import { FormItemProps } from 'antd/es/form/FormItem';
5+
6+
export interface CommonProps {
7+
isReadOnly?: boolean;
8+
isDisabled?: boolean;
9+
isRequired?: boolean;
10+
label?: ReactNode;
11+
helperText?: ReactNode;
12+
description?: ReactNode;
13+
validateOnMount?: boolean;
14+
FormItemProps?: FormItemProps;
15+
placeholder?: ReactNode;
16+
}
17+
18+
export type FormGroupProps = CommonProps & UseFieldApiComponentConfig;
19+
20+
export default FormGroupProps;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { FormTemplateRenderProps, AnyObject } from "@data-driven-forms/react-form-renderer";
2+
3+
export interface FormTemplateProps extends FormTemplateRenderProps {
4+
formWrapperProps?: AnyObject;
5+
layout?: string;
6+
}
7+
8+
declare const FormTemplate: React.ComponentType<FormTemplateProps>;
9+
10+
export default FormTemplate;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { TypographyProps } from 'antd/es/typography/Typography';
2+
import { ParagraphProps } from 'antd/es/typography/Paragraph';
3+
4+
export interface PlainTextProps extends ParagraphProps {
5+
label: string;
6+
name: string;
7+
TypographyProps?: TypographyProps;
8+
}
9+
10+
declare const PlainText: React.ComponentType<PlainTextProps>;
11+
12+
export default PlainText;

packages/ant-component-mapper/src/files/plain-text.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import PropTypes from 'prop-types';
44

55
const { Paragraph } = Typography;
66

7-
const PlainText = ({ label, name, ...rest }) => (
8-
<Typography>
7+
const PlainText = ({ label, name, TypographyProps, ...rest }) => (
8+
<Typography {...TypographyProps}>
99
{label.split('\n').map((paragraph, index) => (
1010
<Paragraph key={`${index}-${name}`} {...rest}>
1111
{paragraph}
@@ -16,7 +16,8 @@ const PlainText = ({ label, name, ...rest }) => (
1616

1717
PlainText.propTypes = {
1818
label: PropTypes.string.isRequired,
19-
name: PropTypes.string.isRequired
19+
name: PropTypes.string.isRequired,
20+
TypographyProps: PropTypes.object
2021
};
2122

2223
export default PlainText;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { FormGroupProps } from "./form-group";
2+
import { AnyObject } from "@data-driven-forms/react-form-renderer";
3+
import { ReactNode } from "react";
4+
5+
import { RadioProps as AntRadioProps } from 'antd/es/radio/interface';
6+
7+
export interface RadioOption extends AnyObject {
8+
value: any;
9+
label: ReactNode;
10+
}
11+
12+
interface InternalRadioProps extends AntRadioProps {
13+
options: RadioOption[];
14+
}
15+
16+
export type RadioProps = InternalRadioProps & FormGroupProps;
17+
18+
declare const Radio: React.ComponentType<RadioProps>;
19+
20+
export default Radio;

0 commit comments

Comments
 (0)