@itwin/itwinui-react 3.18.3 → 3.19.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 +44 -0
- package/DEV-cjs/core/ComboBox/ComboBoxMenuItem.js +1 -1
- package/DEV-cjs/core/Menu/MenuItem.js +8 -7
- package/DEV-cjs/core/Select/Select.js +18 -10
- package/DEV-cjs/core/SideNavigation/SideNavigation.js +2 -2
- package/DEV-cjs/core/Table/ColumnHeader.js +7 -3
- package/DEV-cjs/core/Table/Table.js +65 -5
- package/DEV-cjs/core/Table/cells/DefaultCell.js +14 -9
- package/DEV-cjs/core/Table/columns/actionColumn.js +1 -0
- package/DEV-cjs/core/Table/columns/expanderColumn.js +25 -20
- package/DEV-cjs/core/Table/columns/selectionColumn.js +14 -8
- package/DEV-cjs/core/Table/hooks/useExpanderCell.js +10 -6
- package/DEV-cjs/core/Tag/Tag.js +8 -2
- package/DEV-cjs/core/ThemeProvider/ThemeProvider.js +46 -46
- package/DEV-cjs/core/ToggleSwitch/ToggleSwitch.js +15 -4
- package/DEV-cjs/styles.js +1 -1
- package/DEV-cjs/utils/components/index.js +1 -1
- package/DEV-cjs/utils/components/lineClamp.js +23 -0
- package/DEV-cjs/utils/functions/react.js +18 -4
- package/DEV-cjs/utils/hooks/useControlledState.js +5 -1
- package/DEV-cjs/utils/providers/FutureFlagsProvider.js +48 -0
- package/DEV-cjs/utils/providers/index.js +1 -0
- package/DEV-esm/core/ComboBox/ComboBoxMenuItem.js +1 -1
- package/DEV-esm/core/Menu/MenuItem.js +8 -7
- package/DEV-esm/core/Select/Select.js +19 -10
- package/DEV-esm/core/SideNavigation/SideNavigation.js +2 -2
- package/DEV-esm/core/Table/ColumnHeader.js +8 -4
- package/DEV-esm/core/Table/Table.js +65 -5
- package/DEV-esm/core/Table/cells/DefaultCell.js +15 -10
- package/DEV-esm/core/Table/columns/actionColumn.js +1 -0
- package/DEV-esm/core/Table/columns/expanderColumn.js +25 -20
- package/DEV-esm/core/Table/columns/selectionColumn.js +14 -8
- package/DEV-esm/core/Table/hooks/useExpanderCell.js +10 -6
- package/DEV-esm/core/Tag/Tag.js +11 -3
- package/DEV-esm/core/ThemeProvider/ThemeProvider.js +48 -42
- package/DEV-esm/core/ToggleSwitch/ToggleSwitch.js +15 -5
- package/DEV-esm/styles.js +1 -1
- package/DEV-esm/utils/components/index.js +1 -1
- package/DEV-esm/utils/components/lineClamp.js +13 -0
- package/DEV-esm/utils/functions/react.js +6 -1
- package/DEV-esm/utils/hooks/useControlledState.js +5 -1
- package/DEV-esm/utils/providers/FutureFlagsProvider.js +28 -0
- package/DEV-esm/utils/providers/index.js +1 -0
- package/cjs/core/Buttons/DropdownButton.d.ts +1 -1
- package/cjs/core/ComboBox/ComboBoxMenuItem.d.ts +5 -16
- package/cjs/core/ComboBox/ComboBoxMenuItem.js +1 -1
- package/cjs/core/DropdownMenu/DropdownMenu.d.ts +1 -1
- package/cjs/core/Menu/MenuItem.d.ts +7 -1
- package/cjs/core/Menu/MenuItem.js +8 -7
- package/cjs/core/Popover/Popover.d.ts +5 -3
- package/cjs/core/Select/Select.js +18 -10
- package/cjs/core/SideNavigation/SideNavigation.js +2 -2
- package/cjs/core/Table/ColumnHeader.js +7 -3
- package/cjs/core/Table/Table.d.ts +2 -2
- package/cjs/core/Table/Table.js +65 -5
- package/cjs/core/Table/cells/DefaultCell.js +14 -9
- package/cjs/core/Table/columns/actionColumn.d.ts +1 -0
- package/cjs/core/Table/columns/actionColumn.js +1 -0
- package/cjs/core/Table/columns/expanderColumn.d.ts +2 -2
- package/cjs/core/Table/columns/expanderColumn.js +25 -20
- package/cjs/core/Table/columns/selectionColumn.d.ts +2 -2
- package/cjs/core/Table/columns/selectionColumn.js +14 -8
- package/cjs/core/Table/hooks/useExpanderCell.js +10 -6
- package/cjs/core/Tabs/Tabs.d.ts +4 -1
- package/cjs/core/Tag/Tag.js +8 -2
- package/cjs/core/ThemeProvider/ThemeContext.d.ts +1 -2
- package/cjs/core/ThemeProvider/ThemeProvider.d.ts +8 -18
- package/cjs/core/ThemeProvider/ThemeProvider.js +46 -46
- package/cjs/core/ToggleSwitch/ToggleSwitch.d.ts +21 -0
- package/cjs/core/ToggleSwitch/ToggleSwitch.js +15 -4
- package/cjs/styles.js +1 -1
- package/cjs/utils/components/index.d.ts +1 -1
- package/cjs/utils/components/index.js +1 -1
- package/cjs/utils/components/lineClamp.d.ts +5 -0
- package/cjs/utils/components/lineClamp.js +23 -0
- package/cjs/utils/functions/react.d.ts +5 -0
- package/cjs/utils/functions/react.js +18 -4
- package/cjs/utils/hooks/useControlledState.d.ts +5 -2
- package/cjs/utils/hooks/useControlledState.js +5 -1
- package/cjs/utils/hooks/useGlobals.d.ts +0 -1
- package/cjs/utils/providers/FutureFlagsProvider.d.ts +37 -0
- package/cjs/utils/providers/FutureFlagsProvider.js +48 -0
- package/cjs/utils/providers/index.d.ts +1 -0
- package/cjs/utils/providers/index.js +1 -0
- package/esm/core/Buttons/DropdownButton.d.ts +1 -1
- package/esm/core/ComboBox/ComboBoxMenuItem.d.ts +5 -16
- package/esm/core/ComboBox/ComboBoxMenuItem.js +1 -1
- package/esm/core/DropdownMenu/DropdownMenu.d.ts +1 -1
- package/esm/core/Menu/MenuItem.d.ts +7 -1
- package/esm/core/Menu/MenuItem.js +8 -7
- package/esm/core/Popover/Popover.d.ts +5 -3
- package/esm/core/Select/Select.js +19 -10
- package/esm/core/SideNavigation/SideNavigation.js +2 -2
- package/esm/core/Table/ColumnHeader.js +8 -4
- package/esm/core/Table/Table.d.ts +2 -2
- package/esm/core/Table/Table.js +65 -5
- package/esm/core/Table/cells/DefaultCell.js +15 -10
- package/esm/core/Table/columns/actionColumn.d.ts +1 -0
- package/esm/core/Table/columns/actionColumn.js +1 -0
- package/esm/core/Table/columns/expanderColumn.d.ts +2 -2
- package/esm/core/Table/columns/expanderColumn.js +25 -20
- package/esm/core/Table/columns/selectionColumn.d.ts +2 -2
- package/esm/core/Table/columns/selectionColumn.js +14 -8
- package/esm/core/Table/hooks/useExpanderCell.js +10 -6
- package/esm/core/Tabs/Tabs.d.ts +4 -1
- package/esm/core/Tag/Tag.js +11 -3
- package/esm/core/ThemeProvider/ThemeContext.d.ts +1 -2
- package/esm/core/ThemeProvider/ThemeProvider.d.ts +8 -18
- package/esm/core/ThemeProvider/ThemeProvider.js +48 -42
- package/esm/core/ToggleSwitch/ToggleSwitch.d.ts +21 -0
- package/esm/core/ToggleSwitch/ToggleSwitch.js +15 -5
- package/esm/styles.js +1 -1
- package/esm/utils/components/index.d.ts +1 -1
- package/esm/utils/components/index.js +1 -1
- package/esm/utils/components/lineClamp.d.ts +5 -0
- package/esm/utils/components/lineClamp.js +13 -0
- package/esm/utils/functions/react.d.ts +5 -0
- package/esm/utils/functions/react.js +6 -1
- package/esm/utils/hooks/useControlledState.d.ts +5 -2
- package/esm/utils/hooks/useControlledState.js +5 -1
- package/esm/utils/hooks/useGlobals.d.ts +0 -1
- package/esm/utils/providers/FutureFlagsProvider.d.ts +37 -0
- package/esm/utils/providers/FutureFlagsProvider.js +28 -0
- package/esm/utils/providers/index.d.ts +1 -0
- package/esm/utils/providers/index.js +1 -0
- package/package.json +11 -5
- package/styles.css +10 -10
- package/DEV-cjs/utils/components/LineClamp.js +0 -50
- package/DEV-esm/utils/components/LineClamp.js +0 -36
- package/cjs/utils/components/LineClamp.d.ts +0 -5
- package/cjs/utils/components/LineClamp.js +0 -50
- package/esm/utils/components/LineClamp.d.ts +0 -5
- package/esm/utils/components/LineClamp.js +0 -36
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { defaultColumn } from 'react-table';
|
|
3
3
|
import cx from 'classnames';
|
|
4
|
-
import { Box,
|
|
4
|
+
import { Box, lineClamp, ShadowRoot } from '../../../utils/index.js';
|
|
5
5
|
import { TableInstanceContext } from '../utils.js';
|
|
6
6
|
export const DefaultCellRendererPropsChildren = React.createContext(void 0);
|
|
7
7
|
export const DefaultCell = (props) => {
|
|
@@ -14,6 +14,10 @@ export const DefaultCell = (props) => {
|
|
|
14
14
|
);
|
|
15
15
|
let isCellRendererChildrenCustom =
|
|
16
16
|
React.useContext(DefaultCellRendererPropsChildren) !== props.children;
|
|
17
|
+
let isDefaultTextCell =
|
|
18
|
+
'string' == typeof props.cellProps.value &&
|
|
19
|
+
!isCustomCell &&
|
|
20
|
+
!isCellRendererChildrenCustom;
|
|
17
21
|
let {
|
|
18
22
|
cellElementProps: {
|
|
19
23
|
className: cellElementClassName,
|
|
@@ -28,9 +32,7 @@ export const DefaultCell = (props) => {
|
|
|
28
32
|
className,
|
|
29
33
|
style,
|
|
30
34
|
status,
|
|
31
|
-
clamp =
|
|
32
|
-
!isCustomCell &&
|
|
33
|
-
!isCellRendererChildrenCustom,
|
|
35
|
+
clamp = isDefaultTextCell,
|
|
34
36
|
...rest
|
|
35
37
|
} = props;
|
|
36
38
|
let { key: cellElementKey, ...cellElementPropsRest } = cellElementProps;
|
|
@@ -61,12 +63,14 @@ export const DefaultCell = (props) => {
|
|
|
61
63
|
React.createElement(
|
|
62
64
|
TableCellContent,
|
|
63
65
|
{
|
|
64
|
-
shouldRenderWrapper:
|
|
66
|
+
shouldRenderWrapper: isDefaultTextCell,
|
|
65
67
|
},
|
|
66
68
|
clamp
|
|
67
69
|
? React.createElement(
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
'div',
|
|
71
|
+
{
|
|
72
|
+
className: lineClamp.className,
|
|
73
|
+
},
|
|
70
74
|
React.createElement('slot', null),
|
|
71
75
|
)
|
|
72
76
|
: React.createElement('slot', null),
|
|
@@ -106,15 +110,15 @@ if ('development' === process.env.NODE_ENV)
|
|
|
106
110
|
let TableCellContent = (props) => {
|
|
107
111
|
let { children, shouldRenderWrapper } = props;
|
|
108
112
|
return shouldRenderWrapper
|
|
109
|
-
?
|
|
110
|
-
: React.createElement(
|
|
113
|
+
? React.createElement(
|
|
111
114
|
'div',
|
|
112
115
|
{
|
|
113
116
|
className: '_iui-table-cell-default-content',
|
|
114
117
|
onClick: (e) => e.stopPropagation(),
|
|
115
118
|
},
|
|
116
119
|
children,
|
|
117
|
-
)
|
|
120
|
+
)
|
|
121
|
+
: children;
|
|
118
122
|
};
|
|
119
123
|
let css = `
|
|
120
124
|
._iui-table-cell-default-content {
|
|
@@ -128,4 +132,5 @@ let css = `
|
|
|
128
132
|
inset: -6px;
|
|
129
133
|
z-index: -1;
|
|
130
134
|
}
|
|
135
|
+
${lineClamp.css}
|
|
131
136
|
`;
|
|
@@ -28,6 +28,7 @@ type ActionColumnProps = {
|
|
|
28
28
|
export declare const ActionColumn: <T extends Record<string, unknown>>({ columnManager, }?: ActionColumnProps) => {
|
|
29
29
|
id: string;
|
|
30
30
|
disableResizing: boolean;
|
|
31
|
+
canResize: boolean;
|
|
31
32
|
disableGroupBy: boolean;
|
|
32
33
|
minWidth: number;
|
|
33
34
|
width: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CellRendererProps, Row } from '../../../react-table/react-table.js';
|
|
3
3
|
export declare const EXPANDER_CELL_ID = "iui-table-expander";
|
|
4
4
|
/**
|
|
5
5
|
* Expander column that adds sub-content expander column to the Table.
|
|
@@ -39,6 +39,6 @@ export declare const ExpanderColumn: <T extends Record<string, unknown>>(props?:
|
|
|
39
39
|
maxWidth: number;
|
|
40
40
|
columnClassName: string;
|
|
41
41
|
cellClassName: string;
|
|
42
|
-
Cell: (
|
|
42
|
+
Cell: () => null;
|
|
43
43
|
cellRenderer: (props: CellRendererProps<T>) => React.JSX.Element;
|
|
44
44
|
};
|
|
@@ -15,30 +15,35 @@ export const ExpanderColumn = (props = {}) => {
|
|
|
15
15
|
maxWidth: 48,
|
|
16
16
|
columnClassName: 'iui-slot',
|
|
17
17
|
cellClassName: 'iui-slot',
|
|
18
|
-
Cell: (
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
Cell: () => null,
|
|
19
|
+
cellRenderer: (props) => {
|
|
20
|
+
let { row } = props.cellProps;
|
|
21
|
+
let children = subComponent?.(row)
|
|
22
|
+
? React.createElement(
|
|
23
|
+
IconButton,
|
|
24
|
+
{
|
|
25
|
+
'aria-label': 'Toggle expandable content',
|
|
26
|
+
className: 'iui-table-row-expander',
|
|
27
|
+
styleType: 'borderless',
|
|
28
|
+
size: 'small',
|
|
29
|
+
onClick: (e) => {
|
|
30
|
+
e.stopPropagation();
|
|
31
|
+
row.toggleRowExpanded();
|
|
32
|
+
},
|
|
33
|
+
disabled: isDisabled?.(row.original),
|
|
34
|
+
'aria-expanded': row.isExpanded,
|
|
35
|
+
},
|
|
36
|
+
React.createElement(SvgChevronRight, null),
|
|
37
|
+
)
|
|
38
|
+
: null;
|
|
21
39
|
return React.createElement(
|
|
22
|
-
|
|
40
|
+
DefaultCell,
|
|
23
41
|
{
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
styleType: 'borderless',
|
|
27
|
-
size: 'small',
|
|
28
|
-
onClick: (e) => {
|
|
29
|
-
e.stopPropagation();
|
|
30
|
-
row.toggleRowExpanded();
|
|
31
|
-
},
|
|
32
|
-
disabled: isDisabled?.(props.row.original),
|
|
33
|
-
'aria-expanded': row.isExpanded,
|
|
42
|
+
...props,
|
|
43
|
+
isDisabled: (rowData) => !!isDisabled?.(rowData),
|
|
34
44
|
},
|
|
35
|
-
|
|
45
|
+
children,
|
|
36
46
|
);
|
|
37
47
|
},
|
|
38
|
-
cellRenderer: (props) =>
|
|
39
|
-
React.createElement(DefaultCell, {
|
|
40
|
-
...props,
|
|
41
|
-
isDisabled: (rowData) => !!isDisabled?.(rowData),
|
|
42
|
-
}),
|
|
43
48
|
};
|
|
44
49
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CellRendererProps, HeaderProps } from '../../../react-table/react-table.js';
|
|
3
3
|
export declare const SELECTION_CELL_ID = "iui-table-checkbox-selector";
|
|
4
4
|
/**
|
|
5
5
|
* Selection column that adds selection checkbox column to the Table.
|
|
@@ -28,6 +28,6 @@ export declare const SelectionColumn: <T extends Record<string, unknown>>(props?
|
|
|
28
28
|
columnClassName: string;
|
|
29
29
|
cellClassName: string;
|
|
30
30
|
Header: ({ getToggleAllRowsSelectedProps, toggleAllRowsSelected, rows, preFilteredFlatRows, state, }: HeaderProps<T>) => React.JSX.Element;
|
|
31
|
-
Cell: (
|
|
31
|
+
Cell: () => null;
|
|
32
32
|
cellRenderer: (props: CellRendererProps<T>) => React.JSX.Element;
|
|
33
33
|
};
|
|
@@ -44,8 +44,10 @@ export const SelectionColumn = (props = {}) => {
|
|
|
44
44
|
onChange: () => toggleAllRowsSelected(nextToggleState),
|
|
45
45
|
});
|
|
46
46
|
},
|
|
47
|
-
Cell: (
|
|
48
|
-
|
|
47
|
+
Cell: () => null,
|
|
48
|
+
cellRenderer: (props) => {
|
|
49
|
+
let { row, selectSubRows = true } = props.cellProps;
|
|
50
|
+
let children = React.createElement(Checkbox, {
|
|
49
51
|
...row.getToggleRowSelectedProps(),
|
|
50
52
|
style: {},
|
|
51
53
|
title: '',
|
|
@@ -65,11 +67,15 @@ export const SelectionColumn = (props = {}) => {
|
|
|
65
67
|
);
|
|
66
68
|
else row.toggleRowSelected(!row.isSelected);
|
|
67
69
|
},
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
});
|
|
71
|
+
return React.createElement(
|
|
72
|
+
DefaultCell,
|
|
73
|
+
{
|
|
74
|
+
...props,
|
|
75
|
+
isDisabled: (rowData) => !!isDisabled?.(rowData),
|
|
76
|
+
},
|
|
77
|
+
children,
|
|
78
|
+
);
|
|
79
|
+
},
|
|
74
80
|
};
|
|
75
81
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ExpanderColumn, EXPANDER_CELL_ID } from '../columns/index.js';
|
|
3
|
+
import { DefaultCell } from '../cells/DefaultCell.js';
|
|
3
4
|
export const useExpanderCell =
|
|
4
5
|
(subComponent, expanderCell, isRowDisabled) => (hooks) => {
|
|
5
6
|
if (!subComponent) return;
|
|
@@ -13,14 +14,17 @@ export const useExpanderCell =
|
|
|
13
14
|
return [
|
|
14
15
|
{
|
|
15
16
|
...expanderColumn,
|
|
16
|
-
|
|
17
|
-
? (
|
|
17
|
+
cellRenderer: expanderCell
|
|
18
|
+
? (props) =>
|
|
18
19
|
React.createElement(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
DefaultCell,
|
|
21
|
+
{
|
|
22
|
+
...props,
|
|
23
|
+
isDisabled: (rowData) => !!isRowDisabled?.(rowData),
|
|
24
|
+
},
|
|
25
|
+
expanderCell(props.cellProps),
|
|
22
26
|
)
|
|
23
|
-
: expanderColumn.
|
|
27
|
+
: expanderColumn.cellRenderer,
|
|
24
28
|
},
|
|
25
29
|
...columns,
|
|
26
30
|
];
|
package/esm/core/Tabs/Tabs.d.ts
CHANGED
|
@@ -42,9 +42,12 @@ type TabsWrapperOwnProps = {
|
|
|
42
42
|
*/
|
|
43
43
|
value?: string;
|
|
44
44
|
/**
|
|
45
|
-
* Function that gets called when active tab
|
|
45
|
+
* Function that gets called when active tab *changes* (uncontrolled mode) or should *change* (controlled mode).
|
|
46
46
|
*
|
|
47
47
|
* Should be used alongside `value` prop.
|
|
48
|
+
*
|
|
49
|
+
* If need to listen to each tab click, use `onClick` prop on `Tabs.Tab`.
|
|
50
|
+
* Similarly, for each focus, use `onFocus` prop on `Tabs.Tab`.
|
|
48
51
|
*/
|
|
49
52
|
onValueChange?: (value: string) => void;
|
|
50
53
|
/**
|
package/esm/core/Tag/Tag.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import cx from 'classnames';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
SvgCloseSmall,
|
|
5
|
+
Box,
|
|
6
|
+
ButtonBase,
|
|
7
|
+
mergeEventHandlers,
|
|
8
|
+
} from '../../utils/index.js';
|
|
4
9
|
import { IconButton } from '../Buttons/IconButton.js';
|
|
5
10
|
import { LinkAction, LinkBox } from '../LinkAction/LinkAction.js';
|
|
6
11
|
export const Tag = React.forwardRef((props, forwardedRef) => {
|
|
@@ -35,8 +40,11 @@ export const Tag = React.forwardRef((props, forwardedRef) => {
|
|
|
35
40
|
Box,
|
|
36
41
|
{
|
|
37
42
|
as: shouldUseLinkAction ? LinkAction : 'span',
|
|
38
|
-
onClick: shouldUseLinkAction ? onClick : void 0,
|
|
39
43
|
...labelProps,
|
|
44
|
+
onClick: mergeEventHandlers(
|
|
45
|
+
labelProps?.onClick,
|
|
46
|
+
shouldUseLinkAction ? onClick : void 0,
|
|
47
|
+
),
|
|
40
48
|
className: cx('iui-tag-label', labelProps?.className),
|
|
41
49
|
},
|
|
42
50
|
children,
|
|
@@ -48,9 +56,9 @@ export const Tag = React.forwardRef((props, forwardedRef) => {
|
|
|
48
56
|
{
|
|
49
57
|
styleType: 'borderless',
|
|
50
58
|
size: 'small',
|
|
51
|
-
onClick: onRemove,
|
|
52
59
|
'aria-label': 'Delete tag',
|
|
53
60
|
...removeButtonProps,
|
|
61
|
+
onClick: mergeEventHandlers(removeButtonProps?.onClick, onRemove),
|
|
54
62
|
className: cx('iui-tag-button', removeButtonProps?.className),
|
|
55
63
|
},
|
|
56
64
|
React.createElement(SvgCloseSmall, {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type {
|
|
2
|
+
import type { ThemeOptions, ThemeType } from './ThemeProvider.js';
|
|
3
3
|
export declare const ThemeContext: React.Context<{
|
|
4
4
|
theme?: ThemeType;
|
|
5
5
|
themeOptions?: ThemeOptions;
|
|
6
6
|
portalContainer?: HTMLElement | null;
|
|
7
|
-
future?: FutureOptions;
|
|
8
7
|
} | undefined>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import type { PolymorphicForwardRefComponent } from '../../utils/index.js';
|
|
2
|
+
import type { FutureOptions, PolymorphicForwardRefComponent } from '../../utils/index.js';
|
|
3
3
|
export type ThemeOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* Whether to apply high-contrast versions of light and dark themes.
|
|
@@ -7,18 +7,6 @@ export type ThemeOptions = {
|
|
|
7
7
|
*/
|
|
8
8
|
highContrast?: boolean;
|
|
9
9
|
};
|
|
10
|
-
export type FutureOptions = {
|
|
11
|
-
/**
|
|
12
|
-
* @alpha
|
|
13
|
-
*
|
|
14
|
-
* If enabled, the theme resembles the future iTwinUI version's theme (including alphas) *whenever possible*.
|
|
15
|
-
*
|
|
16
|
-
* This is useful in making apps looks like future versions of iTwinUI to help with incremental adoption.
|
|
17
|
-
*
|
|
18
|
-
* **NOTE**: Since this is a theme bridge to *future* versions, the theme could have breaking changes.
|
|
19
|
-
*/
|
|
20
|
-
themeBridge?: boolean;
|
|
21
|
-
};
|
|
22
10
|
export type ThemeType = 'light' | 'dark' | 'os';
|
|
23
11
|
type RootProps = {
|
|
24
12
|
/**
|
|
@@ -53,12 +41,8 @@ type RootProps = {
|
|
|
53
41
|
*/
|
|
54
42
|
applyBackground?: boolean;
|
|
55
43
|
};
|
|
56
|
-
/**
|
|
57
|
-
* Options to help with early adoption of features from future versions.
|
|
58
|
-
*/
|
|
59
|
-
future?: FutureOptions;
|
|
60
44
|
};
|
|
61
|
-
type ThemeProviderOwnProps = Pick<RootProps, 'theme'
|
|
45
|
+
type ThemeProviderOwnProps = Pick<RootProps, 'theme'> & {
|
|
62
46
|
themeOptions?: RootProps['themeOptions'];
|
|
63
47
|
children: Required<React.ReactNode>;
|
|
64
48
|
/**
|
|
@@ -89,6 +73,12 @@ type ThemeProviderOwnProps = Pick<RootProps, 'theme' | 'future'> & {
|
|
|
89
73
|
* If true or false is passed, it will override the default behavior.
|
|
90
74
|
*/
|
|
91
75
|
includeCss?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Options to help with early adoption of features from future versions.
|
|
78
|
+
*
|
|
79
|
+
* All future options will be automatically inherited across nested ThemeProviders, unless explicitly overridden.
|
|
80
|
+
*/
|
|
81
|
+
future?: true | FutureOptions;
|
|
92
82
|
};
|
|
93
83
|
/**
|
|
94
84
|
* This component provides global state and applies theme to the entire tree
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
useHydration,
|
|
14
14
|
PortalContainerContext,
|
|
15
15
|
useId,
|
|
16
|
+
FutureFlagsProvider,
|
|
17
|
+
useFutureFlag,
|
|
16
18
|
} from '../../utils/index.js';
|
|
17
19
|
import { ThemeContext } from './ThemeContext.js';
|
|
18
20
|
import { ToastProvider, Toaster } from '../Toast/Toaster.js';
|
|
@@ -20,14 +22,14 @@ import { meta } from '../../utils/meta.js';
|
|
|
20
22
|
let versionWithoutDots = meta.version.replace(/\./g, '');
|
|
21
23
|
let OwnerDocumentContext = React.createContext(void 0);
|
|
22
24
|
export const ThemeProvider = React.forwardRef((props, forwardedRef) => {
|
|
23
|
-
var _themeOptions, _themeOptions1
|
|
25
|
+
var _themeOptions, _themeOptions1;
|
|
24
26
|
let {
|
|
25
27
|
theme: themeProp = 'inherit',
|
|
26
28
|
children,
|
|
27
29
|
themeOptions = {},
|
|
28
30
|
portalContainer: portalContainerProp,
|
|
29
31
|
includeCss = 'inherit' === themeProp,
|
|
30
|
-
future = {},
|
|
32
|
+
future: futureProp = {},
|
|
31
33
|
...rest
|
|
32
34
|
} = props;
|
|
33
35
|
useInertPolyfill();
|
|
@@ -39,62 +41,67 @@ export const ThemeProvider = React.forwardRef((props, forwardedRef) => {
|
|
|
39
41
|
(_themeOptions1 = themeOptions).highContrast ??
|
|
40
42
|
(_themeOptions1.highContrast =
|
|
41
43
|
'inherit' === themeProp ? parent.highContrast : void 0);
|
|
42
|
-
(_future = future).themeBridge ??
|
|
43
|
-
(_future.themeBridge = parent.context?.future?.themeBridge);
|
|
44
44
|
let portalContainerFromParent = React.useContext(PortalContainerContext);
|
|
45
|
-
let
|
|
45
|
+
let themeContextValue = React.useMemo(
|
|
46
46
|
() => ({
|
|
47
47
|
theme,
|
|
48
48
|
themeOptions,
|
|
49
|
-
future,
|
|
50
49
|
}),
|
|
51
|
-
[theme, JSON.stringify(themeOptions)
|
|
50
|
+
[theme, JSON.stringify(themeOptions)],
|
|
52
51
|
);
|
|
53
52
|
let [portalContainer, setPortalContainer] = React.useState(
|
|
54
53
|
portalContainerProp || null,
|
|
55
54
|
);
|
|
56
55
|
return React.createElement(
|
|
57
|
-
|
|
56
|
+
FutureFlagsProvider,
|
|
58
57
|
{
|
|
59
|
-
value:
|
|
58
|
+
value: futureProp,
|
|
60
59
|
},
|
|
61
60
|
React.createElement(
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
PortalContainerContext.Provider,
|
|
62
|
+
{
|
|
63
|
+
value: portalContainer,
|
|
64
|
+
},
|
|
64
65
|
React.createElement(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
value: contextValue,
|
|
68
|
-
},
|
|
66
|
+
HydrationProvider,
|
|
67
|
+
null,
|
|
69
68
|
React.createElement(
|
|
70
|
-
|
|
69
|
+
ThemeContext.Provider,
|
|
71
70
|
{
|
|
72
|
-
|
|
71
|
+
value: themeContextValue,
|
|
73
72
|
},
|
|
74
|
-
includeCss && rootElement
|
|
75
|
-
? React.createElement(FallbackStyles, {
|
|
76
|
-
root: rootElement,
|
|
77
|
-
})
|
|
78
|
-
: null,
|
|
79
73
|
React.createElement(
|
|
80
|
-
|
|
74
|
+
ToastProvider,
|
|
81
75
|
{
|
|
82
|
-
|
|
83
|
-
themeOptions: themeOptions,
|
|
84
|
-
future: future,
|
|
85
|
-
ref: useMergedRefs(forwardedRef, setRootElement, useIuiDebugRef),
|
|
86
|
-
...rest,
|
|
76
|
+
inherit: 'inherit' === themeProp && !portalContainerProp,
|
|
87
77
|
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
78
|
+
includeCss && rootElement
|
|
79
|
+
? React.createElement(FallbackStyles, {
|
|
80
|
+
root: rootElement,
|
|
81
|
+
})
|
|
82
|
+
: null,
|
|
83
|
+
React.createElement(
|
|
84
|
+
MainRoot,
|
|
85
|
+
{
|
|
86
|
+
theme: theme,
|
|
87
|
+
themeOptions: themeOptions,
|
|
88
|
+
ref: useMergedRefs(
|
|
89
|
+
forwardedRef,
|
|
90
|
+
setRootElement,
|
|
91
|
+
useIuiDebugRef,
|
|
92
|
+
),
|
|
93
|
+
...rest,
|
|
94
|
+
},
|
|
95
|
+
children,
|
|
96
|
+
React.createElement(PortalContainer, {
|
|
97
|
+
theme: theme,
|
|
98
|
+
themeOptions: themeOptions,
|
|
99
|
+
portalContainerProp: portalContainerProp,
|
|
100
|
+
portalContainerFromParent: portalContainerFromParent,
|
|
101
|
+
setPortalContainer: setPortalContainer,
|
|
102
|
+
isInheritingTheme: 'inherit' === themeProp,
|
|
103
|
+
}),
|
|
104
|
+
),
|
|
98
105
|
),
|
|
99
106
|
),
|
|
100
107
|
),
|
|
@@ -124,12 +131,13 @@ let MainRoot = React.forwardRef((props, forwardedRef) => {
|
|
|
124
131
|
);
|
|
125
132
|
});
|
|
126
133
|
let Root = React.forwardRef((props, forwardedRef) => {
|
|
127
|
-
let { theme, children, themeOptions, className,
|
|
134
|
+
let { theme, children, themeOptions, className, ...rest } = props;
|
|
128
135
|
let prefersDark = useMediaQuery('(prefers-color-scheme: dark)');
|
|
129
136
|
let prefersHighContrast = useMediaQuery('(prefers-contrast: more)');
|
|
130
137
|
let shouldApplyDark = 'dark' === theme || ('os' === theme && prefersDark);
|
|
131
138
|
let shouldApplyHC = themeOptions?.highContrast ?? prefersHighContrast;
|
|
132
139
|
let shouldApplyBackground = themeOptions?.applyBackground;
|
|
140
|
+
let themeBridge = useFutureFlag('themeBridge');
|
|
133
141
|
return React.createElement(
|
|
134
142
|
Box,
|
|
135
143
|
{
|
|
@@ -142,7 +150,7 @@ let Root = React.forwardRef((props, forwardedRef) => {
|
|
|
142
150
|
),
|
|
143
151
|
'data-iui-theme': shouldApplyDark ? 'dark' : 'light',
|
|
144
152
|
'data-iui-contrast': shouldApplyHC ? 'high' : 'default',
|
|
145
|
-
'data-iui-bridge':
|
|
153
|
+
'data-iui-bridge': themeBridge ? 'true' : void 0,
|
|
146
154
|
ref: forwardedRef,
|
|
147
155
|
...rest,
|
|
148
156
|
},
|
|
@@ -191,7 +199,6 @@ let PortalContainer = React.memo(
|
|
|
191
199
|
isInheritingTheme,
|
|
192
200
|
theme,
|
|
193
201
|
themeOptions,
|
|
194
|
-
future,
|
|
195
202
|
}) => {
|
|
196
203
|
let ownerDocument = React.useContext(OwnerDocumentContext);
|
|
197
204
|
let shouldSetupPortalContainer =
|
|
@@ -223,7 +230,6 @@ let PortalContainer = React.memo(
|
|
|
223
230
|
...themeOptions,
|
|
224
231
|
applyBackground: false,
|
|
225
232
|
},
|
|
226
|
-
future: future,
|
|
227
233
|
'data-iui-portal': true,
|
|
228
234
|
style: {
|
|
229
235
|
display: 'contents',
|
|
@@ -14,6 +14,16 @@ type ToggleSwitchProps = {
|
|
|
14
14
|
* @default 'right'
|
|
15
15
|
*/
|
|
16
16
|
labelPosition?: 'left' | 'right';
|
|
17
|
+
/**
|
|
18
|
+
* Passes props to wrapper.
|
|
19
|
+
*
|
|
20
|
+
* By default, `className` and `style` are applied on the wrapper element, and all other DOM props are passed to
|
|
21
|
+
* `<input>` element.
|
|
22
|
+
*
|
|
23
|
+
* When `wrapperProps` is passed or when the `ToggleSwitch.consistentPropsSpread` future flag is enabled, `className`
|
|
24
|
+
* and `style` are applied on the `<input>` element, similar to other DOM props.
|
|
25
|
+
*/
|
|
26
|
+
wrapperProps?: React.HTMLAttributes<HTMLElement>;
|
|
17
27
|
} & ({
|
|
18
28
|
/**
|
|
19
29
|
* Size of the toggle switch.
|
|
@@ -32,6 +42,17 @@ type ToggleSwitchProps = {
|
|
|
32
42
|
});
|
|
33
43
|
/**
|
|
34
44
|
* A switch for turning on and off.
|
|
45
|
+
*
|
|
46
|
+
* ---
|
|
47
|
+
*
|
|
48
|
+
* By default, `className` and `style` are applied on the wrapper element, and all other DOM props are passed to `<input>`
|
|
49
|
+
* element.
|
|
50
|
+
*
|
|
51
|
+
* When `wrapperProps` is passed or when the `ToggleSwitch.consistentPropsSpread` future flag is enabled, `className`
|
|
52
|
+
* and `style` are applied on the `<input>` element, similar to other DOM props.
|
|
53
|
+
*
|
|
54
|
+
* ---
|
|
55
|
+
*
|
|
35
56
|
* @example
|
|
36
57
|
* <caption>Basic toggle</caption>
|
|
37
58
|
* <ToggleSwitch onChange={(e) => console.log(e.target.checked)} defaultChecked />
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import cx from 'classnames';
|
|
3
|
-
import { Box, SvgCheckmark } from '../../utils/index.js';
|
|
3
|
+
import { Box, SvgCheckmark, useFutureFlag } from '../../utils/index.js';
|
|
4
4
|
export const ToggleSwitch = React.forwardRef((props, ref) => {
|
|
5
5
|
let {
|
|
6
6
|
disabled = false,
|
|
@@ -10,15 +10,21 @@ export const ToggleSwitch = React.forwardRef((props, ref) => {
|
|
|
10
10
|
style,
|
|
11
11
|
size = 'default',
|
|
12
12
|
labelProps = {},
|
|
13
|
+
wrapperProps,
|
|
13
14
|
icon: iconProp,
|
|
14
15
|
...rest
|
|
15
16
|
} = props;
|
|
17
|
+
let { consistentPropsSpread } = useFutureFlag('ToggleSwitch') || {};
|
|
18
|
+
let shouldApplyClassNameAndStyleOnInput =
|
|
19
|
+
null != wrapperProps || consistentPropsSpread;
|
|
16
20
|
let shouldShowIcon =
|
|
17
21
|
void 0 === iconProp || (null !== iconProp && 'small' !== size);
|
|
18
22
|
return React.createElement(
|
|
19
23
|
Box,
|
|
20
24
|
{
|
|
21
25
|
as: label ? 'label' : 'div',
|
|
26
|
+
style: shouldApplyClassNameAndStyleOnInput ? void 0 : style,
|
|
27
|
+
...wrapperProps,
|
|
22
28
|
className: cx(
|
|
23
29
|
'iui-toggle-switch-wrapper',
|
|
24
30
|
{
|
|
@@ -26,19 +32,23 @@ export const ToggleSwitch = React.forwardRef((props, ref) => {
|
|
|
26
32
|
'iui-label-on-right': label && 'right' === labelPosition,
|
|
27
33
|
'iui-label-on-left': label && 'left' === labelPosition,
|
|
28
34
|
},
|
|
29
|
-
className,
|
|
35
|
+
shouldApplyClassNameAndStyleOnInput ? void 0 : className,
|
|
36
|
+
wrapperProps?.className,
|
|
30
37
|
),
|
|
31
38
|
'data-iui-size': size,
|
|
32
|
-
style: style,
|
|
33
39
|
},
|
|
34
40
|
React.createElement(Box, {
|
|
35
41
|
as: 'input',
|
|
36
|
-
className: 'iui-toggle-switch',
|
|
37
42
|
type: 'checkbox',
|
|
38
43
|
role: 'switch',
|
|
44
|
+
style: shouldApplyClassNameAndStyleOnInput ? style : void 0,
|
|
45
|
+
...rest,
|
|
46
|
+
className: cx(
|
|
47
|
+
'iui-toggle-switch',
|
|
48
|
+
shouldApplyClassNameAndStyleOnInput ? className : void 0,
|
|
49
|
+
),
|
|
39
50
|
disabled: disabled,
|
|
40
51
|
ref: ref,
|
|
41
|
-
...rest,
|
|
42
52
|
}),
|
|
43
53
|
shouldShowIcon &&
|
|
44
54
|
React.createElement(
|
package/esm/styles.js
CHANGED
|
@@ -9,6 +9,6 @@ export * from './Box.js';
|
|
|
9
9
|
export * from './ButtonBase.js';
|
|
10
10
|
export * from './Portal.js';
|
|
11
11
|
export * from './ShadowRoot.js';
|
|
12
|
-
export * from './
|
|
12
|
+
export * from './lineClamp.js';
|
|
13
13
|
export * from './FieldsetBase.js';
|
|
14
14
|
export * from './OverflowContainer.js';
|
|
@@ -9,6 +9,6 @@ export * from './Box.js';
|
|
|
9
9
|
export * from './ButtonBase.js';
|
|
10
10
|
export * from './Portal.js';
|
|
11
11
|
export * from './ShadowRoot.js';
|
|
12
|
-
export * from './
|
|
12
|
+
export * from './lineClamp.js';
|
|
13
13
|
export * from './FieldsetBase.js';
|
|
14
14
|
export * from './OverflowContainer.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
let className = '_iui-line-clamp';
|
|
2
|
+
let css = `
|
|
3
|
+
.${className} {
|
|
4
|
+
overflow: hidden;
|
|
5
|
+
display: -webkit-box;
|
|
6
|
+
-webkit-line-clamp: var(--_iui-line-clamp, 3);
|
|
7
|
+
-webkit-box-orient: vertical;
|
|
8
|
+
}
|
|
9
|
+
`;
|
|
10
|
+
export const lineClamp = {
|
|
11
|
+
css,
|
|
12
|
+
className,
|
|
13
|
+
};
|