@itwin/components-react 4.3.0 → 4.4.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 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilder.d.ts +23 -9
- package/lib/cjs/components-react/filter-builder/FilterBuilder.d.ts.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilder.js +19 -8
- package/lib/cjs/components-react/filter-builder/FilterBuilder.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderContext.d.ts +8 -5
- package/lib/cjs/components-react/filter-builder/FilterBuilderContext.d.ts.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderContext.js +40 -18
- package/lib/cjs/components-react/filter-builder/FilterBuilderContext.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRule.d.ts.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRule.js +7 -4
- package/lib/cjs/components-react/filter-builder/FilterBuilderRule.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRule.scss +8 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleGroup.d.ts.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleGroup.js +3 -2
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleGroup.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleOperator.d.ts +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleOperator.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleValue.d.ts +11 -2
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleValue.d.ts.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleValue.js +2 -3
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleValue.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderState.d.ts +49 -10
- package/lib/cjs/components-react/filter-builder/FilterBuilderState.d.ts.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderState.js +106 -13
- package/lib/cjs/components-react/filter-builder/FilterBuilderState.js.map +1 -1
- package/lib/cjs/components-react/toolbar/InternalToolbarComponent.d.ts +144 -0
- package/lib/cjs/components-react/toolbar/InternalToolbarComponent.d.ts.map +1 -0
- package/lib/cjs/components-react/toolbar/InternalToolbarComponent.js +550 -0
- package/lib/cjs/components-react/toolbar/InternalToolbarComponent.js.map +1 -0
- package/lib/cjs/components-react/toolbar/ItemWrapper.js +3 -3
- package/lib/cjs/components-react/toolbar/ItemWrapper.js.map +1 -1
- package/lib/cjs/components-react/toolbar/Items.js +5 -5
- package/lib/cjs/components-react/toolbar/Items.js.map +1 -1
- package/lib/cjs/components-react/toolbar/Overflow.js +3 -3
- package/lib/cjs/components-react/toolbar/Overflow.js.map +1 -1
- package/lib/cjs/components-react/toolbar/OverflowPanel.js +5 -5
- package/lib/cjs/components-react/toolbar/OverflowPanel.js.map +1 -1
- package/lib/cjs/components-react/toolbar/PopupItem.js +4 -4
- package/lib/cjs/components-react/toolbar/PopupItem.js.map +1 -1
- package/lib/cjs/components-react/toolbar/PopupItemWithDrag.d.ts +1 -1
- package/lib/cjs/components-react/toolbar/PopupItemWithDrag.d.ts.map +1 -1
- package/lib/cjs/components-react/toolbar/PopupItemWithDrag.js +4 -4
- package/lib/cjs/components-react/toolbar/PopupItemWithDrag.js.map +1 -1
- package/lib/cjs/components-react/toolbar/PopupItemsPanel.js +2 -2
- package/lib/cjs/components-react/toolbar/PopupItemsPanel.js.map +1 -1
- package/lib/cjs/components-react/toolbar/Toolbar.d.ts +2 -2
- package/lib/cjs/components-react/toolbar/Toolbar.d.ts.map +1 -1
- package/lib/cjs/components-react/toolbar/Toolbar.js +2 -69
- package/lib/cjs/components-react/toolbar/Toolbar.js.map +1 -1
- package/lib/cjs/components-react/toolbar/ToolbarWithOverflow.d.ts +5 -105
- package/lib/cjs/components-react/toolbar/ToolbarWithOverflow.d.ts.map +1 -1
- package/lib/cjs/components-react/toolbar/ToolbarWithOverflow.js +6 -481
- package/lib/cjs/components-react/toolbar/ToolbarWithOverflow.js.map +1 -1
- package/lib/cjs/components-react/toolbar/useConditionalSynchedItems.d.ts +14 -0
- package/lib/cjs/components-react/toolbar/useConditionalSynchedItems.d.ts.map +1 -0
- package/lib/cjs/components-react/toolbar/useConditionalSynchedItems.js +119 -0
- package/lib/cjs/components-react/toolbar/useConditionalSynchedItems.js.map +1 -0
- package/lib/cjs/components-react.d.ts +6 -2
- package/lib/cjs/components-react.d.ts.map +1 -1
- package/lib/cjs/components-react.js +6 -2
- package/lib/cjs/components-react.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilder.d.ts +23 -9
- package/lib/esm/components-react/filter-builder/FilterBuilder.d.ts.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilder.js +17 -7
- package/lib/esm/components-react/filter-builder/FilterBuilder.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderContext.d.ts +8 -5
- package/lib/esm/components-react/filter-builder/FilterBuilderContext.d.ts.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderContext.js +40 -18
- package/lib/esm/components-react/filter-builder/FilterBuilderContext.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRule.d.ts.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRule.js +8 -5
- package/lib/esm/components-react/filter-builder/FilterBuilderRule.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRule.scss +8 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleGroup.d.ts.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleGroup.js +3 -2
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleGroup.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleOperator.d.ts +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleOperator.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleValue.d.ts +11 -2
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleValue.d.ts.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleValue.js +2 -3
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleValue.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderState.d.ts +49 -10
- package/lib/esm/components-react/filter-builder/FilterBuilderState.d.ts.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderState.js +99 -7
- package/lib/esm/components-react/filter-builder/FilterBuilderState.js.map +1 -1
- package/lib/esm/components-react/toolbar/InternalToolbarComponent.d.ts +144 -0
- package/lib/esm/components-react/toolbar/InternalToolbarComponent.d.ts.map +1 -0
- package/lib/esm/components-react/toolbar/InternalToolbarComponent.js +514 -0
- package/lib/esm/components-react/toolbar/InternalToolbarComponent.js.map +1 -0
- package/lib/esm/components-react/toolbar/ItemWrapper.js +1 -1
- package/lib/esm/components-react/toolbar/ItemWrapper.js.map +1 -1
- package/lib/esm/components-react/toolbar/Items.js +1 -1
- package/lib/esm/components-react/toolbar/Items.js.map +1 -1
- package/lib/esm/components-react/toolbar/Overflow.js +1 -1
- package/lib/esm/components-react/toolbar/Overflow.js.map +1 -1
- package/lib/esm/components-react/toolbar/OverflowPanel.js +1 -1
- package/lib/esm/components-react/toolbar/OverflowPanel.js.map +1 -1
- package/lib/esm/components-react/toolbar/PopupItem.js +1 -1
- package/lib/esm/components-react/toolbar/PopupItem.js.map +1 -1
- package/lib/esm/components-react/toolbar/PopupItemWithDrag.d.ts +1 -1
- package/lib/esm/components-react/toolbar/PopupItemWithDrag.d.ts.map +1 -1
- package/lib/esm/components-react/toolbar/PopupItemWithDrag.js +1 -1
- package/lib/esm/components-react/toolbar/PopupItemWithDrag.js.map +1 -1
- package/lib/esm/components-react/toolbar/PopupItemsPanel.js +1 -1
- package/lib/esm/components-react/toolbar/PopupItemsPanel.js.map +1 -1
- package/lib/esm/components-react/toolbar/Toolbar.d.ts +2 -2
- package/lib/esm/components-react/toolbar/Toolbar.d.ts.map +1 -1
- package/lib/esm/components-react/toolbar/Toolbar.js +2 -66
- package/lib/esm/components-react/toolbar/Toolbar.js.map +1 -1
- package/lib/esm/components-react/toolbar/ToolbarWithOverflow.d.ts +5 -105
- package/lib/esm/components-react/toolbar/ToolbarWithOverflow.d.ts.map +1 -1
- package/lib/esm/components-react/toolbar/ToolbarWithOverflow.js +5 -471
- package/lib/esm/components-react/toolbar/ToolbarWithOverflow.js.map +1 -1
- package/lib/esm/components-react/toolbar/useConditionalSynchedItems.d.ts +14 -0
- package/lib/esm/components-react/toolbar/useConditionalSynchedItems.d.ts.map +1 -0
- package/lib/esm/components-react/toolbar/useConditionalSynchedItems.js +92 -0
- package/lib/esm/components-react/toolbar/useConditionalSynchedItems.js.map +1 -0
- package/lib/esm/components-react.d.ts +6 -2
- package/lib/esm/components-react.d.ts.map +1 -1
- package/lib/esm/components-react.js +6 -2
- package/lib/esm/components-react.js.map +1 -1
- package/lib/public/locales/en/UiComponents.json +4 -1
- package/package.json +8 -9
|
@@ -3,97 +3,10 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import "./Toolbar.scss";
|
|
5
5
|
import * as React from "react";
|
|
6
|
-
import type {
|
|
6
|
+
import type { CommonToolbarItem, OnItemExecutedFunc } from "@itwin/appui-abstract";
|
|
7
7
|
import type { CommonProps, NoChildrenProps } from "@itwin/core-react";
|
|
8
|
-
import { Direction
|
|
9
|
-
|
|
10
|
-
* @public
|
|
11
|
-
* @deprecated in 4.0. Use [ToolbarCustomItem]($appui-react) instead.
|
|
12
|
-
*/
|
|
13
|
-
export interface CustomToolbarItem extends CustomButtonDefinition {
|
|
14
|
-
/** defines the content to display in popup panel */
|
|
15
|
-
panelContentNode?: React.ReactNode;
|
|
16
|
-
/** If true the popup panel is mounted once and unmounted when button is unmounted. If false the
|
|
17
|
-
* content node is unmounted each time the popup is closed. */
|
|
18
|
-
keepContentsLoaded?: boolean;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Context used by Toolbar items to know if popup panel should be hidden - via AutoHide.
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
|
-
export declare const ToolbarPopupAutoHideContext: React.Context<boolean>;
|
|
25
|
-
/**
|
|
26
|
-
* React hook used to retrieve the ToolbarPopupAutoHideContext.
|
|
27
|
-
* @public
|
|
28
|
-
*/
|
|
29
|
-
export declare function useToolbarPopupAutoHideContext(): boolean;
|
|
30
|
-
/** Describes toolbar item.
|
|
31
|
-
* @public
|
|
32
|
-
* @deprecated in 4.0. Use [ToolbarItem]($appui-react) instead.
|
|
33
|
-
*/
|
|
34
|
-
export type ToolbarItem = ActionButton | GroupButton | CustomToolbarItem;
|
|
35
|
-
/** CustomToolbarItem type guard.
|
|
36
|
-
* @internal
|
|
37
|
-
*/
|
|
38
|
-
export declare function isCustomToolbarItem(item: ToolbarItem): item is CustomToolbarItem;
|
|
39
|
-
/** @internal */
|
|
40
|
-
export declare const getToolbarDirection: (expandsTo: Direction) => OrthogonalDirection;
|
|
41
|
-
/** Available alignment modes of [[Toolbar]] panels.
|
|
42
|
-
* @public
|
|
43
|
-
*/
|
|
44
|
-
export declare enum ToolbarPanelAlignment {
|
|
45
|
-
Start = 0,
|
|
46
|
-
End = 1
|
|
47
|
-
}
|
|
48
|
-
/** Enumeration of Toolbar Opacity setting.
|
|
49
|
-
* @public
|
|
50
|
-
*/
|
|
51
|
-
export declare enum ToolbarOpacitySetting {
|
|
52
|
-
/** Use the default background, box-shadow opacity and backdrop-filter blur */
|
|
53
|
-
Defaults = 0,
|
|
54
|
-
/** Alter the opacity from transparent to the defaults based on mouse proximity */
|
|
55
|
-
Proximity = 1,
|
|
56
|
-
/** Use a transparent background, box-shadow opacity and backdrop-filter blur */
|
|
57
|
-
Transparent = 2
|
|
58
|
-
}
|
|
59
|
-
/** Helpers for [[ToolbarPanelAlignment]].
|
|
60
|
-
* @internal
|
|
61
|
-
*/
|
|
62
|
-
export declare class ToolbarPanelAlignmentHelpers {
|
|
63
|
-
/** Class name of [[ToolbarPanelAlignment.Start]] */
|
|
64
|
-
static readonly START_CLASS_NAME = "components-panel-alignment-start";
|
|
65
|
-
/** Class name of [[ToolbarPanelAlignment.End]] */
|
|
66
|
-
static readonly END_CLASS_NAME = "components-panel-alignment-end";
|
|
67
|
-
/** @returns Class name of specified [[ToolbarPanelAlignment]] */
|
|
68
|
-
static getCssClassName(panelAlignment: ToolbarPanelAlignment): string;
|
|
69
|
-
}
|
|
70
|
-
/** @internal */
|
|
71
|
-
export interface ToolbarOverflowContextProps {
|
|
72
|
-
readonly expandsTo: Direction;
|
|
73
|
-
readonly direction: OrthogonalDirection;
|
|
74
|
-
readonly overflowExpandsTo: Direction;
|
|
75
|
-
readonly overflowDirection: OrthogonalDirection;
|
|
76
|
-
readonly panelAlignment: ToolbarPanelAlignment;
|
|
77
|
-
readonly useDragInteraction: boolean;
|
|
78
|
-
readonly toolbarOpacitySetting: ToolbarOpacitySetting;
|
|
79
|
-
readonly openPopupCount: number;
|
|
80
|
-
readonly onPopupPanelOpenClose: (isOpening: boolean) => void;
|
|
81
|
-
readonly overflowDisplayActive: boolean;
|
|
82
|
-
readonly onItemExecuted: OnItemExecutedFunc;
|
|
83
|
-
readonly onKeyDown: (e: React.KeyboardEvent) => void;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Context used by Toolbar component to provide Direction to child components.
|
|
87
|
-
* @internal
|
|
88
|
-
*/
|
|
89
|
-
export declare const ToolbarWithOverflowDirectionContext: React.Context<ToolbarOverflowContextProps>;
|
|
90
|
-
/** @internal */
|
|
91
|
-
export declare function ToolbarItemComponent({ item, addGroupSeparator, }: {
|
|
92
|
-
item: ToolbarItem;
|
|
93
|
-
addGroupSeparator: boolean;
|
|
94
|
-
}): JSX.Element | null;
|
|
95
|
-
/** @internal */
|
|
96
|
-
export declare function useToolbarWithOverflowDirectionContext(): ToolbarOverflowContextProps;
|
|
8
|
+
import type { Direction } from "./utilities/Direction";
|
|
9
|
+
import type { ToolbarOpacitySetting, ToolbarPanelAlignment } from "./InternalToolbarComponent";
|
|
97
10
|
/** Properties of [[ToolbarWithOverflow]] component.
|
|
98
11
|
* @public
|
|
99
12
|
* @deprecated in 4.0. Use [ToolbarWithOverflowProps]($appui-react) instead.
|
|
@@ -116,23 +29,10 @@ export interface ToolbarWithOverflowProps extends CommonProps, NoChildrenProps {
|
|
|
116
29
|
/** Optional function to call on any KeyDown events processed by toolbar */
|
|
117
30
|
onKeyDown?: (e: React.KeyboardEvent) => void;
|
|
118
31
|
}
|
|
119
|
-
/** Component that displays
|
|
32
|
+
/** Component that displays toolbar items, displaying only the elements that can fit in the available space,
|
|
33
|
+
* and put the other items into a single panel.
|
|
120
34
|
* @public
|
|
121
35
|
* @deprecated in 4.0. Use [ToolbarWithOverflow]($appui-react) instead.
|
|
122
36
|
*/
|
|
123
37
|
export declare function ToolbarWithOverflow(props: ToolbarWithOverflowProps): JSX.Element;
|
|
124
|
-
/** Interface toolbars use to define context for its items.
|
|
125
|
-
* @internal
|
|
126
|
-
*/
|
|
127
|
-
export interface ToolbarItemContextArgs {
|
|
128
|
-
readonly hasOverflow: boolean;
|
|
129
|
-
readonly useHeight: boolean;
|
|
130
|
-
readonly onResize: (w: number) => void;
|
|
131
|
-
}
|
|
132
|
-
/** Interface toolbars use to define context for its items.
|
|
133
|
-
* @internal
|
|
134
|
-
*/
|
|
135
|
-
export declare const ToolbarItemContext: React.Context<ToolbarItemContextArgs>;
|
|
136
|
-
/** @internal */
|
|
137
|
-
export declare function useToolItemEntryContext(): ToolbarItemContextArgs;
|
|
138
38
|
//# sourceMappingURL=ToolbarWithOverflow.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToolbarWithOverflow.d.ts","sourceRoot":"","sources":["../../../../src/components-react/toolbar/ToolbarWithOverflow.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"ToolbarWithOverflow.d.ts","sourceRoot":"","sources":["../../../../src/components-react/toolbar/ToolbarWithOverflow.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,gBAAgB,CAAC;AACxB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EACV,iBAAiB,EACjB,kBAAkB,EACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,4BAA4B,CAAC;AAGpC;;;GAGG;AACH,MAAM,WAAW,wBAAyB,SAAQ,WAAW,EAAE,eAAe;IAC5E,oGAAoG;IACpG,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,4GAA4G;IAC5G,iBAAiB,CAAC,EAAE,SAAS,CAAC;IAC9B,uGAAuG;IACvG,KAAK,EAAE,iBAAiB,EAAE,CAAC;IAC3B,8FAA8F;IAC9F,cAAc,CAAC,EAAE,qBAAqB,CAAC;IACvC,mEAAmE;IACnE,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,oFAAoF;IACpF,qBAAqB,CAAC,EAAE,qBAAqB,CAAC;IAC9C,sDAAsD;IACtD,cAAc,CAAC,EAAE,kBAAkB,CAAC;IACpC,2EAA2E;IAC3E,SAAS,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,CAAC;CAC9C;AAED;;;;GAIG;AAEH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,eAQlE"}
|
|
@@ -6,482 +6,16 @@
|
|
|
6
6
|
* @module Toolbar
|
|
7
7
|
*/
|
|
8
8
|
import "./Toolbar.scss";
|
|
9
|
-
import classnames from "classnames";
|
|
10
9
|
import * as React from "react";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import { ToolbarItems } from "./Items";
|
|
15
|
-
import { ItemWrapper, useResizeObserverSingleDimension } from "./ItemWrapper";
|
|
16
|
-
import { ToolbarOverflowButton } from "./Overflow";
|
|
17
|
-
import { ToolbarOverflowPanel } from "./OverflowPanel";
|
|
18
|
-
import { PopupItem } from "./PopupItem";
|
|
19
|
-
import { PopupItemsPanel } from "./PopupItemsPanel";
|
|
20
|
-
import { PopupItemWithDrag } from "./PopupItemWithDrag";
|
|
21
|
-
import { Direction, DirectionHelpers, OrthogonalDirection, OrthogonalDirectionHelpers, } from "./utilities/Direction";
|
|
22
|
-
import { UiComponents } from "../UiComponents";
|
|
23
|
-
import { SvgPlaceholder } from "@itwin/itwinui-icons-react";
|
|
24
|
-
/**
|
|
25
|
-
* Context used by Toolbar items to know if popup panel should be hidden - via AutoHide.
|
|
26
|
-
* @public
|
|
27
|
-
*/
|
|
28
|
-
export const ToolbarPopupAutoHideContext = React.createContext(false);
|
|
29
|
-
/**
|
|
30
|
-
* React hook used to retrieve the ToolbarPopupAutoHideContext.
|
|
31
|
-
* @public
|
|
32
|
-
*/
|
|
33
|
-
export function useToolbarPopupAutoHideContext() {
|
|
34
|
-
return React.useContext(ToolbarPopupAutoHideContext);
|
|
35
|
-
}
|
|
36
|
-
/** CustomToolbarItem type guard.
|
|
37
|
-
* @internal
|
|
38
|
-
*/
|
|
39
|
-
export function isCustomToolbarItem(
|
|
40
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
41
|
-
item
|
|
42
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
43
|
-
) {
|
|
44
|
-
return !!item.isCustom && "panelContentNode" in item; // eslint-disable-line deprecation/deprecation
|
|
45
|
-
}
|
|
46
|
-
/** @internal */
|
|
47
|
-
export const getToolbarDirection = (expandsTo) => {
|
|
48
|
-
const orthogonalDirection = DirectionHelpers.getOrthogonalDirection(expandsTo);
|
|
49
|
-
return OrthogonalDirectionHelpers.inverse(orthogonalDirection);
|
|
50
|
-
};
|
|
51
|
-
/** Available alignment modes of [[Toolbar]] panels.
|
|
52
|
-
* @public
|
|
53
|
-
*/
|
|
54
|
-
export var ToolbarPanelAlignment;
|
|
55
|
-
(function (ToolbarPanelAlignment) {
|
|
56
|
-
ToolbarPanelAlignment[ToolbarPanelAlignment["Start"] = 0] = "Start";
|
|
57
|
-
ToolbarPanelAlignment[ToolbarPanelAlignment["End"] = 1] = "End";
|
|
58
|
-
})(ToolbarPanelAlignment || (ToolbarPanelAlignment = {}));
|
|
59
|
-
/** Enumeration of Toolbar Opacity setting.
|
|
60
|
-
* @public
|
|
61
|
-
*/
|
|
62
|
-
export var ToolbarOpacitySetting;
|
|
63
|
-
(function (ToolbarOpacitySetting) {
|
|
64
|
-
/** Use the default background, box-shadow opacity and backdrop-filter blur */
|
|
65
|
-
ToolbarOpacitySetting[ToolbarOpacitySetting["Defaults"] = 0] = "Defaults";
|
|
66
|
-
/** Alter the opacity from transparent to the defaults based on mouse proximity */
|
|
67
|
-
ToolbarOpacitySetting[ToolbarOpacitySetting["Proximity"] = 1] = "Proximity";
|
|
68
|
-
/** Use a transparent background, box-shadow opacity and backdrop-filter blur */
|
|
69
|
-
ToolbarOpacitySetting[ToolbarOpacitySetting["Transparent"] = 2] = "Transparent";
|
|
70
|
-
})(ToolbarOpacitySetting || (ToolbarOpacitySetting = {}));
|
|
71
|
-
/** Helpers for [[ToolbarPanelAlignment]].
|
|
72
|
-
* @internal
|
|
73
|
-
*/
|
|
74
|
-
class ToolbarPanelAlignmentHelpers {
|
|
75
|
-
/** @returns Class name of specified [[ToolbarPanelAlignment]] */
|
|
76
|
-
static getCssClassName(panelAlignment) {
|
|
77
|
-
switch (panelAlignment) {
|
|
78
|
-
case ToolbarPanelAlignment.Start:
|
|
79
|
-
return ToolbarPanelAlignmentHelpers.START_CLASS_NAME;
|
|
80
|
-
case ToolbarPanelAlignment.End:
|
|
81
|
-
return ToolbarPanelAlignmentHelpers.END_CLASS_NAME;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
/** Class name of [[ToolbarPanelAlignment.Start]] */
|
|
86
|
-
ToolbarPanelAlignmentHelpers.START_CLASS_NAME = "components-panel-alignment-start";
|
|
87
|
-
/** Class name of [[ToolbarPanelAlignment.End]] */
|
|
88
|
-
ToolbarPanelAlignmentHelpers.END_CLASS_NAME = "components-panel-alignment-end";
|
|
89
|
-
export { ToolbarPanelAlignmentHelpers };
|
|
90
|
-
/**
|
|
91
|
-
* Context used by Toolbar component to provide Direction to child components.
|
|
92
|
-
* @internal
|
|
93
|
-
*/
|
|
94
|
-
export const ToolbarWithOverflowDirectionContext = React.createContext({
|
|
95
|
-
expandsTo: Direction.Bottom,
|
|
96
|
-
direction: OrthogonalDirection.Horizontal,
|
|
97
|
-
overflowExpandsTo: Direction.Right,
|
|
98
|
-
overflowDirection: OrthogonalDirection.Vertical,
|
|
99
|
-
panelAlignment: ToolbarPanelAlignment.Start,
|
|
100
|
-
useDragInteraction: false,
|
|
101
|
-
toolbarOpacitySetting: ToolbarOpacitySetting.Proximity,
|
|
102
|
-
openPopupCount: 0,
|
|
103
|
-
onPopupPanelOpenClose: /* istanbul ignore next */ (_isOpening) => { },
|
|
104
|
-
overflowDisplayActive: false,
|
|
105
|
-
onItemExecuted: /* istanbul ignore next */ (_item) => void {},
|
|
106
|
-
onKeyDown: /* istanbul ignore next */ (_e) => void {},
|
|
107
|
-
});
|
|
108
|
-
/** @internal */
|
|
109
|
-
function CustomItem({ item, addGroupSeparator, }) {
|
|
110
|
-
const { useDragInteraction } = useToolbarWithOverflowDirectionContext();
|
|
111
|
-
const icon = React.useMemo(() => (item.icon &&
|
|
112
|
-
IconHelper.getIconReactNode(item.icon, item.internalData)) || (
|
|
113
|
-
// istanbul ignore next
|
|
114
|
-
React.createElement(Icon, { className: "icon", iconSpec: React.createElement(SvgPlaceholder, null) })), [item.icon, item.internalData]);
|
|
115
|
-
const isDisabled = React.useMemo(() => ConditionalBooleanValue.getValue(item.isDisabled), [item.isDisabled]);
|
|
116
|
-
const title = React.useMemo(() => {
|
|
117
|
-
var _a;
|
|
118
|
-
/* istanbul ignore next */ return (_a = ConditionalStringValue.getValue(item.label)) !== null && _a !== void 0 ? _a : item.id;
|
|
119
|
-
}, [item.id, item.label]);
|
|
120
|
-
const badge = React.useMemo(() => BadgeUtilities.getComponentForBadgeType(item.badgeType), [item.badgeType]);
|
|
121
|
-
return (React.createElement(PopupItem, { key: item.id, itemId: item.id, icon: icon, isDisabled: isDisabled, title: title, panel: item.panelContentNode, hideIndicator: useDragInteraction, badge: badge, addGroupSeparator: addGroupSeparator, keepContentsMounted: item.keepContentsLoaded }));
|
|
122
|
-
}
|
|
123
|
-
/** @internal */
|
|
124
|
-
function GroupPopupItem({ item, addGroupSeparator, }) {
|
|
125
|
-
const { useDragInteraction } = useToolbarWithOverflowDirectionContext();
|
|
126
|
-
const title = ConditionalStringValue.getValue(item.label);
|
|
127
|
-
const badge = BadgeUtilities.getComponentForBadgeType(item.badgeType);
|
|
128
|
-
const panel = React.useMemo(() => React.createElement(PopupItemsPanel, { groupItem: item, activateOnPointerUp: false }), [item]);
|
|
129
|
-
// istanbul ignore next
|
|
130
|
-
const providerId = "providerId" in item ? item.providerId : undefined;
|
|
131
|
-
if (useDragInteraction) {
|
|
132
|
-
return (React.createElement(PopupItemWithDrag, { key: item.id, itemId: item.id, providerId: providerId, itemPriority: item.itemPriority, groupPriority: item.groupPriority, icon: IconHelper.getIconReactNode(item.icon, item.internalData), isDisabled: ConditionalBooleanValue.getValue(item.isDisabled), title: title, groupItem: item, badge: badge, addGroupSeparator: addGroupSeparator }));
|
|
133
|
-
}
|
|
134
|
-
return (React.createElement(PopupItem, { key: item.id, itemId: item.id, providerId: providerId, itemPriority: item.itemPriority, groupPriority: item.groupPriority, icon: IconHelper.getIconReactNode(item.icon, item.internalData), isDisabled: ConditionalBooleanValue.getValue(item.isDisabled), title: title, panel: panel, badge: badge, hideIndicator: useDragInteraction, addGroupSeparator: addGroupSeparator }));
|
|
135
|
-
}
|
|
136
|
-
/** @internal */
|
|
137
|
-
function ActionItem({ item, addGroupSeparator, }) {
|
|
138
|
-
const title = ConditionalStringValue.getValue(item.label);
|
|
139
|
-
const badge = BadgeUtilities.getComponentForBadgeType(item.badgeType);
|
|
140
|
-
const { onItemExecuted } = useToolbarWithOverflowDirectionContext();
|
|
141
|
-
const onExecute = React.useCallback(() => {
|
|
142
|
-
item.execute();
|
|
143
|
-
onItemExecuted(item);
|
|
144
|
-
}, [item, onItemExecuted]);
|
|
145
|
-
// istanbul ignore next
|
|
146
|
-
const providerId = "providerId" in item ? item.providerId : undefined;
|
|
147
|
-
return (React.createElement(ToolbarButtonItem, { itemId: item.id, providerId: providerId, itemPriority: item.itemPriority, groupPriority: item.groupPriority, key: item.id, isDisabled: ConditionalBooleanValue.getValue(item.isDisabled), title: title, icon: IconHelper.getIconReactNode(item.icon, item.internalData), isActive: item.isActive, onClick: onExecute, badge: badge, addGroupSeparator: addGroupSeparator }));
|
|
148
|
-
}
|
|
149
|
-
/** @internal */
|
|
150
|
-
export function ToolbarItemComponent({ item, addGroupSeparator, }) {
|
|
151
|
-
if (ToolbarItemUtilities.isGroupButton(item)) {
|
|
152
|
-
return React.createElement(GroupPopupItem, { item: item, addGroupSeparator: addGroupSeparator });
|
|
153
|
-
}
|
|
154
|
-
else if (isCustomToolbarItem(item)) {
|
|
155
|
-
return React.createElement(CustomItem, { item: item, addGroupSeparator: addGroupSeparator });
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
// istanbul ignore else
|
|
159
|
-
if (ToolbarItemUtilities.isActionButton(item)) {
|
|
160
|
-
return React.createElement(ActionItem, { item: item, addGroupSeparator: addGroupSeparator });
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
// istanbul ignore next
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
/** @internal */
|
|
167
|
-
export function useToolbarWithOverflowDirectionContext() {
|
|
168
|
-
return React.useContext(ToolbarWithOverflowDirectionContext);
|
|
169
|
-
}
|
|
170
|
-
function OverflowItemsContainer(p) {
|
|
171
|
-
return React.createElement(React.Fragment, null, p.children);
|
|
172
|
-
}
|
|
173
|
-
function getItemWrapperClass(child) {
|
|
174
|
-
// istanbul ignore else
|
|
175
|
-
if (React.isValidElement(child)) {
|
|
176
|
-
if (child.props && child.props.addGroupSeparator)
|
|
177
|
-
return "components-toolbar-button-add-gap-before";
|
|
178
|
-
}
|
|
179
|
-
return undefined;
|
|
180
|
-
}
|
|
181
|
-
/** Component that displays tool settings as a bar across the top of the content view.
|
|
10
|
+
import { InternalToolbarComponent } from "./InternalToolbarComponent";
|
|
11
|
+
/** Component that displays toolbar items, displaying only the elements that can fit in the available space,
|
|
12
|
+
* and put the other items into a single panel.
|
|
182
13
|
* @public
|
|
183
14
|
* @deprecated in 4.0. Use [ToolbarWithOverflow]($appui-react) instead.
|
|
184
15
|
*/
|
|
185
16
|
// eslint-disable-next-line deprecation/deprecation
|
|
186
17
|
export function ToolbarWithOverflow(props) {
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
const panelAlignment = props.panelAlignment
|
|
190
|
-
? props.panelAlignment
|
|
191
|
-
: ToolbarPanelAlignment.Start;
|
|
192
|
-
const useHeight = expandsTo === Direction.Right || expandsTo === Direction.Left;
|
|
193
|
-
const [isOverflowPanelOpen, setIsOverflowPanelOpen] = React.useState(false);
|
|
194
|
-
const [popupPanelCount, setPopupPanelCount] = React.useState(0);
|
|
195
|
-
const overflowTitle = React.useRef(UiComponents.translate("toolbar.overflow"));
|
|
196
|
-
const isMounted = React.useRef(false);
|
|
197
|
-
React.useEffect(() => {
|
|
198
|
-
isMounted.current = true;
|
|
199
|
-
return () => {
|
|
200
|
-
isMounted.current = false;
|
|
201
|
-
};
|
|
202
|
-
});
|
|
203
|
-
const handlePopupPanelOpenClose = React.useCallback((isOpening) => {
|
|
204
|
-
// use setTimeout to avoid warning about setting state in ToolbarWithOverflow from render method of PopupItem/PopupItemWithDrag
|
|
205
|
-
setTimeout(() => {
|
|
206
|
-
// istanbul ignore next
|
|
207
|
-
if (!isMounted.current)
|
|
208
|
-
return;
|
|
209
|
-
setPopupPanelCount((prev) => {
|
|
210
|
-
/* istanbul ignore next */
|
|
211
|
-
const nextCount = isOpening ? prev + 1 : prev - 1;
|
|
212
|
-
return nextCount < 0 ? /* istanbul ignore next */ 0 : nextCount;
|
|
213
|
-
});
|
|
214
|
-
});
|
|
215
|
-
}, []);
|
|
216
|
-
const ref = React.useRef(null);
|
|
217
|
-
const width = React.useRef(undefined);
|
|
218
|
-
const availableNodes = React.useMemo(() => {
|
|
219
|
-
return props.items.map((item, index) => {
|
|
220
|
-
let addGroupSeparator = false;
|
|
221
|
-
if (index > 0)
|
|
222
|
-
addGroupSeparator =
|
|
223
|
-
item.groupPriority !== props.items[index - 1].groupPriority;
|
|
224
|
-
return (React.createElement(ToolbarItemComponent, { key: item.id, item: item, addGroupSeparator: !!addGroupSeparator }));
|
|
225
|
-
});
|
|
226
|
-
}, [props.items]);
|
|
227
|
-
/* overflowItemKeys - keys of items to show in overflow panel
|
|
228
|
-
* handleContainerResize - handler called when container <div> is resized.
|
|
229
|
-
* handleOverflowResize - handler called when determining size of overflow indicator/button.
|
|
230
|
-
* handleEntryResize - handler called when determining size of each item/button. */
|
|
231
|
-
const [overflowItemKeys, handleContainerResize, handleOverflowResize, handleEntryResize,] = useOverflow(availableNodes, panelAlignment === ToolbarPanelAlignment.End);
|
|
232
|
-
// handler called by ResizeObserver
|
|
233
|
-
const handleResize = React.useCallback((w) => {
|
|
234
|
-
width.current = w;
|
|
235
|
-
width.current !== undefined && handleContainerResize(width.current);
|
|
236
|
-
}, [handleContainerResize]);
|
|
237
|
-
const resizeObserverRef = useResizeObserverSingleDimension(handleResize, useHeight);
|
|
238
|
-
const handleClick = React.useCallback(() => {
|
|
239
|
-
setIsOverflowPanelOpen((prev) => !prev);
|
|
240
|
-
}, []);
|
|
241
|
-
// istanbul ignore next - NEEDSWORK add complete tests
|
|
242
|
-
const handleClose = React.useCallback(() => {
|
|
243
|
-
setIsOverflowPanelOpen(false);
|
|
244
|
-
}, []);
|
|
245
|
-
const refs = useRefs(ref, resizeObserverRef);
|
|
246
|
-
const availableItems = React.Children.toArray(availableNodes);
|
|
247
|
-
const displayedItems = availableItems.reduce((acc, child, index) => {
|
|
248
|
-
const key = getChildKey(child, index);
|
|
249
|
-
if (!overflowItemKeys || overflowItemKeys.indexOf(key) < 0) {
|
|
250
|
-
acc.push([key, child]);
|
|
251
|
-
}
|
|
252
|
-
return acc;
|
|
253
|
-
}, []);
|
|
254
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
255
|
-
const overflowPanelItems = overflowItemKeys
|
|
256
|
-
? availableItems.reduce((acc, child, index) => {
|
|
257
|
-
const key = getChildKey(child, index);
|
|
258
|
-
if (overflowItemKeys.indexOf(key) >= 0) {
|
|
259
|
-
acc.push([key, child]);
|
|
260
|
-
}
|
|
261
|
-
return acc;
|
|
262
|
-
}, [])
|
|
263
|
-
: [];
|
|
264
|
-
const direction = getToolbarDirection(expandsTo);
|
|
265
|
-
const overflowExpandsTo = undefined !== props.overflowExpandsTo
|
|
266
|
-
? props.overflowExpandsTo
|
|
267
|
-
: Direction.Right;
|
|
268
|
-
const addOverflowButton = React.useCallback((atStart) => {
|
|
269
|
-
const overflowItems = !!atStart
|
|
270
|
-
? overflowPanelItems.reverse()
|
|
271
|
-
: overflowPanelItems;
|
|
272
|
-
return (React.createElement(ToolbarItemContext.Provider, { value: {
|
|
273
|
-
hasOverflow: false,
|
|
274
|
-
useHeight,
|
|
275
|
-
onResize: handleOverflowResize,
|
|
276
|
-
} },
|
|
277
|
-
React.createElement(ToolbarOverflowButton, { expandsTo: expandsTo, onClick: handleClick, onClose: handleClose, open: overflowItems.length > 0 && isOverflowPanelOpen, panelNode: React.createElement(ToolbarOverflowPanel, null,
|
|
278
|
-
React.createElement(OverflowItemsContainer, null, overflowItems.map(([key, child]) => {
|
|
279
|
-
return (React.createElement(ToolbarItemContext.Provider, { key: key, value: {
|
|
280
|
-
hasOverflow: true,
|
|
281
|
-
useHeight,
|
|
282
|
-
onResize: () => { },
|
|
283
|
-
} }, React.createElement(ItemWrapper, { className: getItemWrapperClass(child) }, child)));
|
|
284
|
-
}))), title: overflowTitle.current })));
|
|
285
|
-
}, [
|
|
286
|
-
handleClick,
|
|
287
|
-
handleClose,
|
|
288
|
-
handleOverflowResize,
|
|
289
|
-
isOverflowPanelOpen,
|
|
290
|
-
expandsTo,
|
|
291
|
-
overflowPanelItems,
|
|
292
|
-
useHeight,
|
|
293
|
-
]);
|
|
294
|
-
const className = classnames("components-toolbar-overflow-sizer", OrthogonalDirectionHelpers.getCssClassName(direction), props.className);
|
|
295
|
-
const showOverflowAtStart = direction === OrthogonalDirection.Horizontal &&
|
|
296
|
-
panelAlignment === ToolbarPanelAlignment.End;
|
|
297
|
-
/* The ItemWrapper is used to wrap the <Item> <ExpandableItem> with a <div> that specifies a ref that the sizing logic uses to determine the
|
|
298
|
-
size of the item. */
|
|
299
|
-
return (React.createElement(ToolbarWithOverflowDirectionContext.Provider, { value: {
|
|
300
|
-
expandsTo,
|
|
301
|
-
direction,
|
|
302
|
-
overflowExpandsTo,
|
|
303
|
-
panelAlignment,
|
|
304
|
-
useDragInteraction,
|
|
305
|
-
toolbarOpacitySetting: undefined !== props.toolbarOpacitySetting
|
|
306
|
-
? props.toolbarOpacitySetting
|
|
307
|
-
: ToolbarOpacitySetting.Proximity,
|
|
308
|
-
overflowDirection: direction === OrthogonalDirection.Horizontal
|
|
309
|
-
? OrthogonalDirection.Vertical
|
|
310
|
-
: OrthogonalDirection.Horizontal,
|
|
311
|
-
openPopupCount: popupPanelCount,
|
|
312
|
-
onPopupPanelOpenClose: handlePopupPanelOpenClose,
|
|
313
|
-
overflowDisplayActive: overflowPanelItems.length > 0 && isOverflowPanelOpen,
|
|
314
|
-
onItemExecuted: props.onItemExecuted ? props.onItemExecuted : () => { },
|
|
315
|
-
onKeyDown: props.onKeyDown
|
|
316
|
-
? props.onKeyDown
|
|
317
|
-
: /* istanbul ignore next */ (_e) => { },
|
|
318
|
-
} }, availableItems.length > 0 && (React.createElement("div", { className: className, ref: refs, style: props.style, onKeyDown: props.onKeyDown, role: "presentation" },
|
|
319
|
-
React.createElement(ToolbarItems, { className: "components-items", direction: direction },
|
|
320
|
-
(!overflowItemKeys || overflowItemKeys.length > 0) &&
|
|
321
|
-
showOverflowAtStart &&
|
|
322
|
-
addOverflowButton(true),
|
|
323
|
-
displayedItems.map(([key, child]) => {
|
|
324
|
-
const onEntryResize = handleEntryResize(key);
|
|
325
|
-
return (React.createElement(ToolbarItemContext.Provider, { key: key, value: {
|
|
326
|
-
hasOverflow: false,
|
|
327
|
-
useHeight,
|
|
328
|
-
onResize: onEntryResize,
|
|
329
|
-
} }, React.createElement(ItemWrapper, { className: getItemWrapperClass(child) }, child)));
|
|
330
|
-
}),
|
|
331
|
-
(!overflowItemKeys || overflowItemKeys.length > 0) &&
|
|
332
|
-
!showOverflowAtStart &&
|
|
333
|
-
addOverflowButton(false))))));
|
|
334
|
-
}
|
|
335
|
-
/** Returns key of a child. Must be used along with React.Children.toArray to preserve the semantics of availableItems.
|
|
336
|
-
* @internal
|
|
337
|
-
*/
|
|
338
|
-
function getChildKey(child, index) {
|
|
339
|
-
// istanbul ignore else
|
|
340
|
-
if (React.isValidElement(child) && child.key !== null) {
|
|
341
|
-
return child.key.toString();
|
|
342
|
-
}
|
|
343
|
-
// istanbul ignore next
|
|
344
|
-
return index.toString();
|
|
345
|
-
}
|
|
346
|
-
/** Returns a subset of toolbar item entry keys that exceed given width and should be overflowItemKeys.
|
|
347
|
-
* @internal
|
|
348
|
-
*/
|
|
349
|
-
function determineOverflowItems(size, entries, overflowButtonSize, overflowButtonAtStart) {
|
|
350
|
-
let toolbarSize = 0;
|
|
351
|
-
const buttonPadding = 2;
|
|
352
|
-
if (overflowButtonAtStart && entries.length > 0) {
|
|
353
|
-
let i = entries.length - 1;
|
|
354
|
-
for (; i >= 0; i--) {
|
|
355
|
-
const w = entries[i][1] + buttonPadding;
|
|
356
|
-
const newSettingsWidth = toolbarSize + w;
|
|
357
|
-
if (newSettingsWidth > size) {
|
|
358
|
-
toolbarSize += overflowButtonSize + buttonPadding;
|
|
359
|
-
break;
|
|
360
|
-
}
|
|
361
|
-
toolbarSize = newSettingsWidth;
|
|
362
|
-
}
|
|
363
|
-
if (i >= 0) {
|
|
364
|
-
let j = i + 1;
|
|
365
|
-
for (; j < entries.length; j++) {
|
|
366
|
-
if (toolbarSize <= size)
|
|
367
|
-
break;
|
|
368
|
-
const w = entries[j][1] + buttonPadding;
|
|
369
|
-
toolbarSize -= w;
|
|
370
|
-
}
|
|
371
|
-
return entries.slice(0, j).map((e) => e[0]);
|
|
372
|
-
}
|
|
373
|
-
else {
|
|
374
|
-
return [];
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
else {
|
|
378
|
-
let i = 0;
|
|
379
|
-
for (; i < entries.length; i++) {
|
|
380
|
-
const w = entries[i][1] + buttonPadding;
|
|
381
|
-
const newSettingsWidth = toolbarSize + w;
|
|
382
|
-
if (newSettingsWidth > size) {
|
|
383
|
-
toolbarSize += overflowButtonSize + buttonPadding;
|
|
384
|
-
break;
|
|
385
|
-
}
|
|
386
|
-
toolbarSize = newSettingsWidth;
|
|
387
|
-
}
|
|
388
|
-
let j = i;
|
|
389
|
-
for (; j > 0; j--) {
|
|
390
|
-
if (toolbarSize <= size)
|
|
391
|
-
break;
|
|
392
|
-
const w = entries[j][1] + buttonPadding;
|
|
393
|
-
toolbarSize -= w;
|
|
394
|
-
}
|
|
395
|
-
return entries.slice(j).map((e) => e[0]);
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
/** Hook that returns a list of overflowItemKeys availableItems.
|
|
399
|
-
* @internal
|
|
400
|
-
*/
|
|
401
|
-
function useOverflow(availableItems, overflowButtonAtStart) {
|
|
402
|
-
const [overflowItemKeys, setOverflown] = React.useState();
|
|
403
|
-
const itemSizes = React.useRef(new Map());
|
|
404
|
-
const size = React.useRef(undefined);
|
|
405
|
-
const overflowButtonSize = React.useRef(undefined);
|
|
406
|
-
const calculateOverflow = React.useCallback(() => {
|
|
407
|
-
const sizes = verifiedMapEntries(itemSizes.current);
|
|
408
|
-
if (size.current === undefined ||
|
|
409
|
-
sizes === undefined ||
|
|
410
|
-
overflowButtonSize.current === undefined) {
|
|
411
|
-
setOverflown(undefined);
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
// Calculate overflow.
|
|
415
|
-
const newOverflown = determineOverflowItems(size.current, [...sizes.entries()], overflowButtonSize.current, overflowButtonAtStart);
|
|
416
|
-
setOverflown((prevOverflown) => {
|
|
417
|
-
return eql(prevOverflown, newOverflown) ? prevOverflown : newOverflown;
|
|
418
|
-
});
|
|
419
|
-
}, [overflowButtonAtStart]);
|
|
420
|
-
React.useLayoutEffect(() => {
|
|
421
|
-
const newEntryWidths = new Map();
|
|
422
|
-
const array = React.Children.toArray(availableItems);
|
|
423
|
-
for (let i = 0; i < array.length; i++) {
|
|
424
|
-
const child = array[i];
|
|
425
|
-
const key = getChildKey(child, i);
|
|
426
|
-
const lastW = itemSizes.current.get(key);
|
|
427
|
-
newEntryWidths.set(key, lastW);
|
|
428
|
-
}
|
|
429
|
-
itemSizes.current = newEntryWidths;
|
|
430
|
-
calculateOverflow();
|
|
431
|
-
}, [availableItems, calculateOverflow]);
|
|
432
|
-
const handleContainerResize = React.useCallback((w) => {
|
|
433
|
-
const calculate = size.current !== w;
|
|
434
|
-
size.current = w;
|
|
435
|
-
calculate && calculateOverflow();
|
|
436
|
-
}, [calculateOverflow]);
|
|
437
|
-
const handleOverflowResize = React.useCallback((w) => {
|
|
438
|
-
const calculate = overflowButtonSize.current !== w;
|
|
439
|
-
overflowButtonSize.current = w;
|
|
440
|
-
calculate && calculateOverflow();
|
|
441
|
-
}, [calculateOverflow]);
|
|
442
|
-
const handleEntryResize = React.useCallback((key) => (w) => {
|
|
443
|
-
const oldW = itemSizes.current.get(key);
|
|
444
|
-
if (oldW !== w) {
|
|
445
|
-
itemSizes.current.set(key, w);
|
|
446
|
-
calculateOverflow();
|
|
447
|
-
}
|
|
448
|
-
}, [calculateOverflow]);
|
|
449
|
-
return [
|
|
450
|
-
overflowItemKeys,
|
|
451
|
-
handleContainerResize,
|
|
452
|
-
handleOverflowResize,
|
|
453
|
-
handleEntryResize,
|
|
454
|
-
];
|
|
455
|
-
}
|
|
456
|
-
/** Interface toolbars use to define context for its items.
|
|
457
|
-
* @internal
|
|
458
|
-
*/
|
|
459
|
-
export const ToolbarItemContext = React.createContext(null);
|
|
460
|
-
/** @internal */
|
|
461
|
-
export function useToolItemEntryContext() {
|
|
462
|
-
return React.useContext(ToolbarItemContext);
|
|
463
|
-
}
|
|
464
|
-
function verifiedMapEntries(map) {
|
|
465
|
-
for (const [, val] of map) {
|
|
466
|
-
// istanbul ignore next during unit testing
|
|
467
|
-
if (val === undefined)
|
|
468
|
-
return undefined;
|
|
469
|
-
}
|
|
470
|
-
return map;
|
|
471
|
-
}
|
|
472
|
-
function eql(prev, value) {
|
|
473
|
-
if (!prev)
|
|
474
|
-
return false;
|
|
475
|
-
// istanbul ignore next
|
|
476
|
-
if (prev.length !== value.length)
|
|
477
|
-
return false;
|
|
478
|
-
for (let i = 0; i < prev.length; i++) {
|
|
479
|
-
const p = prev[i];
|
|
480
|
-
const v = value[i];
|
|
481
|
-
// istanbul ignore next
|
|
482
|
-
if (p !== v)
|
|
483
|
-
return false;
|
|
484
|
-
}
|
|
485
|
-
return true;
|
|
18
|
+
const { overflowExpandsTo, ...internalProps } = props;
|
|
19
|
+
return (React.createElement(InternalToolbarComponent, { enableOverflow: { overflowExpandsTo }, ...internalProps }));
|
|
486
20
|
}
|
|
487
21
|
//# sourceMappingURL=ToolbarWithOverflow.js.map
|