@paygreen/pgui 2.8.1 → 2.8.2

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.
@@ -4,7 +4,7 @@ export type InputDayPickerProps = {
4
4
  name: string;
5
5
  placeholder?: string;
6
6
  onChange: Dispatch<SetStateAction<string | undefined | null>>;
7
- value?: string | Date;
7
+ value?: string | Date | null;
8
8
  locale?: string;
9
9
  variant?: 'unstyled' | 'filled' | 'outlined';
10
10
  format?: string;
package/dist/esm/index.js CHANGED
@@ -62340,43 +62340,12 @@ dayjs.extend(customParseFormat);
62340
62340
  dayjs.extend(utc);
62341
62341
  dayjs.extend(isoWeek);
62342
62342
  var InputRangePicker = function (_a) {
62343
- var fromLabel = _a.fromLabel, toLabel = _a.toLabel, value = _a.value, onChange = _a.onChange, minDate = _a.minDate, maxDate = _a.maxDate, _b = _a.withTime, withTime = _b === void 0 ? false : _b, _c = _a.format, format = _c === void 0 ? withTime ? 'DD/MM/YYYY HH:mm' : 'DD/MM/YYYY' : _c, _d = _a.variant, variant = _d === void 0 ? 'unstyled' : _d, props = __rest$2(_a, ["fromLabel", "toLabel", "value", "onChange", "minDate", "maxDate", "withTime", "format", "variant"]);
62344
- var _e = useState(), fromValue = _e[0], setFromValue = _e[1];
62345
- var _f = useState(), toValue = _f[0], setToValue = _f[1];
62346
- var _g = useState(minDate), formatedMinDate = _g[0], setFormatedMinDate = _g[1];
62347
- var _h = useState(maxDate), formatedMaxDate = _h[0], setFormatedMaxDate = _h[1];
62348
- useEffect(function () {
62349
- if (!withTime) {
62350
- var formatedMin = minDate
62351
- ? dayjs(dayjs(minDate).startOf('day').toISOString()).toDate()
62352
- : null;
62353
- var formatedMax = maxDate
62354
- ? dayjs(dayjs(maxDate).endOf('day').toISOString()).toDate()
62355
- : null;
62356
- setFormatedMinDate(formatedMin);
62357
- setFormatedMaxDate(formatedMax);
62358
- }
62359
- }, [withTime]);
62360
- useEffect(function () {
62361
- onChange({
62362
- from: fromValue ? dayjs(fromValue).toDate() : null,
62363
- to: toValue ? dayjs(toValue).toDate() : null
62364
- });
62365
- }, [fromValue, toValue]);
62366
- useEffect(function () {
62367
- if (!withTime) {
62368
- if (value === null || value === void 0 ? void 0 : value.from) {
62369
- if (dayjs(value.from).diff(dayjs(formatedMinDate).utcOffset(0, true)) < 0) {
62370
- setFromValue(dayjs(formatedMinDate).utcOffset(0, true).toISOString());
62371
- }
62372
- }
62373
- if (value === null || value === void 0 ? void 0 : value.to) {
62374
- if (dayjs(value.to).diff(dayjs(formatedMaxDate).utcOffset(0, true)) > 0) {
62375
- setToValue(dayjs(formatedMaxDate).utcOffset(0, true).toISOString());
62376
- }
62377
- }
62378
- }
62379
- }, [withTime, fromValue, toValue]);
62343
+ var _b, _c;
62344
+ var fromLabel = _a.fromLabel, toLabel = _a.toLabel, value = _a.value, onChange = _a.onChange, _d = _a.minDate, minDate = _d === void 0 ? null : _d, _e = _a.maxDate, maxDate = _e === void 0 ? null : _e, _f = _a.withTime, withTime = _f === void 0 ? false : _f, _g = _a.format, format = _g === void 0 ? 'DD/MM/YYYY' : _g, _h = _a.variant, variant = _h === void 0 ? 'unstyled' : _h, props = __rest$2(_a, ["fromLabel", "toLabel", "value", "onChange", "minDate", "maxDate", "withTime", "format", "variant"]);
62345
+ var _j = useState(minDate), formatedMinDate = _j[0], setFormatedMinDate = _j[1];
62346
+ var _k = useState(maxDate), formatedMaxDate = _k[0], setFormatedMaxDate = _k[1];
62347
+ var fromValue = ((_b = value === null || value === void 0 ? void 0 : value.from) === null || _b === void 0 ? void 0 : _b.toISOString()) || undefined;
62348
+ var toValue = ((_c = value === null || value === void 0 ? void 0 : value.to) === null || _c === void 0 ? void 0 : _c.toISOString()) || undefined;
62380
62349
  var fromFunc = function (_a) {
62381
62350
  var date = _a.date;
62382
62351
  if (toValue) {
@@ -62431,17 +62400,53 @@ var InputRangePicker = function (_a) {
62431
62400
  return 'after-max-date';
62432
62401
  }
62433
62402
  };
62434
- return (React__default.createElement(Wrap, __assign$2({ flexWrap: "wrap", w: "full", maxW: "full" }, props),
62403
+ var handleChange = function (from, to) {
62404
+ if (withTime) {
62405
+ return onChange({
62406
+ from: from ? dayjs(from).toDate() : null,
62407
+ to: to ? dayjs(to).toDate() : null
62408
+ });
62409
+ }
62410
+ return onChange({
62411
+ from: from ? dayjs(from).startOf('day').toDate() : null,
62412
+ to: to ? dayjs(to).startOf('day').toDate() : null
62413
+ });
62414
+ };
62415
+ useEffect(function () {
62416
+ if (!withTime) {
62417
+ var formatedMin = minDate
62418
+ ? dayjs(dayjs(minDate).startOf('day').toISOString()).toDate()
62419
+ : null;
62420
+ var formatedMax = maxDate
62421
+ ? dayjs(dayjs(maxDate).endOf('day').toISOString()).toDate()
62422
+ : null;
62423
+ setFormatedMinDate(formatedMin);
62424
+ setFormatedMaxDate(formatedMax);
62425
+ if (fromValue) {
62426
+ if (formatedMin &&
62427
+ dayjs(fromValue).diff(dayjs(formatedMin).utcOffset(0, true)) < 0) {
62428
+ fromValue = dayjs(formatedMin).utcOffset(0, true).toISOString();
62429
+ }
62430
+ }
62431
+ if (toValue) {
62432
+ if (formatedMax &&
62433
+ dayjs(toValue).diff(dayjs(formatedMax).utcOffset(0, true)) > 0) {
62434
+ toValue = dayjs(formatedMax).utcOffset(0, true).toISOString();
62435
+ }
62436
+ }
62437
+ }
62438
+ }, [withTime]);
62439
+ return (React__default.createElement(Wrap, { flexWrap: "wrap", w: "full", maxW: "full" },
62435
62440
  React__default.createElement(WrapItem, { flex: "1", alignItems: "center", minW: "fit-content" },
62436
62441
  React__default.createElement(Text, { mr: 2, wordBreak: "normal" }, fromLabel),
62437
- React__default.createElement(InputDayPicker, { name: "from", onChange: function (e) {
62438
- setFromValue(e);
62439
- }, value: fromValue, format: format, minDate: formatedMinDate, maxDate: (value === null || value === void 0 ? void 0 : value.to) || maxDate, calendarFunc: fromFunc, withTime: withTime, variant: variant, minW: "11.5rem", w: "full" })),
62442
+ React__default.createElement(InputDayPicker, __assign$2({ name: "from", onChange: function (e) {
62443
+ handleChange(e, toValue);
62444
+ }, value: fromValue, format: withTime ? "".concat(format, " HH:mm") : format, minDate: formatedMinDate, maxDate: (value === null || value === void 0 ? void 0 : value.to) || maxDate, calendarFunc: fromFunc, withTime: withTime, variant: variant, minW: "11.5rem", w: "full" }, props))),
62440
62445
  React__default.createElement(WrapItem, { flex: "1", alignItems: "center", minW: "fit-content" },
62441
62446
  React__default.createElement(Text, { mr: 2, wordBreak: "normal" }, toLabel),
62442
- React__default.createElement(InputDayPicker, { name: "to", onChange: function (e) {
62443
- setToValue(e);
62444
- }, value: toValue, format: format, minDate: (value === null || value === void 0 ? void 0 : value.from) || formatedMinDate, maxDate: formatedMaxDate, calendarFunc: toFunc, withTime: withTime, variant: variant, minW: "11.5rem", w: "full" }))));
62447
+ React__default.createElement(InputDayPicker, __assign$2({ name: "to", onChange: function (e) {
62448
+ handleChange(fromValue, e);
62449
+ }, value: toValue, format: withTime ? "".concat(format, " HH:mm") : format, minDate: (value === null || value === void 0 ? void 0 : value.from) || formatedMinDate, maxDate: formatedMaxDate, calendarFunc: toFunc, withTime: withTime, variant: variant, minW: "11.5rem", w: "full" }, props)))));
62445
62450
  };
62446
62451
 
62447
62452
  var ModalResponsive = function (_a) {