@paygreen/pgui 2.8.0 → 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,13 +4,13 @@ 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;
11
11
  withTime?: boolean;
12
12
  minDate?: Date | null | undefined;
13
13
  maxDate?: Date | null | undefined;
14
- calendarFunc: (date: any) => 'after-max-date' | 'before-min-date' | undefined;
14
+ calendarFunc?: (date: any) => 'after-max-date' | 'before-min-date' | undefined;
15
15
  } & InputProps;
16
16
  export declare const InputDayPicker: ({ name, placeholder, value, onChange, locale, variant, format, withTime, minDate, maxDate, calendarFunc, ...inputProps }: InputDayPickerProps) => JSX.Element;
@@ -9,6 +9,6 @@ export type NewDayPickerProps = {
9
9
  withTime?: boolean;
10
10
  minDate?: Date | null;
11
11
  maxDate?: Date | null;
12
- calendarFunc: (date: any) => 'after-max-date' | 'before-min-date' | undefined;
12
+ calendarFunc?: (date: any) => 'after-max-date' | 'before-min-date' | undefined;
13
13
  };
14
14
  export declare const NewDayPicker: ({ defaultValue, onChange, locale, customFormat, withTime, minDate, maxDate, calendarFunc, ...props }: NewDayPickerProps) => JSX.Element;
package/dist/esm/index.js CHANGED
@@ -42934,15 +42934,16 @@ var NewDayPicker = function (_a) {
42934
42934
  borderRadius: '9999px'
42935
42935
  }
42936
42936
  };
42937
- return (React__default.createElement(VStack, __assign$2({ spacing: "2", maxW: "full", p: 2, w: "fit-content", maxWidth: "30rem", borderRadius: "md" }, props),
42937
+ return (React__default.createElement(VStack, __assign$2({ spacing: "2", maxW: "full", p: 2, w: "fit-content", maxWidth: "30rem", borderRadius: "md", minH: "22.75rem" }, props),
42938
42938
  React__default.createElement(Stack, { direction: { base: 'column', sm: 'row' }, spacing: 2, w: "full" },
42939
- React__default.createElement(Calendar, { locale: locale, minDate: minDate, maxDate: maxDate, tileClassName: calendarFunc, onChange: function (e) {
42940
- setValue(e);
42941
- onChange(dayjs(e).toISOString());
42942
- setTimeValue('00:00');
42943
- setInputValue(dayjs(e).locale(locale).format(format));
42944
- setIsInvalid(false);
42945
- }, value: dayjs(value).toDate() }),
42939
+ React__default.createElement(Box, { minH: "19.25rem" },
42940
+ React__default.createElement(Calendar, { locale: locale, minDate: minDate, maxDate: maxDate, tileClassName: calendarFunc, onChange: function (e) {
42941
+ setValue(e);
42942
+ onChange(dayjs(e).toISOString());
42943
+ setTimeValue('00:00');
42944
+ setInputValue(dayjs(e).locale(locale).format(format));
42945
+ setIsInvalid(false);
42946
+ }, value: dayjs(value).toDate() })),
42946
42947
  withTime && (React__default.createElement(Flex$1, { backgroundColor: "gray.100", p: "2", borderRadius: "sm", h: { base: '8rem', sm: 'auto' }, w: "full", minW: "8rem", alignItems: "center" },
42947
42948
  React__default.createElement(Box, { w: "full", h: "full", maxH: "16rem", overflowY: "auto", sx: customScrollBar },
42948
42949
  React__default.createElement(VStack, { w: "full" }, timer.map(function (t) { return (React__default.createElement(Button$1, { key: t, size: "sm", w: "full", isActive: t === timeValue, onClick: function () {
@@ -42980,7 +42981,7 @@ var NewDayPicker = function (_a) {
42980
42981
  .set('hours', parseInt(t.slice(0, 2), 10))
42981
42982
  .set('minutes', parseInt(t.slice(-2), 10))
42982
42983
  .diff(dayjs(maxDate)) > 0) }, t)); })))))),
42983
- React__default.createElement(HStack, { w: "full" },
42984
+ React__default.createElement(HStack, { flex: "1", w: "full", alignItems: "flex-end" },
42984
42985
  React__default.createElement(InputGroup, { w: "full", size: "sm" },
42985
42986
  React__default.createElement(InputLeftElement, { pointerEvents: "none", color: "gray.300", fontSize: "1.2em", children: React__default.createElement(Icon$1, { as: MdCalendarToday }) }),
42986
42987
  React__default.createElement(Input$4, { as: InputMask, mask: withTime ? '**/**/**** **:**' : '**/**/****', value: inputValue, onChange: function (e) {
@@ -43043,8 +43044,8 @@ var InputDayPicker = function (_a) {
43043
43044
  React__default.createElement(Popover, { closeOnBlur: true, closeOnEsc: true, isOpen: isOpen, onClose: onClose, placement: "bottom", autoFocus: true },
43044
43045
  React__default.createElement(PopoverTrigger, null,
43045
43046
  React__default.createElement(InputGroup, null,
43046
- React__default.createElement(Input$4, __assign$2({ as: Button$1, onClick: onToggle, name: name, fontWeight: "normal", justifyContent: "flex-start", background: variant === 'filled' ? 'gray.100' : 'white', _hover: {
43047
- background: variant === 'filled' ? 'gray.200' : 'gray.50'
43047
+ React__default.createElement(Input$4, __assign$2({ as: Button$1, onClick: onToggle, name: name, fontWeight: "normal", justifyContent: "flex-start", background: variant === 'filled' ? 'gray.50' : 'white', _hover: {
43048
+ background: variant === 'filled' ? 'gray.100' : 'gray.50'
43048
43049
  } }, inputProps), value ? dayjs(value).format(format) : placeholder),
43049
43050
  value && (React__default.createElement(InputRightElement, { onClick: function () {
43050
43051
  onChange(null);
@@ -62339,43 +62340,12 @@ dayjs.extend(customParseFormat);
62339
62340
  dayjs.extend(utc);
62340
62341
  dayjs.extend(isoWeek);
62341
62342
  var InputRangePicker = function (_a) {
62342
- 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"]);
62343
- var _e = useState(), fromValue = _e[0], setFromValue = _e[1];
62344
- var _f = useState(), toValue = _f[0], setToValue = _f[1];
62345
- var _g = useState(minDate), formatedMinDate = _g[0], setFormatedMinDate = _g[1];
62346
- var _h = useState(maxDate), formatedMaxDate = _h[0], setFormatedMaxDate = _h[1];
62347
- useEffect(function () {
62348
- if (!withTime) {
62349
- var formatedMin = minDate
62350
- ? dayjs(dayjs(minDate).startOf('day').toISOString()).toDate()
62351
- : null;
62352
- var formatedMax = maxDate
62353
- ? dayjs(dayjs(maxDate).endOf('day').toISOString()).toDate()
62354
- : null;
62355
- setFormatedMinDate(formatedMin);
62356
- setFormatedMaxDate(formatedMax);
62357
- }
62358
- }, [withTime]);
62359
- useEffect(function () {
62360
- onChange({
62361
- from: fromValue ? dayjs(fromValue).toDate() : null,
62362
- to: toValue ? dayjs(toValue).toDate() : null
62363
- });
62364
- }, [fromValue, toValue]);
62365
- useEffect(function () {
62366
- if (!withTime) {
62367
- if (value === null || value === void 0 ? void 0 : value.from) {
62368
- if (dayjs(value.from).diff(dayjs(formatedMinDate).utcOffset(0, true)) < 0) {
62369
- setFromValue(dayjs(formatedMinDate).utcOffset(0, true).toISOString());
62370
- }
62371
- }
62372
- if (value === null || value === void 0 ? void 0 : value.to) {
62373
- if (dayjs(value.to).diff(dayjs(formatedMaxDate).utcOffset(0, true)) > 0) {
62374
- setToValue(dayjs(formatedMaxDate).utcOffset(0, true).toISOString());
62375
- }
62376
- }
62377
- }
62378
- }, [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;
62379
62349
  var fromFunc = function (_a) {
62380
62350
  var date = _a.date;
62381
62351
  if (toValue) {
@@ -62430,17 +62400,53 @@ var InputRangePicker = function (_a) {
62430
62400
  return 'after-max-date';
62431
62401
  }
62432
62402
  };
62433
- 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" },
62434
62440
  React__default.createElement(WrapItem, { flex: "1", alignItems: "center", minW: "fit-content" },
62435
62441
  React__default.createElement(Text, { mr: 2, wordBreak: "normal" }, fromLabel),
62436
- React__default.createElement(InputDayPicker, { name: "from", onChange: function (e) {
62437
- setFromValue(e);
62438
- }, 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))),
62439
62445
  React__default.createElement(WrapItem, { flex: "1", alignItems: "center", minW: "fit-content" },
62440
62446
  React__default.createElement(Text, { mr: 2, wordBreak: "normal" }, toLabel),
62441
- React__default.createElement(InputDayPicker, { name: "to", onChange: function (e) {
62442
- setToValue(e);
62443
- }, 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)))));
62444
62450
  };
62445
62451
 
62446
62452
  var ModalResponsive = function (_a) {