@itwin/itwinui-react 1.45.0 → 1.46.0

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.
Files changed (88) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/cjs/core/Breadcrumbs/Breadcrumbs.d.ts +116 -0
  3. package/cjs/core/Breadcrumbs/Breadcrumbs.js +2 -3
  4. package/cjs/core/ButtonGroup/ButtonGroup.js +1 -1
  5. package/cjs/core/ColorPicker/ColorSwatch.d.ts +1 -1
  6. package/cjs/core/DatePicker/DatePicker.d.ts +24 -4
  7. package/cjs/core/DatePicker/DatePicker.js +116 -19
  8. package/cjs/core/Dialog/Dialog.d.ts +5 -5
  9. package/cjs/core/Dialog/Dialog.js +38 -6
  10. package/cjs/core/Dialog/DialogBackdrop.d.ts +2 -2
  11. package/cjs/core/Dialog/DialogBackdrop.js +2 -2
  12. package/cjs/core/Dialog/DialogContext.d.ts +31 -0
  13. package/cjs/core/Dialog/DialogDragContext.d.ts +8 -0
  14. package/cjs/core/Dialog/DialogDragContext.js +28 -0
  15. package/cjs/core/Dialog/DialogMain.d.ts +2 -2
  16. package/cjs/core/Dialog/DialogMain.js +46 -6
  17. package/cjs/core/Dialog/DialogTitleBar.d.ts +2 -2
  18. package/cjs/core/Dialog/DialogTitleBar.js +12 -2
  19. package/cjs/core/Modal/Modal.js +1 -1
  20. package/cjs/core/Table/Table.d.ts +6 -0
  21. package/cjs/core/Table/Table.js +51 -6
  22. package/cjs/core/Table/actionHandlers/index.d.ts +1 -1
  23. package/cjs/core/Table/actionHandlers/index.js +2 -1
  24. package/cjs/core/Table/actionHandlers/resizeHandler.d.ts +2 -0
  25. package/cjs/core/Table/actionHandlers/selectHandler.d.ts +5 -0
  26. package/cjs/core/Table/actionHandlers/selectHandler.js +35 -2
  27. package/cjs/core/index.d.ts +3 -1
  28. package/cjs/core/index.js +6 -3
  29. package/cjs/core/utils/components/Resizer.d.ts +31 -0
  30. package/cjs/core/utils/components/Resizer.js +206 -0
  31. package/cjs/core/utils/components/VirtualScroll.js +26 -24
  32. package/cjs/core/utils/components/index.d.ts +1 -0
  33. package/cjs/core/utils/components/index.js +1 -0
  34. package/cjs/core/utils/functions/index.d.ts +1 -0
  35. package/cjs/core/utils/functions/index.js +1 -0
  36. package/cjs/core/utils/functions/styles.d.ts +6 -0
  37. package/cjs/core/utils/functions/styles.js +21 -0
  38. package/cjs/core/utils/hooks/useContainerWidth.d.ts +1 -1
  39. package/cjs/core/utils/hooks/useDragAndDrop.d.ts +14 -0
  40. package/cjs/core/utils/hooks/useDragAndDrop.js +110 -0
  41. package/cjs/core/utils/hooks/useEventListener.d.ts +1 -1
  42. package/cjs/core/utils/hooks/useOverflow.d.ts +1 -1
  43. package/cjs/core/utils/hooks/useResizeObserver.d.ts +1 -1
  44. package/cjs/types/react-table-config.d.ts +2 -1
  45. package/esm/core/Breadcrumbs/Breadcrumbs.d.ts +116 -0
  46. package/esm/core/Breadcrumbs/Breadcrumbs.js +2 -3
  47. package/esm/core/ButtonGroup/ButtonGroup.js +1 -1
  48. package/esm/core/ColorPicker/ColorSwatch.d.ts +1 -1
  49. package/esm/core/DatePicker/DatePicker.d.ts +24 -4
  50. package/esm/core/DatePicker/DatePicker.js +116 -19
  51. package/esm/core/Dialog/Dialog.d.ts +5 -5
  52. package/esm/core/Dialog/Dialog.js +37 -5
  53. package/esm/core/Dialog/DialogBackdrop.d.ts +2 -2
  54. package/esm/core/Dialog/DialogBackdrop.js +2 -2
  55. package/esm/core/Dialog/DialogContext.d.ts +31 -0
  56. package/esm/core/Dialog/DialogDragContext.d.ts +8 -0
  57. package/esm/core/Dialog/DialogDragContext.js +21 -0
  58. package/esm/core/Dialog/DialogMain.d.ts +2 -2
  59. package/esm/core/Dialog/DialogMain.js +47 -7
  60. package/esm/core/Dialog/DialogTitleBar.d.ts +2 -2
  61. package/esm/core/Dialog/DialogTitleBar.js +12 -2
  62. package/esm/core/Modal/Modal.js +1 -1
  63. package/esm/core/Table/Table.d.ts +6 -0
  64. package/esm/core/Table/Table.js +53 -8
  65. package/esm/core/Table/actionHandlers/index.d.ts +1 -1
  66. package/esm/core/Table/actionHandlers/index.js +1 -1
  67. package/esm/core/Table/actionHandlers/resizeHandler.d.ts +2 -0
  68. package/esm/core/Table/actionHandlers/selectHandler.d.ts +5 -0
  69. package/esm/core/Table/actionHandlers/selectHandler.js +33 -1
  70. package/esm/core/index.d.ts +3 -1
  71. package/esm/core/index.js +2 -1
  72. package/esm/core/utils/components/Resizer.d.ts +31 -0
  73. package/esm/core/utils/components/Resizer.js +199 -0
  74. package/esm/core/utils/components/VirtualScroll.js +26 -24
  75. package/esm/core/utils/components/index.d.ts +1 -0
  76. package/esm/core/utils/components/index.js +1 -0
  77. package/esm/core/utils/functions/index.d.ts +1 -0
  78. package/esm/core/utils/functions/index.js +1 -0
  79. package/esm/core/utils/functions/styles.d.ts +6 -0
  80. package/esm/core/utils/functions/styles.js +17 -0
  81. package/esm/core/utils/hooks/useContainerWidth.d.ts +1 -1
  82. package/esm/core/utils/hooks/useDragAndDrop.d.ts +14 -0
  83. package/esm/core/utils/hooks/useDragAndDrop.js +103 -0
  84. package/esm/core/utils/hooks/useEventListener.d.ts +1 -1
  85. package/esm/core/utils/hooks/useOverflow.d.ts +1 -1
  86. package/esm/core/utils/hooks/useResizeObserver.d.ts +1 -1
  87. package/esm/types/react-table-config.d.ts +2 -1
  88. package/package.json +1 -1
@@ -52,7 +52,7 @@ import '@itwin/itwinui-css/css/breadcrumbs.css';
52
52
  * </Breadcrumbs>
53
53
  */
54
54
  export var Breadcrumbs = React.forwardRef(function (props, ref) {
55
- var items = props.children, _a = props.currentIndex, currentIndex = _a === void 0 ? items.length - 1 : _a, separator = props.separator, className = props.className, rest = __rest(props, ["children", "currentIndex", "separator", "className"]);
55
+ var items = props.children, _a = props.currentIndex, currentIndex = _a === void 0 ? items.length - 1 : _a, separator = props.separator, overflowButton = props.overflowButton, className = props.className, rest = __rest(props, ["children", "currentIndex", "separator", "overflowButton", "className"]);
56
56
  useTheme();
57
57
  var _b = useOverflow(items), overflowRef = _b[0], visibleCount = _b[1];
58
58
  var refs = useMergedRefs(overflowRef, ref);
@@ -62,8 +62,7 @@ export var Breadcrumbs = React.forwardRef(function (props, ref) {
62
62
  React.createElement(ListItem, { item: items[0], isActive: currentIndex === 0 }),
63
63
  React.createElement(Separator, { separator: separator }))),
64
64
  items.length - visibleCount > 0 && (React.createElement(React.Fragment, null,
65
- React.createElement("li", { className: 'iui-breadcrumbs-item iui-breadcrumbs-item-overrides' },
66
- React.createElement("span", { className: 'iui-breadcrumbs-text' }, "\u2026")),
65
+ React.createElement("li", { className: 'iui-breadcrumbs-item iui-breadcrumbs-item-overrides' }, overflowButton ? (overflowButton(visibleCount)) : (React.createElement("span", { className: 'iui-breadcrumbs-text' }, "\u2026"))),
67
66
  React.createElement(Separator, { separator: separator }))),
68
67
  items
69
68
  .slice(visibleCount > 1
@@ -72,7 +72,7 @@ export var ButtonGroup = React.forwardRef(function (props, ref) {
72
72
  overflowButton &&
73
73
  overflowPlacement === 'start' && (React.createElement("div", null, overflowButton(visibleCount))),
74
74
  visibleCount < items.length
75
- ? items.slice(0, visibleCount - 1)
75
+ ? items.slice(0, Math.max(0, visibleCount - 1))
76
76
  : items,
77
77
  visibleCount < items.length &&
78
78
  overflowButton &&
@@ -17,5 +17,5 @@ export declare type ColorSwatchProps = {
17
17
  * <ColorSwatch color='#23450b' onClick={onClick}/>
18
18
  * <ColorSwatch color={{ r: 255, g: 255, b: 0 }} onClick={onClick}/>
19
19
  */
20
- export declare const ColorSwatch: React.ForwardRefExoticComponent<Pick<ColorSwatchProps, "dir" | "slot" | "style" | "title" | "id" | "aria-disabled" | "children" | "role" | "className" | "onClick" | "accessKey" | "draggable" | "hidden" | "lang" | "translate" | "prefix" | "contentEditable" | "inputMode" | "tabIndex" | "onFocus" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "color" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key" | "contextMenu" | "placeholder" | "spellCheck" | "radioGroup" | "about" | "datatype" | "inlist" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "is" | "isActive"> & React.RefAttributes<HTMLDivElement>>;
20
+ export declare const ColorSwatch: React.ForwardRefExoticComponent<Pick<ColorSwatchProps, "dir" | "slot" | "style" | "title" | "id" | "aria-disabled" | "children" | "role" | "className" | "onClick" | "accessKey" | "onPointerDown" | "draggable" | "hidden" | "lang" | "translate" | "prefix" | "contentEditable" | "inputMode" | "tabIndex" | "onFocus" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "color" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key" | "contextMenu" | "placeholder" | "spellCheck" | "radioGroup" | "about" | "datatype" | "inlist" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "is" | "isActive"> & React.RefAttributes<HTMLDivElement>>;
21
21
  export default ColorSwatch;
@@ -10,15 +10,35 @@ export declare const generateLocalizedStrings: (locale?: string) => {
10
10
  shortDays: string[];
11
11
  days: string[];
12
12
  };
13
- export declare type DatePickerProps = {
13
+ export declare type DateRangePickerProps = {
14
14
  /**
15
- * Selected date.
15
+ * Enable date range support.
16
+ * @default false
16
17
  */
17
- date?: Date;
18
+ enableRangeSelect?: false;
19
+ /**
20
+ * Selected start date
21
+ */
22
+ startDate?: undefined;
23
+ /**
24
+ * Selected end date
25
+ */
26
+ endDate?: undefined;
18
27
  /**
19
28
  * Callback when date is changed.
20
29
  */
21
30
  onChange?: (date: Date) => void;
31
+ } | {
32
+ enableRangeSelect: true;
33
+ startDate: Date;
34
+ endDate: Date;
35
+ onChange?: (startDate: Date, endDate: Date) => void;
36
+ };
37
+ export declare type DatePickerProps = {
38
+ /**
39
+ * Selected date.
40
+ */
41
+ date?: Date;
22
42
  /**
23
43
  * Pass localized week days (start from sunday) and months.
24
44
  * Use helper function `generateLocalizedStrings` to generate strings using `Intl.DateTimeFormat`.
@@ -41,7 +61,7 @@ export declare type DatePickerProps = {
41
61
  * @default false
42
62
  */
43
63
  showYearSelection?: boolean;
44
- } & Omit<TimePickerProps, 'date' | 'onChange' | 'setFocusHour'>;
64
+ } & DateRangePickerProps & Omit<TimePickerProps, 'date' | 'onChange' | 'setFocusHour'>;
45
65
  /**
46
66
  * Date picker component
47
67
  * @example
@@ -41,6 +41,33 @@ var isSameDay = function (a, b) {
41
41
  a.getMonth() === b.getMonth() &&
42
42
  a.getDate() === b.getDate());
43
43
  };
44
+ var isInDateRange = function (date, startDate, endDate) {
45
+ if (!date || !startDate || !endDate) {
46
+ return false;
47
+ }
48
+ var minDate = new Date(startDate);
49
+ var maxDate = new Date(endDate);
50
+ var testDate = new Date(date);
51
+ testDate && testDate.setHours(0, 0, 0, 0);
52
+ minDate && minDate.setHours(0, 0, 0, 0);
53
+ maxDate && maxDate.setHours(0, 0, 0, 0);
54
+ return testDate > minDate && testDate < maxDate;
55
+ };
56
+ // compares to see if one date is earlier than another
57
+ var isBefore = function (beforeDate, afterDate) {
58
+ if (!beforeDate || !afterDate) {
59
+ return false;
60
+ }
61
+ var firstDate = new Date(beforeDate);
62
+ var secondDate = new Date(afterDate);
63
+ firstDate && firstDate.setHours(0, 0, 0, 0);
64
+ secondDate && secondDate.setHours(0, 0, 0, 0);
65
+ return firstDate < secondDate;
66
+ };
67
+ // Type guard for multiple did not work
68
+ var isSingleOnChange = function (onChange, enableRangeSelect) {
69
+ return !enableRangeSelect;
70
+ };
44
71
  var defaultMonths = [
45
72
  'January',
46
73
  'February',
@@ -121,16 +148,20 @@ export var generateLocalizedStrings = function (locale) {
121
148
  * <DatePicker date={new Date()} onChange={(e) => console.log('New date value: ' + e)} />
122
149
  */
123
150
  export var DatePicker = function (props) {
124
- var _a, _b, _c;
125
- var date = props.date, onChange = props.onChange, localizedNames = props.localizedNames, className = props.className, style = props.style, _d = props.setFocus, setFocus = _d === void 0 ? false : _d, _e = props.showTime, showTime = _e === void 0 ? false : _e, _f = props.use12Hours, use12Hours = _f === void 0 ? false : _f, precision = props.precision, hourStep = props.hourStep, minuteStep = props.minuteStep, secondStep = props.secondStep, _g = props.showYearSelection, showYearSelection = _g === void 0 ? false : _g, rest = __rest(props, ["date", "onChange", "localizedNames", "className", "style", "setFocus", "showTime", "use12Hours", "precision", "hourStep", "minuteStep", "secondStep", "showYearSelection"]);
151
+ var _a, _b, _c, _d, _e, _f, _g, _h;
152
+ var date = props.date, onChange = props.onChange, localizedNames = props.localizedNames, className = props.className, style = props.style, _j = props.setFocus, setFocus = _j === void 0 ? false : _j, _k = props.showTime, showTime = _k === void 0 ? false : _k, _l = props.use12Hours, use12Hours = _l === void 0 ? false : _l, precision = props.precision, hourStep = props.hourStep, minuteStep = props.minuteStep, secondStep = props.secondStep, _m = props.showYearSelection, showYearSelection = _m === void 0 ? false : _m, _o = props.enableRangeSelect, enableRangeSelect = _o === void 0 ? false : _o, startDate = props.startDate, endDate = props.endDate, rest = __rest(props, ["date", "onChange", "localizedNames", "className", "style", "setFocus", "showTime", "use12Hours", "precision", "hourStep", "minuteStep", "secondStep", "showYearSelection", "enableRangeSelect", "startDate", "endDate"]);
126
153
  useTheme();
127
154
  var monthNames = (_a = localizedNames === null || localizedNames === void 0 ? void 0 : localizedNames.months) !== null && _a !== void 0 ? _a : defaultMonths;
128
155
  var shortDays = (_b = localizedNames === null || localizedNames === void 0 ? void 0 : localizedNames.shortDays) !== null && _b !== void 0 ? _b : defaultShortDays;
129
156
  var longDays = (_c = localizedNames === null || localizedNames === void 0 ? void 0 : localizedNames.days) !== null && _c !== void 0 ? _c : defaultLongDays;
130
- var _h = React.useState(date), selectedDay = _h[0], setSelectedDay = _h[1];
131
- var _j = React.useState(selectedDay !== null && selectedDay !== void 0 ? selectedDay : new Date()), focusedDay = _j[0], setFocusedDay = _j[1];
132
- var _k = React.useState(selectedDay ? selectedDay.getMonth() : new Date().getMonth()), displayedMonthIndex = _k[0], setDisplayedMonthIndex = _k[1];
133
- var _l = React.useState(selectedDay ? selectedDay.getFullYear() : new Date().getFullYear()), displayedYear = _l[0], setDisplayedYear = _l[1];
157
+ var _p = React.useState(date), selectedDay = _p[0], setSelectedDay = _p[1];
158
+ var _q = React.useState(startDate), selectedStartDay = _q[0], setSelectedStartDay = _q[1];
159
+ var _r = React.useState(endDate), selectedEndDay = _r[0], setSelectedEndDay = _r[1];
160
+ var _s = React.useState((_d = selectedStartDay !== null && selectedStartDay !== void 0 ? selectedStartDay : selectedDay) !== null && _d !== void 0 ? _d : new Date()), focusedDay = _s[0], setFocusedDay = _s[1];
161
+ var _t = React.useState((_f = (_e = selectedStartDay === null || selectedStartDay === void 0 ? void 0 : selectedStartDay.getMonth()) !== null && _e !== void 0 ? _e : selectedDay === null || selectedDay === void 0 ? void 0 : selectedDay.getMonth()) !== null && _f !== void 0 ? _f : new Date().getMonth()), displayedMonthIndex = _t[0], setDisplayedMonthIndex = _t[1];
162
+ var _u = React.useState((_h = (_g = selectedStartDay === null || selectedStartDay === void 0 ? void 0 : selectedStartDay.getFullYear()) !== null && _g !== void 0 ? _g : selectedDay === null || selectedDay === void 0 ? void 0 : selectedDay.getFullYear()) !== null && _h !== void 0 ? _h : new Date().getFullYear()), displayedYear = _u[0], setDisplayedYear = _u[1];
163
+ // boolean that toggles between the user picking the start date and end date for date range
164
+ var _v = React.useState(true), isSelectingStartDate = _v[0], setIsSelectingStartDate = _v[1];
134
165
  // Used to focus days only when days are changed
135
166
  // e.g. without this, when changing months day would be focused
136
167
  var needFocus = React.useRef(setFocus);
@@ -144,11 +175,16 @@ export var DatePicker = function (props) {
144
175
  setDisplayedYear(newYear);
145
176
  }, []);
146
177
  React.useEffect(function () {
178
+ var _a, _b, _c, _d;
147
179
  var currentDate = new Date();
148
180
  setSelectedDay(date);
149
- setFocusedDay(date !== null && date !== void 0 ? date : currentDate);
150
- setMonthAndYear(date ? date.getMonth() : currentDate.getMonth(), date ? date.getFullYear() : currentDate.getFullYear());
151
- }, [date, setMonthAndYear]);
181
+ setSelectedStartDay(startDate);
182
+ setSelectedEndDay(endDate);
183
+ if (!enableRangeSelect) {
184
+ setFocusedDay(date !== null && date !== void 0 ? date : currentDate);
185
+ }
186
+ setMonthAndYear((_b = (_a = startDate === null || startDate === void 0 ? void 0 : startDate.getMonth()) !== null && _a !== void 0 ? _a : date === null || date === void 0 ? void 0 : date.getMonth()) !== null && _b !== void 0 ? _b : currentDate.getMonth(), (_d = (_c = startDate === null || startDate === void 0 ? void 0 : startDate.getFullYear()) !== null && _c !== void 0 ? _c : date === null || date === void 0 ? void 0 : date.getFullYear()) !== null && _d !== void 0 ? _d : currentDate.getFullYear());
187
+ }, [date, setMonthAndYear, startDate, endDate, enableRangeSelect]);
152
188
  var days = React.useMemo(function () {
153
189
  var offsetToFirst = new Date(displayedYear, displayedMonthIndex, 1).getDay();
154
190
  // if its sunday, show one week before
@@ -172,7 +208,8 @@ export var DatePicker = function (props) {
172
208
  return weeksInMonth;
173
209
  }, [days]);
174
210
  var getNewFocusedDate = function (newYear, newMonth) {
175
- var currentDate = selectedDay !== null && selectedDay !== void 0 ? selectedDay : new Date();
211
+ var _a;
212
+ var currentDate = (_a = selectedStartDay !== null && selectedStartDay !== void 0 ? selectedStartDay : selectedDay) !== null && _a !== void 0 ? _a : new Date();
176
213
  var newDate = new Date(newYear, newMonth, currentDate.getDate(), currentDate.getHours(), currentDate.getMinutes(), currentDate.getSeconds());
177
214
  return newDate;
178
215
  };
@@ -199,14 +236,55 @@ export var DatePicker = function (props) {
199
236
  setFocusedDay(getNewFocusedDate(newYear, newMonth));
200
237
  };
201
238
  var onDayClick = function (day) {
202
- if (day.getMonth() !== (selectedDay === null || selectedDay === void 0 ? void 0 : selectedDay.getMonth())) {
203
- setMonthAndYear(day.getMonth(), day.getFullYear());
239
+ // single date selection
240
+ if (!enableRangeSelect) {
241
+ if (day.getMonth() !== (selectedDay === null || selectedDay === void 0 ? void 0 : selectedDay.getMonth())) {
242
+ setMonthAndYear(day.getMonth(), day.getFullYear());
243
+ }
244
+ var currentDate = selectedDay !== null && selectedDay !== void 0 ? selectedDay : new Date();
245
+ var newDate = new Date(day.getFullYear(), day.getMonth(), day.getDate(), currentDate.getHours(), currentDate.getMinutes(), currentDate.getSeconds());
246
+ setSelectedDay(newDate);
247
+ setFocusedDay(newDate);
248
+ isSingleOnChange(onChange, enableRangeSelect) && (onChange === null || onChange === void 0 ? void 0 : onChange(newDate));
249
+ }
250
+ // start date selection (date range only)
251
+ else if (isSelectingStartDate) {
252
+ if (day.getMonth() !== (selectedStartDay === null || selectedStartDay === void 0 ? void 0 : selectedStartDay.getMonth())) {
253
+ setMonthAndYear(day.getMonth(), day.getFullYear());
254
+ }
255
+ var currentStartDate = selectedStartDay !== null && selectedStartDay !== void 0 ? selectedStartDay : new Date();
256
+ var newStartDate = new Date(day.getFullYear(), day.getMonth(), day.getDate(), currentStartDate.getHours(), currentStartDate.getMinutes(), currentStartDate.getSeconds());
257
+ setSelectedStartDay(newStartDate);
258
+ setFocusedDay(newStartDate);
259
+ // if the start date is after the end date or the end date is undefined, reset the end date
260
+ if (!isBefore(newStartDate, selectedEndDay)) {
261
+ setSelectedEndDay(newStartDate);
262
+ onChange === null || onChange === void 0 ? void 0 : onChange(newStartDate, newStartDate);
263
+ }
264
+ else {
265
+ selectedEndDay && (onChange === null || onChange === void 0 ? void 0 : onChange(newStartDate, selectedEndDay));
266
+ }
267
+ setIsSelectingStartDate(false);
268
+ }
269
+ // end date selection (date range only)
270
+ else {
271
+ if (day.getMonth() !== (selectedEndDay === null || selectedEndDay === void 0 ? void 0 : selectedEndDay.getMonth())) {
272
+ setMonthAndYear(day.getMonth(), day.getFullYear());
273
+ }
274
+ var currentEndDate = selectedEndDay !== null && selectedEndDay !== void 0 ? selectedEndDay : new Date();
275
+ var newEndDate = new Date(day.getFullYear(), day.getMonth(), day.getDate(), currentEndDate.getHours(), currentEndDate.getMinutes(), currentEndDate.getSeconds());
276
+ setFocusedDay(newEndDate);
277
+ // if the end date is before the start date, move back the start date and still have user select end date
278
+ if (!isBefore(newEndDate, selectedStartDay)) {
279
+ setSelectedEndDay(newEndDate);
280
+ selectedStartDay && (onChange === null || onChange === void 0 ? void 0 : onChange(selectedStartDay, newEndDate));
281
+ setIsSelectingStartDate(true);
282
+ }
283
+ else {
284
+ setSelectedStartDay(newEndDate);
285
+ selectedEndDay && (onChange === null || onChange === void 0 ? void 0 : onChange(newEndDate, selectedEndDay));
286
+ }
204
287
  }
205
- var currentDate = selectedDay !== null && selectedDay !== void 0 ? selectedDay : new Date();
206
- var newDate = new Date(day.getFullYear(), day.getMonth(), day.getDate(), currentDate.getHours(), currentDate.getMinutes(), currentDate.getSeconds());
207
- setSelectedDay(newDate);
208
- setFocusedDay(newDate);
209
- onChange === null || onChange === void 0 ? void 0 : onChange(newDate);
210
288
  };
211
289
  var handleCalendarKeyDown = function (event) {
212
290
  if (!focusedDay) {
@@ -263,9 +341,23 @@ export var DatePicker = function (props) {
263
341
  return 'iui-calendar-day-outside-month';
264
342
  }
265
343
  var dayClass = 'iui-calendar-day';
266
- if (isSameDay(day, selectedDay)) {
344
+ var isSelectedDay = isSameDay(day, selectedDay) ||
345
+ (isSameDay(day, selectedStartDay) && isSameDay(day, selectedEndDay));
346
+ if (isSelectedDay) {
267
347
  dayClass += '-selected';
268
348
  }
349
+ else if (isSameDay(day, selectedStartDay)) {
350
+ dayClass += '-range-start';
351
+ }
352
+ else if (isSameDay(day, selectedEndDay)) {
353
+ dayClass += '-range-end';
354
+ }
355
+ // adds range class to dates between start and end date
356
+ if (selectedStartDay &&
357
+ selectedEndDay &&
358
+ isInDateRange(day, selectedStartDay, selectedEndDay)) {
359
+ dayClass += '-range';
360
+ }
269
361
  if (isSameDay(day, new Date())) {
270
362
  dayClass += '-today';
271
363
  }
@@ -297,6 +389,11 @@ export var DatePicker = function (props) {
297
389
  } }, dateValue));
298
390
  })));
299
391
  }))),
300
- showTime && (React.createElement(TimePicker, { date: selectedDay, use12Hours: use12Hours, precision: precision, hourStep: hourStep, minuteStep: minuteStep, secondStep: secondStep, onChange: function (date) { return onChange === null || onChange === void 0 ? void 0 : onChange(date); } }))));
392
+ showTime && (React.createElement(TimePicker, { date: selectedStartDay !== null && selectedStartDay !== void 0 ? selectedStartDay : selectedDay, use12Hours: use12Hours, precision: precision, hourStep: hourStep, minuteStep: minuteStep, secondStep: secondStep, onChange: function (date) {
393
+ var _a, _b, _c, _d, _e, _f;
394
+ return isSingleOnChange(onChange, enableRangeSelect)
395
+ ? onChange === null || onChange === void 0 ? void 0 : onChange(date)
396
+ : onChange === null || onChange === void 0 ? void 0 : onChange(new Date((_a = selectedStartDay === null || selectedStartDay === void 0 ? void 0 : selectedStartDay.getFullYear()) !== null && _a !== void 0 ? _a : date.getFullYear(), (_b = selectedStartDay === null || selectedStartDay === void 0 ? void 0 : selectedStartDay.getMonth()) !== null && _b !== void 0 ? _b : date.getMonth(), (_c = selectedStartDay === null || selectedStartDay === void 0 ? void 0 : selectedStartDay.getDate()) !== null && _c !== void 0 ? _c : date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()), new Date((_d = selectedEndDay === null || selectedEndDay === void 0 ? void 0 : selectedEndDay.getFullYear()) !== null && _d !== void 0 ? _d : date.getFullYear(), (_e = selectedEndDay === null || selectedEndDay === void 0 ? void 0 : selectedEndDay.getMonth()) !== null && _e !== void 0 ? _e : date.getMonth(), (_f = selectedEndDay === null || selectedEndDay === void 0 ? void 0 : selectedEndDay.getDate()) !== null && _f !== void 0 ? _f : date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()));
397
+ } }))));
301
398
  };
302
399
  export default DatePicker;
@@ -6,7 +6,7 @@ export declare type DialogProps = {
6
6
  * Dialog content.
7
7
  */
8
8
  children: React.ReactNode;
9
- } & DialogContextProps;
9
+ } & Omit<DialogContextProps, 'dialogRootRef'> & React.ComponentPropsWithRef<'div'>;
10
10
  /**
11
11
  * Dialog component.
12
12
  * @example
@@ -29,10 +29,10 @@ export declare type DialogProps = {
29
29
  * </Dialog.Main>
30
30
  * </Dialog>
31
31
  */
32
- export declare const Dialog: ((props: DialogProps) => JSX.Element) & {
33
- Backdrop: React.ForwardRefExoticComponent<Pick<import("./DialogBackdrop").DialogBackdropProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "isVisible" | "isDismissible" | "closeOnExternalClick"> & React.RefAttributes<HTMLDivElement>>;
34
- Main: React.ForwardRefExoticComponent<Pick<import("./DialogMain").DialogMainProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "styleType" | "isOpen" | "isDismissible" | "closeOnEsc" | "trapFocus" | "preventDocumentScroll"> & React.RefAttributes<HTMLDivElement>>;
35
- TitleBar: React.ForwardRefExoticComponent<Pick<import("./DialogTitleBar").DialogTitleBarProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "isDismissible" | "titleText"> & React.RefAttributes<HTMLDivElement>> & {
32
+ export declare const Dialog: React.ForwardRefExoticComponent<Pick<DialogProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "setFocus" | "isOpen" | "isDismissible" | "isDraggable" | "closeOnExternalClick" | "closeOnEsc" | "trapFocus" | "preventDocumentScroll" | "isResizable" | "relativeTo"> & React.RefAttributes<HTMLDivElement>> & {
33
+ Backdrop: React.ForwardRefExoticComponent<Pick<import("./DialogBackdrop").DialogBackdropProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "isVisible" | "isDismissible" | "closeOnExternalClick" | "relativeTo"> & React.RefAttributes<HTMLDivElement>>;
34
+ Main: React.ForwardRefExoticComponent<Pick<import("./DialogMain").DialogMainProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "styleType" | "setFocus" | "isOpen" | "isDismissible" | "isDraggable" | "closeOnEsc" | "trapFocus" | "preventDocumentScroll" | "isResizable" | "relativeTo"> & React.RefAttributes<HTMLDivElement>>;
35
+ TitleBar: React.ForwardRefExoticComponent<Pick<import("./DialogTitleBar").DialogTitleBarProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "isDismissible" | "isDraggable" | "titleText"> & React.RefAttributes<HTMLDivElement>> & {
36
36
  Title: React.ForwardRefExoticComponent<Pick<import("./DialogTitleBarTitle").DialogTitleBarTitleProps, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & React.RefAttributes<HTMLDivElement>>;
37
37
  };
38
38
  Content: React.ForwardRefExoticComponent<Pick<import("./DialogContent").DialogContentProps, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & React.RefAttributes<HTMLDivElement>>;
@@ -1,15 +1,39 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
1
23
  /*---------------------------------------------------------------------------------------------
2
24
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
25
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
26
  *--------------------------------------------------------------------------------------------*/
5
27
  import React from 'react';
28
+ import cx from 'classnames';
6
29
  import '@itwin/itwinui-css/css/dialog.css';
7
30
  import { DialogTitleBar } from './DialogTitleBar';
8
31
  import { DialogContent } from './DialogContent';
9
32
  import { DialogBackdrop } from './DialogBackdrop';
10
33
  import { DialogContext } from './DialogContext';
11
34
  import { DialogButtonBar } from './DialogButtonBar';
12
- import DialogMain from './DialogMain';
35
+ import { DialogMain } from './DialogMain';
36
+ import { useMergedRefs } from '../utils';
13
37
  /**
14
38
  * Dialog component.
15
39
  * @example
@@ -32,8 +56,10 @@ import DialogMain from './DialogMain';
32
56
  * </Dialog.Main>
33
57
  * </Dialog>
34
58
  */
35
- export var Dialog = Object.assign(function (props) {
36
- var children = props.children, _a = props.trapFocus, trapFocus = _a === void 0 ? false : _a, _b = props.preventDocumentScroll, preventDocumentScroll = _b === void 0 ? false : _b, _c = props.isOpen, isOpen = _c === void 0 ? false : _c, _d = props.isDismissible, isDismissible = _d === void 0 ? true : _d, _e = props.closeOnEsc, closeOnEsc = _e === void 0 ? true : _e, _f = props.closeOnExternalClick, closeOnExternalClick = _f === void 0 ? false : _f, onClose = props.onClose;
59
+ export var Dialog = Object.assign(React.forwardRef(function (props, ref) {
60
+ var children = props.children, _a = props.trapFocus, trapFocus = _a === void 0 ? false : _a, _b = props.setFocus, setFocus = _b === void 0 ? false : _b, _c = props.preventDocumentScroll, preventDocumentScroll = _c === void 0 ? false : _c, _d = props.isOpen, isOpen = _d === void 0 ? false : _d, _e = props.isDismissible, isDismissible = _e === void 0 ? true : _e, _f = props.closeOnEsc, closeOnEsc = _f === void 0 ? true : _f, _g = props.closeOnExternalClick, closeOnExternalClick = _g === void 0 ? false : _g, onClose = props.onClose, _h = props.isDraggable, isDraggable = _h === void 0 ? false : _h, _j = props.isResizable, isResizable = _j === void 0 ? false : _j, _k = props.relativeTo, relativeTo = _k === void 0 ? 'viewport' : _k, className = props.className, style = props.style, rest = __rest(props, ["children", "trapFocus", "setFocus", "preventDocumentScroll", "isOpen", "isDismissible", "closeOnEsc", "closeOnExternalClick", "onClose", "isDraggable", "isResizable", "relativeTo", "className", "style"]);
61
+ var dialogRootRef = React.useRef(null);
62
+ var refs = useMergedRefs(ref, dialogRootRef);
37
63
  return (React.createElement(DialogContext.Provider, { value: {
38
64
  isOpen: isOpen,
39
65
  onClose: onClose,
@@ -42,8 +68,14 @@ export var Dialog = Object.assign(function (props) {
42
68
  isDismissible: isDismissible,
43
69
  preventDocumentScroll: preventDocumentScroll,
44
70
  trapFocus: trapFocus,
45
- } }, children));
46
- }, {
71
+ setFocus: setFocus,
72
+ isDraggable: isDraggable,
73
+ isResizable: isResizable,
74
+ relativeTo: relativeTo,
75
+ dialogRootRef: dialogRootRef,
76
+ } },
77
+ React.createElement("div", __assign({ className: cx('iui-dialog-wrapper', className), ref: refs, style: __assign({ position: relativeTo === 'container' ? 'absolute' : 'fixed' }, style) }, rest), children)));
78
+ }), {
47
79
  Backdrop: DialogBackdrop,
48
80
  Main: DialogMain,
49
81
  TitleBar: DialogTitleBar,
@@ -1,12 +1,12 @@
1
1
  import React from 'react';
2
2
  import { BackdropProps } from '../Backdrop';
3
3
  import { DialogContextProps } from './DialogContext';
4
- export declare type DialogBackdropProps = BackdropProps & Pick<DialogContextProps, 'onClose' | 'isDismissible' | 'closeOnExternalClick'>;
4
+ export declare type DialogBackdropProps = BackdropProps & Pick<DialogContextProps, 'onClose' | 'isDismissible' | 'closeOnExternalClick' | 'relativeTo'>;
5
5
  /**
6
6
  * Backdrop component for dialog. Recommended to be used with `Dialog`
7
7
  * then its visibility is being controlled by dialog's `isOpen` prop.
8
8
  * @example
9
9
  * <Dialog.Backdrop />
10
10
  */
11
- export declare const DialogBackdrop: React.ForwardRefExoticComponent<Pick<DialogBackdropProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "isVisible" | "isDismissible" | "closeOnExternalClick"> & React.RefAttributes<HTMLDivElement>>;
11
+ export declare const DialogBackdrop: React.ForwardRefExoticComponent<Pick<DialogBackdropProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "isVisible" | "isDismissible" | "closeOnExternalClick" | "relativeTo"> & React.RefAttributes<HTMLDivElement>>;
12
12
  export default DialogBackdrop;
@@ -36,7 +36,7 @@ import { useDialogContext } from './DialogContext';
36
36
  */
37
37
  export var DialogBackdrop = React.forwardRef(function (props, ref) {
38
38
  var dialogContext = useDialogContext();
39
- var _a = props.isVisible, isVisible = _a === void 0 ? dialogContext.isOpen : _a, _b = props.isDismissible, isDismissible = _b === void 0 ? dialogContext.isDismissible : _b, _c = props.onClose, onClose = _c === void 0 ? dialogContext.onClose : _c, _d = props.closeOnExternalClick, closeOnExternalClick = _d === void 0 ? dialogContext.closeOnExternalClick : _d, onMouseDown = props.onMouseDown, rest = __rest(props, ["isVisible", "isDismissible", "onClose", "closeOnExternalClick", "onMouseDown"]);
39
+ var _a = props.isVisible, isVisible = _a === void 0 ? dialogContext.isOpen : _a, _b = props.isDismissible, isDismissible = _b === void 0 ? dialogContext.isDismissible : _b, _c = props.onClose, onClose = _c === void 0 ? dialogContext.onClose : _c, _d = props.closeOnExternalClick, closeOnExternalClick = _d === void 0 ? dialogContext.closeOnExternalClick : _d, _e = props.relativeTo, relativeTo = _e === void 0 ? dialogContext.relativeTo : _e, onMouseDown = props.onMouseDown, style = props.style, rest = __rest(props, ["isVisible", "isDismissible", "onClose", "closeOnExternalClick", "relativeTo", "onMouseDown", "style"]);
40
40
  var backdropRef = React.useRef(null);
41
41
  var refs = useMergedRefs(backdropRef, ref);
42
42
  var handleMouseDown = function (event) {
@@ -50,6 +50,6 @@ export var DialogBackdrop = React.forwardRef(function (props, ref) {
50
50
  }
51
51
  onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(event);
52
52
  };
53
- return (React.createElement(Backdrop, __assign({ isVisible: isVisible, ref: refs, onMouseDown: handleMouseDown }, rest)));
53
+ return (React.createElement(Backdrop, __assign({ isVisible: isVisible, ref: refs, onMouseDown: handleMouseDown, style: __assign({ pointerEvents: 'auto', position: relativeTo === 'container' ? 'absolute' : 'fixed' }, style) }, rest)));
54
54
  });
55
55
  export default DialogBackdrop;
@@ -29,11 +29,42 @@ export declare type DialogContextProps = {
29
29
  * @default false
30
30
  */
31
31
  trapFocus?: boolean;
32
+ /**
33
+ * If true, focuses the dialog.
34
+ * @default false
35
+ */
36
+ setFocus?: boolean;
32
37
  /**
33
38
  * Prevents body from being scrollable. This is useful when the dialog is modal.
34
39
  * @default false
35
40
  */
36
41
  preventDocumentScroll?: boolean;
42
+ /**
43
+ * Flag whether dialog is draggable.
44
+ *
45
+ * If you want to make dialog draggable relatively to the container, you should use set `relativeTo` to `container`.
46
+ *
47
+ * @default false
48
+ */
49
+ isDraggable?: boolean;
50
+ /**
51
+ * Flag whether dialog is resizable.
52
+ * @default false
53
+ */
54
+ isResizable?: boolean;
55
+ /**
56
+ * Whether dialog should be positioned relatively to a container or the viewport.
57
+ *
58
+ * Using `'container'` will absolutely position this dialog relative to the closest positioned ancestor.
59
+ * In other words, you must place the dialog as a child of an element that has `position` set to
60
+ * something other than `static`, e.g. `position: relative`.
61
+ * @default 'viewport'
62
+ */
63
+ relativeTo?: 'container' | 'viewport';
64
+ /**
65
+ * Dialog root ref. For internal use.
66
+ */
67
+ dialogRootRef?: React.RefObject<HTMLDivElement>;
37
68
  };
38
69
  export declare const DialogContext: React.Context<DialogContextProps | undefined>;
39
70
  export declare const useDialogContext: () => DialogContextProps;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ export declare type DialogDragContextProps = {
3
+ onPointerDown?: (e: React.PointerEvent<HTMLElement>) => void;
4
+ };
5
+ export declare const DialogDragContext: React.Context<DialogDragContextProps | undefined>;
6
+ export declare const useDialogDragContext: () => {
7
+ onPointerDown?: ((e: React.PointerEvent<HTMLElement>) => void) | undefined;
8
+ };
@@ -0,0 +1,21 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ /*---------------------------------------------------------------------------------------------
13
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
14
+ * See LICENSE.md in the project root for license terms and full copyright notice.
15
+ *--------------------------------------------------------------------------------------------*/
16
+ import React from 'react';
17
+ export var DialogDragContext = React.createContext(undefined);
18
+ export var useDialogDragContext = function () {
19
+ var context = React.useContext(DialogDragContext);
20
+ return __assign({}, context);
21
+ };
@@ -11,7 +11,7 @@ export declare type DialogMainProps = {
11
11
  * Content of the dialog.
12
12
  */
13
13
  children: React.ReactNode;
14
- } & Omit<DialogContextProps, 'closeOnExternalClick'> & React.ComponentPropsWithRef<'div'>;
14
+ } & Omit<DialogContextProps, 'closeOnExternalClick' | 'dialogRootRef'> & React.ComponentPropsWithRef<'div'>;
15
15
  /**
16
16
  * Dialog component which can wrap any content.
17
17
  * @example
@@ -32,5 +32,5 @@ export declare type DialogMainProps = {
32
32
  * </Dialog.ButtonBar>
33
33
  * </Dialog.Main>
34
34
  */
35
- export declare const DialogMain: React.ForwardRefExoticComponent<Pick<DialogMainProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "styleType" | "isOpen" | "isDismissible" | "closeOnEsc" | "trapFocus" | "preventDocumentScroll"> & React.RefAttributes<HTMLDivElement>>;
35
+ export declare const DialogMain: React.ForwardRefExoticComponent<Pick<DialogMainProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "styleType" | "setFocus" | "isOpen" | "isDismissible" | "isDraggable" | "closeOnEsc" | "trapFocus" | "preventDocumentScroll" | "isResizable" | "relativeTo"> & React.RefAttributes<HTMLDivElement>>;
36
36
  export default DialogMain;