@paygreen/pgui 2.14.0 → 2.14.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.
package/dist/cjs/index.js CHANGED
@@ -7928,92 +7928,38 @@ function MdCalendarToday (props) {
7928
7928
  return GenIcon({"tag":"svg","attr":{"viewBox":"0 0 24 24"},"child":[{"tag":"path","attr":{"fill":"none","d":"M0 0h24v24H0z"}},{"tag":"path","attr":{"d":"M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"}}]})(props);
7929
7929
  }
7930
7930
 
7931
- // Unique ID creation requires a high quality random # generator. In the browser we therefore
7932
- // require the crypto API and do not support built-in fallback to lower quality random number
7933
- // generators (like Math.random()).
7934
- let getRandomValues;
7935
- const rnds8 = new Uint8Array(16);
7936
- function rng() {
7937
- // lazy load so that environments that need to polyfill have a chance to do so
7938
- if (!getRandomValues) {
7939
- // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation.
7940
- getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto);
7941
-
7942
- if (!getRandomValues) {
7943
- throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
7944
- }
7945
- }
7946
-
7947
- return getRandomValues(rnds8);
7948
- }
7949
-
7950
- /**
7951
- * Convert array of 16 byte values to UUID string format of the form:
7952
- * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
7953
- */
7954
-
7955
- const byteToHex = [];
7956
-
7957
- for (let i = 0; i < 256; ++i) {
7958
- byteToHex.push((i + 0x100).toString(16).slice(1));
7959
- }
7960
-
7961
- function unsafeStringify(arr, offset = 0) {
7962
- // Note: Be careful editing this code! It's been tuned for performance
7963
- // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
7964
- return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
7965
- }
7966
-
7967
- const randomUUID = typeof crypto !== 'undefined' && crypto.randomUUID && crypto.randomUUID.bind(crypto);
7968
- var native = {
7969
- randomUUID
7970
- };
7971
-
7972
- function v4(options, buf, offset) {
7973
- if (native.randomUUID && !buf && !options) {
7974
- return native.randomUUID();
7975
- }
7976
-
7977
- options = options || {};
7978
- const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
7979
-
7980
- rnds[6] = rnds[6] & 0x0f | 0x40;
7981
- rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
7982
-
7983
- if (buf) {
7984
- offset = offset || 0;
7985
-
7986
- for (let i = 0; i < 16; ++i) {
7987
- buf[offset + i] = rnds[i];
7988
- }
7989
-
7990
- return buf;
7991
- }
7992
-
7993
- return unsafeStringify(rnds);
7994
- }
7995
-
7996
7931
  dayjs.extend(customParseFormat);
7997
7932
  dayjs.extend(utc);
7998
7933
  var InputDayPicker = function (_a) {
7999
- var value = _a.value, onChange = _a.onChange, placeholder = _a.placeholder, name = _a.name, isDisabled = _a.isDisabled, withTime = _a.withTime, _b = _a.locale, locale = _b === void 0 ? 'en' : _b, minDate = _a.minDate, maxDate = _a.maxDate, dateFormat = _a.dateFormat, _c = _a.variant, variant = _c === void 0 ? 'filled' : _c, inputProps = _a.inputProps, dayPickerProps = _a.dayPickerProps;
8000
- var _d = react.useDisclosure(), isOpen = _d.isOpen, onOpen = _d.onOpen, onClose = _d.onClose;
7934
+ var value = _a.value, onChange = _a.onChange, placeholder = _a.placeholder, name = _a.name, isDisabled = _a.isDisabled, withTime = _a.withTime, _b = _a.locale, locale = _b === void 0 ? 'en' : _b, minDate = _a.minDate, maxDate = _a.maxDate, _c = _a.variant, variant = _c === void 0 ? 'filled' : _c, inputProps = _a.inputProps, dayPickerProps = _a.dayPickerProps, isOpenProp = _a.isOpen, onOpenProp = _a.onOpen, onCloseProp = _a.onClose;
7935
+ var disclosure = react.useDisclosure();
7936
+ var isOpen = isOpenProp || disclosure.isOpen;
7937
+ var onOpen = onOpenProp || disclosure.onOpen;
7938
+ var onClose = onCloseProp || disclosure.onClose;
8001
7939
  var inputLeftElementColor = react.useColorModeValue('gray.400', 'gray.600');
8002
7940
  var inputLeftElementDisabledColor = react.useColorModeValue('gray.600', 'gray.400');
8003
7941
  var dialogSheetBg = react.useColorModeValue('gray.50', 'gray.800');
8004
- var defaultDateFormat = dateFormat
8005
- ? dateFormat
8006
- : withTime
7942
+ var defaultDateFormat = locale === 'fr'
7943
+ ? withTime
8007
7944
  ? 'DD/MM/YYYY HH:mm'
8008
- : 'DD/MM/YYYY';
8009
- var _e = React.useState(value ? dayjs(value).format(defaultDateFormat) : ''), dateValue = _e[0], setDateValue = _e[1];
7945
+ : 'DD/MM/YYYY'
7946
+ : withTime
7947
+ ? 'MM/DD/YYYY HH:mm'
7948
+ : 'MM/DD/YYYY';
7949
+ var _d = React.useState(value ? dayjs(value).format(defaultDateFormat) : ''), dateValue = _d[0], setDateValue = _d[1];
7950
+ // Update the input value when the value prop changes
7951
+ React.useEffect(function () {
7952
+ setDateValue(dayjs(value).isValid() ? dayjs(value).format(defaultDateFormat) : '');
7953
+ }, [value]);
8010
7954
  // Add new state variables for hours and minutes
8011
- var _f = React.useState('00'), hours = _f[0], setHours = _f[1];
8012
- var _g = React.useState('00'), minutes = _g[0], setMinutes = _g[1];
7955
+ var _e = React.useState('00'), hours = _e[0], setHours = _e[1];
7956
+ var _f = React.useState('00'), minutes = _f[0], setMinutes = _f[1];
8013
7957
  // Update the input value when the value prop changes
8014
7958
  var handleInputChange = function (date) {
8015
- if (!date)
7959
+ if (!date) {
8016
7960
  setDateValue('');
7961
+ onChange(null);
7962
+ }
8017
7963
  var dateInput = dayjs(date, defaultDateFormat, true);
8018
7964
  if (dateInput.isValid()) {
8019
7965
  if (isOpen)
@@ -8024,9 +7970,6 @@ var InputDayPicker = function (_a) {
8024
7970
  setMinutes(parseInt(dateInput.format('mm'), 10).toString());
8025
7971
  onChange(dateInput.toDate());
8026
7972
  }
8027
- else {
8028
- onChange(null);
8029
- }
8030
7973
  };
8031
7974
  // Update the input value when the value prop changes
8032
7975
  var handleDateSelection = function (date) {
@@ -8052,7 +7995,7 @@ var InputDayPicker = function (_a) {
8052
7995
  cursor: isDisabled ? 'not-allowed' : 'pointer'
8053
7996
  }, onClick: function () { return !isDisabled && (isOpen ? onClose() : onOpen()); } },
8054
7997
  React__default["default"].createElement(react.Icon, { as: MdCalendarToday })),
8055
- React__default["default"].createElement(react.Input, __assign$2({ width: "full", disabled: isDisabled, name: name || 'date-input', type: "text", variant: variant, placeholder: placeholder || defaultDateFormat, value: dateValue, onChange: function (e) {
7998
+ React__default["default"].createElement(react.Input, __assign$2({ minWidth: withTime ? '13rem' : '10rem', width: "full", disabled: isDisabled, name: name || 'date-input', type: "text", variant: variant, placeholder: placeholder || defaultDateFormat, value: dateValue, onChange: function (e) {
8056
7999
  var newValue = e.currentTarget.value
8057
8000
  .replace(/[^0-9 /:]/g, '')
8058
8001
  .slice(0, withTime ? 16 : 10); // Sanitize the input
@@ -8068,7 +8011,7 @@ var InputDayPicker = function (_a) {
8068
8011
  handleInputChange(null);
8069
8012
  } },
8070
8013
  React__default["default"].createElement(react.Icon, { as: MdClose })))),
8071
- isOpen && (React__default["default"].createElement(react.Box, { key: v4(), position: 'absolute', border: '1px solid', borderColor: 'gray.400', bg: dialogSheetBg, borderRadius: 'md', tabIndex: -1, zIndex: 9999, className: "dialog-sheet", role: "dialog", "aria-label": "DayPicker calendar", mt: 2 },
8014
+ isOpen && (React__default["default"].createElement(react.Box, { position: 'absolute', border: '1px solid', borderColor: 'gray.400', bg: dialogSheetBg, borderRadius: 'md', tabIndex: -1, zIndex: 9999, className: "dialog-sheet", role: "dialog", "aria-label": "DayPicker calendar", mt: 2 },
8072
8015
  React__default["default"].createElement(DayPicker, __assign$2({ locale: locale === 'en' ? enUS : fr$1, fromDate: minDate || new Date('1900-01-01'), toDate: maxDate || new Date('2100-12-31'), initialFocus: isOpen, mode: "single", disabled: isDisabled,
8073
8016
  // Put the default date or today's date if the value is empty
8074
8017
  selected: dayjs(dateValue, defaultDateFormat, true).isValid()
@@ -19108,19 +19051,43 @@ var InputPhone = function (_a) {
19108
19051
  };
19109
19052
 
19110
19053
  var InputRangePicker = function (_a) {
19111
- var value = _a.value, onChange = _a.onChange, placeholder = _a.placeholder, name = _a.name, isDisabled = _a.isDisabled, withTime = _a.withTime, _b = _a.locale, locale = _b === void 0 ? 'en' : _b, minDate = _a.minDate, maxDate = _a.maxDate, dateFormat = _a.dateFormat, _c = _a.variant, variant = _c === void 0 ? 'filled' : _c;
19112
- var _d = React.useState((value === null || value === void 0 ? void 0 : value.from) || null), fromValue = _d[0], setFromValue = _d[1];
19113
- var _e = React.useState((value === null || value === void 0 ? void 0 : value.to) || null), toValue = _e[0], setToValue = _e[1];
19054
+ var _b;
19055
+ var value = _a.value, onChange = _a.onChange, placeholder = _a.placeholder, name = _a.name, isDisabled = _a.isDisabled, withTime = _a.withTime, _c = _a.locale, locale = _c === void 0 ? 'en' : _c, minStartDate = _a.minStartDate, maxStartDate = _a.maxStartDate, minEndDate = _a.minEndDate, maxEndDate = _a.maxEndDate, _d = _a.variant, variant = _d === void 0 ? 'filled' : _d, _e = _a.breakpoint, breakpoint = _e === void 0 ? 'md' : _e, inputProps = _a.inputProps, dayPickerProps = _a.dayPickerProps;
19056
+ var _f = React.useState((value === null || value === void 0 ? void 0 : value.from) || null), fromValue = _f[0], setFromValue = _f[1];
19057
+ var _g = React.useState((value === null || value === void 0 ? void 0 : value.to) || null), toValue = _g[0], setToValue = _g[1];
19058
+ var _h = react.useDisclosure(), isOpenFrom = _h.isOpen, onOpenFrom = _h.onOpen, onCloseFrom = _h.onClose;
19059
+ var _j = react.useDisclosure(), isOpenTo = _j.isOpen, onOpenTo = _j.onOpen, onCloseTo = _j.onClose;
19060
+ // close the other date picker when one is opened
19061
+ React.useEffect(function () {
19062
+ if (isOpenFrom) {
19063
+ onCloseTo();
19064
+ }
19065
+ }, [isOpenFrom]);
19066
+ React.useEffect(function () {
19067
+ if (isOpenTo) {
19068
+ onCloseFrom();
19069
+ }
19070
+ }, [isOpenTo]);
19071
+ // Update the parent state when the local state changes
19114
19072
  React.useEffect(function () {
19115
- onChange({ from: fromValue, to: toValue });
19073
+ var newValue = { from: fromValue, to: toValue };
19074
+ if (JSON.stringify(newValue) !== JSON.stringify(value)) {
19075
+ onChange(newValue);
19076
+ }
19116
19077
  }, [fromValue, toValue]);
19117
- var flexDirection = react.useBreakpointValue({
19118
- base: 'column',
19119
- sm: 'row'
19120
- });
19078
+ // Update the state when the props value changes
19079
+ React.useEffect(function () {
19080
+ setFromValue((value === null || value === void 0 ? void 0 : value.from) || null);
19081
+ setToValue((value === null || value === void 0 ? void 0 : value.to) || null);
19082
+ }, [value]);
19083
+ var flexDirection = react.useBreakpointValue((_b = {
19084
+ base: 'column'
19085
+ },
19086
+ _b[breakpoint] = 'row',
19087
+ _b));
19121
19088
  return (React__default["default"].createElement(react.Flex, { flexDirection: flexDirection, gap: 2 },
19122
- React__default["default"].createElement(InputDayPicker, { value: fromValue, onChange: setFromValue, placeholder: placeholder, name: name, isDisabled: isDisabled, withTime: withTime, locale: locale, minDate: minDate, maxDate: maxDate, dateFormat: dateFormat, variant: variant }),
19123
- React__default["default"].createElement(InputDayPicker, { value: toValue, onChange: setToValue, placeholder: placeholder, name: name, isDisabled: isDisabled, withTime: withTime, locale: locale, minDate: minDate, maxDate: maxDate, dateFormat: dateFormat, variant: variant })));
19089
+ React__default["default"].createElement(InputDayPicker, { value: fromValue, onChange: setFromValue, placeholder: placeholder, name: name, isDisabled: isDisabled, withTime: withTime, locale: locale, minDate: minStartDate, maxDate: maxStartDate, variant: variant, inputProps: inputProps, dayPickerProps: dayPickerProps, onClose: onCloseFrom, onOpen: onOpenFrom, isOpen: isOpenFrom }),
19090
+ React__default["default"].createElement(InputDayPicker, { value: toValue, onChange: setToValue, placeholder: placeholder, name: name, isDisabled: isDisabled, withTime: withTime, locale: locale, minDate: minEndDate, maxDate: maxEndDate, variant: variant, inputProps: inputProps, dayPickerProps: dayPickerProps, onClose: onCloseTo, onOpen: onOpenTo, isOpen: isOpenTo })));
19124
19091
  };
19125
19092
 
19126
19093
  var ModalResponsive = function (_a) {
@@ -59330,7 +59297,8 @@ var Input = {
59330
59297
  boxShadow: "0 0 0 1px ".concat(props.theme.colors.gray[300])
59331
59298
  },
59332
59299
  _placeholder: {
59333
- color: 'gray.500'
59300
+ color: 'gray.500',
59301
+ opacity: 1
59334
59302
  }
59335
59303
  },
59336
59304
  addon: {
@@ -59354,7 +59322,8 @@ var Input = {
59354
59322
  boxShadow: "0 0 0 1px ".concat(props.theme.colors.gray[300])
59355
59323
  },
59356
59324
  _placeholder: {
59357
- color: 'gray.500'
59325
+ color: 'gray.500',
59326
+ opacity: 1
59358
59327
  }
59359
59328
  },
59360
59329
  addon: {