@faasjs/ant-design 0.0.2-beta.323 → 0.0.2-beta.327
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +23 -8
- package/dist/index.js +22 -4
- package/dist/index.mjs +28 -6
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as antd_lib_form_Form from 'antd/lib/form/Form';
|
|
2
|
-
import { FormItemProps as FormItemProps$1, InputProps, InputNumberProps, SwitchProps, FormProps as FormProps$1 } from 'antd';
|
|
2
|
+
import { FormItemProps as FormItemProps$1, InputProps, InputNumberProps, SwitchProps, SelectProps, FormProps as FormProps$1 } from 'antd';
|
|
3
3
|
import { RuleObject } from 'rc-field-form/lib/interface';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
4
5
|
|
|
5
6
|
declare type FaasItemType = 'string' | 'string[]' | 'number' | 'number[]' | 'boolean';
|
|
6
7
|
declare type FaasItemProps = {
|
|
@@ -13,22 +14,36 @@ declare type FaasItemProps = {
|
|
|
13
14
|
title?: string;
|
|
14
15
|
};
|
|
15
16
|
|
|
16
|
-
declare type
|
|
17
|
+
declare type StringProps = {
|
|
17
18
|
type?: 'string' | 'string[]';
|
|
18
19
|
input?: InputProps;
|
|
19
|
-
}
|
|
20
|
-
|
|
20
|
+
};
|
|
21
|
+
declare type NumberProps = {
|
|
22
|
+
type?: 'number' | 'number[]';
|
|
21
23
|
input?: InputNumberProps;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
+
};
|
|
25
|
+
declare type BooleanProps = {
|
|
26
|
+
type?: 'boolean';
|
|
24
27
|
input?: SwitchProps;
|
|
25
28
|
};
|
|
29
|
+
declare type OptionType<T = any> = {
|
|
30
|
+
label: ReactNode;
|
|
31
|
+
value?: T;
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
children?: Omit<OptionType<T>, 'children'>[];
|
|
34
|
+
};
|
|
35
|
+
declare type OptionsProps<T = any> = {
|
|
36
|
+
options?: OptionType<T>[];
|
|
37
|
+
type?: 'string' | 'string[]' | 'number' | 'number[]';
|
|
38
|
+
input?: SelectProps<any>;
|
|
39
|
+
};
|
|
40
|
+
declare type FormItemInputProps<T = any> = StringProps | NumberProps | BooleanProps | OptionsProps<T>;
|
|
26
41
|
declare type FormItemProps<T = any> = {
|
|
27
42
|
children?: JSX.Element;
|
|
28
43
|
rules?: RuleObject[];
|
|
29
44
|
label?: string | false;
|
|
30
|
-
} & FormItemInputProps & FaasItemProps & FormItemProps$1<T>;
|
|
31
|
-
declare function FormItem<T>(props: FormItemProps<T>): JSX.Element;
|
|
45
|
+
} & FormItemInputProps<T> & FaasItemProps & FormItemProps$1<T>;
|
|
46
|
+
declare function FormItem<T = any>(props: FormItemProps<T>): JSX.Element;
|
|
32
47
|
|
|
33
48
|
declare type FormProps<T = any> = {
|
|
34
49
|
items: FormItemProps[];
|
package/dist/index.js
CHANGED
|
@@ -75,6 +75,16 @@ function FormItem(props) {
|
|
|
75
75
|
propsCopy.type = "string";
|
|
76
76
|
if (!propsCopy.rules)
|
|
77
77
|
propsCopy.rules = [];
|
|
78
|
+
if (propsCopy.required)
|
|
79
|
+
propsCopy.rules.push({
|
|
80
|
+
required: true,
|
|
81
|
+
message: `${propsCopy.label} is required`
|
|
82
|
+
});
|
|
83
|
+
if (!propsCopy.input)
|
|
84
|
+
propsCopy.input = {};
|
|
85
|
+
if (propsCopy.options) {
|
|
86
|
+
propsCopy.input.options = propsCopy.options;
|
|
87
|
+
}
|
|
78
88
|
switch (propsCopy.type) {
|
|
79
89
|
case "boolean":
|
|
80
90
|
propsCopy.valuePropName = "checked";
|
|
@@ -88,12 +98,16 @@ function FormItem(props) {
|
|
|
88
98
|
return /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, __spreadValues({}, computedProps), computedProps.children);
|
|
89
99
|
switch (computedProps.type) {
|
|
90
100
|
case "string":
|
|
91
|
-
return /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, __spreadValues({}, computedProps), /* @__PURE__ */ import_react.default.createElement(import_antd.Input, __spreadValues({}, computedProps.input)));
|
|
101
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, __spreadValues({}, computedProps), computedProps.options ? /* @__PURE__ */ import_react.default.createElement(import_antd.Select, __spreadValues({}, computedProps.input)) : /* @__PURE__ */ import_react.default.createElement(import_antd.Input, __spreadValues({}, computedProps.input)));
|
|
92
102
|
case "string[]":
|
|
103
|
+
if (computedProps.options)
|
|
104
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, __spreadValues({}, computedProps), /* @__PURE__ */ import_react.default.createElement(import_antd.Select, __spreadValues({
|
|
105
|
+
mode: "multiple"
|
|
106
|
+
}, computedProps.input)));
|
|
93
107
|
return /* @__PURE__ */ import_react.default.createElement(import_antd.Form.List, {
|
|
94
108
|
name: computedProps.name,
|
|
95
109
|
rules: computedProps.rules
|
|
96
|
-
}, (fields, { add, remove }) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
110
|
+
}, (fields, { add, remove }) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, computedProps.label && /* @__PURE__ */ import_react.default.createElement("div", {
|
|
97
111
|
className: "ant-form-item-label"
|
|
98
112
|
}, /* @__PURE__ */ import_react.default.createElement("label", {
|
|
99
113
|
className: computedProps.rules.find((r) => r.required) && "ant-form-item-required"
|
|
@@ -120,16 +134,20 @@ function FormItem(props) {
|
|
|
120
134
|
icon: /* @__PURE__ */ import_react.default.createElement(import_icons.PlusOutlined, null)
|
|
121
135
|
}))));
|
|
122
136
|
case "number":
|
|
123
|
-
return /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, __spreadValues({}, computedProps), /* @__PURE__ */ import_react.default.createElement(import_antd.InputNumber, __spreadValues({
|
|
137
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, __spreadValues({}, computedProps), computedProps.options ? /* @__PURE__ */ import_react.default.createElement(import_antd.Select, __spreadValues({}, computedProps.input)) : /* @__PURE__ */ import_react.default.createElement(import_antd.InputNumber, __spreadValues({
|
|
124
138
|
style: { width: "100%" }
|
|
125
139
|
}, computedProps.input)));
|
|
126
140
|
case "number[]":
|
|
141
|
+
if (computedProps.options)
|
|
142
|
+
return /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, __spreadValues({}, computedProps), /* @__PURE__ */ import_react.default.createElement(import_antd.Select, __spreadValues({
|
|
143
|
+
mode: "multiple"
|
|
144
|
+
}, computedProps.input)));
|
|
127
145
|
return /* @__PURE__ */ import_react.default.createElement(import_antd.Form.List, {
|
|
128
146
|
name: computedProps.name,
|
|
129
147
|
rules: computedProps.rules
|
|
130
148
|
}, (fields, { add, remove }) => {
|
|
131
149
|
var _a;
|
|
132
|
-
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", {
|
|
150
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, computedProps.label && /* @__PURE__ */ import_react.default.createElement("div", {
|
|
133
151
|
className: "ant-form-item-label"
|
|
134
152
|
}, /* @__PURE__ */ import_react.default.createElement("label", {
|
|
135
153
|
className: ((_a = computedProps.rules) == null ? void 0 : _a.find((r) => r.required)) && "ant-form-item-required"
|
package/dist/index.mjs
CHANGED
|
@@ -34,10 +34,14 @@ import {
|
|
|
34
34
|
Form as AntdForm,
|
|
35
35
|
Input,
|
|
36
36
|
InputNumber,
|
|
37
|
-
Switch
|
|
37
|
+
Switch,
|
|
38
|
+
Select
|
|
38
39
|
} from "antd";
|
|
39
40
|
import { MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
|
|
40
|
-
import {
|
|
41
|
+
import {
|
|
42
|
+
useEffect,
|
|
43
|
+
useState
|
|
44
|
+
} from "react";
|
|
41
45
|
import { upperFirst } from "lodash";
|
|
42
46
|
function FormItem(props) {
|
|
43
47
|
const [computedProps, setComputedProps] = useState();
|
|
@@ -53,6 +57,16 @@ function FormItem(props) {
|
|
|
53
57
|
propsCopy.type = "string";
|
|
54
58
|
if (!propsCopy.rules)
|
|
55
59
|
propsCopy.rules = [];
|
|
60
|
+
if (propsCopy.required)
|
|
61
|
+
propsCopy.rules.push({
|
|
62
|
+
required: true,
|
|
63
|
+
message: `${propsCopy.label} is required`
|
|
64
|
+
});
|
|
65
|
+
if (!propsCopy.input)
|
|
66
|
+
propsCopy.input = {};
|
|
67
|
+
if (propsCopy.options) {
|
|
68
|
+
propsCopy.input.options = propsCopy.options;
|
|
69
|
+
}
|
|
56
70
|
switch (propsCopy.type) {
|
|
57
71
|
case "boolean":
|
|
58
72
|
propsCopy.valuePropName = "checked";
|
|
@@ -66,12 +80,16 @@ function FormItem(props) {
|
|
|
66
80
|
return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), computedProps.children);
|
|
67
81
|
switch (computedProps.type) {
|
|
68
82
|
case "string":
|
|
69
|
-
return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), /* @__PURE__ */ React.createElement(Input, __spreadValues({}, computedProps.input)));
|
|
83
|
+
return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), computedProps.options ? /* @__PURE__ */ React.createElement(Select, __spreadValues({}, computedProps.input)) : /* @__PURE__ */ React.createElement(Input, __spreadValues({}, computedProps.input)));
|
|
70
84
|
case "string[]":
|
|
85
|
+
if (computedProps.options)
|
|
86
|
+
return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), /* @__PURE__ */ React.createElement(Select, __spreadValues({
|
|
87
|
+
mode: "multiple"
|
|
88
|
+
}, computedProps.input)));
|
|
71
89
|
return /* @__PURE__ */ React.createElement(AntdForm.List, {
|
|
72
90
|
name: computedProps.name,
|
|
73
91
|
rules: computedProps.rules
|
|
74
|
-
}, (fields, { add, remove }) => /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
92
|
+
}, (fields, { add, remove }) => /* @__PURE__ */ React.createElement(React.Fragment, null, computedProps.label && /* @__PURE__ */ React.createElement("div", {
|
|
75
93
|
className: "ant-form-item-label"
|
|
76
94
|
}, /* @__PURE__ */ React.createElement("label", {
|
|
77
95
|
className: computedProps.rules.find((r) => r.required) && "ant-form-item-required"
|
|
@@ -98,16 +116,20 @@ function FormItem(props) {
|
|
|
98
116
|
icon: /* @__PURE__ */ React.createElement(PlusOutlined, null)
|
|
99
117
|
}))));
|
|
100
118
|
case "number":
|
|
101
|
-
return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), /* @__PURE__ */ React.createElement(InputNumber, __spreadValues({
|
|
119
|
+
return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), computedProps.options ? /* @__PURE__ */ React.createElement(Select, __spreadValues({}, computedProps.input)) : /* @__PURE__ */ React.createElement(InputNumber, __spreadValues({
|
|
102
120
|
style: { width: "100%" }
|
|
103
121
|
}, computedProps.input)));
|
|
104
122
|
case "number[]":
|
|
123
|
+
if (computedProps.options)
|
|
124
|
+
return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), /* @__PURE__ */ React.createElement(Select, __spreadValues({
|
|
125
|
+
mode: "multiple"
|
|
126
|
+
}, computedProps.input)));
|
|
105
127
|
return /* @__PURE__ */ React.createElement(AntdForm.List, {
|
|
106
128
|
name: computedProps.name,
|
|
107
129
|
rules: computedProps.rules
|
|
108
130
|
}, (fields, { add, remove }) => {
|
|
109
131
|
var _a;
|
|
110
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
|
|
132
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, computedProps.label && /* @__PURE__ */ React.createElement("div", {
|
|
111
133
|
className: "ant-form-item-label"
|
|
112
134
|
}, /* @__PURE__ */ React.createElement("label", {
|
|
113
135
|
className: ((_a = computedProps.rules) == null ? void 0 : _a.find((r) => r.required)) && "ant-form-item-required"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@faasjs/ant-design",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.327",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"funding": "https://github.com/sponsors/faasjs",
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "
|
|
19
|
+
"build": "tsup src/index.ts --format esm,cjs --inject react-shim.js",
|
|
20
|
+
"build:types": "tsup-node src/index.ts --dts-only"
|
|
20
21
|
},
|
|
21
22
|
"files": [
|
|
22
23
|
"dist"
|
|
@@ -32,6 +33,7 @@
|
|
|
32
33
|
"@types/lodash": "*",
|
|
33
34
|
"@testing-library/jest-dom": "*",
|
|
34
35
|
"@testing-library/react": "*",
|
|
36
|
+
"@testing-library/user-event": "*",
|
|
35
37
|
"tsup": "*",
|
|
36
38
|
"typescript": "*"
|
|
37
39
|
},
|