@itwin/itwinui-react 1.45.0 → 1.47.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.
- package/CHANGELOG.md +31 -0
- package/cjs/core/Breadcrumbs/Breadcrumbs.d.ts +116 -0
- package/cjs/core/Breadcrumbs/Breadcrumbs.js +2 -3
- package/cjs/core/ButtonGroup/ButtonGroup.js +1 -1
- package/cjs/core/ColorPicker/ColorSwatch.d.ts +1 -1
- package/cjs/core/DatePicker/DatePicker.d.ts +24 -4
- package/cjs/core/DatePicker/DatePicker.js +116 -19
- package/cjs/core/Dialog/Dialog.d.ts +5 -5
- package/cjs/core/Dialog/Dialog.js +38 -6
- package/cjs/core/Dialog/DialogBackdrop.d.ts +2 -2
- package/cjs/core/Dialog/DialogBackdrop.js +2 -2
- package/cjs/core/Dialog/DialogContext.d.ts +31 -0
- package/cjs/core/Dialog/DialogDragContext.d.ts +8 -0
- package/cjs/core/Dialog/DialogDragContext.js +28 -0
- package/cjs/core/Dialog/DialogMain.d.ts +2 -2
- package/cjs/core/Dialog/DialogMain.js +46 -6
- package/cjs/core/Dialog/DialogTitleBar.d.ts +2 -2
- package/cjs/core/Dialog/DialogTitleBar.js +12 -2
- package/cjs/core/Modal/Modal.js +1 -1
- package/cjs/core/Table/Table.d.ts +6 -0
- package/cjs/core/Table/Table.js +73 -17
- package/cjs/core/Table/actionHandlers/index.d.ts +1 -1
- package/cjs/core/Table/actionHandlers/index.js +2 -1
- package/cjs/core/Table/actionHandlers/resizeHandler.d.ts +2 -0
- package/cjs/core/Table/actionHandlers/selectHandler.d.ts +5 -0
- package/cjs/core/Table/actionHandlers/selectHandler.js +35 -2
- package/cjs/core/Table/filters/FilterToggle.d.ts +0 -1
- package/cjs/core/Table/filters/FilterToggle.js +3 -3
- package/cjs/core/Table/hooks/useResizeColumns.d.ts +33 -1
- package/cjs/core/Table/hooks/useResizeColumns.js +89 -29
- package/cjs/core/index.d.ts +3 -1
- package/cjs/core/index.js +6 -3
- package/cjs/core/utils/components/Resizer.d.ts +31 -0
- package/cjs/core/utils/components/Resizer.js +206 -0
- package/cjs/core/utils/components/VirtualScroll.js +26 -24
- package/cjs/core/utils/components/index.d.ts +1 -0
- package/cjs/core/utils/components/index.js +1 -0
- package/cjs/core/utils/functions/index.d.ts +1 -0
- package/cjs/core/utils/functions/index.js +1 -0
- package/cjs/core/utils/functions/styles.d.ts +6 -0
- package/cjs/core/utils/functions/styles.js +21 -0
- package/cjs/core/utils/hooks/useContainerWidth.d.ts +1 -1
- package/cjs/core/utils/hooks/useDragAndDrop.d.ts +14 -0
- package/cjs/core/utils/hooks/useDragAndDrop.js +110 -0
- package/cjs/core/utils/hooks/useEventListener.d.ts +1 -1
- package/cjs/core/utils/hooks/useOverflow.d.ts +1 -1
- package/cjs/core/utils/hooks/useResizeObserver.d.ts +1 -1
- package/cjs/types/react-table-config.d.ts +13 -1
- package/esm/core/Breadcrumbs/Breadcrumbs.d.ts +116 -0
- package/esm/core/Breadcrumbs/Breadcrumbs.js +2 -3
- package/esm/core/ButtonGroup/ButtonGroup.js +1 -1
- package/esm/core/ColorPicker/ColorSwatch.d.ts +1 -1
- package/esm/core/DatePicker/DatePicker.d.ts +24 -4
- package/esm/core/DatePicker/DatePicker.js +116 -19
- package/esm/core/Dialog/Dialog.d.ts +5 -5
- package/esm/core/Dialog/Dialog.js +37 -5
- package/esm/core/Dialog/DialogBackdrop.d.ts +2 -2
- package/esm/core/Dialog/DialogBackdrop.js +2 -2
- package/esm/core/Dialog/DialogContext.d.ts +31 -0
- package/esm/core/Dialog/DialogDragContext.d.ts +8 -0
- package/esm/core/Dialog/DialogDragContext.js +21 -0
- package/esm/core/Dialog/DialogMain.d.ts +2 -2
- package/esm/core/Dialog/DialogMain.js +47 -7
- package/esm/core/Dialog/DialogTitleBar.d.ts +2 -2
- package/esm/core/Dialog/DialogTitleBar.js +12 -2
- package/esm/core/Modal/Modal.js +1 -1
- package/esm/core/Table/Table.d.ts +6 -0
- package/esm/core/Table/Table.js +76 -20
- package/esm/core/Table/actionHandlers/index.d.ts +1 -1
- package/esm/core/Table/actionHandlers/index.js +1 -1
- package/esm/core/Table/actionHandlers/resizeHandler.d.ts +2 -0
- package/esm/core/Table/actionHandlers/selectHandler.d.ts +5 -0
- package/esm/core/Table/actionHandlers/selectHandler.js +33 -1
- package/esm/core/Table/filters/FilterToggle.d.ts +0 -1
- package/esm/core/Table/filters/FilterToggle.js +4 -4
- package/esm/core/Table/hooks/useResizeColumns.d.ts +33 -1
- package/esm/core/Table/hooks/useResizeColumns.js +89 -29
- package/esm/core/index.d.ts +3 -1
- package/esm/core/index.js +2 -1
- package/esm/core/utils/components/Resizer.d.ts +31 -0
- package/esm/core/utils/components/Resizer.js +199 -0
- package/esm/core/utils/components/VirtualScroll.js +26 -24
- package/esm/core/utils/components/index.d.ts +1 -0
- package/esm/core/utils/components/index.js +1 -0
- package/esm/core/utils/functions/index.d.ts +1 -0
- package/esm/core/utils/functions/index.js +1 -0
- package/esm/core/utils/functions/styles.d.ts +6 -0
- package/esm/core/utils/functions/styles.js +17 -0
- package/esm/core/utils/hooks/useContainerWidth.d.ts +1 -1
- package/esm/core/utils/hooks/useDragAndDrop.d.ts +14 -0
- package/esm/core/utils/hooks/useDragAndDrop.js +103 -0
- package/esm/core/utils/hooks/useEventListener.d.ts +1 -1
- package/esm/core/utils/hooks/useOverflow.d.ts +1 -1
- package/esm/core/utils/hooks/useResizeObserver.d.ts +1 -1
- package/esm/types/react-table-config.d.ts +13 -1
- package/package.json +1 -1
|
@@ -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,
|
|
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
|
|
131
|
-
var
|
|
132
|
-
var
|
|
133
|
-
var
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
|
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
|
-
|
|
203
|
-
|
|
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
|
-
|
|
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) {
|
|
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:
|
|
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.
|
|
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
|
-
|
|
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;
|
|
@@ -26,10 +26,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
26
26
|
*--------------------------------------------------------------------------------------------*/
|
|
27
27
|
import React from 'react';
|
|
28
28
|
import cx from 'classnames';
|
|
29
|
-
import { FocusTrap, useMergedRefs, useTheme } from '../utils';
|
|
29
|
+
import { FocusTrap, getTranslateValues, useLatestRef, Resizer, useMergedRefs, useTheme, } from '../utils';
|
|
30
30
|
import '@itwin/itwinui-css/css/dialog.css';
|
|
31
31
|
import { useDialogContext } from './DialogContext';
|
|
32
32
|
import { CSSTransition } from 'react-transition-group';
|
|
33
|
+
import { DialogDragContext } from './DialogDragContext';
|
|
34
|
+
import useDragAndDrop from '../utils/hooks/useDragAndDrop';
|
|
33
35
|
/**
|
|
34
36
|
* Dialog component which can wrap any content.
|
|
35
37
|
* @example
|
|
@@ -52,14 +54,19 @@ import { CSSTransition } from 'react-transition-group';
|
|
|
52
54
|
*/
|
|
53
55
|
export var DialogMain = React.forwardRef(function (props, ref) {
|
|
54
56
|
var dialogContext = useDialogContext();
|
|
55
|
-
var className = props.className, children = props.children, _a = props.styleType, styleType = _a === void 0 ? 'default' : _a, _b = props.isOpen, isOpen = _b === void 0 ? dialogContext.isOpen : _b, _c = props.isDismissible, isDismissible = _c === void 0 ? dialogContext.isDismissible : _c, _d = props.onClose, onClose = _d === void 0 ? dialogContext.onClose : _d, _e = props.closeOnEsc, closeOnEsc = _e === void 0 ? dialogContext.closeOnEsc : _e, _f = props.trapFocus, trapFocus = _f === void 0 ? dialogContext.trapFocus : _f, _g = props.preventDocumentScroll, preventDocumentScroll =
|
|
57
|
+
var className = props.className, children = props.children, _a = props.styleType, styleType = _a === void 0 ? 'default' : _a, _b = props.isOpen, isOpen = _b === void 0 ? dialogContext.isOpen : _b, _c = props.isDismissible, isDismissible = _c === void 0 ? dialogContext.isDismissible : _c, _d = props.onClose, onClose = _d === void 0 ? dialogContext.onClose : _d, _e = props.closeOnEsc, closeOnEsc = _e === void 0 ? dialogContext.closeOnEsc : _e, _f = props.trapFocus, trapFocus = _f === void 0 ? dialogContext.trapFocus : _f, _g = props.setFocus, setFocus = _g === void 0 ? dialogContext.setFocus : _g, _h = props.preventDocumentScroll, preventDocumentScroll = _h === void 0 ? dialogContext.preventDocumentScroll : _h, onKeyDown = props.onKeyDown, _j = props.isDraggable, isDraggable = _j === void 0 ? dialogContext.isDraggable : _j, _k = props.isResizable, isResizable = _k === void 0 ? dialogContext.isResizable : _k, propStyle = props.style, rest = __rest(props, ["className", "children", "styleType", "isOpen", "isDismissible", "onClose", "closeOnEsc", "trapFocus", "setFocus", "preventDocumentScroll", "onKeyDown", "isDraggable", "isResizable", "style"]);
|
|
56
58
|
useTheme();
|
|
59
|
+
var _l = React.useState(), style = _l[0], setStyle = _l[1];
|
|
57
60
|
var dialogRef = React.useRef(null);
|
|
58
61
|
var refs = useMergedRefs(dialogRef, ref);
|
|
59
62
|
// Focuses dialog when opened and brings back focus to the previously focused element when closed.
|
|
60
63
|
var previousFocusedElement = React.useRef();
|
|
64
|
+
var setFocusRef = useLatestRef(setFocus);
|
|
61
65
|
React.useEffect(function () {
|
|
62
66
|
var _a, _b, _c;
|
|
67
|
+
if (!setFocusRef.current) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
63
70
|
if (isOpen) {
|
|
64
71
|
previousFocusedElement.current = (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument.activeElement;
|
|
65
72
|
(_b = dialogRef.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
@@ -73,17 +80,25 @@ export var DialogMain = React.forwardRef(function (props, ref) {
|
|
|
73
80
|
(ref === null || ref === void 0 ? void 0 : ref.contains(document.activeElement)) &&
|
|
74
81
|
((_a = previousFocusedElement.current) === null || _a === void 0 ? void 0 : _a.focus());
|
|
75
82
|
};
|
|
83
|
+
}, [isOpen, setFocusRef]);
|
|
84
|
+
var originalBodyOverflow = React.useRef('');
|
|
85
|
+
React.useEffect(function () {
|
|
86
|
+
if (isOpen) {
|
|
87
|
+
originalBodyOverflow.current = document.body.style.overflow;
|
|
88
|
+
}
|
|
76
89
|
}, [isOpen]);
|
|
77
90
|
// Prevents document from scrolling when the dialog is open.
|
|
78
|
-
var originalBodyOverflow = React.useRef('');
|
|
79
91
|
React.useEffect(function () {
|
|
80
92
|
var _a;
|
|
81
93
|
var ownerDocument = (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.ownerDocument;
|
|
82
|
-
|
|
94
|
+
// If there is no `ownerDocument` or `preventDocumentScroll` is false or
|
|
95
|
+
// document body originally has `overflow: hidden` (possibly from other/parent dialog), then do nothing.
|
|
96
|
+
if (!ownerDocument ||
|
|
97
|
+
!preventDocumentScroll ||
|
|
98
|
+
originalBodyOverflow.current === 'hidden') {
|
|
83
99
|
return;
|
|
84
100
|
}
|
|
85
101
|
if (isOpen) {
|
|
86
|
-
originalBodyOverflow.current = ownerDocument.body.style.overflow;
|
|
87
102
|
ownerDocument.body.style.overflow = 'hidden';
|
|
88
103
|
}
|
|
89
104
|
else {
|
|
@@ -101,13 +116,38 @@ export var DialogMain = React.forwardRef(function (props, ref) {
|
|
|
101
116
|
}
|
|
102
117
|
onKeyDown === null || onKeyDown === void 0 ? void 0 : onKeyDown(event);
|
|
103
118
|
};
|
|
119
|
+
var _m = useDragAndDrop(dialogRef, dialogContext.dialogRootRef, isDraggable), onPointerDown = _m.onPointerDown, transform = _m.transform;
|
|
120
|
+
var handlePointerDown = React.useCallback(function (event) {
|
|
121
|
+
if (isDraggable) {
|
|
122
|
+
onPointerDown(event);
|
|
123
|
+
}
|
|
124
|
+
}, [isDraggable, onPointerDown]);
|
|
125
|
+
// Prevents dialog from moving when window is being resized
|
|
126
|
+
React.useLayoutEffect(function () {
|
|
127
|
+
var _a;
|
|
128
|
+
if (!isDraggable || !isOpen) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
var rect = (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
132
|
+
var _b = getTranslateValues(dialogRef.current), translateX = _b[0], translateY = _b[1];
|
|
133
|
+
setStyle(function (oldStyle) {
|
|
134
|
+
var _a, _b;
|
|
135
|
+
return (__assign(__assign({}, oldStyle), { width: rect === null || rect === void 0 ? void 0 : rect.width, height: rect === null || rect === void 0 ? void 0 : rect.height, left: (_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.offsetLeft, top: (_b = dialogRef.current) === null || _b === void 0 ? void 0 : _b.offsetTop, transform: "translate(".concat(translateX, "px,").concat(translateY, "px)") }));
|
|
136
|
+
});
|
|
137
|
+
}, [isDraggable, isOpen]);
|
|
138
|
+
var setResizeStyle = React.useCallback(function (newStyle) {
|
|
139
|
+
setStyle(function (oldStyle) { return (__assign(__assign({}, oldStyle), newStyle)); });
|
|
140
|
+
}, []);
|
|
104
141
|
var content = (React.createElement("div", __assign({ className: cx('iui-dialog', {
|
|
105
142
|
'iui-dialog-default': styleType === 'default',
|
|
106
143
|
'iui-dialog-full-page': styleType === 'fullPage',
|
|
107
144
|
'iui-dialog-visible': isOpen,
|
|
108
|
-
|
|
145
|
+
'iui-dialog-draggable': isDraggable,
|
|
146
|
+
}, className), role: 'dialog', ref: refs, onKeyDown: handleKeyDown, tabIndex: -1, style: __assign(__assign({ transform: transform, overflow: 'unset' }, style), propStyle) }, rest),
|
|
147
|
+
isResizable && (React.createElement(Resizer, { elementRef: dialogRef, containerRef: dialogContext.dialogRootRef, onResizeEnd: setResizeStyle })),
|
|
148
|
+
children));
|
|
109
149
|
return (React.createElement(CSSTransition, { in: isOpen, classNames: 'iui-dialog-animation', timeout: { exit: 600 }, unmountOnExit: true, nodeRef: dialogRef },
|
|
110
|
-
React.createElement(
|
|
150
|
+
React.createElement(DialogDragContext.Provider, { value: { onPointerDown: handlePointerDown } },
|
|
111
151
|
trapFocus && React.createElement(FocusTrap, null, content),
|
|
112
152
|
!trapFocus && content)));
|
|
113
153
|
});
|
|
@@ -10,7 +10,7 @@ export declare type DialogTitleBarProps = {
|
|
|
10
10
|
* Dialog title.
|
|
11
11
|
*/
|
|
12
12
|
titleText?: React.ReactNode;
|
|
13
|
-
} & Pick<DialogContextProps, 'isDismissible' | 'onClose'> & React.ComponentPropsWithRef<'div'>;
|
|
13
|
+
} & Pick<DialogContextProps, 'isDismissible' | 'onClose' | 'isDraggable'> & React.ComponentPropsWithRef<'div'>;
|
|
14
14
|
/**
|
|
15
15
|
* Dialog title bar. Recommended to be used as a child of `Dialog`.
|
|
16
16
|
* @example
|
|
@@ -28,7 +28,7 @@ export declare type DialogTitleBarProps = {
|
|
|
28
28
|
* </IconButton>
|
|
29
29
|
* </Dialog.TitleBar>
|
|
30
30
|
*/
|
|
31
|
-
export declare const DialogTitleBar: React.ForwardRefExoticComponent<Pick<DialogTitleBarProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "isDismissible" | "titleText"> & React.RefAttributes<HTMLDivElement>> & {
|
|
31
|
+
export declare const DialogTitleBar: React.ForwardRefExoticComponent<Pick<DialogTitleBarProps, "onClose" | "key" | keyof React.HTMLAttributes<HTMLDivElement> | "isDismissible" | "isDraggable" | "titleText"> & React.RefAttributes<HTMLDivElement>> & {
|
|
32
32
|
Title: React.ForwardRefExoticComponent<Pick<import("./DialogTitleBarTitle").DialogTitleBarTitleProps, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & React.RefAttributes<HTMLDivElement>>;
|
|
33
33
|
};
|
|
34
34
|
export default DialogTitleBar;
|
|
@@ -32,6 +32,7 @@ import { IconButton } from '../Buttons';
|
|
|
32
32
|
import '@itwin/itwinui-css/css/dialog.css';
|
|
33
33
|
import { useDialogContext } from './DialogContext';
|
|
34
34
|
import { DialogTitleBarTitle } from './DialogTitleBarTitle';
|
|
35
|
+
import { useDialogDragContext } from './DialogDragContext';
|
|
35
36
|
/**
|
|
36
37
|
* Dialog title bar. Recommended to be used as a child of `Dialog`.
|
|
37
38
|
* @example
|
|
@@ -51,9 +52,18 @@ import { DialogTitleBarTitle } from './DialogTitleBarTitle';
|
|
|
51
52
|
*/
|
|
52
53
|
export var DialogTitleBar = Object.assign(React.forwardRef(function (props, ref) {
|
|
53
54
|
var dialogContext = useDialogContext();
|
|
54
|
-
var children = props.children, titleText = props.titleText, _a = props.isDismissible, isDismissible = _a === void 0 ? dialogContext.isDismissible : _a, _b = props.onClose, onClose = _b === void 0 ? dialogContext.onClose : _b, className = props.className, rest = __rest(props, ["children", "titleText", "isDismissible", "onClose", "className"]);
|
|
55
|
+
var children = props.children, titleText = props.titleText, _a = props.isDismissible, isDismissible = _a === void 0 ? dialogContext.isDismissible : _a, _b = props.onClose, onClose = _b === void 0 ? dialogContext.onClose : _b, _c = props.isDraggable, isDraggable = _c === void 0 ? dialogContext.isDraggable : _c, className = props.className, onPointerDownProp = props.onPointerDown, rest = __rest(props, ["children", "titleText", "isDismissible", "onClose", "isDraggable", "className", "onPointerDown"]);
|
|
56
|
+
var onPointerDown = useDialogDragContext().onPointerDown;
|
|
57
|
+
var handlePointerDown = React.useCallback(function (event) {
|
|
58
|
+
onPointerDownProp === null || onPointerDownProp === void 0 ? void 0 : onPointerDownProp(event);
|
|
59
|
+
if (!event.defaultPrevented) {
|
|
60
|
+
onPointerDown === null || onPointerDown === void 0 ? void 0 : onPointerDown(event);
|
|
61
|
+
}
|
|
62
|
+
}, [onPointerDown, onPointerDownProp]);
|
|
55
63
|
useTheme();
|
|
56
|
-
return (React.createElement("div", __assign({ className: cx('iui-dialog-title-bar', className
|
|
64
|
+
return (React.createElement("div", __assign({ className: cx('iui-dialog-title-bar', className, {
|
|
65
|
+
'iui-dialog-title-bar-filled': isDraggable,
|
|
66
|
+
}), ref: ref, onPointerDown: handlePointerDown }, rest), children ? (children) : (React.createElement(React.Fragment, null,
|
|
57
67
|
React.createElement(DialogTitleBarTitle, null, titleText),
|
|
58
68
|
isDismissible && (React.createElement(IconButton, { size: 'small', styleType: 'borderless', onClick: onClose, "aria-label": 'Close' },
|
|
59
69
|
React.createElement(SvgClose, null)))))));
|
package/esm/core/Modal/Modal.js
CHANGED
|
@@ -54,7 +54,7 @@ export var Modal = function (props) {
|
|
|
54
54
|
var _a = props.isOpen, isOpen = _a === void 0 ? false : _a, _b = props.isDismissible, isDismissible = _b === void 0 ? true : _b, _c = props.closeOnEsc, closeOnEsc = _c === void 0 ? true : _c, _d = props.closeOnExternalClick, closeOnExternalClick = _d === void 0 ? true : _d, onClose = props.onClose, title = props.title, children = props.children, _e = props.modalRootId, modalRootId = _e === void 0 ? 'iui-react-portal-container' : _e, _f = props.ownerDocument, ownerDocument = _f === void 0 ? getDocument() : _f, rest = __rest(props, ["isOpen", "isDismissible", "closeOnEsc", "closeOnExternalClick", "onClose", "title", "children", "modalRootId", "ownerDocument"]);
|
|
55
55
|
useTheme();
|
|
56
56
|
var container = getContainer(modalRootId, ownerDocument);
|
|
57
|
-
return !!container ? (ReactDOM.createPortal(React.createElement(Dialog, { isOpen: isOpen, closeOnEsc: closeOnEsc, closeOnExternalClick: closeOnExternalClick, isDismissible: isDismissible, onClose: onClose, preventDocumentScroll: true, trapFocus: true },
|
|
57
|
+
return !!container ? (ReactDOM.createPortal(React.createElement(Dialog, { isOpen: isOpen, closeOnEsc: closeOnEsc, closeOnExternalClick: closeOnExternalClick, isDismissible: isDismissible, onClose: onClose, preventDocumentScroll: true, trapFocus: true, setFocus: true },
|
|
58
58
|
React.createElement(Dialog.Backdrop, null),
|
|
59
59
|
React.createElement(Dialog.Main, __assign({ "aria-modal": true }, rest),
|
|
60
60
|
React.createElement(Dialog.TitleBar, { titleText: title }),
|
|
@@ -116,6 +116,12 @@ export declare type TableProps<T extends Record<string, unknown> = Record<string
|
|
|
116
116
|
* Must be memoized.
|
|
117
117
|
*/
|
|
118
118
|
onFilter?: (filters: TableFilterValue<T>[], state: TableState<T>) => void;
|
|
119
|
+
/**
|
|
120
|
+
* Value used for global filtering.
|
|
121
|
+
* Use with `globalFilter` and/or `manualGlobalFilter` to handle filtering yourself e.g. filter in server-side.
|
|
122
|
+
* Must be memoized.
|
|
123
|
+
*/
|
|
124
|
+
globalFilterValue?: unknown;
|
|
119
125
|
/**
|
|
120
126
|
* Content shown when there is no data after filtering.
|
|
121
127
|
*/
|