@itwin/itwinui-react 1.44.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.
- package/CHANGELOG.md +27 -0
- package/README.md +2 -2
- 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 +9 -1
- package/cjs/core/Table/Table.js +51 -6
- package/cjs/core/Table/TableRowMemoized.d.ts +10 -2
- package/cjs/core/Table/TableRowMemoized.js +23 -7
- 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/cells/DefaultCell.d.ts +14 -1
- package/cjs/core/Table/cells/DefaultCell.js +10 -4
- package/cjs/core/index.d.ts +3 -1
- package/cjs/core/index.js +6 -3
- package/cjs/core/utils/components/MiddleTextTruncation.d.ts +15 -1
- package/cjs/core/utils/components/MiddleTextTruncation.js +14 -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 +2 -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 +9 -1
- package/esm/core/Table/Table.js +53 -8
- package/esm/core/Table/TableRowMemoized.d.ts +10 -2
- package/esm/core/Table/TableRowMemoized.js +23 -7
- 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/cells/DefaultCell.d.ts +14 -1
- package/esm/core/Table/cells/DefaultCell.js +10 -4
- package/esm/core/index.d.ts +3 -1
- package/esm/core/index.js +2 -1
- package/esm/core/utils/components/MiddleTextTruncation.d.ts +15 -1
- package/esm/core/utils/components/MiddleTextTruncation.js +14 -3
- 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 +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useDragAndDrop = void 0;
|
|
7
|
+
/*---------------------------------------------------------------------------------------------
|
|
8
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
9
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
10
|
+
*--------------------------------------------------------------------------------------------*/
|
|
11
|
+
var react_1 = __importDefault(require("react"));
|
|
12
|
+
var functions_1 = require("../functions");
|
|
13
|
+
var useEventListener_1 = require("./useEventListener");
|
|
14
|
+
var useResizeObserver_1 = require("./useResizeObserver");
|
|
15
|
+
var getContainerRect = function (containerRef) {
|
|
16
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
17
|
+
var containerRect = (_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
18
|
+
return {
|
|
19
|
+
top: (_b = containerRect === null || containerRect === void 0 ? void 0 : containerRect.top) !== null && _b !== void 0 ? _b : 0,
|
|
20
|
+
right: (_e = (_c = containerRect === null || containerRect === void 0 ? void 0 : containerRect.right) !== null && _c !== void 0 ? _c : (_d = (0, functions_1.getWindow)()) === null || _d === void 0 ? void 0 : _d.innerWidth) !== null && _e !== void 0 ? _e : 0,
|
|
21
|
+
bottom: (_h = (_f = containerRect === null || containerRect === void 0 ? void 0 : containerRect.bottom) !== null && _f !== void 0 ? _f : (_g = (0, functions_1.getWindow)()) === null || _g === void 0 ? void 0 : _g.innerHeight) !== null && _h !== void 0 ? _h : 0,
|
|
22
|
+
left: (_j = containerRect === null || containerRect === void 0 ? void 0 : containerRect.left) !== null && _j !== void 0 ? _j : 0,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Helper hook that handles elements drag logic.
|
|
27
|
+
* @param elementRef Element ref that is draggable.
|
|
28
|
+
* @param containerRect Bounding rectangle of container element that element can't go outside. If not passed window is used as a container.
|
|
29
|
+
* @returns
|
|
30
|
+
* `onPointerDown` - handler that is called when pointer is down and handles all the dragging logic.
|
|
31
|
+
* `transform` - current transform of the element, it is used to preserve drag position when element visibility is being toggled.
|
|
32
|
+
*/
|
|
33
|
+
var useDragAndDrop = function (elementRef, containerRef, enabled) {
|
|
34
|
+
if (enabled === void 0) { enabled = true; }
|
|
35
|
+
var grabOffsetX = react_1.default.useRef(0);
|
|
36
|
+
var grabOffsetY = react_1.default.useRef(0);
|
|
37
|
+
var translateX = react_1.default.useRef();
|
|
38
|
+
var translateY = react_1.default.useRef();
|
|
39
|
+
var containerRectRef = react_1.default.useRef(getContainerRect(containerRef));
|
|
40
|
+
var adjustTransform = react_1.default.useCallback(function () {
|
|
41
|
+
var _a;
|
|
42
|
+
if (!elementRef.current || !enabled) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
var _b = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect(), top = _b.top, right = _b.right, bottom = _b.bottom, left = _b.left;
|
|
46
|
+
var _c = (0, functions_1.getTranslateValues)(elementRef.current), newTranslateX = _c[0], newTranslateY = _c[1];
|
|
47
|
+
containerRectRef.current = getContainerRect(containerRef);
|
|
48
|
+
if (bottom > containerRectRef.current.bottom) {
|
|
49
|
+
newTranslateY -= bottom - containerRectRef.current.bottom;
|
|
50
|
+
}
|
|
51
|
+
if (top < containerRectRef.current.top) {
|
|
52
|
+
newTranslateY += containerRectRef.current.top - top;
|
|
53
|
+
}
|
|
54
|
+
if (right > containerRectRef.current.right) {
|
|
55
|
+
newTranslateX -= right - containerRectRef.current.right;
|
|
56
|
+
}
|
|
57
|
+
if (left < containerRectRef.current.left) {
|
|
58
|
+
newTranslateX += containerRectRef.current.left - left;
|
|
59
|
+
}
|
|
60
|
+
translateX.current = newTranslateX;
|
|
61
|
+
translateY.current = newTranslateY;
|
|
62
|
+
elementRef.current.style.transform = "translate(".concat(newTranslateX, "px, ").concat(newTranslateY, "px)");
|
|
63
|
+
}, [containerRef, elementRef, enabled]);
|
|
64
|
+
var _a = (0, useResizeObserver_1.useResizeObserver)(adjustTransform), resizeRef = _a[0], resizeObserver = _a[1];
|
|
65
|
+
resizeRef(containerRef === null || containerRef === void 0 ? void 0 : containerRef.current);
|
|
66
|
+
react_1.default.useEffect(function () {
|
|
67
|
+
return function () {
|
|
68
|
+
resizeObserver === null || resizeObserver === void 0 ? void 0 : resizeObserver.disconnect();
|
|
69
|
+
};
|
|
70
|
+
}, [resizeObserver]);
|
|
71
|
+
(0, useEventListener_1.useEventListener)('resize', function () {
|
|
72
|
+
adjustTransform();
|
|
73
|
+
if (translateX.current != null && translateY.current != null) {
|
|
74
|
+
setTransform("translate(".concat(translateX.current, "px, ").concat(translateY.current, "px)"));
|
|
75
|
+
}
|
|
76
|
+
}, (0, functions_1.getWindow)());
|
|
77
|
+
var _b = react_1.default.useState(''), transform = _b[0], setTransform = _b[1];
|
|
78
|
+
var onPointerMove = react_1.default.useRef(function (event) {
|
|
79
|
+
if (!elementRef.current) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
var newTranslateX = event.clientX - grabOffsetX.current;
|
|
83
|
+
var newTranslateY = event.clientY - grabOffsetY.current;
|
|
84
|
+
elementRef.current.style.transform = "translate(".concat(newTranslateX, "px, ").concat(newTranslateY, "px)");
|
|
85
|
+
adjustTransform();
|
|
86
|
+
});
|
|
87
|
+
var originalUserSelect = react_1.default.useRef('');
|
|
88
|
+
var onPointerDown = react_1.default.useCallback(function (e) {
|
|
89
|
+
if (!elementRef.current || e.button !== 0 || !enabled) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
var _a = (0, functions_1.getTranslateValues)(elementRef.current), x = _a[0], y = _a[1];
|
|
93
|
+
grabOffsetX.current = e.clientX - x;
|
|
94
|
+
grabOffsetY.current = e.clientY - y;
|
|
95
|
+
originalUserSelect.current = elementRef.current.style.userSelect;
|
|
96
|
+
// Prevents from selecting inner content when dragging.
|
|
97
|
+
elementRef.current.style.userSelect = 'none';
|
|
98
|
+
elementRef.current.ownerDocument.addEventListener('pointermove', onPointerMove.current);
|
|
99
|
+
elementRef.current.ownerDocument.addEventListener('pointerup', function () {
|
|
100
|
+
setTransform("translate(".concat(translateX.current, "px, ").concat(translateY.current, "px)"));
|
|
101
|
+
document.removeEventListener('pointermove', onPointerMove.current);
|
|
102
|
+
if (elementRef.current) {
|
|
103
|
+
elementRef.current.style.userSelect = originalUserSelect.current;
|
|
104
|
+
}
|
|
105
|
+
}, { once: true });
|
|
106
|
+
}, [elementRef, enabled]);
|
|
107
|
+
return { onPointerDown: onPointerDown, transform: transform };
|
|
108
|
+
};
|
|
109
|
+
exports.useDragAndDrop = useDragAndDrop;
|
|
110
|
+
exports.default = exports.useDragAndDrop;
|
|
@@ -7,4 +7,4 @@
|
|
|
7
7
|
* containerRef.current?.ownerDocument,
|
|
8
8
|
* );
|
|
9
9
|
*/
|
|
10
|
-
export declare const useEventListener: (eventName: string, handler: (event: Event) => void, element: HTMLElement | Document | undefined) => void;
|
|
10
|
+
export declare const useEventListener: (eventName: string, handler: (event: Event) => void, element: HTMLElement | Document | Window | undefined) => void;
|
|
@@ -21,4 +21,4 @@ import React from 'react';
|
|
|
21
21
|
* </div>
|
|
22
22
|
* );
|
|
23
23
|
*/
|
|
24
|
-
export declare const useOverflow: <T extends HTMLElement>(items: React.ReactNode[] | string, disabled?: boolean, orientation?: 'horizontal' | 'vertical') => readonly [(instance: T | null) => void, number];
|
|
24
|
+
export declare const useOverflow: <T extends HTMLElement>(items: React.ReactNode[] | string, disabled?: boolean, orientation?: 'horizontal' | 'vertical') => readonly [(instance: T | null | undefined) => void, number];
|
|
@@ -10,4 +10,4 @@
|
|
|
10
10
|
* ...
|
|
11
11
|
* return <div ref={ref}>...</div>;
|
|
12
12
|
*/
|
|
13
|
-
export declare const useResizeObserver: <T extends HTMLElement>(onResize: (size: DOMRectReadOnly) => void) => readonly [(element: T | null) => void, ResizeObserver | undefined];
|
|
13
|
+
export declare const useResizeObserver: <T extends HTMLElement>(onResize: (size: DOMRectReadOnly) => void) => readonly [(element: T | null | undefined) => void, ResizeObserver | undefined];
|
|
@@ -19,7 +19,7 @@ declare module 'react-table' {
|
|
|
19
19
|
*/
|
|
20
20
|
isDisabled?: (rowData: D) => boolean;
|
|
21
21
|
};
|
|
22
|
-
interface TableOptions<D extends object = {}> extends Omit<UseTableOptions<D>, 'data'>, UseRowSelectOptions<D>, UseExpandedOptions<D>, UseFiltersOptions<D>, UsePaginationOptions<D>, Omit<UseResizeColumnsOptions<D>, 'disableResizing'>, UseSortByOptions<D> {
|
|
22
|
+
interface TableOptions<D extends object = {}> extends Omit<UseTableOptions<D>, 'data'>, UseRowSelectOptions<D>, UseExpandedOptions<D>, UseFiltersOptions<D>, UsePaginationOptions<D>, UseGlobalFiltersOptions<D>, UseGlobalFiltersColumnOptions<D>, Omit<UseResizeColumnsOptions<D>, 'disableResizing'>, UseSortByOptions<D> {
|
|
23
23
|
/**
|
|
24
24
|
* Table data list.
|
|
25
25
|
* Must be memoized.
|
|
@@ -50,6 +50,7 @@ declare module 'react-table' {
|
|
|
50
50
|
isScrolledToRight?: boolean;
|
|
51
51
|
isScrolledToLeft?: boolean;
|
|
52
52
|
};
|
|
53
|
+
lastSelectedRowId?: string;
|
|
53
54
|
}
|
|
54
55
|
interface ColumnInterface<D extends object = {}> extends UseSortByColumnOptions<D>, UseFiltersColumnOptions<D>, UseResizeColumnsColumnOptions<D> {
|
|
55
56
|
/**
|
|
@@ -16,6 +16,64 @@ export declare type BreadcrumbsProps = {
|
|
|
16
16
|
* Defaults to the `SvgChevronRight` icon.
|
|
17
17
|
*/
|
|
18
18
|
separator?: React.ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* If specified, this prop will be used to show a custom button when overflow happens,
|
|
21
|
+
* i.e. when there is not enough space to fit all the breadcrumbs.
|
|
22
|
+
*
|
|
23
|
+
* Expects a function that takes the number of items that are visible
|
|
24
|
+
* and returns the `ReactNode` to render.
|
|
25
|
+
*
|
|
26
|
+
* @example <caption>Uses the overflow button to redirect to the previous breadcrumb</caption>
|
|
27
|
+
* <Breadcrumbs
|
|
28
|
+
* overflowButton={(visibleCount: number) => {
|
|
29
|
+
* const previousBreadcrumb = visibleCount > 1 ? items.length - visibleCount : items.length - 2;
|
|
30
|
+
* return (
|
|
31
|
+
* <Tooltip content={`Item ${previousBreadcrumb}`} placement='bottom'>
|
|
32
|
+
* <IconButton
|
|
33
|
+
* onClick={() => {
|
|
34
|
+
* // click on "previousBreadcrumb"
|
|
35
|
+
* }}
|
|
36
|
+
* >
|
|
37
|
+
* <SvgMoreSmall />
|
|
38
|
+
* </IconButton>
|
|
39
|
+
* </Tooltip>
|
|
40
|
+
* );
|
|
41
|
+
* }}
|
|
42
|
+
* >
|
|
43
|
+
* {items}
|
|
44
|
+
* </Breadcrumbs>
|
|
45
|
+
*
|
|
46
|
+
* @example <caption>Uses the overflow button to add a dropdown that contains hidden breadcrumbs</caption>
|
|
47
|
+
* <Breadcrumbs
|
|
48
|
+
* overflowButton={(visibleCount) => (
|
|
49
|
+
* <DropdownMenu
|
|
50
|
+
* menuItems={(close) =>
|
|
51
|
+
* Array(items.length - visibleCount)
|
|
52
|
+
* .fill(null)
|
|
53
|
+
* .map((_, _index) => {
|
|
54
|
+
* const index = visibleCount > 1 ? _index + 1 : _index;
|
|
55
|
+
* const onClick = () => {
|
|
56
|
+
* // click on "index" breadcrumb
|
|
57
|
+
* close();
|
|
58
|
+
* };
|
|
59
|
+
* return (
|
|
60
|
+
* <MenuItem key={index} onClick={onClick}>
|
|
61
|
+
* Item {index}
|
|
62
|
+
* </MenuItem>
|
|
63
|
+
* );
|
|
64
|
+
* })
|
|
65
|
+
* }
|
|
66
|
+
* >
|
|
67
|
+
* <IconButton>
|
|
68
|
+
* <SvgMoreSmall />
|
|
69
|
+
* </IconButton>
|
|
70
|
+
* </DropdownMenu>
|
|
71
|
+
* )}
|
|
72
|
+
* >
|
|
73
|
+
* {items}
|
|
74
|
+
* </Breadcrumbs>
|
|
75
|
+
*/
|
|
76
|
+
overflowButton?: (visibleCount: number) => React.ReactNode;
|
|
19
77
|
} & Omit<CommonProps, 'title'>;
|
|
20
78
|
/**
|
|
21
79
|
* A breadcrumb trail is used as a navigational aid to help users keep track
|
|
@@ -54,5 +112,63 @@ export declare const Breadcrumbs: React.ForwardRefExoticComponent<{
|
|
|
54
112
|
* Defaults to the `SvgChevronRight` icon.
|
|
55
113
|
*/
|
|
56
114
|
separator?: React.ReactNode;
|
|
115
|
+
/**
|
|
116
|
+
* If specified, this prop will be used to show a custom button when overflow happens,
|
|
117
|
+
* i.e. when there is not enough space to fit all the breadcrumbs.
|
|
118
|
+
*
|
|
119
|
+
* Expects a function that takes the number of items that are visible
|
|
120
|
+
* and returns the `ReactNode` to render.
|
|
121
|
+
*
|
|
122
|
+
* @example <caption>Uses the overflow button to redirect to the previous breadcrumb</caption>
|
|
123
|
+
* <Breadcrumbs
|
|
124
|
+
* overflowButton={(visibleCount: number) => {
|
|
125
|
+
* const previousBreadcrumb = visibleCount > 1 ? items.length - visibleCount : items.length - 2;
|
|
126
|
+
* return (
|
|
127
|
+
* <Tooltip content={`Item ${previousBreadcrumb}`} placement='bottom'>
|
|
128
|
+
* <IconButton
|
|
129
|
+
* onClick={() => {
|
|
130
|
+
* // click on "previousBreadcrumb"
|
|
131
|
+
* }}
|
|
132
|
+
* >
|
|
133
|
+
* <SvgMoreSmall />
|
|
134
|
+
* </IconButton>
|
|
135
|
+
* </Tooltip>
|
|
136
|
+
* );
|
|
137
|
+
* }}
|
|
138
|
+
* >
|
|
139
|
+
* {items}
|
|
140
|
+
* </Breadcrumbs>
|
|
141
|
+
*
|
|
142
|
+
* @example <caption>Uses the overflow button to add a dropdown that contains hidden breadcrumbs</caption>
|
|
143
|
+
* <Breadcrumbs
|
|
144
|
+
* overflowButton={(visibleCount) => (
|
|
145
|
+
* <DropdownMenu
|
|
146
|
+
* menuItems={(close) =>
|
|
147
|
+
* Array(items.length - visibleCount)
|
|
148
|
+
* .fill(null)
|
|
149
|
+
* .map((_, _index) => {
|
|
150
|
+
* const index = visibleCount > 1 ? _index + 1 : _index;
|
|
151
|
+
* const onClick = () => {
|
|
152
|
+
* // click on "index" breadcrumb
|
|
153
|
+
* close();
|
|
154
|
+
* };
|
|
155
|
+
* return (
|
|
156
|
+
* <MenuItem key={index} onClick={onClick}>
|
|
157
|
+
* Item {index}
|
|
158
|
+
* </MenuItem>
|
|
159
|
+
* );
|
|
160
|
+
* })
|
|
161
|
+
* }
|
|
162
|
+
* >
|
|
163
|
+
* <IconButton>
|
|
164
|
+
* <SvgMoreSmall />
|
|
165
|
+
* </IconButton>
|
|
166
|
+
* </DropdownMenu>
|
|
167
|
+
* )}
|
|
168
|
+
* >
|
|
169
|
+
* {items}
|
|
170
|
+
* </Breadcrumbs>
|
|
171
|
+
*/
|
|
172
|
+
overflowButton?: ((visibleCount: number) => React.ReactNode) | undefined;
|
|
57
173
|
} & Omit<CommonProps, "title"> & React.RefAttributes<HTMLElement>>;
|
|
58
174
|
export default Breadcrumbs;
|
|
@@ -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" | "
|
|
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
|
|
13
|
+
export declare type DateRangePickerProps = {
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Enable date range support.
|
|
16
|
+
* @default false
|
|
16
17
|
*/
|
|
17
|
-
|
|
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,
|
|
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>>;
|