@itwin/itwinui-react 3.7.4 → 3.8.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 +11 -0
- package/cjs/core/Carousel/Carousel.d.ts +4 -4
- package/cjs/core/Carousel/CarouselNavigation.d.ts +4 -4
- package/cjs/core/LabeledSelect/LabeledSelect.d.ts +2 -2
- package/cjs/core/Popover/Popover.d.ts +2 -2
- package/cjs/core/Table/Table.js +1 -1
- package/cjs/core/Table/cells/DefaultCell.d.ts +2 -1
- package/cjs/core/Table/cells/DefaultCell.js +6 -1
- package/cjs/core/Table/utils.d.ts +3 -1
- package/cjs/core/Table/utils.js +30 -1
- package/cjs/core/ThemeProvider/ThemeProvider.js +8 -7
- package/cjs/core/Tile/Tile.d.ts +2 -2
- package/cjs/core/VisuallyHidden/VisuallyHidden.js +2 -2
- package/cjs/core/utils/components/ShadowRoot.js +26 -24
- package/cjs/core/utils/hooks/index.d.ts +1 -0
- package/cjs/core/utils/hooks/index.js +1 -0
- package/cjs/core/utils/hooks/useMediaQuery.d.ts +1 -1
- package/cjs/core/utils/hooks/useMediaQuery.js +11 -26
- package/cjs/core/utils/hooks/useSyncExternalStore.d.ts +5 -0
- package/cjs/core/utils/hooks/useSyncExternalStore.js +68 -0
- package/cjs/core/utils/index.d.ts +1 -0
- package/cjs/core/utils/index.js +1 -0
- package/cjs/core/utils/providers/HydrationProvider.d.ts +16 -0
- package/cjs/core/utils/providers/HydrationProvider.js +75 -0
- package/cjs/core/utils/providers/index.d.ts +1 -0
- package/cjs/core/utils/providers/index.js +21 -0
- package/esm/core/Carousel/Carousel.d.ts +4 -4
- package/esm/core/Carousel/CarouselNavigation.d.ts +4 -4
- package/esm/core/LabeledSelect/LabeledSelect.d.ts +2 -2
- package/esm/core/Popover/Popover.d.ts +2 -2
- package/esm/core/Table/Table.js +2 -2
- package/esm/core/Table/cells/DefaultCell.d.ts +2 -1
- package/esm/core/Table/cells/DefaultCell.js +6 -1
- package/esm/core/Table/utils.d.ts +3 -1
- package/esm/core/Table/utils.js +6 -0
- package/esm/core/ThemeProvider/ThemeProvider.js +9 -8
- package/esm/core/Tile/Tile.d.ts +2 -2
- package/esm/core/VisuallyHidden/VisuallyHidden.js +3 -3
- package/esm/core/utils/components/ShadowRoot.js +26 -24
- package/esm/core/utils/hooks/index.d.ts +1 -0
- package/esm/core/utils/hooks/index.js +1 -0
- package/esm/core/utils/hooks/useMediaQuery.d.ts +1 -1
- package/esm/core/utils/hooks/useMediaQuery.js +11 -26
- package/esm/core/utils/hooks/useSyncExternalStore.d.ts +5 -0
- package/esm/core/utils/hooks/useSyncExternalStore.js +42 -0
- package/esm/core/utils/index.d.ts +1 -0
- package/esm/core/utils/index.js +1 -0
- package/esm/core/utils/providers/HydrationProvider.d.ts +16 -0
- package/esm/core/utils/providers/HydrationProvider.js +47 -0
- package/esm/core/utils/providers/index.d.ts +1 -0
- package/esm/core/utils/providers/index.js +5 -0
- package/package.json +2 -2
- package/styles.css +1 -677
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/*---------------------------------------------------------------------------------------------
|
|
18
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
19
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
20
|
+
*--------------------------------------------------------------------------------------------*/
|
|
21
|
+
__exportStar(require("./HydrationProvider.js"), exports);
|
|
@@ -48,7 +48,7 @@ export declare const Carousel: PolymorphicForwardRefComponent<"section", Carouse
|
|
|
48
48
|
labelProps?: Omit<Omit<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
49
49
|
ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
|
|
50
50
|
}, "as" | "children" | "content" | "portal" | keyof {
|
|
51
|
-
placement?: import("@floating-ui/
|
|
51
|
+
placement?: import("@floating-ui/utils").Placement | undefined;
|
|
52
52
|
visible?: boolean | undefined;
|
|
53
53
|
onVisibleChange?: ((visible: boolean) => void) | undefined;
|
|
54
54
|
autoUpdateOptions?: {
|
|
@@ -74,7 +74,7 @@ export declare const Carousel: PolymorphicForwardRefComponent<"section", Carouse
|
|
|
74
74
|
content: React.ReactNode;
|
|
75
75
|
children?: React.ReactNode;
|
|
76
76
|
} & import("../utils/index.js").PortalProps & {
|
|
77
|
-
placement?: import("@floating-ui/
|
|
77
|
+
placement?: import("@floating-ui/utils").Placement | undefined;
|
|
78
78
|
visible?: boolean | undefined;
|
|
79
79
|
onVisibleChange?: ((visible: boolean) => void) | undefined;
|
|
80
80
|
autoUpdateOptions?: {
|
|
@@ -111,7 +111,7 @@ export declare const Carousel: PolymorphicForwardRefComponent<"section", Carouse
|
|
|
111
111
|
labelProps?: Omit<Omit<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
112
112
|
ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
|
|
113
113
|
}, "as" | "children" | "content" | "portal" | keyof {
|
|
114
|
-
placement?: import("@floating-ui/
|
|
114
|
+
placement?: import("@floating-ui/utils").Placement | undefined;
|
|
115
115
|
visible?: boolean | undefined;
|
|
116
116
|
onVisibleChange?: ((visible: boolean) => void) | undefined;
|
|
117
117
|
autoUpdateOptions?: {
|
|
@@ -137,7 +137,7 @@ export declare const Carousel: PolymorphicForwardRefComponent<"section", Carouse
|
|
|
137
137
|
content: React.ReactNode;
|
|
138
138
|
children?: React.ReactNode;
|
|
139
139
|
} & import("../utils/index.js").PortalProps & {
|
|
140
|
-
placement?: import("@floating-ui/
|
|
140
|
+
placement?: import("@floating-ui/utils").Placement | undefined;
|
|
141
141
|
visible?: boolean | undefined;
|
|
142
142
|
onVisibleChange?: ((visible: boolean) => void) | undefined;
|
|
143
143
|
autoUpdateOptions?: {
|
|
@@ -15,7 +15,7 @@ export declare const CarouselNavigation: PolymorphicForwardRefComponent<"div", {
|
|
|
15
15
|
labelProps?: Omit<Omit<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
16
16
|
ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
|
|
17
17
|
}, "as" | "children" | "content" | "portal" | keyof {
|
|
18
|
-
placement?: import("@floating-ui/
|
|
18
|
+
placement?: import("@floating-ui/utils").Placement | undefined;
|
|
19
19
|
visible?: boolean | undefined;
|
|
20
20
|
onVisibleChange?: ((visible: boolean) => void) | undefined;
|
|
21
21
|
autoUpdateOptions?: {
|
|
@@ -41,7 +41,7 @@ export declare const CarouselNavigation: PolymorphicForwardRefComponent<"div", {
|
|
|
41
41
|
content: React.ReactNode;
|
|
42
42
|
children?: React.ReactNode;
|
|
43
43
|
} & import("../utils/index.js").PortalProps & {
|
|
44
|
-
placement?: import("@floating-ui/
|
|
44
|
+
placement?: import("@floating-ui/utils").Placement | undefined;
|
|
45
45
|
visible?: boolean | undefined;
|
|
46
46
|
onVisibleChange?: ((visible: boolean) => void) | undefined;
|
|
47
47
|
autoUpdateOptions?: {
|
|
@@ -78,7 +78,7 @@ export declare const CarouselNavigation: PolymorphicForwardRefComponent<"div", {
|
|
|
78
78
|
labelProps?: Omit<Omit<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
79
79
|
ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
|
|
80
80
|
}, "as" | "children" | "content" | "portal" | keyof {
|
|
81
|
-
placement?: import("@floating-ui/
|
|
81
|
+
placement?: import("@floating-ui/utils").Placement | undefined;
|
|
82
82
|
visible?: boolean | undefined;
|
|
83
83
|
onVisibleChange?: ((visible: boolean) => void) | undefined;
|
|
84
84
|
autoUpdateOptions?: {
|
|
@@ -104,7 +104,7 @@ export declare const CarouselNavigation: PolymorphicForwardRefComponent<"div", {
|
|
|
104
104
|
content: React.ReactNode;
|
|
105
105
|
children?: React.ReactNode;
|
|
106
106
|
} & import("../utils/index.js").PortalProps & {
|
|
107
|
-
placement?: import("@floating-ui/
|
|
107
|
+
placement?: import("@floating-ui/utils").Placement | undefined;
|
|
108
108
|
visible?: boolean | undefined;
|
|
109
109
|
onVisibleChange?: ((visible: boolean) => void) | undefined;
|
|
110
110
|
autoUpdateOptions?: {
|
|
@@ -297,7 +297,7 @@ export declare const LabeledSelect: <T>(props: ({
|
|
|
297
297
|
menuClassName?: string | undefined;
|
|
298
298
|
menuStyle?: React.CSSProperties | undefined;
|
|
299
299
|
popoverProps?: Pick<{
|
|
300
|
-
placement?: import("@floating-ui/
|
|
300
|
+
placement?: import("@floating-ui/utils").Placement | undefined;
|
|
301
301
|
visible?: boolean | undefined;
|
|
302
302
|
onVisibleChange?: ((visible: boolean) => void) | undefined;
|
|
303
303
|
closeOnOutsideClick?: boolean | undefined;
|
|
@@ -427,7 +427,7 @@ export declare const LabeledSelect: <T>(props: ({
|
|
|
427
427
|
menuClassName?: string | undefined;
|
|
428
428
|
menuStyle?: React.CSSProperties | undefined;
|
|
429
429
|
popoverProps?: Pick<{
|
|
430
|
-
placement?: import("@floating-ui/
|
|
430
|
+
placement?: import("@floating-ui/utils").Placement | undefined;
|
|
431
431
|
visible?: boolean | undefined;
|
|
432
432
|
onVisibleChange?: ((visible: boolean) => void) | undefined;
|
|
433
433
|
closeOnOutsideClick?: boolean | undefined;
|
|
@@ -71,7 +71,7 @@ type PopoverInternalProps = {
|
|
|
71
71
|
};
|
|
72
72
|
export declare const usePopover: (options: PopoverOptions & PopoverInternalProps) => {
|
|
73
73
|
placement: Placement;
|
|
74
|
-
strategy: import("@floating-ui/
|
|
74
|
+
strategy: import("@floating-ui/utils").Strategy;
|
|
75
75
|
middlewareData: import("@floating-ui/core").MiddlewareData;
|
|
76
76
|
x: number;
|
|
77
77
|
y: number;
|
|
@@ -92,7 +92,7 @@ export declare const usePopover: (options: PopoverOptions & PopoverInternalProps
|
|
|
92
92
|
x: number;
|
|
93
93
|
y: number;
|
|
94
94
|
placement: Placement;
|
|
95
|
-
strategy: import("@floating-ui/
|
|
95
|
+
strategy: import("@floating-ui/utils").Strategy;
|
|
96
96
|
middlewareData: import("@floating-ui/core").MiddlewareData;
|
|
97
97
|
isPositioned: boolean;
|
|
98
98
|
update: () => void;
|
package/esm/core/Table/Table.js
CHANGED
|
@@ -7,7 +7,7 @@ import cx from 'classnames';
|
|
|
7
7
|
import { actions as TableActions, useFlexLayout, useFilters, useRowSelect, useSortBy, useTable, useExpanded, usePagination, useColumnOrder, useGlobalFilter, } from 'react-table';
|
|
8
8
|
import { ProgressRadial } from '../ProgressIndicators/ProgressRadial.js';
|
|
9
9
|
import { useGlobals, useResizeObserver, SvgSortDown, SvgSortUp, useLayoutEffect, Box, createWarningLogger, ShadowRoot, LineClamp, useMergedRefs, } from '../utils/index.js';
|
|
10
|
-
import { getCellStyle, getStickyStyle, getSubRowStyle } from './utils.js';
|
|
10
|
+
import { TableColumnsContext, getCellStyle, getStickyStyle, getSubRowStyle, } from './utils.js';
|
|
11
11
|
import { TableRowMemoized } from './TableRowMemoized.js';
|
|
12
12
|
import { FilterToggle } from './filters/index.js';
|
|
13
13
|
import { customFilterFunctions } from './filters/customFilterFunctions.js';
|
|
@@ -384,7 +384,7 @@ export const Table = (props) => {
|
|
|
384
384
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
385
385
|
}, []);
|
|
386
386
|
const isHeaderDirectClick = React.useRef(false);
|
|
387
|
-
return (React.createElement(
|
|
387
|
+
return (React.createElement(TableColumnsContext.Provider, { value: columns },
|
|
388
388
|
React.createElement(Box, { ref: useMergedRefs(tableRef, (element) => {
|
|
389
389
|
ownerDocument.current = element?.ownerDocument;
|
|
390
390
|
resizeRef(element);
|
|
@@ -16,7 +16,8 @@ export type DefaultCellProps<T extends Record<string, unknown>> = {
|
|
|
16
16
|
/**
|
|
17
17
|
* Should the contents of the cell be clamped after a certain number of lines?
|
|
18
18
|
*
|
|
19
|
-
* Will be enabled by default if the cell content is a string
|
|
19
|
+
* Will be enabled by default if the cell content is a string and a custom `Cell`
|
|
20
|
+
* is not specified in the column object.
|
|
20
21
|
*/
|
|
21
22
|
clamp?: boolean;
|
|
22
23
|
} & CellRendererProps<T> & React.ComponentPropsWithoutRef<'div'>;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import cx from 'classnames';
|
|
7
7
|
import { Box, LineClamp, ShadowRoot } from '../../utils/index.js';
|
|
8
|
+
import { TableColumnsContext } from '../utils.js';
|
|
8
9
|
/**
|
|
9
10
|
* Default cell.
|
|
10
11
|
* It should be passed to `cellRenderer`.
|
|
@@ -17,7 +18,11 @@ import { Box, LineClamp, ShadowRoot } from '../../utils/index.js';
|
|
|
17
18
|
* }
|
|
18
19
|
*/
|
|
19
20
|
export const DefaultCell = (props) => {
|
|
20
|
-
const
|
|
21
|
+
const columnsProp = React.useContext(TableColumnsContext);
|
|
22
|
+
const isCustomCell = React.useMemo(() => columnsProp
|
|
23
|
+
.find(({ id }) => props.cellProps.column.id === id)
|
|
24
|
+
?.hasOwnProperty('Cell'), [props.cellProps.column.id, columnsProp]);
|
|
25
|
+
const { cellElementProps: { className: cellElementClassName, style: cellElementStyle, ...cellElementProps }, children, startIcon, endIcon, cellProps, isDisabled, className, style, status, clamp = typeof cellProps.value === 'string' && !isCustomCell, ...rest } = props;
|
|
21
26
|
return (React.createElement(Box, { ...cellElementProps, ...rest, className: cx(cellElementClassName, className), "aria-disabled": isDisabled?.(cellProps.row.original) || undefined, "data-iui-status": status, style: { ...cellElementStyle, ...style } },
|
|
22
27
|
React.createElement(ShadowRoot, null,
|
|
23
28
|
React.createElement("slot", { name: 'start' }),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { ColumnInstance, Column } from '../../react-table/react-table.js';
|
|
2
3
|
export declare const getCellStyle: <T extends Record<string, unknown>>(column: ColumnInstance<T>, isTableResizing: boolean) => React.CSSProperties | undefined;
|
|
3
4
|
export declare const getStickyStyle: <T extends Record<string, unknown>>(column: ColumnInstance<T>, columnList: ColumnInstance<T>[]) => React.CSSProperties;
|
|
4
5
|
export declare const getSubRowStyle: ({ density, depth }: {
|
|
@@ -7,3 +8,4 @@ export declare const getSubRowStyle: ({ density, depth }: {
|
|
|
7
8
|
}) => {
|
|
8
9
|
paddingInlineStart: number;
|
|
9
10
|
};
|
|
11
|
+
export declare const TableColumnsContext: React.Context<Column[]>;
|
package/esm/core/Table/utils.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import * as React from 'react';
|
|
1
6
|
export const getCellStyle = (column, isTableResizing) => {
|
|
2
7
|
const style = {};
|
|
3
8
|
style.flex = `1 1 145px`;
|
|
@@ -59,3 +64,4 @@ export const getSubRowStyle = ({ density = 'default', depth = 1 }) => {
|
|
|
59
64
|
paddingInlineStart: cellPadding + depth * multiplier,
|
|
60
65
|
};
|
|
61
66
|
};
|
|
67
|
+
export const TableColumnsContext = React.createContext([]);
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import * as ReactDOM from 'react-dom';
|
|
7
7
|
import cx from 'classnames';
|
|
8
|
-
import { useMediaQuery, useMergedRefs, Box, useLayoutEffect, useControlledState, useLatestRef, importCss, isUnitTest, } from '../utils/index.js';
|
|
8
|
+
import { useMediaQuery, useMergedRefs, Box, useLayoutEffect, useControlledState, useLatestRef, importCss, isUnitTest, HydrationProvider, } from '../utils/index.js';
|
|
9
9
|
import { ThemeContext } from './ThemeContext.js';
|
|
10
10
|
import { ToastProvider, Toaster } from '../Toast/Toaster.js';
|
|
11
11
|
/**
|
|
@@ -56,13 +56,14 @@ export const ThemeProvider = React.forwardRef((props, forwardedRef) => {
|
|
|
56
56
|
// we do include all dependencies below, but we want to stringify the objects as they could be different on each render
|
|
57
57
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
58
|
[theme, JSON.stringify(themeOptions), portalContainer]);
|
|
59
|
-
return (React.createElement(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
React.createElement(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
React.createElement(Toaster, null)))
|
|
59
|
+
return (React.createElement(HydrationProvider, null,
|
|
60
|
+
React.createElement(ThemeContext.Provider, { value: contextValue },
|
|
61
|
+
includeCss && rootElement ? (React.createElement(FallbackStyles, { root: rootElement })) : null,
|
|
62
|
+
React.createElement(Root, { theme: theme, themeOptions: themeOptions, ref: useMergedRefs(forwardedRef, setRootElement), ...rest },
|
|
63
|
+
React.createElement(ToastProvider, null,
|
|
64
|
+
children,
|
|
65
|
+
portaledPortalContainer ? (ReactDOM.createPortal(React.createElement(Toaster, null), portaledPortalContainer)) : (React.createElement("div", { ref: setPortalContainer, style: { display: 'contents' } },
|
|
66
|
+
React.createElement(Toaster, null))))))));
|
|
66
67
|
});
|
|
67
68
|
// ----------------------------------------------------------------------------
|
|
68
69
|
const Root = React.forwardRef((props, forwardedRef) => {
|
package/esm/core/Tile/Tile.d.ts
CHANGED
|
@@ -255,7 +255,7 @@ export declare const Tile: PolymorphicForwardRefComponent<"div", TileLegacyProps
|
|
|
255
255
|
labelProps?: Omit<Omit<Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
256
256
|
ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
|
|
257
257
|
}, "as" | "children" | "content" | "portal" | keyof {
|
|
258
|
-
placement?: import("@floating-ui/
|
|
258
|
+
placement?: import("@floating-ui/utils").Placement | undefined;
|
|
259
259
|
visible?: boolean | undefined;
|
|
260
260
|
onVisibleChange?: ((visible: boolean) => void) | undefined;
|
|
261
261
|
autoUpdateOptions?: {
|
|
@@ -281,7 +281,7 @@ export declare const Tile: PolymorphicForwardRefComponent<"div", TileLegacyProps
|
|
|
281
281
|
content: React.ReactNode;
|
|
282
282
|
children?: React.ReactNode;
|
|
283
283
|
} & import("../utils/index.js").PortalProps & {
|
|
284
|
-
placement?: import("@floating-ui/
|
|
284
|
+
placement?: import("@floating-ui/utils").Placement | undefined;
|
|
285
285
|
visible?: boolean | undefined;
|
|
286
286
|
onVisibleChange?: ((visible: boolean) => void) | undefined;
|
|
287
287
|
autoUpdateOptions?: {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import cx from 'classnames';
|
|
7
|
-
import { Box, ShadowRoot,
|
|
7
|
+
import { Box, ShadowRoot, useHydration } from '../utils/index.js';
|
|
8
8
|
/**
|
|
9
9
|
* Hides content visually but keeps it still accessible to screen readers
|
|
10
10
|
* and other assistive technologies.
|
|
@@ -17,12 +17,12 @@ import { Box, ShadowRoot, useIsClient } from '../utils/index.js';
|
|
|
17
17
|
*/
|
|
18
18
|
export const VisuallyHidden = React.forwardRef((props, ref) => {
|
|
19
19
|
const { as: asProp = 'span', className, unhideOnFocus = true, children: childrenProp, ...rest } = props;
|
|
20
|
-
const
|
|
20
|
+
const isHydrated = useHydration() === 'hydrated';
|
|
21
21
|
// ShadowRoot is not supported on all elements, so we only use it for few common ones.
|
|
22
22
|
const children = !['div', 'span', 'p'].includes(asProp) ? (childrenProp) : (React.createElement(React.Fragment, null,
|
|
23
23
|
React.createElement(ShadowRoot, { css: css },
|
|
24
24
|
React.createElement("slot", null)),
|
|
25
|
-
|
|
25
|
+
isHydrated && childrenProp));
|
|
26
26
|
return (React.createElement(Box, { as: asProp, className: cx('iui-visually-hidden', className), "data-iui-unhide-on-focus": unhideOnFocus ? true : undefined, ref: ref, ...rest }, children));
|
|
27
27
|
});
|
|
28
28
|
// ----------------------------------------------------------------------------
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import * as ReactDOM from 'react-dom';
|
|
7
7
|
import { useLatestRef, useLayoutEffect } from '../hooks/index.js';
|
|
8
|
+
import { useHydration } from '../providers/index.js';
|
|
8
9
|
const isBrowser = typeof document !== 'undefined';
|
|
9
10
|
const supportsDSD = isBrowser && 'shadowRootMode' in HTMLTemplateElement.prototype;
|
|
10
11
|
const supportsAdoptedStylesheets = isBrowser && 'adoptedStyleSheets' in Document.prototype;
|
|
@@ -15,7 +16,7 @@ const supportsAdoptedStylesheets = isBrowser && 'adoptedStyleSheets' in Document
|
|
|
15
16
|
* @private
|
|
16
17
|
*/
|
|
17
18
|
export const ShadowRoot = ({ children, css }) => {
|
|
18
|
-
const
|
|
19
|
+
const isHydrating = useHydration() === 'hydrating';
|
|
19
20
|
if (!isBrowser) {
|
|
20
21
|
return (React.createElement("template", { shadowrootmode: 'open' },
|
|
21
22
|
css && React.createElement("style", null, css),
|
|
@@ -23,7 +24,7 @@ export const ShadowRoot = ({ children, css }) => {
|
|
|
23
24
|
}
|
|
24
25
|
// In browsers that support DSD, the template will be automatically removed as soon as it's parsed.
|
|
25
26
|
// To pass hydration, the first client render needs to emulate this browser behavior and return null.
|
|
26
|
-
if (supportsDSD &&
|
|
27
|
+
if (supportsDSD && isHydrating) {
|
|
27
28
|
return null;
|
|
28
29
|
}
|
|
29
30
|
return React.createElement(ClientShadowRoot, { css: css }, children);
|
|
@@ -48,31 +49,38 @@ function useShadowRoot(templateRef, { css = '' }) {
|
|
|
48
49
|
const [shadowRoot, setShadowRoot] = React.useState(null);
|
|
49
50
|
const styleSheet = React.useRef();
|
|
50
51
|
const latestCss = useLatestRef(css);
|
|
52
|
+
const latestShadowRoot = useLatestRef(shadowRoot);
|
|
51
53
|
useLayoutEffect(() => {
|
|
52
54
|
const parent = templateRef.current?.parentElement;
|
|
53
55
|
if (!parent) {
|
|
54
56
|
return;
|
|
55
57
|
}
|
|
56
|
-
|
|
57
|
-
parent.shadowRoot
|
|
58
|
-
|
|
59
|
-
const shadow = parent.shadowRoot || parent.attachShadow({ mode: 'open' });
|
|
60
|
-
if (supportsAdoptedStylesheets) {
|
|
61
|
-
// create an empty stylesheet and add it to the shadowRoot
|
|
62
|
-
const currentWindow = shadow.ownerDocument.defaultView || globalThis;
|
|
63
|
-
styleSheet.current = new currentWindow.CSSStyleSheet();
|
|
64
|
-
shadow.adoptedStyleSheets = [styleSheet.current];
|
|
65
|
-
// add the CSS immediately to avoid FOUC (one-time)
|
|
66
|
-
if (latestCss.current) {
|
|
67
|
-
styleSheet.current.replaceSync(latestCss.current);
|
|
58
|
+
const setupOrReuseShadowRoot = () => {
|
|
59
|
+
if (parent.shadowRoot && latestShadowRoot.current === null) {
|
|
60
|
+
parent.shadowRoot.replaceChildren(); // Remove previous shadowroot content
|
|
68
61
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
const shadow = parent.shadowRoot || parent.attachShadow({ mode: 'open' });
|
|
63
|
+
if (supportsAdoptedStylesheets) {
|
|
64
|
+
// create an empty stylesheet and add it to the shadowRoot
|
|
65
|
+
const currentWindow = shadow.ownerDocument.defaultView || globalThis;
|
|
66
|
+
styleSheet.current = new currentWindow.CSSStyleSheet();
|
|
67
|
+
shadow.adoptedStyleSheets = [styleSheet.current];
|
|
68
|
+
// add the CSS immediately to avoid FOUC (one-time)
|
|
69
|
+
if (latestCss.current) {
|
|
70
|
+
styleSheet.current.replaceSync(latestCss.current);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Flush the state immediately after shadow-root is attached, to ensure that layout
|
|
74
|
+
// measurements in parent component are correct.
|
|
75
|
+
// Without this, the parent component may end up measuring the layout when the shadow-root
|
|
76
|
+
// is attached in the DOM but React hasn't rendered any slots or content into it yet.
|
|
72
77
|
ReactDOM.flushSync(() => setShadowRoot(shadow));
|
|
78
|
+
};
|
|
79
|
+
queueMicrotask(() => {
|
|
80
|
+
setupOrReuseShadowRoot();
|
|
73
81
|
});
|
|
74
82
|
return () => void setShadowRoot(null);
|
|
75
|
-
}, [templateRef, latestCss]);
|
|
83
|
+
}, [templateRef, latestCss, latestShadowRoot]);
|
|
76
84
|
// Synchronize `css` with contents of the existing stylesheet
|
|
77
85
|
useLayoutEffect(() => {
|
|
78
86
|
if (css && supportsAdoptedStylesheets) {
|
|
@@ -81,9 +89,3 @@ function useShadowRoot(templateRef, { css = '' }) {
|
|
|
81
89
|
}, [css]);
|
|
82
90
|
return shadowRoot;
|
|
83
91
|
}
|
|
84
|
-
// ----------------------------------------------------------------------------
|
|
85
|
-
function useIsFirstRender() {
|
|
86
|
-
const [isFirstRender, setIsFirstRender] = React.useState(true);
|
|
87
|
-
React.useEffect(() => setIsFirstRender(false), []);
|
|
88
|
-
return isFirstRender;
|
|
89
|
-
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useMediaQuery: (queryString: string) => boolean;
|
|
1
|
+
export declare const useMediaQuery: (queryString: string) => boolean | undefined;
|
|
@@ -3,32 +3,17 @@
|
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import * as React from 'react';
|
|
6
|
-
import {
|
|
7
|
-
import { useLayoutEffect } from './useIsomorphicLayoutEffect.js';
|
|
6
|
+
import { useSyncExternalStore } from './useSyncExternalStore.js';
|
|
8
7
|
export const useMediaQuery = (queryString) => {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (mediaQueryList != undefined) {
|
|
14
|
-
setMatches(mediaQueryList.matches);
|
|
15
|
-
try {
|
|
16
|
-
mediaQueryList.addEventListener('change', handleChange);
|
|
17
|
-
}
|
|
18
|
-
catch {
|
|
19
|
-
// Safari 13 fallback
|
|
20
|
-
mediaQueryList.addListener?.(handleChange);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return () => {
|
|
24
|
-
try {
|
|
25
|
-
mediaQueryList?.removeEventListener('change', handleChange);
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
// Safari 13 fallback
|
|
29
|
-
mediaQueryList?.removeListener?.(handleChange);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
8
|
+
const getSnapshot = React.useCallback(() => {
|
|
9
|
+
return typeof window !== 'undefined'
|
|
10
|
+
? window.matchMedia?.(queryString).matches
|
|
11
|
+
: undefined;
|
|
32
12
|
}, [queryString]);
|
|
33
|
-
|
|
13
|
+
const subscribe = React.useCallback((onChange) => {
|
|
14
|
+
const mediaQueryList = window.matchMedia?.(queryString);
|
|
15
|
+
mediaQueryList?.addEventListener?.('change', onChange);
|
|
16
|
+
return () => mediaQueryList?.removeEventListener?.('change', onChange);
|
|
17
|
+
}, [queryString]);
|
|
18
|
+
return useSyncExternalStore(subscribe, getSnapshot, () => undefined);
|
|
34
19
|
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
const _React = React; // prevent bundlers from stripping the namespace import
|
|
7
|
+
/**
|
|
8
|
+
* Wrapper around `React.useSyncExternalStore` that uses a shim for React 17.
|
|
9
|
+
*/
|
|
10
|
+
export const useSyncExternalStore = _React.useSyncExternalStore || useSyncExternalStoreShim;
|
|
11
|
+
// ----------------------------------------------------------------------------
|
|
12
|
+
/**
|
|
13
|
+
* The shim below is adapted from React's source to make it ESM-compatible.
|
|
14
|
+
*
|
|
15
|
+
* Note: This does not use `getServerSnapshot` at all, because there is
|
|
16
|
+
* apparently no way to check "hydrating" state in pre-18.
|
|
17
|
+
*
|
|
18
|
+
* @see https://github.com/facebook/react/tree/main/packages/use-sync-external-store
|
|
19
|
+
*/
|
|
20
|
+
function useSyncExternalStoreShim(subscribe, getSnapshot) {
|
|
21
|
+
const value = getSnapshot();
|
|
22
|
+
const [{ instance }, forceUpdate] = React.useState({
|
|
23
|
+
instance: { value, getSnapshot },
|
|
24
|
+
});
|
|
25
|
+
React.useLayoutEffect(() => {
|
|
26
|
+
instance.value = value;
|
|
27
|
+
instance.getSnapshot = getSnapshot;
|
|
28
|
+
if (!Object.is(value, getSnapshot())) {
|
|
29
|
+
forceUpdate({ instance });
|
|
30
|
+
}
|
|
31
|
+
}, [subscribe, value, getSnapshot]); // eslint-disable-line
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
const synchronize = () => {
|
|
34
|
+
if (!Object.is(instance.value, instance.getSnapshot())) {
|
|
35
|
+
forceUpdate({ instance });
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
synchronize();
|
|
39
|
+
return subscribe(synchronize);
|
|
40
|
+
}, [subscribe]); // eslint-disable-line
|
|
41
|
+
return value;
|
|
42
|
+
}
|
package/esm/core/utils/index.js
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Hook that returns the hydration status of the app.
|
|
4
|
+
*
|
|
5
|
+
* @returns one of the following values:
|
|
6
|
+
* - `"hydrated"` after hydration is *definitely* complete (or is a pure client render)
|
|
7
|
+
* - `"hydrating"` if we know for sure that hydration is happening (in React 18)
|
|
8
|
+
* - `undefined` if the hydration status is unknown
|
|
9
|
+
*
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
export declare const useHydration: () => "hydrated" | "hydrating" | undefined;
|
|
13
|
+
/** @private */
|
|
14
|
+
export declare const HydrationProvider: ({ children, }: {
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
}) => React.JSX.Element;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import { useSyncExternalStore, useIsClient } from '../hooks/index.js';
|
|
7
|
+
const HydrationContext = React.createContext(false);
|
|
8
|
+
const noopSubscribe = () => () => { };
|
|
9
|
+
const isServer = typeof window === 'undefined';
|
|
10
|
+
/**
|
|
11
|
+
* Hook that returns the hydration status of the app.
|
|
12
|
+
*
|
|
13
|
+
* @returns one of the following values:
|
|
14
|
+
* - `"hydrated"` after hydration is *definitely* complete (or is a pure client render)
|
|
15
|
+
* - `"hydrating"` if we know for sure that hydration is happening (in React 18)
|
|
16
|
+
* - `undefined` if the hydration status is unknown
|
|
17
|
+
*
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
export const useHydration = () => {
|
|
21
|
+
// Returns true only if getServerSnapshot is called on the client.
|
|
22
|
+
// In React 18, this is true during hydration.
|
|
23
|
+
const hydrating = useSyncExternalStore(noopSubscribe, () => false, () => !isServer);
|
|
24
|
+
// Returns true after hydration is complete (in all React versions).
|
|
25
|
+
const hydrated = React.useContext(HydrationContext);
|
|
26
|
+
const hydratedFallback = useIsClient();
|
|
27
|
+
if (hydrated || hydratedFallback) {
|
|
28
|
+
return 'hydrated';
|
|
29
|
+
}
|
|
30
|
+
else if (hydrating) {
|
|
31
|
+
return 'hydrating';
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
};
|
|
35
|
+
/** @private */
|
|
36
|
+
export const HydrationProvider = ({ children, }) => {
|
|
37
|
+
const [isHydrated, setIsHydrated] = React.useState(React.useContext(HydrationContext));
|
|
38
|
+
const onHydrate = React.useCallback(() => setIsHydrated(true), []);
|
|
39
|
+
return (React.createElement(HydrationContext.Provider, { value: isHydrated },
|
|
40
|
+
!isHydrated ? React.createElement(HydrationCheck, { onHydrate: onHydrate }) : null,
|
|
41
|
+
children));
|
|
42
|
+
};
|
|
43
|
+
/** This is extracted into a child component to ensure it runs first. */
|
|
44
|
+
const HydrationCheck = ({ onHydrate }) => {
|
|
45
|
+
React.useEffect(() => void onHydrate(), [onHydrate]);
|
|
46
|
+
return null;
|
|
47
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './HydrationProvider.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
export * from './HydrationProvider.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/itwinui-react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.0",
|
|
4
4
|
"author": "Bentley Systems",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"ux"
|
|
57
57
|
],
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@floating-ui/react": "^0.26.
|
|
59
|
+
"@floating-ui/react": "^0.26.10",
|
|
60
60
|
"@itwin/itwinui-illustrations-react": "^2.1.0",
|
|
61
61
|
"classnames": "^2.3.2",
|
|
62
62
|
"react-table": "^7.8.0",
|