@pnkx-lib/ui 1.9.66 → 1.9.68
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/style.css +1 -1
- package/es/chunks/{Upload-D0erjks6.js → AntdIcon-C_gQ5ue_.js} +2957 -106
- package/es/chunks/Switch-B6W4c5eS.js +259 -0
- package/es/chunks/{index-B349so_8.js → index-DqjSCJir.js} +94 -4698
- package/es/fields/index.js +2 -2
- package/es/index.js +3 -3
- package/es/ui/index.js +2 -2
- package/package.json +1 -1
- package/types/fields.d.ts +4 -1
- package/types/index.d.ts +29 -10
- package/types/ui.d.ts +25 -9
- package/es/chunks/Switch-DQhQEc3A.js +0 -153
@@ -0,0 +1,259 @@
|
|
1
|
+
import { g as get, j as jsxRuntimeExports, L as Label, t as twMerge, E as ErrorMessage, T as Typography, c as Icon, _ as _extends, d as classNames } from './AntdIcon-C_gQ5ue_.js';
|
2
|
+
import { Select as Select$1, Radio, Upload, Image, Switch as Switch$1 } from 'antd';
|
3
|
+
import * as React from 'react';
|
4
|
+
import { useState } from 'react';
|
5
|
+
|
6
|
+
const Select = (props) => {
|
7
|
+
//! State
|
8
|
+
const {
|
9
|
+
field,
|
10
|
+
formState,
|
11
|
+
label,
|
12
|
+
required,
|
13
|
+
afterOnChange,
|
14
|
+
classNameContainer,
|
15
|
+
classNameSelect,
|
16
|
+
...restProps
|
17
|
+
} = props;
|
18
|
+
const { name, value, onChange, onBlur } = field || {};
|
19
|
+
const { touchedFields, errors, isSubmitted } = formState || {};
|
20
|
+
const isTouched = get(touchedFields, name);
|
21
|
+
const errorMessage = get(errors, name)?.message;
|
22
|
+
//! Function
|
23
|
+
const handleChange = (val) => {
|
24
|
+
onChange?.(val);
|
25
|
+
afterOnChange?.(val);
|
26
|
+
};
|
27
|
+
const renderErrorMessage = () => {
|
28
|
+
if (!errorMessage) return null;
|
29
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
30
|
+
ErrorMessage,
|
31
|
+
{
|
32
|
+
errorMessage,
|
33
|
+
isTouched,
|
34
|
+
isSubmitted
|
35
|
+
}
|
36
|
+
);
|
37
|
+
};
|
38
|
+
//! Render
|
39
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: classNameContainer, children: [
|
40
|
+
label && /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { label, required }),
|
41
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
42
|
+
Select$1,
|
43
|
+
{
|
44
|
+
onChange: handleChange,
|
45
|
+
onBlur,
|
46
|
+
value,
|
47
|
+
optionLabelProp: "label",
|
48
|
+
status: (isTouched || isSubmitted) && Boolean(errorMessage) ? "error" : void 0,
|
49
|
+
className: twMerge("w-full", classNameSelect),
|
50
|
+
...restProps
|
51
|
+
}
|
52
|
+
),
|
53
|
+
renderErrorMessage()
|
54
|
+
] });
|
55
|
+
};
|
56
|
+
|
57
|
+
const RadioGroup = (props) => {
|
58
|
+
//! State
|
59
|
+
const {
|
60
|
+
field,
|
61
|
+
formState,
|
62
|
+
customStyleRadio,
|
63
|
+
customStyleWrap = "",
|
64
|
+
afterOnChange,
|
65
|
+
options,
|
66
|
+
...restProps
|
67
|
+
} = props;
|
68
|
+
const { name, value, onChange } = field || {};
|
69
|
+
const { touchedFields, errors, isSubmitted } = formState || {};
|
70
|
+
const isTouched = get(touchedFields, name);
|
71
|
+
const errorMessage = get(errors, name)?.message;
|
72
|
+
//! Function
|
73
|
+
const handleChange = (e) => {
|
74
|
+
onChange?.(e);
|
75
|
+
afterOnChange?.(e?.target?.value);
|
76
|
+
};
|
77
|
+
const renderErrorMessage = () => {
|
78
|
+
if (!errorMessage) return null;
|
79
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
80
|
+
ErrorMessage,
|
81
|
+
{
|
82
|
+
errorMessage,
|
83
|
+
isTouched,
|
84
|
+
isSubmitted
|
85
|
+
}
|
86
|
+
);
|
87
|
+
};
|
88
|
+
//! Render
|
89
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: customStyleWrap, children: [
|
90
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Radio.Group, { onChange: handleChange, value, ...restProps, children: options.map((item) => /* @__PURE__ */ jsxRuntimeExports.jsx(
|
91
|
+
Radio,
|
92
|
+
{
|
93
|
+
value: item.value,
|
94
|
+
className: customStyleRadio,
|
95
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsxs(Typography.Text, { children: [
|
96
|
+
" ",
|
97
|
+
item.label
|
98
|
+
] })
|
99
|
+
},
|
100
|
+
`${name}-${item.value}`
|
101
|
+
)) }),
|
102
|
+
renderErrorMessage()
|
103
|
+
] });
|
104
|
+
};
|
105
|
+
|
106
|
+
// This icon file is generated automatically.
|
107
|
+
var PlusOutlined$1 = { "icon": { "tag": "svg", "attrs": { "viewBox": "64 64 896 896", "focusable": "false" }, "children": [{ "tag": "path", "attrs": { "d": "M482 152h60q8 0 8 8v704q0 8-8 8h-60q-8 0-8-8V160q0-8 8-8z" } }, { "tag": "path", "attrs": { "d": "M192 474h672q8 0 8 8v60q0 8-8 8H160q-8 0-8-8v-60q0-8 8-8z" } }] }, "name": "plus", "theme": "outlined" };
|
108
|
+
|
109
|
+
var PlusOutlined = function PlusOutlined(props, ref) {
|
110
|
+
return /*#__PURE__*/React.createElement(Icon, _extends({}, props, {
|
111
|
+
ref: ref,
|
112
|
+
icon: PlusOutlined$1
|
113
|
+
}));
|
114
|
+
};
|
115
|
+
|
116
|
+
/** */
|
117
|
+
var RefIcon = /*#__PURE__*/React.forwardRef(PlusOutlined);
|
118
|
+
if (process.env.NODE_ENV !== 'production') {
|
119
|
+
RefIcon.displayName = 'PlusOutlined';
|
120
|
+
}
|
121
|
+
|
122
|
+
const getBase64 = (file) => new Promise((resolve, reject) => {
|
123
|
+
const reader = new FileReader();
|
124
|
+
reader.readAsDataURL(file);
|
125
|
+
reader.onload = () => resolve(reader.result);
|
126
|
+
reader.onerror = (error) => reject(error);
|
127
|
+
});
|
128
|
+
const UploadField = (props) => {
|
129
|
+
//! State
|
130
|
+
const {
|
131
|
+
field,
|
132
|
+
formState,
|
133
|
+
label,
|
134
|
+
required,
|
135
|
+
maxFiles = 8,
|
136
|
+
uploadButtonText = "Upload",
|
137
|
+
// typeLabel = "text12Regular",
|
138
|
+
customStyleContainer,
|
139
|
+
customStyleUpload,
|
140
|
+
afterOnChange,
|
141
|
+
disabled,
|
142
|
+
...restProps
|
143
|
+
} = props;
|
144
|
+
const { name, value = [], onChange } = field || {};
|
145
|
+
const { touchedFields, errors, isSubmitted } = formState || {};
|
146
|
+
const isTouched = get(touchedFields, name);
|
147
|
+
const errorMessage = get(errors, name)?.message;
|
148
|
+
const [previewOpen, setPreviewOpen] = useState(false);
|
149
|
+
const [previewImage, setPreviewImage] = useState("");
|
150
|
+
//! Function
|
151
|
+
const handlePreview = async (file) => {
|
152
|
+
if (!file.url && !file.preview) {
|
153
|
+
file.preview = await getBase64(file.originFileObj);
|
154
|
+
}
|
155
|
+
setPreviewImage(file.url || file.preview);
|
156
|
+
setPreviewOpen(true);
|
157
|
+
};
|
158
|
+
const handleChange = ({ fileList }) => {
|
159
|
+
onChange?.(fileList);
|
160
|
+
afterOnChange?.(fileList);
|
161
|
+
};
|
162
|
+
const uploadButton = /* @__PURE__ */ jsxRuntimeExports.jsxs("button", { style: { border: 0, background: "none" }, type: "button", children: [
|
163
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(RefIcon, {}),
|
164
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { marginTop: 8 }, children: uploadButtonText })
|
165
|
+
] });
|
166
|
+
const renderErrorMessage = () => {
|
167
|
+
if (!errorMessage) return null;
|
168
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
169
|
+
ErrorMessage,
|
170
|
+
{
|
171
|
+
errorMessage,
|
172
|
+
isTouched,
|
173
|
+
isSubmitted
|
174
|
+
}
|
175
|
+
);
|
176
|
+
};
|
177
|
+
//! Render
|
178
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: customStyleContainer, children: [
|
179
|
+
label && /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { label, required }),
|
180
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
181
|
+
Upload,
|
182
|
+
{
|
183
|
+
listType: "picture-card",
|
184
|
+
fileList: value,
|
185
|
+
onPreview: handlePreview,
|
186
|
+
onChange: handleChange,
|
187
|
+
disabled,
|
188
|
+
className: customStyleUpload,
|
189
|
+
...restProps,
|
190
|
+
children: value.length >= maxFiles ? null : uploadButton
|
191
|
+
}
|
192
|
+
),
|
193
|
+
renderErrorMessage(),
|
194
|
+
previewImage && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
195
|
+
Image,
|
196
|
+
{
|
197
|
+
wrapperStyle: { display: "none" },
|
198
|
+
preview: {
|
199
|
+
visible: previewOpen,
|
200
|
+
onVisibleChange: (visible) => setPreviewOpen(visible),
|
201
|
+
afterOpenChange: (visible) => !visible && setPreviewImage("")
|
202
|
+
},
|
203
|
+
src: previewImage
|
204
|
+
}
|
205
|
+
)
|
206
|
+
] });
|
207
|
+
};
|
208
|
+
|
209
|
+
const Switch = (props) => {
|
210
|
+
//! State
|
211
|
+
const {
|
212
|
+
field,
|
213
|
+
formState,
|
214
|
+
label,
|
215
|
+
required,
|
216
|
+
afterOnChange,
|
217
|
+
customStyleContainer,
|
218
|
+
customStyleSwitch,
|
219
|
+
disabled,
|
220
|
+
...restProps
|
221
|
+
} = props;
|
222
|
+
const { name, value, onChange } = field || {};
|
223
|
+
const { touchedFields, errors, isSubmitted } = formState || {};
|
224
|
+
const isTouched = get(touchedFields, name);
|
225
|
+
const errorMessage = get(errors, name)?.message;
|
226
|
+
//! Function
|
227
|
+
const handleChange = (checked) => {
|
228
|
+
onChange?.(checked);
|
229
|
+
afterOnChange?.(checked);
|
230
|
+
};
|
231
|
+
const renderErrorMessage = () => {
|
232
|
+
if (!errorMessage) return null;
|
233
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
234
|
+
ErrorMessage,
|
235
|
+
{
|
236
|
+
errorMessage,
|
237
|
+
isTouched,
|
238
|
+
isSubmitted
|
239
|
+
}
|
240
|
+
);
|
241
|
+
};
|
242
|
+
//! Render
|
243
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: customStyleContainer, children: [
|
244
|
+
label && /* @__PURE__ */ jsxRuntimeExports.jsx(Label, { label, required }),
|
245
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
246
|
+
Switch$1,
|
247
|
+
{
|
248
|
+
checked: !!value,
|
249
|
+
onChange: handleChange,
|
250
|
+
className: classNames("focus:outline-none", customStyleSwitch),
|
251
|
+
disabled,
|
252
|
+
...restProps
|
253
|
+
}
|
254
|
+
),
|
255
|
+
renderErrorMessage()
|
256
|
+
] });
|
257
|
+
};
|
258
|
+
|
259
|
+
export { RadioGroup as R, Select as S, UploadField as U, Switch as a };
|