@pisell/materials 1.0.386 → 1.0.388

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.
@@ -52,7 +52,15 @@ var isValidDate = (dateString, format) => {
52
52
  pc: 1080
53
53
  });
54
54
  var DatePickerCpt = (props) => {
55
- const { picker, onChange, value, format: propsFormat, defaultValue, showTime, ...others } = props;
55
+ const {
56
+ picker,
57
+ onChange,
58
+ value,
59
+ format: propsFormat,
60
+ defaultValue,
61
+ showTime,
62
+ ...others
63
+ } = props;
56
64
  const { locale } = (0, import_react.useContext)(import_antd.ConfigProvider.ConfigContext);
57
65
  const [currentShortcut, setCurrentShortcut] = (0, import_react.useState)("");
58
66
  const [open, setOpen] = (0, import_react.useState)(false);
@@ -61,7 +69,9 @@ var DatePickerCpt = (props) => {
61
69
  const [valueStr, setValueStr] = (0, import_react.useState)("");
62
70
  const [error, setError] = (0, import_react.useState)(false);
63
71
  const ref = (0, import_react.useRef)(null);
72
+ const panelRef = (0, import_react.useRef)(null);
64
73
  const canClose = (0, import_react.useRef)(true);
74
+ const [panelTimeWidth, setPanelTimeWidth] = (0, import_react.useState)(0);
65
75
  const responsive = (0, import_useResponsive.default)();
66
76
  const isDesktop = !("ontouchstart" in window || navigator.maxTouchPoints);
67
77
  (0, import_react.useEffect)(() => {
@@ -71,7 +81,7 @@ var DatePickerCpt = (props) => {
71
81
  setValue(value);
72
82
  }, [value]);
73
83
  (0, import_react.useEffect)(() => {
74
- setValueStr((_value == null ? void 0 : _value.format(format)) || "");
84
+ setValueStr((_value == null ? void 0 : _value.format(format || "YYYY-MM-DD")) || "");
75
85
  }, [_value]);
76
86
  const customPresetItems = (0, import_react.useMemo)(() => {
77
87
  const preset = [
@@ -132,6 +142,7 @@ var DatePickerCpt = (props) => {
132
142
  }, [propsFormat, locale]);
133
143
  const handleSelectChange = (e) => {
134
144
  var _a;
145
+ canClose.current = true;
135
146
  const shortcut = e.target.value;
136
147
  setCurrentShortcut(shortcut);
137
148
  const date = (_a = import_constants.presetDetailMap[shortcut]) == null ? void 0 : _a.getValue();
@@ -141,6 +152,7 @@ var DatePickerCpt = (props) => {
141
152
  const handleTodayClick = () => {
142
153
  const val = (0, import_dayjs.default)().startOf("day");
143
154
  handleChange(val);
155
+ handleOpenChange(false);
144
156
  };
145
157
  const handleOpenChange = (visible) => {
146
158
  if (!visible) {
@@ -157,15 +169,19 @@ var DatePickerCpt = (props) => {
157
169
  };
158
170
  const handleOk = (val) => {
159
171
  const returnValue = val || _value;
160
- onChange == null ? void 0 : onChange(returnValue, returnValue == null ? void 0 : returnValue.format(format));
172
+ onChange == null ? void 0 : onChange(returnValue, returnValue == null ? void 0 : returnValue.format("YYYY-MM-DD"));
161
173
  handleOpenChange(false);
162
174
  };
163
- const handleChange = (val, valStr) => {
164
- canClose.current = true;
175
+ const handleChange = (val, valStr, isNotChange) => {
176
+ if (!showTime) {
177
+ canClose.current = true;
178
+ }
165
179
  setError(false);
166
180
  setCurrentShortcut("");
167
181
  setValue(val);
168
- handleOk(val);
182
+ if (!isNotChange) {
183
+ handleOk(val);
184
+ }
169
185
  };
170
186
  const handleApply = () => {
171
187
  if (error)
@@ -183,21 +199,90 @@ var DatePickerCpt = (props) => {
183
199
  setError(true);
184
200
  }
185
201
  };
186
- if ((!picker || picker === "date") && !showTime && /^[^Hhms]*$/.test(format)) {
202
+ (0, import_react.useEffect)(() => {
203
+ var _a;
204
+ let width = 0;
205
+ const childElements = ((_a = panelRef.current) == null ? void 0 : _a.getElementsByClassName(
206
+ "pisell-lowcode-picker-time-panel"
207
+ )) || [];
208
+ if (childElements.length > 0) {
209
+ const childElement = childElements[0];
210
+ width = childElement.offsetWidth;
211
+ }
212
+ if (width > 0) {
213
+ setPanelTimeWidth(width);
214
+ }
215
+ }, [open]);
216
+ const handleSelect = (val) => {
217
+ canClose.current = !showTime;
218
+ setValue(val);
219
+ };
220
+ const handleTimeChange = (val) => {
221
+ setValue(
222
+ (preVal) => {
223
+ var _a, _b;
224
+ return ((_b = (_a = preVal == null ? void 0 : preVal.set("hour", (val == null ? void 0 : val.get("hour")) || 0)) == null ? void 0 : _a.set("minute", (val == null ? void 0 : val.get("minute")) || 0)) == null ? void 0 : _b.set("second", (val == null ? void 0 : val.get("second")) || 0)) || null;
225
+ }
226
+ );
227
+ };
228
+ const timeInputProps = (0, import_react.useMemo)(() => {
229
+ let step = 1;
230
+ let _format = "";
231
+ if ((showTime == null ? void 0 : showTime.format) === "HH:mm") {
232
+ step = void 0;
233
+ _format = "HH:mm";
234
+ } else if ((showTime == null ? void 0 : showTime.format) === "HH:mm:ss" || showTime) {
235
+ step = 1;
236
+ _format = "HH:mm:ss";
237
+ }
238
+ return {
239
+ step,
240
+ onChange: (e) => {
241
+ const val = e.target.value;
242
+ handleTimeChange(window.dayjs(val, _format));
243
+ },
244
+ value: _value == null ? void 0 : _value.format(_format)
245
+ };
246
+ }, [showTime, _value]);
247
+ if (!picker || picker === "date") {
187
248
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
188
249
  import_antd.DatePicker,
189
250
  {
190
251
  ...others,
191
- showTime: false,
192
252
  ref,
253
+ onSelect: handleSelect,
254
+ showTime: isDesktop ? showTime : false,
193
255
  defaultValue,
194
256
  showNow: false,
195
- onChange: handleChange,
257
+ onChange: (val, valStr) => handleChange(val, valStr, !isDesktop && showTime),
196
258
  open: popupOpen,
197
- className: (0, import_classnames.default)("pisell-lowcode-mode-date-picker", others.className),
259
+ renderExtraFooter: !(!showTime || isDesktop) ? () => {
260
+ return /* @__PURE__ */ import_react.default.createElement(
261
+ "div",
262
+ {
263
+ onMouseDown: (e) => {
264
+ canClose.current = false;
265
+ e.stopPropagation();
266
+ }
267
+ },
268
+ /* @__PURE__ */ import_react.default.createElement("div", { className: "date-picker-time-label" }, "Time"),
269
+ /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(
270
+ "input",
271
+ {
272
+ type: "time",
273
+ className: "date-picker-input-time",
274
+ ...timeInputProps
275
+ }
276
+ ))
277
+ );
278
+ } : void 0,
279
+ className: (0, import_classnames.default)(
280
+ "pisell-lowcode-mode-date-picker",
281
+ others.className
282
+ ),
198
283
  value: _value,
199
284
  onOpenChange: (o) => {
200
- if (!o && !canClose.current) {
285
+ if (!o && (!canClose.current || showTime)) {
201
286
  return;
202
287
  }
203
288
  handleOpenChange(o);
@@ -207,36 +292,54 @@ var DatePickerCpt = (props) => {
207
292
  popupClassName: "date-picker-popup-wrap",
208
293
  format: currentShortcut ? () => import_constants.presetDetailMap[currentShortcut].label() : format,
209
294
  panelRender: (panelNode) => {
210
- const dom = /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode-date-picker-custom-wrap" }, /* @__PURE__ */ import_react.default.createElement(
295
+ const dom = /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
211
296
  "div",
212
297
  {
213
- className: "pisell-lowcode-date-picker-custom-action",
214
- onMouseDown: (e) => {
215
- canClose.current = false;
216
- e.stopPropagation();
217
- }
298
+ className: (0, import_classnames.default)(
299
+ "pisell-lowcode-date-picker-custom-wrap",
300
+ {
301
+ ["pisell-lowcode-date-picker-custom-wrap-show-time"]: showTime
302
+ }
303
+ ),
304
+ ref: panelRef
218
305
  },
219
- /* @__PURE__ */ import_react.default.createElement("div", { style: { width: "50%" } }, /* @__PURE__ */ import_react.default.createElement(
220
- import_antd.Input,
221
- {
222
- size: "large",
223
- placeholder: (0, import_dayjs.default)().format(format),
224
- value: valueStr,
225
- onChange: handleDataStrChange
226
- }
227
- ), error && /* @__PURE__ */ import_react.default.createElement("span", { className: "date-picker-error" }, (0, import_locales.getText)("date-picker-invalid-date"))),
228
- /* @__PURE__ */ import_react.default.createElement(
229
- import_browserSelect.default,
306
+ !showTime && /* @__PURE__ */ import_react.default.createElement(
307
+ "div",
230
308
  {
231
- value: currentShortcut || "custom",
232
- className: "date-picker-toolbar-select",
233
- options: customPresetItems,
234
- size: "large",
235
- onChange: handleSelectChange,
236
- style: { width: "50%" }
237
- }
238
- )
239
- ), panelNode), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode-custom-footer" }, /* @__PURE__ */ import_react.default.createElement(
309
+ className: "pisell-lowcode-date-picker-custom-action",
310
+ onMouseDown: (e) => {
311
+ canClose.current = false;
312
+ e.stopPropagation();
313
+ },
314
+ style: {
315
+ width: `calc(100% - 48px - ${panelTimeWidth}px)`
316
+ }
317
+ },
318
+ /* @__PURE__ */ import_react.default.createElement("div", { style: { width: "50%" } }, /* @__PURE__ */ import_react.default.createElement(
319
+ import_antd.Input,
320
+ {
321
+ size: "large",
322
+ placeholder: (0, import_dayjs.default)().format(
323
+ format || "YYYY-MM-DD"
324
+ ),
325
+ value: valueStr,
326
+ onChange: handleDataStrChange
327
+ }
328
+ ), error && /* @__PURE__ */ import_react.default.createElement("span", { className: "date-picker-error" }, (0, import_locales.getText)("date-picker-invalid-date"))),
329
+ /* @__PURE__ */ import_react.default.createElement(
330
+ import_browserSelect.default,
331
+ {
332
+ value: currentShortcut || "custom",
333
+ className: "date-picker-toolbar-select",
334
+ options: customPresetItems,
335
+ size: "large",
336
+ onChange: handleSelectChange,
337
+ style: { width: "50%" }
338
+ }
339
+ )
340
+ ),
341
+ panelNode
342
+ ), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode-custom-footer" }, /* @__PURE__ */ import_react.default.createElement(
240
343
  "span",
241
344
  {
242
345
  className: "pisell-lowcode-custom-footer-today",
@@ -253,7 +356,7 @@ var DatePickerCpt = (props) => {
253
356
  {
254
357
  placement: "bottom",
255
358
  open,
256
- height: 565,
359
+ height: "auto",
257
360
  closable: false,
258
361
  styles: {
259
362
  content: {