@faasjs/ant-design 0.0.2-beta.327 → 0.0.2-beta.328
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.js +25 -8
- package/dist/index.mjs +26 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -75,11 +75,21 @@ function FormItem(props) {
|
|
|
75
75
|
propsCopy.type = "string";
|
|
76
76
|
if (!propsCopy.rules)
|
|
77
77
|
propsCopy.rules = [];
|
|
78
|
-
if (propsCopy.required)
|
|
79
|
-
propsCopy.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
if (propsCopy.required) {
|
|
79
|
+
if (propsCopy.type.endsWith("[]"))
|
|
80
|
+
propsCopy.rules.push({
|
|
81
|
+
required: true,
|
|
82
|
+
validator: async (_, values) => {
|
|
83
|
+
if (!values || values.length < 1)
|
|
84
|
+
return Promise.reject(Error(`${propsCopy.label || propsCopy.title} is required`));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
else
|
|
88
|
+
propsCopy.rules.push({
|
|
89
|
+
required: true,
|
|
90
|
+
message: `${propsCopy.label || propsCopy.title} is required`
|
|
91
|
+
});
|
|
92
|
+
}
|
|
83
93
|
if (!propsCopy.input)
|
|
84
94
|
propsCopy.input = {};
|
|
85
95
|
if (propsCopy.options) {
|
|
@@ -107,7 +117,7 @@ function FormItem(props) {
|
|
|
107
117
|
return /* @__PURE__ */ import_react.default.createElement(import_antd.Form.List, {
|
|
108
118
|
name: computedProps.name,
|
|
109
119
|
rules: computedProps.rules
|
|
110
|
-
}, (fields, { add, remove }) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, computedProps.label && /* @__PURE__ */ import_react.default.createElement("div", {
|
|
120
|
+
}, (fields, { add, remove }, { errors }) => /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, computedProps.label && /* @__PURE__ */ import_react.default.createElement("div", {
|
|
111
121
|
className: "ant-form-item-label"
|
|
112
122
|
}, /* @__PURE__ */ import_react.default.createElement("label", {
|
|
113
123
|
className: computedProps.rules.find((r) => r.required) && "ant-form-item-required"
|
|
@@ -132,6 +142,8 @@ function FormItem(props) {
|
|
|
132
142
|
block: true,
|
|
133
143
|
onClick: () => add(),
|
|
134
144
|
icon: /* @__PURE__ */ import_react.default.createElement(import_icons.PlusOutlined, null)
|
|
145
|
+
}), /* @__PURE__ */ import_react.default.createElement(import_antd.Form.ErrorList, {
|
|
146
|
+
errors
|
|
135
147
|
}))));
|
|
136
148
|
case "number":
|
|
137
149
|
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({
|
|
@@ -145,7 +157,7 @@ function FormItem(props) {
|
|
|
145
157
|
return /* @__PURE__ */ import_react.default.createElement(import_antd.Form.List, {
|
|
146
158
|
name: computedProps.name,
|
|
147
159
|
rules: computedProps.rules
|
|
148
|
-
}, (fields, { add, remove }) => {
|
|
160
|
+
}, (fields, { add, remove }, { errors }) => {
|
|
149
161
|
var _a;
|
|
150
162
|
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, computedProps.label && /* @__PURE__ */ import_react.default.createElement("div", {
|
|
151
163
|
className: "ant-form-item-label"
|
|
@@ -174,6 +186,8 @@ function FormItem(props) {
|
|
|
174
186
|
block: true,
|
|
175
187
|
onClick: () => add(),
|
|
176
188
|
icon: /* @__PURE__ */ import_react.default.createElement(import_icons.PlusOutlined, null)
|
|
189
|
+
}), /* @__PURE__ */ import_react.default.createElement(import_antd.Form.ErrorList, {
|
|
190
|
+
errors
|
|
177
191
|
})));
|
|
178
192
|
});
|
|
179
193
|
case "boolean":
|
|
@@ -187,7 +201,10 @@ function FormItem(props) {
|
|
|
187
201
|
var Form = function(props) {
|
|
188
202
|
return /* @__PURE__ */ import_react.default.createElement(import_antd2.Form, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ import_react.default.createElement(FormItem, __spreadValues({
|
|
189
203
|
key: item.id
|
|
190
|
-
}, item)))
|
|
204
|
+
}, item))), /* @__PURE__ */ import_react.default.createElement(import_antd2.Button, {
|
|
205
|
+
htmlType: "submit",
|
|
206
|
+
type: "primary"
|
|
207
|
+
}, "Submit"));
|
|
191
208
|
};
|
|
192
209
|
Form.useForm = import_antd2.Form.useForm;
|
|
193
210
|
module.exports = __toCommonJS(src_exports);
|
package/dist/index.mjs
CHANGED
|
@@ -23,6 +23,7 @@ import React from "react";
|
|
|
23
23
|
|
|
24
24
|
// src/components/Form.tsx
|
|
25
25
|
import {
|
|
26
|
+
Button as Button2,
|
|
26
27
|
Form as AntdForm2
|
|
27
28
|
} from "antd";
|
|
28
29
|
|
|
@@ -57,11 +58,21 @@ function FormItem(props) {
|
|
|
57
58
|
propsCopy.type = "string";
|
|
58
59
|
if (!propsCopy.rules)
|
|
59
60
|
propsCopy.rules = [];
|
|
60
|
-
if (propsCopy.required)
|
|
61
|
-
propsCopy.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
if (propsCopy.required) {
|
|
62
|
+
if (propsCopy.type.endsWith("[]"))
|
|
63
|
+
propsCopy.rules.push({
|
|
64
|
+
required: true,
|
|
65
|
+
validator: async (_, values) => {
|
|
66
|
+
if (!values || values.length < 1)
|
|
67
|
+
return Promise.reject(Error(`${propsCopy.label || propsCopy.title} is required`));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
else
|
|
71
|
+
propsCopy.rules.push({
|
|
72
|
+
required: true,
|
|
73
|
+
message: `${propsCopy.label || propsCopy.title} is required`
|
|
74
|
+
});
|
|
75
|
+
}
|
|
65
76
|
if (!propsCopy.input)
|
|
66
77
|
propsCopy.input = {};
|
|
67
78
|
if (propsCopy.options) {
|
|
@@ -89,7 +100,7 @@ function FormItem(props) {
|
|
|
89
100
|
return /* @__PURE__ */ React.createElement(AntdForm.List, {
|
|
90
101
|
name: computedProps.name,
|
|
91
102
|
rules: computedProps.rules
|
|
92
|
-
}, (fields, { add, remove }) => /* @__PURE__ */ React.createElement(React.Fragment, null, computedProps.label && /* @__PURE__ */ React.createElement("div", {
|
|
103
|
+
}, (fields, { add, remove }, { errors }) => /* @__PURE__ */ React.createElement(React.Fragment, null, computedProps.label && /* @__PURE__ */ React.createElement("div", {
|
|
93
104
|
className: "ant-form-item-label"
|
|
94
105
|
}, /* @__PURE__ */ React.createElement("label", {
|
|
95
106
|
className: computedProps.rules.find((r) => r.required) && "ant-form-item-required"
|
|
@@ -114,6 +125,8 @@ function FormItem(props) {
|
|
|
114
125
|
block: true,
|
|
115
126
|
onClick: () => add(),
|
|
116
127
|
icon: /* @__PURE__ */ React.createElement(PlusOutlined, null)
|
|
128
|
+
}), /* @__PURE__ */ React.createElement(AntdForm.ErrorList, {
|
|
129
|
+
errors
|
|
117
130
|
}))));
|
|
118
131
|
case "number":
|
|
119
132
|
return /* @__PURE__ */ React.createElement(AntdForm.Item, __spreadValues({}, computedProps), computedProps.options ? /* @__PURE__ */ React.createElement(Select, __spreadValues({}, computedProps.input)) : /* @__PURE__ */ React.createElement(InputNumber, __spreadValues({
|
|
@@ -127,7 +140,7 @@ function FormItem(props) {
|
|
|
127
140
|
return /* @__PURE__ */ React.createElement(AntdForm.List, {
|
|
128
141
|
name: computedProps.name,
|
|
129
142
|
rules: computedProps.rules
|
|
130
|
-
}, (fields, { add, remove }) => {
|
|
143
|
+
}, (fields, { add, remove }, { errors }) => {
|
|
131
144
|
var _a;
|
|
132
145
|
return /* @__PURE__ */ React.createElement(React.Fragment, null, computedProps.label && /* @__PURE__ */ React.createElement("div", {
|
|
133
146
|
className: "ant-form-item-label"
|
|
@@ -156,6 +169,8 @@ function FormItem(props) {
|
|
|
156
169
|
block: true,
|
|
157
170
|
onClick: () => add(),
|
|
158
171
|
icon: /* @__PURE__ */ React.createElement(PlusOutlined, null)
|
|
172
|
+
}), /* @__PURE__ */ React.createElement(AntdForm.ErrorList, {
|
|
173
|
+
errors
|
|
159
174
|
})));
|
|
160
175
|
});
|
|
161
176
|
case "boolean":
|
|
@@ -169,7 +184,10 @@ function FormItem(props) {
|
|
|
169
184
|
var Form = function(props) {
|
|
170
185
|
return /* @__PURE__ */ React.createElement(AntdForm2, __spreadValues({}, props), props.items.map((item) => /* @__PURE__ */ React.createElement(FormItem, __spreadValues({
|
|
171
186
|
key: item.id
|
|
172
|
-
}, item)))
|
|
187
|
+
}, item))), /* @__PURE__ */ React.createElement(Button2, {
|
|
188
|
+
htmlType: "submit",
|
|
189
|
+
type: "primary"
|
|
190
|
+
}, "Submit"));
|
|
173
191
|
};
|
|
174
192
|
Form.useForm = AntdForm2.useForm;
|
|
175
193
|
export {
|