@auth0/quantum-product 2.9.5 → 2.9.7

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/chip/chip.js CHANGED
@@ -92,5 +92,5 @@ var Root = (0, styled_1.styled)(Chip_1.default, { name: exports.chipComponentNam
92
92
  });
93
93
  exports.Chip = React.forwardRef(function (props, ref) {
94
94
  var selected = props.selected, _a = props.deleteIcon, deleteIcon = _a === void 0 ? React.createElement(icon_1.XIcon, null) : _a, analyticsId = props.analyticsId, chipProps = __rest(props, ["selected", "deleteIcon", "analyticsId"]);
95
- return (React.createElement(Root, __assign({ ref: ref, deleteIcon: deleteIcon, ownerState: { selected: selected } }, (analyticsId && { 'data-analytics-id': analyticsId }), chipProps, { title: props === null || props === void 0 ? void 0 : props.label })));
95
+ return (React.createElement(Root, __assign({ ref: ref, deleteIcon: deleteIcon, ownerState: { selected: selected }, title: props === null || props === void 0 ? void 0 : props.label }, (analyticsId && { 'data-analytics-id': analyticsId }), chipProps)));
96
96
  });
@@ -108,7 +108,9 @@ var Content = (0, styled_1.styled)(card_1.Card, { name: date_picker_classes_1.da
108
108
  var theme = _a.theme, ownerState = _a.ownerState;
109
109
  return ({
110
110
  maxHeight: 'calc(100% - 96px)',
111
- minWidth: theme.typography.pxToRem(180),
111
+ minWidth: ownerState.currentView === 'options' && ownerState.inputWidth
112
+ ? "".concat(ownerState.inputWidth, "px")
113
+ : theme.typography.pxToRem(180),
112
114
  width: ownerState.currentView === 'options'
113
115
  ? ownerState.inputWidth
114
116
  ? "".concat(ownerState.inputWidth, "px")
@@ -239,23 +241,36 @@ var ButtonContainer = (0, styled_1.styled)(box_1.Box, { name: date_picker_classe
239
241
  });
240
242
  });
241
243
  exports.DatePickerPopover = React.forwardRef(function (props, ref) {
242
- var anchorEl = props.anchorEl, open = props.open, onClose = props.onClose, onDateSelect = props.onDateSelect, options = props.options, value = props.value, _a = props.dateFormat, dateFormat = _a === void 0 ? 'MM/dd/yyyy' : _a, _b = props.timeFormat, timeFormat = _b === void 0 ? 'HH:mm:ss' : _b, minDate = props.minDate, maxDate = props.maxDate, PopoverProps = props.PopoverProps, _c = props.showTwoMonths, showTwoMonths = _c === void 0 ? false : _c, _d = props.isRangeSelection, isRangeSelection = _d === void 0 ? false : _d, _e = props.showTimeInput, showTimeInput = _e === void 0 ? false : _e, propClasses = props.classes, rootProps = __rest(props, ["anchorEl", "open", "onClose", "onDateSelect", "options", "value", "dateFormat", "timeFormat", "minDate", "maxDate", "PopoverProps", "showTwoMonths", "isRangeSelection", "showTimeInput", "classes"]);
244
+ var anchorEl = props.anchorEl, open = props.open, onClose = props.onClose, onDateSelect = props.onDateSelect, options = props.options, value = props.value, _a = props.dateFormat, dateFormat = _a === void 0 ? 'MM/dd/yyyy' : _a, _b = props.timeFormat, timeFormat = _b === void 0 ? 'HH:mm:ss' : _b, minDate = props.minDate, maxDate = props.maxDate, PopoverProps = props.PopoverProps, _c = props.showTwoMonths, showTwoMonths = _c === void 0 ? false : _c, _d = props.isRangeSelection, isRangeSelection = _d === void 0 ? false : _d, _e = props.showTimeInput, showTimeInput = _e === void 0 ? false : _e, widthRef = props.widthRef, propClasses = props.classes, rootProps = __rest(props, ["anchorEl", "open", "onClose", "onDateSelect", "options", "value", "dateFormat", "timeFormat", "minDate", "maxDate", "PopoverProps", "showTwoMonths", "isRangeSelection", "showTimeInput", "widthRef", "classes"]);
243
245
  var classes = (0, classes_1.useMergedClasses)(date_picker_classes_1.datePickerPopoverClasses, date_picker_classes_1.getDatePickerPopoverUtilityClass, propClasses);
244
- var _f = __read(React.useState(options ? 'options' : 'calendar'), 2), currentView = _f[0], setCurrentView = _f[1];
246
+ var isCustomValue = React.useMemo(function () {
247
+ if (!options || !value)
248
+ return false;
249
+ return !options.some(function (option) { return option.value !== 'custom' && option.value === value; });
250
+ }, [options, value]);
251
+ var getInitialView = React.useCallback(function () {
252
+ if (!options)
253
+ return 'calendar';
254
+ if (value && isCustomValue)
255
+ return 'calendar';
256
+ return 'options';
257
+ }, [options, value, isCustomValue]);
258
+ var _f = __read(React.useState(getInitialView()), 2), currentView = _f[0], setCurrentView = _f[1];
245
259
  var _g = __read(React.useState({}), 2), rangeSelection = _g[0], setRangeSelection = _g[1];
246
260
  var _h = __read(React.useState({ hours: '00', minutes: '00', seconds: '00' }), 2), startTime = _h[0], setStartTime = _h[1];
247
261
  var _j = __read(React.useState({ hours: '00', minutes: '00', seconds: '00' }), 2), endTime = _j[0], setEndTime = _j[1];
248
262
  var shouldAutoFocusTimeInput = React.useRef(false);
249
- // Reset state when popover closes
250
263
  React.useEffect(function () {
251
264
  if (!open) {
252
265
  setRangeSelection({});
253
- if (options) {
254
- setCurrentView('options');
255
- }
266
+ setCurrentView(getInitialView());
256
267
  }
257
- }, [open, options]);
258
- // Parse and set single date selection when value changes
268
+ }, [open, getInitialView]);
269
+ React.useEffect(function () {
270
+ if (open && options && value && isCustomValue) {
271
+ setCurrentView('calendar');
272
+ }
273
+ }, [open, options, value, isCustomValue]);
259
274
  React.useEffect(function () {
260
275
  if (!value || isRangeSelection || !open)
261
276
  return;
@@ -271,7 +286,7 @@ exports.DatePickerPopover = React.forwardRef(function (props, ref) {
271
286
  }, [open, value, isRangeSelection, dateFormat, timeFormat, showTimeInput]);
272
287
  // Parse and set range selection when value changes
273
288
  React.useEffect(function () {
274
- if (!open || !value || !isRangeSelection || !value.includes('-'))
289
+ if (!open || !value || !isRangeSelection || !value.includes(date_picker_utils_1.DATE_RANGE_SEPARATOR))
275
290
  return;
276
291
  var _a = (0, date_picker_utils_1.parseDateRange)(value, dateFormat, showTimeInput ? timeFormat : undefined), from = _a.from, to = _a.to;
277
292
  if (from && to) {
@@ -307,7 +322,6 @@ exports.DatePickerPopover = React.forwardRef(function (props, ref) {
307
322
  selectedDate = selection.to;
308
323
  }
309
324
  }
310
- // Apply the selected date if found
311
325
  if (selectedDate) {
312
326
  if (showTimeInput) {
313
327
  var newDate = (0, date_picker_utils_1.applyTimeToDate)(selectedDate, startTime);
@@ -320,7 +334,6 @@ exports.DatePickerPopover = React.forwardRef(function (props, ref) {
320
334
  }
321
335
  return;
322
336
  }
323
- // Handle range selection mode - with early returns to reduce nesting
324
337
  if (!selection.from)
325
338
  return;
326
339
  if (!selection.to) {
@@ -418,11 +431,14 @@ exports.DatePickerPopover = React.forwardRef(function (props, ref) {
418
431
  var canApplyDate = isRangeSelection ? rangeSelection.from && rangeSelection.to : !!rangeSelection.from;
419
432
  var _k = __read(React.useState(null), 2), inputWidth = _k[0], setInputWidth = _k[1];
420
433
  React.useEffect(function () {
421
- if (open && anchorEl) {
422
- var width = anchorEl.getBoundingClientRect().width;
423
- setInputWidth(width);
434
+ if (open) {
435
+ var elementToMeasure = (widthRef === null || widthRef === void 0 ? void 0 : widthRef.current) || anchorEl;
436
+ if (elementToMeasure) {
437
+ var width = elementToMeasure.getBoundingClientRect().width;
438
+ setInputWidth(width);
439
+ }
424
440
  }
425
- }, [open, anchorEl]);
441
+ }, [open, anchorEl, widthRef]);
426
442
  var ownerState = {
427
443
  showTwoMonths: showTwoMonths,
428
444
  isRangeSelection: isRangeSelection,
@@ -433,7 +449,7 @@ exports.DatePickerPopover = React.forwardRef(function (props, ref) {
433
449
  }, transformOrigin: {
434
450
  vertical: 'top',
435
451
  horizontal: 'left',
436
- }, marginThreshold: 0, style: { marginTop: '-24px' } }, PopoverProps, rootProps),
452
+ }, marginThreshold: 0 }, PopoverProps, rootProps),
437
453
  React.createElement(Content, { className: classes.content, ownerState: __assign(__assign({}, ownerState), { inputWidth: inputWidth, currentView: currentView }) }, currentView === 'options' && options ? (React.createElement(dropdown_menu_1.DropdownMenuList, null, options.map(function (option, index) { return (React.createElement(dropdown_menu_1.DropdownMenuListItem, { key: index, title: option.text, selected: option.value === value, onClick: function () { return handleOptionSelect(option.value); } })); }))) : (React.createElement(React.Fragment, null,
438
454
  React.createElement(CalendarWrapper, { className: classes.calendarWrapper },
439
455
  React.createElement(react_day_picker_1.DayPicker, { mode: "range", selected: selectedValue, onSelect: handleCalendarSelect, showOutsideDays: true, numberOfMonths: showTwoMonths ? 2 : 1, pagedNavigation: showTwoMonths, disabled: __spreadArray(__spreadArray([], __read((minDate ? [{ before: new Date(minDate) }] : [])), false), __read((maxDate ? [{ after: new Date(maxDate) }] : [])), false) })),
@@ -5,7 +5,7 @@ export interface IDatePickerTriggerProps {
5
5
  'aria-haspopup'?: 'dialog';
6
6
  'aria-expanded'?: boolean;
7
7
  id?: string;
8
- onClick(event: React.MouseEvent<HTMLDivElement>): void;
8
+ onClick(event: React.MouseEvent<HTMLElement>): void;
9
9
  }
10
10
  export interface IDatePickerStateValue {
11
11
  triggerProps: IDatePickerTriggerProps;
@@ -26,6 +26,7 @@ export interface IDatePickerBaseProps {
26
26
  showTimeInput?: boolean;
27
27
  allowTimestampPasting?: boolean;
28
28
  timestampUnit?: 'ms' | 's';
29
+ openOnIconOnly?: boolean;
29
30
  classes?: Partial<DatePickerClasses>;
30
31
  }
31
32
  export interface IDatePickerPopoverProps {
@@ -43,5 +44,6 @@ export interface IDatePickerPopoverProps {
43
44
  showTwoMonths?: boolean;
44
45
  isRangeSelection?: boolean;
45
46
  showTimeInput?: boolean;
47
+ widthRef?: React.RefObject<HTMLElement>;
46
48
  classes?: Partial<DatePickerPopoverClasses>;
47
49
  }
@@ -1,3 +1,4 @@
1
+ export declare const DATE_RANGE_SEPARATOR = " - ";
1
2
  /**
2
3
  * Formats a date object using the specified format string
3
4
  */
@@ -27,8 +27,9 @@ var __read = (this && this.__read) || function (o, n) {
27
27
  return ar;
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.parseSmartDate = exports.applyTimeToDate = exports.extractTimeComponents = exports.formatDateRange = exports.parseDateRange = exports.parseTimestamp = exports.tryParseDate = exports.parseDate = exports.formatDate = void 0;
30
+ exports.parseSmartDate = exports.applyTimeToDate = exports.extractTimeComponents = exports.formatDateRange = exports.parseDateRange = exports.parseTimestamp = exports.tryParseDate = exports.parseDate = exports.formatDate = exports.DATE_RANGE_SEPARATOR = void 0;
31
31
  var date_fns_1 = require("date-fns");
32
+ exports.DATE_RANGE_SEPARATOR = ' - ';
32
33
  /**
33
34
  * Formats a date object using the specified format string
34
35
  */
@@ -93,10 +94,10 @@ exports.parseTimestamp = parseTimestamp;
93
94
  * Parses a date range string (format: "start - end")
94
95
  */
95
96
  var parseDateRange = function (rangeString, dateFormat, timeFormat) {
96
- if (!rangeString.includes('-')) {
97
+ if (!rangeString.includes(exports.DATE_RANGE_SEPARATOR)) {
97
98
  return { from: null, to: null };
98
99
  }
99
- var _a = __read(rangeString.split('-').map(function (s) { return s.trim(); }), 2), fromStr = _a[0], toStr = _a[1];
100
+ var _a = __read(rangeString.split(exports.DATE_RANGE_SEPARATOR).map(function (s) { return s.trim(); }), 2), fromStr = _a[0], toStr = _a[1];
100
101
  var fullFormat = timeFormat ? "".concat(dateFormat, " ").concat(timeFormat) : dateFormat;
101
102
  var from = (0, exports.parseDate)(fromStr, fullFormat);
102
103
  var to = (0, exports.parseDate)(toStr, fullFormat);
@@ -119,7 +120,7 @@ var formatDateRange = function (from, to, dateFormat, timeFormat) {
119
120
  if (!to) {
120
121
  return (0, exports.formatDate)(from, formatString);
121
122
  }
122
- return "".concat((0, exports.formatDate)(from, formatString), " - ").concat((0, exports.formatDate)(to, formatString));
123
+ return "".concat((0, exports.formatDate)(from, formatString)).concat(exports.DATE_RANGE_SEPARATOR).concat((0, exports.formatDate)(to, formatString));
123
124
  };
124
125
  exports.formatDateRange = formatDateRange;
125
126
  /**
@@ -77,6 +77,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
77
77
  exports.DatePicker = void 0;
78
78
  var React = __importStar(require("react"));
79
79
  var icon_1 = require("../icon");
80
+ var icon_button_1 = require("../icon-button");
80
81
  var styled_1 = require("../styled");
81
82
  var classes_1 = require("../styles/classes");
82
83
  var text_field_1 = require("../text-field");
@@ -91,12 +92,14 @@ var Root = (0, styled_1.styled)('div', { name: date_picker_classes_1.datePickerC
91
92
  width: '100%',
92
93
  });
93
94
  exports.DatePicker = React.forwardRef(function (props, ref) {
94
- var value = props.value, onChange = props.onChange, _a = props.dateFormat, dateFormat = _a === void 0 ? 'MM/dd/yyyy' : _a, _b = props.timeFormat, timeFormat = _b === void 0 ? 'HH:mm:ss' : _b, minDate = props.minDate, maxDate = props.maxDate, _c = props.placeholder, placeholder = _c === void 0 ? dateFormat + (props.showTimeInput ? ' ' + timeFormat : '') : _c, _d = props.disabled, disabled = _d === void 0 ? false : _d, _e = props.fullWidth, fullWidth = _e === void 0 ? false : _e, _f = props.size, size = _f === void 0 ? 'medium' : _f, _g = props.readOnly, readOnly = _g === void 0 ? false : _g, _h = props.required, required = _h === void 0 ? false : _h, _j = props.error, error = _j === void 0 ? false : _j, helperText = props.helperText, options = props.options, _k = props.isRangeSelection, isRangeSelection = _k === void 0 ? false : _k, _l = props.showTwoMonths, showTwoMonths = _l === void 0 ? false : _l, _m = props.showTimeInput, showTimeInput = _m === void 0 ? false : _m, _o = props.allowTimestampPasting, allowTimestampPasting = _o === void 0 ? false : _o, _p = props.timestampUnit, timestampUnit = _p === void 0 ? 'ms' : _p, _q = props.TextFieldProps, TextFieldProps = _q === void 0 ? {} : _q, propClasses = props.classes, externalState = props.state, rootProps = __rest(props, ["value", "onChange", "dateFormat", "timeFormat", "minDate", "maxDate", "placeholder", "disabled", "fullWidth", "size", "readOnly", "required", "error", "helperText", "options", "isRangeSelection", "showTwoMonths", "showTimeInput", "allowTimestampPasting", "timestampUnit", "TextFieldProps", "classes", "state"]);
95
+ var value = props.value, onChange = props.onChange, _a = props.dateFormat, dateFormat = _a === void 0 ? 'MM/dd/yyyy' : _a, _b = props.timeFormat, timeFormat = _b === void 0 ? 'HH:mm:ss' : _b, minDate = props.minDate, maxDate = props.maxDate, _c = props.placeholder, placeholder = _c === void 0 ? dateFormat + (props.showTimeInput ? ' ' + timeFormat : '') : _c, _d = props.disabled, disabled = _d === void 0 ? false : _d, _e = props.fullWidth, fullWidth = _e === void 0 ? false : _e, _f = props.size, size = _f === void 0 ? 'medium' : _f, _g = props.readOnly, readOnly = _g === void 0 ? false : _g, _h = props.required, required = _h === void 0 ? false : _h, _j = props.error, error = _j === void 0 ? false : _j, helperText = props.helperText, options = props.options, _k = props.isRangeSelection, isRangeSelection = _k === void 0 ? false : _k, _l = props.showTwoMonths, showTwoMonths = _l === void 0 ? false : _l, _m = props.showTimeInput, showTimeInput = _m === void 0 ? false : _m, _o = props.allowTimestampPasting, allowTimestampPasting = _o === void 0 ? false : _o, _p = props.timestampUnit, timestampUnit = _p === void 0 ? 'ms' : _p, _q = props.openOnIconOnly, openOnIconOnly = _q === void 0 ? false : _q, _r = props.TextFieldProps, TextFieldProps = _r === void 0 ? {} : _r, propClasses = props.classes, externalState = props.state, rootProps = __rest(props, ["value", "onChange", "dateFormat", "timeFormat", "minDate", "maxDate", "placeholder", "disabled", "fullWidth", "size", "readOnly", "required", "error", "helperText", "options", "isRangeSelection", "showTwoMonths", "showTimeInput", "allowTimestampPasting", "timestampUnit", "openOnIconOnly", "TextFieldProps", "classes", "state"]);
95
96
  var classes = (0, classes_1.useMergedClasses)(date_picker_classes_1.datePickerClasses, date_picker_classes_1.getDatePickerUtilityClass, propClasses);
96
97
  var internalState = (0, date_picker_state_1.useDatePickerState)();
97
- var _r = externalState || internalState, triggerProps = _r.triggerProps, popoverProps = _r.popoverProps;
98
- var _s = __read(React.useState(value || ''), 2), displayValue = _s[0], setDisplayValue = _s[1];
98
+ var _s = externalState || internalState, triggerProps = _s.triggerProps, popoverProps = _s.popoverProps;
99
+ var _t = __read(React.useState(value || ''), 2), displayValue = _t[0], setDisplayValue = _t[1];
99
100
  var inputRef = React.useRef(null);
101
+ var textFieldRef = React.useRef(null);
102
+ var _u = __read(React.useState(null), 2), anchorEl = _u[0], setAnchorEl = _u[1];
100
103
  React.useEffect(function () {
101
104
  setDisplayValue(value || '');
102
105
  }, [value]);
@@ -107,9 +110,14 @@ exports.DatePicker = React.forwardRef(function (props, ref) {
107
110
  onChange(newValue);
108
111
  }
109
112
  if (shouldClose) {
113
+ setAnchorEl(null);
110
114
  popoverProps.onClose();
111
115
  }
112
116
  };
117
+ var handlePopoverClose = function () {
118
+ setAnchorEl(null);
119
+ popoverProps.onClose();
120
+ };
113
121
  var handlePaste = function (event) {
114
122
  if (!allowTimestampPasting)
115
123
  return;
@@ -164,13 +172,31 @@ exports.DatePicker = React.forwardRef(function (props, ref) {
164
172
  showTimeInput: showTimeInput,
165
173
  } },
166
174
  React.createElement(Root, __assign({ ref: ref, className: (0, clsx_1.default)(classes.root), ownerState: ownerState }, rootProps),
167
- React.createElement(text_field_1.TextField, __assign({ value: displayValue, onChange: handleInputChange, onPaste: handlePaste, placeholder: placeholder, disabled: disabled, fullWidth: fullWidth, size: size, readOnly: readOnly, required: required, error: error, helperText: helperText, inputRef: inputRef, endAdornment: React.createElement(icon_1.CalendarIcon, null), className: classes.input }, triggerProps, { onClick: function (e) {
168
- if (!disabled && !readOnly) {
175
+ React.createElement(text_field_1.TextField, __assign({ ref: textFieldRef, value: displayValue, onChange: handleInputChange, onPaste: handlePaste, placeholder: placeholder, disabled: disabled, fullWidth: fullWidth, size: size, readOnly: readOnly, required: required, error: error, helperText: helperText, inputRef: inputRef, endAdornment: openOnIconOnly ? (React.createElement(icon_button_1.IconButton, { label: "Open calendar", color: "inherit", size: "small", variant: "link", "aria-label": "Open calendar", disabled: disabled, sx: {
176
+ padding: 0,
177
+ marginRight: '-9px',
178
+ borderRadius: 0.25,
179
+ '&:focus': {
180
+ outline: 'none',
181
+ backgroundColor: function (theme) { return theme.tokens.color_bg_button_hover; },
182
+ },
183
+ }, onClick: function (e) {
184
+ e.stopPropagation();
185
+ if (!disabled && !readOnly && inputRef.current) {
186
+ setAnchorEl(inputRef.current);
187
+ triggerProps.onClick(e);
188
+ }
189
+ } },
190
+ React.createElement(icon_1.CalendarIcon, { size: 16 }))) : (React.createElement(icon_1.CalendarIcon, { size: 16 })), className: classes.input }, triggerProps, { onClick: function (e) {
191
+ if (!disabled && !readOnly && !openOnIconOnly) {
192
+ if (inputRef.current) {
193
+ setAnchorEl(inputRef.current);
194
+ }
169
195
  triggerProps.onClick(e);
170
196
  }
171
197
  if (TextFieldProps.onClick) {
172
198
  TextFieldProps.onClick(e);
173
199
  }
174
200
  } }, TextFieldProps)),
175
- React.createElement(date_picker_popover_1.DatePickerPopover, __assign({}, popoverProps, { onDateSelect: handleDateSelect, options: options, minDate: minDate, maxDate: maxDate, value: displayValue, dateFormat: dateFormat, timeFormat: timeFormat, showTwoMonths: showTwoMonths, isRangeSelection: isRangeSelection, showTimeInput: showTimeInput })))));
201
+ React.createElement(date_picker_popover_1.DatePickerPopover, __assign({}, popoverProps, { anchorEl: anchorEl, open: Boolean(anchorEl), onClose: handlePopoverClose, onDateSelect: handleDateSelect, options: options, minDate: minDate, maxDate: maxDate, value: displayValue, dateFormat: dateFormat, timeFormat: timeFormat, showTwoMonths: showTwoMonths, isRangeSelection: isRangeSelection, showTimeInput: showTimeInput, widthRef: textFieldRef })))));
176
202
  });
package/esm/chip/chip.js CHANGED
@@ -56,5 +56,5 @@ var Root = styled(MuiChip, { name: chipComponentName, slot: 'Root' })(function (
56
56
  });
57
57
  export var Chip = React.forwardRef(function (props, ref) {
58
58
  var selected = props.selected, _a = props.deleteIcon, deleteIcon = _a === void 0 ? React.createElement(XIcon, null) : _a, analyticsId = props.analyticsId, chipProps = __rest(props, ["selected", "deleteIcon", "analyticsId"]);
59
- return (React.createElement(Root, __assign({ ref: ref, deleteIcon: deleteIcon, ownerState: { selected: selected } }, (analyticsId && { 'data-analytics-id': analyticsId }), chipProps, { title: props === null || props === void 0 ? void 0 : props.label })));
59
+ return (React.createElement(Root, __assign({ ref: ref, deleteIcon: deleteIcon, ownerState: { selected: selected }, title: props === null || props === void 0 ? void 0 : props.label }, (analyticsId && { 'data-analytics-id': analyticsId }), chipProps)));
60
60
  });
@@ -58,7 +58,7 @@ import { useMergedClasses } from '../styles/classes';
58
58
  import clsx from '../utils/clsx';
59
59
  import { datePickerPopoverClasses, datePickerPopoverComponentName, getDatePickerPopoverUtilityClass, } from './date-picker-classes';
60
60
  import { DatePickerTimeInput } from './date-picker-time-input';
61
- import { applyTimeToDate, extractTimeComponents, formatDate, formatDateRange, parseDate, parseDateRange, } from './date-picker-utils';
61
+ import { applyTimeToDate, DATE_RANGE_SEPARATOR, extractTimeComponents, formatDate, formatDateRange, parseDate, parseDateRange, } from './date-picker-utils';
62
62
  var Root = styled(Popover, { name: datePickerPopoverComponentName, slot: 'Root' })(function (_a) {
63
63
  var theme = _a.theme;
64
64
  return ({
@@ -69,7 +69,9 @@ var Content = styled(Card, { name: datePickerPopoverComponentName, slot: 'Conten
69
69
  var theme = _a.theme, ownerState = _a.ownerState;
70
70
  return ({
71
71
  maxHeight: 'calc(100% - 96px)',
72
- minWidth: theme.typography.pxToRem(180),
72
+ minWidth: ownerState.currentView === 'options' && ownerState.inputWidth
73
+ ? "".concat(ownerState.inputWidth, "px")
74
+ : theme.typography.pxToRem(180),
73
75
  width: ownerState.currentView === 'options'
74
76
  ? ownerState.inputWidth
75
77
  ? "".concat(ownerState.inputWidth, "px")
@@ -200,23 +202,36 @@ var ButtonContainer = styled(Box, { name: datePickerPopoverComponentName, slot:
200
202
  });
201
203
  });
202
204
  export var DatePickerPopover = React.forwardRef(function (props, ref) {
203
- var anchorEl = props.anchorEl, open = props.open, onClose = props.onClose, onDateSelect = props.onDateSelect, options = props.options, value = props.value, _a = props.dateFormat, dateFormat = _a === void 0 ? 'MM/dd/yyyy' : _a, _b = props.timeFormat, timeFormat = _b === void 0 ? 'HH:mm:ss' : _b, minDate = props.minDate, maxDate = props.maxDate, PopoverProps = props.PopoverProps, _c = props.showTwoMonths, showTwoMonths = _c === void 0 ? false : _c, _d = props.isRangeSelection, isRangeSelection = _d === void 0 ? false : _d, _e = props.showTimeInput, showTimeInput = _e === void 0 ? false : _e, propClasses = props.classes, rootProps = __rest(props, ["anchorEl", "open", "onClose", "onDateSelect", "options", "value", "dateFormat", "timeFormat", "minDate", "maxDate", "PopoverProps", "showTwoMonths", "isRangeSelection", "showTimeInput", "classes"]);
205
+ var anchorEl = props.anchorEl, open = props.open, onClose = props.onClose, onDateSelect = props.onDateSelect, options = props.options, value = props.value, _a = props.dateFormat, dateFormat = _a === void 0 ? 'MM/dd/yyyy' : _a, _b = props.timeFormat, timeFormat = _b === void 0 ? 'HH:mm:ss' : _b, minDate = props.minDate, maxDate = props.maxDate, PopoverProps = props.PopoverProps, _c = props.showTwoMonths, showTwoMonths = _c === void 0 ? false : _c, _d = props.isRangeSelection, isRangeSelection = _d === void 0 ? false : _d, _e = props.showTimeInput, showTimeInput = _e === void 0 ? false : _e, widthRef = props.widthRef, propClasses = props.classes, rootProps = __rest(props, ["anchorEl", "open", "onClose", "onDateSelect", "options", "value", "dateFormat", "timeFormat", "minDate", "maxDate", "PopoverProps", "showTwoMonths", "isRangeSelection", "showTimeInput", "widthRef", "classes"]);
204
206
  var classes = useMergedClasses(datePickerPopoverClasses, getDatePickerPopoverUtilityClass, propClasses);
205
- var _f = __read(React.useState(options ? 'options' : 'calendar'), 2), currentView = _f[0], setCurrentView = _f[1];
207
+ var isCustomValue = React.useMemo(function () {
208
+ if (!options || !value)
209
+ return false;
210
+ return !options.some(function (option) { return option.value !== 'custom' && option.value === value; });
211
+ }, [options, value]);
212
+ var getInitialView = React.useCallback(function () {
213
+ if (!options)
214
+ return 'calendar';
215
+ if (value && isCustomValue)
216
+ return 'calendar';
217
+ return 'options';
218
+ }, [options, value, isCustomValue]);
219
+ var _f = __read(React.useState(getInitialView()), 2), currentView = _f[0], setCurrentView = _f[1];
206
220
  var _g = __read(React.useState({}), 2), rangeSelection = _g[0], setRangeSelection = _g[1];
207
221
  var _h = __read(React.useState({ hours: '00', minutes: '00', seconds: '00' }), 2), startTime = _h[0], setStartTime = _h[1];
208
222
  var _j = __read(React.useState({ hours: '00', minutes: '00', seconds: '00' }), 2), endTime = _j[0], setEndTime = _j[1];
209
223
  var shouldAutoFocusTimeInput = React.useRef(false);
210
- // Reset state when popover closes
211
224
  React.useEffect(function () {
212
225
  if (!open) {
213
226
  setRangeSelection({});
214
- if (options) {
215
- setCurrentView('options');
216
- }
227
+ setCurrentView(getInitialView());
217
228
  }
218
- }, [open, options]);
219
- // Parse and set single date selection when value changes
229
+ }, [open, getInitialView]);
230
+ React.useEffect(function () {
231
+ if (open && options && value && isCustomValue) {
232
+ setCurrentView('calendar');
233
+ }
234
+ }, [open, options, value, isCustomValue]);
220
235
  React.useEffect(function () {
221
236
  if (!value || isRangeSelection || !open)
222
237
  return;
@@ -232,7 +247,7 @@ export var DatePickerPopover = React.forwardRef(function (props, ref) {
232
247
  }, [open, value, isRangeSelection, dateFormat, timeFormat, showTimeInput]);
233
248
  // Parse and set range selection when value changes
234
249
  React.useEffect(function () {
235
- if (!open || !value || !isRangeSelection || !value.includes('-'))
250
+ if (!open || !value || !isRangeSelection || !value.includes(DATE_RANGE_SEPARATOR))
236
251
  return;
237
252
  var _a = parseDateRange(value, dateFormat, showTimeInput ? timeFormat : undefined), from = _a.from, to = _a.to;
238
253
  if (from && to) {
@@ -268,7 +283,6 @@ export var DatePickerPopover = React.forwardRef(function (props, ref) {
268
283
  selectedDate = selection.to;
269
284
  }
270
285
  }
271
- // Apply the selected date if found
272
286
  if (selectedDate) {
273
287
  if (showTimeInput) {
274
288
  var newDate = applyTimeToDate(selectedDate, startTime);
@@ -281,7 +295,6 @@ export var DatePickerPopover = React.forwardRef(function (props, ref) {
281
295
  }
282
296
  return;
283
297
  }
284
- // Handle range selection mode - with early returns to reduce nesting
285
298
  if (!selection.from)
286
299
  return;
287
300
  if (!selection.to) {
@@ -379,11 +392,14 @@ export var DatePickerPopover = React.forwardRef(function (props, ref) {
379
392
  var canApplyDate = isRangeSelection ? rangeSelection.from && rangeSelection.to : !!rangeSelection.from;
380
393
  var _k = __read(React.useState(null), 2), inputWidth = _k[0], setInputWidth = _k[1];
381
394
  React.useEffect(function () {
382
- if (open && anchorEl) {
383
- var width = anchorEl.getBoundingClientRect().width;
384
- setInputWidth(width);
395
+ if (open) {
396
+ var elementToMeasure = (widthRef === null || widthRef === void 0 ? void 0 : widthRef.current) || anchorEl;
397
+ if (elementToMeasure) {
398
+ var width = elementToMeasure.getBoundingClientRect().width;
399
+ setInputWidth(width);
400
+ }
385
401
  }
386
- }, [open, anchorEl]);
402
+ }, [open, anchorEl, widthRef]);
387
403
  var ownerState = {
388
404
  showTwoMonths: showTwoMonths,
389
405
  isRangeSelection: isRangeSelection,
@@ -394,7 +410,7 @@ export var DatePickerPopover = React.forwardRef(function (props, ref) {
394
410
  }, transformOrigin: {
395
411
  vertical: 'top',
396
412
  horizontal: 'left',
397
- }, marginThreshold: 0, style: { marginTop: '-24px' } }, PopoverProps, rootProps),
413
+ }, marginThreshold: 0 }, PopoverProps, rootProps),
398
414
  React.createElement(Content, { className: classes.content, ownerState: __assign(__assign({}, ownerState), { inputWidth: inputWidth, currentView: currentView }) }, currentView === 'options' && options ? (React.createElement(DropdownMenuList, null, options.map(function (option, index) { return (React.createElement(DropdownMenuListItem, { key: index, title: option.text, selected: option.value === value, onClick: function () { return handleOptionSelect(option.value); } })); }))) : (React.createElement(React.Fragment, null,
399
415
  React.createElement(CalendarWrapper, { className: classes.calendarWrapper },
400
416
  React.createElement(DayPicker, { mode: "range", selected: selectedValue, onSelect: handleCalendarSelect, showOutsideDays: true, numberOfMonths: showTwoMonths ? 2 : 1, pagedNavigation: showTwoMonths, disabled: __spreadArray(__spreadArray([], __read((minDate ? [{ before: new Date(minDate) }] : [])), false), __read((maxDate ? [{ after: new Date(maxDate) }] : [])), false) })),
@@ -26,6 +26,7 @@ var __read = (this && this.__read) || function (o, n) {
26
26
  return ar;
27
27
  };
28
28
  import { format, isValid, parse } from 'date-fns';
29
+ export var DATE_RANGE_SEPARATOR = ' - ';
29
30
  /**
30
31
  * Formats a date object using the specified format string
31
32
  */
@@ -86,10 +87,10 @@ export var parseTimestamp = function (timestamp, unit) {
86
87
  * Parses a date range string (format: "start - end")
87
88
  */
88
89
  export var parseDateRange = function (rangeString, dateFormat, timeFormat) {
89
- if (!rangeString.includes('-')) {
90
+ if (!rangeString.includes(DATE_RANGE_SEPARATOR)) {
90
91
  return { from: null, to: null };
91
92
  }
92
- var _a = __read(rangeString.split('-').map(function (s) { return s.trim(); }), 2), fromStr = _a[0], toStr = _a[1];
93
+ var _a = __read(rangeString.split(DATE_RANGE_SEPARATOR).map(function (s) { return s.trim(); }), 2), fromStr = _a[0], toStr = _a[1];
93
94
  var fullFormat = timeFormat ? "".concat(dateFormat, " ").concat(timeFormat) : dateFormat;
94
95
  var from = parseDate(fromStr, fullFormat);
95
96
  var to = parseDate(toStr, fullFormat);
@@ -111,7 +112,7 @@ export var formatDateRange = function (from, to, dateFormat, timeFormat) {
111
112
  if (!to) {
112
113
  return formatDate(from, formatString);
113
114
  }
114
- return "".concat(formatDate(from, formatString), " - ").concat(formatDate(to, formatString));
115
+ return "".concat(formatDate(from, formatString)).concat(DATE_RANGE_SEPARATOR).concat(formatDate(to, formatString));
115
116
  };
116
117
  /**
117
118
  * Extract time components from a date
@@ -38,6 +38,7 @@ var __read = (this && this.__read) || function (o, n) {
38
38
  };
39
39
  import * as React from 'react';
40
40
  import { CalendarIcon } from '../icon';
41
+ import { IconButton } from '../icon-button';
41
42
  import { styled } from '../styled';
42
43
  import { useMergedClasses } from '../styles/classes';
43
44
  import { TextField } from '../text-field';
@@ -52,12 +53,14 @@ var Root = styled('div', { name: datePickerComponentName, slot: 'Root' })({
52
53
  width: '100%',
53
54
  });
54
55
  export var DatePicker = React.forwardRef(function (props, ref) {
55
- var value = props.value, onChange = props.onChange, _a = props.dateFormat, dateFormat = _a === void 0 ? 'MM/dd/yyyy' : _a, _b = props.timeFormat, timeFormat = _b === void 0 ? 'HH:mm:ss' : _b, minDate = props.minDate, maxDate = props.maxDate, _c = props.placeholder, placeholder = _c === void 0 ? dateFormat + (props.showTimeInput ? ' ' + timeFormat : '') : _c, _d = props.disabled, disabled = _d === void 0 ? false : _d, _e = props.fullWidth, fullWidth = _e === void 0 ? false : _e, _f = props.size, size = _f === void 0 ? 'medium' : _f, _g = props.readOnly, readOnly = _g === void 0 ? false : _g, _h = props.required, required = _h === void 0 ? false : _h, _j = props.error, error = _j === void 0 ? false : _j, helperText = props.helperText, options = props.options, _k = props.isRangeSelection, isRangeSelection = _k === void 0 ? false : _k, _l = props.showTwoMonths, showTwoMonths = _l === void 0 ? false : _l, _m = props.showTimeInput, showTimeInput = _m === void 0 ? false : _m, _o = props.allowTimestampPasting, allowTimestampPasting = _o === void 0 ? false : _o, _p = props.timestampUnit, timestampUnit = _p === void 0 ? 'ms' : _p, _q = props.TextFieldProps, TextFieldProps = _q === void 0 ? {} : _q, propClasses = props.classes, externalState = props.state, rootProps = __rest(props, ["value", "onChange", "dateFormat", "timeFormat", "minDate", "maxDate", "placeholder", "disabled", "fullWidth", "size", "readOnly", "required", "error", "helperText", "options", "isRangeSelection", "showTwoMonths", "showTimeInput", "allowTimestampPasting", "timestampUnit", "TextFieldProps", "classes", "state"]);
56
+ var value = props.value, onChange = props.onChange, _a = props.dateFormat, dateFormat = _a === void 0 ? 'MM/dd/yyyy' : _a, _b = props.timeFormat, timeFormat = _b === void 0 ? 'HH:mm:ss' : _b, minDate = props.minDate, maxDate = props.maxDate, _c = props.placeholder, placeholder = _c === void 0 ? dateFormat + (props.showTimeInput ? ' ' + timeFormat : '') : _c, _d = props.disabled, disabled = _d === void 0 ? false : _d, _e = props.fullWidth, fullWidth = _e === void 0 ? false : _e, _f = props.size, size = _f === void 0 ? 'medium' : _f, _g = props.readOnly, readOnly = _g === void 0 ? false : _g, _h = props.required, required = _h === void 0 ? false : _h, _j = props.error, error = _j === void 0 ? false : _j, helperText = props.helperText, options = props.options, _k = props.isRangeSelection, isRangeSelection = _k === void 0 ? false : _k, _l = props.showTwoMonths, showTwoMonths = _l === void 0 ? false : _l, _m = props.showTimeInput, showTimeInput = _m === void 0 ? false : _m, _o = props.allowTimestampPasting, allowTimestampPasting = _o === void 0 ? false : _o, _p = props.timestampUnit, timestampUnit = _p === void 0 ? 'ms' : _p, _q = props.openOnIconOnly, openOnIconOnly = _q === void 0 ? false : _q, _r = props.TextFieldProps, TextFieldProps = _r === void 0 ? {} : _r, propClasses = props.classes, externalState = props.state, rootProps = __rest(props, ["value", "onChange", "dateFormat", "timeFormat", "minDate", "maxDate", "placeholder", "disabled", "fullWidth", "size", "readOnly", "required", "error", "helperText", "options", "isRangeSelection", "showTwoMonths", "showTimeInput", "allowTimestampPasting", "timestampUnit", "openOnIconOnly", "TextFieldProps", "classes", "state"]);
56
57
  var classes = useMergedClasses(datePickerClasses, getDatePickerUtilityClass, propClasses);
57
58
  var internalState = useDatePickerState();
58
- var _r = externalState || internalState, triggerProps = _r.triggerProps, popoverProps = _r.popoverProps;
59
- var _s = __read(React.useState(value || ''), 2), displayValue = _s[0], setDisplayValue = _s[1];
59
+ var _s = externalState || internalState, triggerProps = _s.triggerProps, popoverProps = _s.popoverProps;
60
+ var _t = __read(React.useState(value || ''), 2), displayValue = _t[0], setDisplayValue = _t[1];
60
61
  var inputRef = React.useRef(null);
62
+ var textFieldRef = React.useRef(null);
63
+ var _u = __read(React.useState(null), 2), anchorEl = _u[0], setAnchorEl = _u[1];
61
64
  React.useEffect(function () {
62
65
  setDisplayValue(value || '');
63
66
  }, [value]);
@@ -68,9 +71,14 @@ export var DatePicker = React.forwardRef(function (props, ref) {
68
71
  onChange(newValue);
69
72
  }
70
73
  if (shouldClose) {
74
+ setAnchorEl(null);
71
75
  popoverProps.onClose();
72
76
  }
73
77
  };
78
+ var handlePopoverClose = function () {
79
+ setAnchorEl(null);
80
+ popoverProps.onClose();
81
+ };
74
82
  var handlePaste = function (event) {
75
83
  if (!allowTimestampPasting)
76
84
  return;
@@ -125,13 +133,31 @@ export var DatePicker = React.forwardRef(function (props, ref) {
125
133
  showTimeInput: showTimeInput,
126
134
  } },
127
135
  React.createElement(Root, __assign({ ref: ref, className: clsx(classes.root), ownerState: ownerState }, rootProps),
128
- React.createElement(TextField, __assign({ value: displayValue, onChange: handleInputChange, onPaste: handlePaste, placeholder: placeholder, disabled: disabled, fullWidth: fullWidth, size: size, readOnly: readOnly, required: required, error: error, helperText: helperText, inputRef: inputRef, endAdornment: React.createElement(CalendarIcon, null), className: classes.input }, triggerProps, { onClick: function (e) {
129
- if (!disabled && !readOnly) {
136
+ React.createElement(TextField, __assign({ ref: textFieldRef, value: displayValue, onChange: handleInputChange, onPaste: handlePaste, placeholder: placeholder, disabled: disabled, fullWidth: fullWidth, size: size, readOnly: readOnly, required: required, error: error, helperText: helperText, inputRef: inputRef, endAdornment: openOnIconOnly ? (React.createElement(IconButton, { label: "Open calendar", color: "inherit", size: "small", variant: "link", "aria-label": "Open calendar", disabled: disabled, sx: {
137
+ padding: 0,
138
+ marginRight: '-9px',
139
+ borderRadius: 0.25,
140
+ '&:focus': {
141
+ outline: 'none',
142
+ backgroundColor: function (theme) { return theme.tokens.color_bg_button_hover; },
143
+ },
144
+ }, onClick: function (e) {
145
+ e.stopPropagation();
146
+ if (!disabled && !readOnly && inputRef.current) {
147
+ setAnchorEl(inputRef.current);
148
+ triggerProps.onClick(e);
149
+ }
150
+ } },
151
+ React.createElement(CalendarIcon, { size: 16 }))) : (React.createElement(CalendarIcon, { size: 16 })), className: classes.input }, triggerProps, { onClick: function (e) {
152
+ if (!disabled && !readOnly && !openOnIconOnly) {
153
+ if (inputRef.current) {
154
+ setAnchorEl(inputRef.current);
155
+ }
130
156
  triggerProps.onClick(e);
131
157
  }
132
158
  if (TextFieldProps.onClick) {
133
159
  TextFieldProps.onClick(e);
134
160
  }
135
161
  } }, TextFieldProps)),
136
- React.createElement(DatePickerPopover, __assign({}, popoverProps, { onDateSelect: handleDateSelect, options: options, minDate: minDate, maxDate: maxDate, value: displayValue, dateFormat: dateFormat, timeFormat: timeFormat, showTwoMonths: showTwoMonths, isRangeSelection: isRangeSelection, showTimeInput: showTimeInput })))));
162
+ React.createElement(DatePickerPopover, __assign({}, popoverProps, { anchorEl: anchorEl, open: Boolean(anchorEl), onClose: handlePopoverClose, onDateSelect: handleDateSelect, options: options, minDate: minDate, maxDate: maxDate, value: displayValue, dateFormat: dateFormat, timeFormat: timeFormat, showTwoMonths: showTwoMonths, isRangeSelection: isRangeSelection, showTimeInput: showTimeInput, widthRef: textFieldRef })))));
137
163
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auth0/quantum-product",
3
- "version": "2.9.5",
3
+ "version": "2.9.7",
4
4
  "sideEffects": false,
5
5
  "license": "Apache-2.0",
6
6
  "publishConfig": {
@@ -25,7 +25,7 @@
25
25
  "react-dom": "*"
26
26
  },
27
27
  "scripts": {
28
- "artifactory": "cd ./build && npm publish",
28
+ "artifactory": "cd ./build && npm publish --access public",
29
29
  "build-storybook": "storybook build",
30
30
  "build": "yarn clean && yarn build:cjs && yarn build:esm && yarn copy:files",
31
31
  "build:cjs": "node --max-old-space-size=8192 ../../node_modules/.bin/tsc --project ./tsconfig.publish.json",