Skip to content

Commit f54f4db

Browse files
Merge pull request #10 from iron-tech-space/editable_table
Add export `FormItems` and `FormItem`
2 parents 2cfac46 + 371b124 commit f54f4db

File tree

20 files changed

+229
-210
lines changed

20 files changed

+229
-210
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.0.78
2+
3+
- Add export `FormItems` and `FormItem`
4+
15
## 0.0.77
26

37
- Fix Ant Table two load configs
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
11
export default FormItems;
22
declare function FormItems(props: any): any;
3-
declare namespace FormItems {
4-
namespace propTypes {
5-
const items: PropTypes.Validator<(object | null | undefined)[]>;
6-
}
7-
}
8-
import PropTypes from "prop-types";

dist/components/Form/FormProps.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ export declare type FormBodyProps = React.HTMLAttributes<HTMLDivElement> & {
99
scrollable?: boolean;
1010
};
1111
export declare type FormFooterProps = React.HTMLAttributes<HTMLDivElement>;
12+
export declare type FormItemsProps = {
13+
items: object[];
14+
};
15+
export declare type FormItemProps = {
16+
child: object;
17+
};
1218
export interface FormProps extends AntFormProps {
1319
/** Не делать отступы у формы от краев блока. **Only config Form** */
1420
noPadding?: boolean;

dist/components/Form/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import Form from "./Form";
2-
export type { FormProps, FormHeaderProps, FormBodyProps, FormFooterProps } from "./FormProps";
2+
export type { FormProps, FormHeaderProps, FormBodyProps, FormFooterProps, FormItemsProps, FormItemProps } from "./FormProps";
33
export { FormHeader as RtFormHeader } from "./Form";
44
export { FormBody as RtFormBody } from "./Form";
55
export { FormFooter as RtFormFooter } from "./Form";
6+
export { default as RtFormItems } from "./FormItems";
7+
export { default as RtFormItem } from "./FormItem";
68
export default Form;

dist/components/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { FormProps } from "./Form";
1515
import { FormHeaderProps } from "./Form";
1616
import { FormBodyProps } from "./Form";
1717
import { FormFooterProps } from "./Form";
18+
import { FormItemsProps } from "./Form";
19+
import { FormItemProps } from "./Form";
1820
import { FormListProps } from "antd/lib/form";
1921
import { InputNumberProps } from "antd/lib/input-number";
2022
import { InputProps } from "antd/lib/input/Input";
@@ -53,6 +55,8 @@ export declare const Form: FunctionComponent<FormProps>;
5355
export declare const FormHeader: FunctionComponent<FormHeaderProps>;
5456
export declare const FormBody: FunctionComponent<FormBodyProps>;
5557
export declare const FormFooter: FunctionComponent<FormFooterProps>;
58+
export declare const FormItems: FunctionComponent<FormItemsProps>;
59+
export declare const FormItem: FunctionComponent<FormItemProps>;
5660
export declare const FormList: FunctionComponent<FormListProps & StoreProps>;
5761
export declare const InputNumber: FunctionComponent<InputNumberProps & StoreProps>;
5862
export declare const Input: FunctionComponent<InputProps & StoreProps>;

dist/index.es.js

Lines changed: 66 additions & 68 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.es.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 67 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/components/Form/FormItems.js

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,79 +5,74 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument
55

66
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
77

8+
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
9+
810
import React from "react";
9-
import PropTypes from "prop-types";
1011
import FormItem from "./FormItem";
1112

12-
import { getObjectExcludedProps } from "../utils/baseUtils";
1313
import { renderDeclarativeByName } from "../core/renders";
1414

15-
var excludeProps = ["children", "componentType"];
16-
1715
var FormItems = function FormItems(props) {
1816
var items = props.items;
19-
2017
// console.log('FormItems props => ', props);
2118

22-
var getItems = function getItems(data, antFormListParams) {
23-
19+
var getItems = function getItems(data, formListProps) {
2420
return data && data.map(function (item, index) {
25-
var itemProps = getObjectExcludedProps(item, excludeProps);
21+
var componentType = item.componentType,
22+
children = item.children,
23+
itemProps = _objectWithoutProperties(item, ["componentType", "children"]);
2624
// console.log('FormItems index => ', index);
2725

28-
switch (item.componentType) {
26+
27+
switch (componentType) {
2928
case "Item":
3029
var _item = _extends({}, item);
3130
var _key = index;
32-
if (antFormListParams && antFormListParams.field) {
31+
if (formListProps && formListProps.field) {
3332
if (_item.name) {
3433
if (Array.isArray(_item.name)) {
35-
_item.name = [antFormListParams.field.name].concat(_toConsumableArray(_item.name));
36-
_item.fieldKey = [antFormListParams.field.name].concat(_toConsumableArray(_item.name));
34+
_item.name = [formListProps.field.name].concat(_toConsumableArray(_item.name));
35+
_item.fieldKey = [formListProps.field.name].concat(_toConsumableArray(_item.name));
3736
} else {
38-
_item.name = [antFormListParams.field.name, _item.name];
39-
_item.fieldKey = [antFormListParams.field.name].concat(_toConsumableArray(_item.name));
37+
_item.name = [formListProps.field.name, _item.name];
38+
_item.fieldKey = [formListProps.field.name].concat(_toConsumableArray(_item.name));
4039
}
4140
}
4241
}
4342
// console.log('_item ', _item.name);
44-
return React.createElement(FormItem, _extends({ key: "" + _key }, _item, { field: _extends({}, antFormListParams) }));
43+
return React.createElement(FormItem, _extends({ key: "" + _key }, _item, { field: _extends({}, formListProps) }));
4544
case "ListItems":
4645
return React.createElement(
4746
_Form.List,
4847
_extends({ key: index }, itemProps),
4948
function (fields, operation) {
5049
var param = { fields: [].concat(_toConsumableArray(fields)), operation: _extends({}, operation) };
51-
return getItems(item.children, param);
50+
return getItems(children, param);
5251
}
5352
);
5453
case "ListItem":
55-
// console.log('antFormListParams => ', antFormListParams);
54+
// console.log('formListProps => ', formListProps);
5655
return React.createElement(
5756
"div",
5857
{ key: index },
59-
antFormListParams && antFormListParams.fields && antFormListParams.fields.map(function (field, fIndex) {
58+
formListProps && formListProps.fields && formListProps.fields.map(function (field, fIndex) {
6059
// console.log('index field.key', index, field);
61-
var param = _extends({ field: _extends({}, field) }, antFormListParams);
60+
var param = _extends({ field: _extends({}, field) }, formListProps);
6261
return React.createElement(
6362
"div",
6463
{ key: field.key },
65-
getItems(item.children, param),
64+
getItems(children, param),
6665
" "
6766
);
6867
})
6968
);
7069
default:
71-
return renderDeclarativeByName(item.componentType)(_extends({ key: index }, itemProps))(getItems(item.children, antFormListParams));
70+
return renderDeclarativeByName(componentType)(_extends({ key: index }, itemProps))(getItems(children, formListProps));
7271
}
7372
}) || null;
7473
};
7574

7675
return getItems(items);
7776
};
7877

79-
FormItems.propTypes = {
80-
items: PropTypes.arrayOf(PropTypes.object).isRequired
81-
};
82-
8378
export default FormItems;

0 commit comments

Comments
 (0)