Skip to content

Commit 65f40ef

Browse files
authored
Merge pull request #647 from rvsia/antTS
fix(ANT): add types for components
2 parents a215ed6 + 155e48a commit 65f40ef

22 files changed

+378
-6
lines changed

packages/ant-component-mapper/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
"description": "Component mapper for Ant Design component mapper form data-driven-forms.",
55
"main": "dist/cjs/index.js",
66
"module": "dist/esm/index.js",
7+
"typings": "dist/cjs/index.d.ts",
78
"license": "Apache-2.0",
89
"scripts": {
910
"start": "webpack-dev-server --env dev --config ./config/webpack.config.js --open --hot",
10-
"build": "yarn build:cjs && yarn build:esm && yarn build:umd",
11+
"build": "yarn build:cjs && yarn build:esm && yarn build:umd && yarn build:typings",
1112
"build:cjs": "BABEL_ENV=cjs rollup -c ./rollup.config.js --format=cjs --environment FORMAT:cjs",
1213
"build:esm": "BABEL_ENV=esm rollup -c ./rollup.config.js --format=esm --environment FORMAT:esm",
1314
"build:umd": "rollup -c ./rollup.config.js --format=umd --environment FORMAT:umd",
1415
"vendor": "webpack --env vendor --config ./config/webpack.config.js",
15-
"release": "semantic-release"
16+
"release": "semantic-release",
17+
"build:typings": "node ../../scripts/copy-files.js"
1618
},
1719
"files": [
1820
"dist/"
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;

0 commit comments

Comments
 (0)