@itwin/appui-react 5.8.0 → 5.9.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.
Files changed (56) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/lib/appui-react/hooks/useSafeContext.d.ts +7 -0
  3. package/lib/appui-react/hooks/useSafeContext.d.ts.map +1 -0
  4. package/lib/appui-react/hooks/useSafeContext.js +17 -0
  5. package/lib/appui-react/hooks/useSafeContext.js.map +1 -0
  6. package/lib/appui-react/toolbar/new-toolbars/ActionItem.d.ts +2 -2
  7. package/lib/appui-react/toolbar/new-toolbars/ActionItem.d.ts.map +1 -1
  8. package/lib/appui-react/toolbar/new-toolbars/ActionItem.js +2 -1
  9. package/lib/appui-react/toolbar/new-toolbars/ActionItem.js.map +1 -1
  10. package/lib/appui-react/toolbar/new-toolbars/CustomItem.d.ts +2 -2
  11. package/lib/appui-react/toolbar/new-toolbars/CustomItem.d.ts.map +1 -1
  12. package/lib/appui-react/toolbar/new-toolbars/CustomItem.js +3 -2
  13. package/lib/appui-react/toolbar/new-toolbars/CustomItem.js.map +1 -1
  14. package/lib/appui-react/toolbar/new-toolbars/GroupItem.d.ts +2 -3
  15. package/lib/appui-react/toolbar/new-toolbars/GroupItem.d.ts.map +1 -1
  16. package/lib/appui-react/toolbar/new-toolbars/GroupItem.js +6 -7
  17. package/lib/appui-react/toolbar/new-toolbars/GroupItem.js.map +1 -1
  18. package/lib/appui-react/toolbar/new-toolbars/Item.d.ts +3 -5
  19. package/lib/appui-react/toolbar/new-toolbars/Item.d.ts.map +1 -1
  20. package/lib/appui-react/toolbar/new-toolbars/Item.js +15 -19
  21. package/lib/appui-react/toolbar/new-toolbars/Item.js.map +1 -1
  22. package/lib/appui-react/toolbar/new-toolbars/OverflowButton.d.ts +0 -1
  23. package/lib/appui-react/toolbar/new-toolbars/OverflowButton.d.ts.map +1 -1
  24. package/lib/appui-react/toolbar/new-toolbars/OverflowButton.js +3 -2
  25. package/lib/appui-react/toolbar/new-toolbars/OverflowButton.js.map +1 -1
  26. package/lib/appui-react/toolbar/new-toolbars/Separator.d.ts +8 -0
  27. package/lib/appui-react/toolbar/new-toolbars/Separator.d.ts.map +1 -0
  28. package/lib/appui-react/toolbar/new-toolbars/Separator.js +19 -0
  29. package/lib/appui-react/toolbar/new-toolbars/Separator.js.map +1 -0
  30. package/lib/appui-react/toolbar/new-toolbars/Separator.scss +32 -0
  31. package/lib/appui-react/toolbar/new-toolbars/Surface.d.ts +5 -3
  32. package/lib/appui-react/toolbar/new-toolbars/Surface.d.ts.map +1 -1
  33. package/lib/appui-react/toolbar/new-toolbars/Surface.js.map +1 -1
  34. package/lib/appui-react/toolbar/new-toolbars/Surface.scss +4 -2
  35. package/lib/appui-react/toolbar/new-toolbars/ToolGroup.d.ts +0 -5
  36. package/lib/appui-react/toolbar/new-toolbars/ToolGroup.d.ts.map +1 -1
  37. package/lib/appui-react/toolbar/new-toolbars/ToolGroup.js +50 -19
  38. package/lib/appui-react/toolbar/new-toolbars/ToolGroup.js.map +1 -1
  39. package/lib/appui-react/toolbar/new-toolbars/Toolbar.d.ts +5 -0
  40. package/lib/appui-react/toolbar/new-toolbars/Toolbar.d.ts.map +1 -1
  41. package/lib/appui-react/toolbar/new-toolbars/Toolbar.js +45 -12
  42. package/lib/appui-react/toolbar/new-toolbars/Toolbar.js.map +1 -1
  43. package/lib/appui-react/toolbar/new-toolbars/useOverflow.js +2 -2
  44. package/lib/appui-react/toolbar/new-toolbars/useOverflow.js.map +1 -1
  45. package/lib/appui-react/widget-panels/useWidgetDirection.d.ts +1 -1
  46. package/lib/appui-react/widget-panels/useWidgetDirection.js +1 -1
  47. package/lib/appui-react/widget-panels/useWidgetDirection.js.map +1 -1
  48. package/lib/appui-react/widgets/useWidget.d.ts +5 -1
  49. package/lib/appui-react/widgets/useWidget.d.ts.map +1 -1
  50. package/lib/appui-react/widgets/useWidget.js +5 -1
  51. package/lib/appui-react/widgets/useWidget.js.map +1 -1
  52. package/lib/cjs/appui-react/toolbar/new-toolbars/Separator.scss +32 -0
  53. package/lib/cjs/appui-react/toolbar/new-toolbars/Surface.scss +4 -2
  54. package/lib/esm/appui-react/toolbar/new-toolbars/Separator.scss +32 -0
  55. package/lib/esm/appui-react/toolbar/new-toolbars/Surface.scss +4 -2
  56. package/package.json +8 -8
@@ -9,10 +9,5 @@ interface ToolGroupProps extends CommonProps {
9
9
  }
10
10
  /** @internal */
11
11
  export declare function ToolGroup({ children, className, ...props }: ToolGroupProps): React.JSX.Element;
12
- export declare namespace ToolGroup {
13
- var ActionItem: React.ForwardRefExoticComponent<import("./ActionItem.js").ActionItemProps & React.RefAttributes<HTMLButtonElement>>;
14
- var GroupItem: React.ForwardRefExoticComponent<import("./GroupItem.js").GroupItemProps & React.RefAttributes<HTMLButtonElement>>;
15
- var CustomItem: React.ForwardRefExoticComponent<import("./CustomItem.js").CustomItemProps & React.RefAttributes<HTMLButtonElement>>;
16
- }
17
12
  export {};
18
13
  //# sourceMappingURL=ToolGroup.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ToolGroup.d.ts","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/ToolGroup.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,kBAAkB,CAAC;AAE1B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAWrD,UAAU,cAAe,SAAQ,WAAW;IAC1C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAID,gBAAgB;AAChB,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,qBAoE1E;yBApEe,SAAS"}
1
+ {"version":3,"file":"ToolGroup.d.ts","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/ToolGroup.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,kBAAkB,CAAC;AAE1B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AASrD,UAAU,cAAe,SAAQ,WAAW;IAC1C,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAID,gBAAgB;AAChB,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,qBA0E1E"}
@@ -8,20 +8,15 @@
8
8
  import "./ToolGroup.scss";
9
9
  import classnames from "classnames";
10
10
  import * as React from "react";
11
- import { ActionItem } from "./ActionItem.js";
12
- import { GroupItem } from "./GroupItem.js";
13
- import { CustomItem } from "./CustomItem.js";
14
11
  import { OverflowButton } from "./OverflowButton.js";
15
12
  import { useOverflow } from "./useOverflow.js";
16
13
  import { getChildKey } from "../../layout/tool-settings/Docked.js";
17
14
  import { ToolbarContext } from "./Toolbar.js";
18
15
  import { Surface } from "./Surface.js";
16
+ import { useSafeContext } from "../../hooks/useSafeContext.js";
19
17
  /** @internal */
20
18
  export function ToolGroup({ children, className, ...props }) {
21
- const context = React.useContext(ToolbarContext);
22
- const expandsTo = context?.expandsTo ?? "bottom";
23
- const panelAlignment = context?.panelAlignment ?? "start";
24
- const orientation = getOrientation(expandsTo);
19
+ const { panelAlignment, orientation } = useSafeContext(ToolbarContext);
25
20
  const childrenArray = React.Children.toArray(children);
26
21
  const keyToChildMap = childrenArray.reduce((acc, child, index) => {
27
22
  const childKey = getChildKey(child, index);
@@ -35,7 +30,14 @@ export function ToolGroup({ children, className, ...props }) {
35
30
  const element = itemRefs.current.get(item);
36
31
  if (!element)
37
32
  return { width: 0, height: 0 };
38
- return element.getBoundingClientRect();
33
+ const elementSize = element.getBoundingClientRect();
34
+ const separatorSize = getSeparatorSize(element);
35
+ if (!separatorSize)
36
+ return elementSize;
37
+ return {
38
+ width: elementSize.width + separatorSize.width,
39
+ height: elementSize.height + separatorSize.height,
40
+ };
39
41
  }, []);
40
42
  const getOverflowSize = React.useCallback(() => {
41
43
  const element = overflowRef.current;
@@ -64,17 +66,46 @@ export function ToolGroup({ children, className, ...props }) {
64
66
  }),
65
67
  renderOverflow && (React.createElement(OverflowButton, { ref: overflowRef }, overflown.map(([_, child]) => child))))));
66
68
  }
67
- ToolGroup.ActionItem = ActionItem;
68
- ToolGroup.GroupItem = GroupItem;
69
- ToolGroup.CustomItem = CustomItem;
70
- function getOrientation(expandsTo) {
71
- switch (expandsTo) {
72
- case "left":
73
- case "right":
74
- return "vertical";
75
- case "top":
76
- case "bottom":
77
- return "horizontal";
69
+ // First item in the group reserves space for the separator to correctly calculate the overflow.
70
+ function getSeparatorSize(toolbarItem) {
71
+ const firstInGroup = isFirstInGroup(toolbarItem);
72
+ if (!firstInGroup)
73
+ return undefined;
74
+ // Last group does not have a separator.
75
+ if (isLastGroup(toolbarItem))
76
+ return undefined;
77
+ const separator = getSeparator(toolbarItem);
78
+ if (!separator)
79
+ return undefined;
80
+ return separator.getBoundingClientRect();
81
+ }
82
+ // Returns if the toolbar item is the first in its group.
83
+ function isFirstInGroup(toolbarItem) {
84
+ const prev = toolbarItem.previousElementSibling;
85
+ if (prev?.tagName === "BUTTON")
86
+ return false;
87
+ return true;
88
+ }
89
+ // Returns if the toolbar item is in the last group of the toolbar.
90
+ function isLastGroup(toolbarItem) {
91
+ let el = toolbarItem.nextElementSibling;
92
+ while (el) {
93
+ if (el.tagName === "BUTTON" && el.hasAttribute("data-item-id")) {
94
+ return false;
95
+ }
96
+ el = el.nextElementSibling;
97
+ }
98
+ return true;
99
+ }
100
+ // Returns the first separator element after the toolbar item, if it exists.
101
+ function getSeparator(toolbarItem) {
102
+ let el = toolbarItem.nextElementSibling;
103
+ while (el) {
104
+ if (el.classList.contains("uifw-toolbar-newToolbars-separator")) {
105
+ return el;
106
+ }
107
+ el = el.nextElementSibling;
78
108
  }
109
+ return undefined;
79
110
  }
80
111
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,cAAc,CACrB,SAAwD;IAExD,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,MAAM,CAAC;QACZ,KAAK,OAAO;YACV,OAAO,UAAU,CAAC;QACpB,KAAK,KAAK,CAAC;QACX,KAAK,QAAQ;YACX,OAAO,YAAY,CAAC;IACxB,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Toolbar\n */\n\nimport \"./ToolGroup.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { ActionItem } from \"./ActionItem.js\";\nimport { GroupItem } from \"./GroupItem.js\";\nimport { CustomItem } from \"./CustomItem.js\";\nimport { OverflowButton } from \"./OverflowButton.js\";\nimport { useOverflow } from \"./useOverflow.js\";\nimport { getChildKey } from \"../../layout/tool-settings/Docked.js\";\nimport { ToolbarContext } from \"./Toolbar.js\";\nimport { Surface } from \"./Surface.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-deprecated\ninterface ToolGroupProps extends CommonProps {\n children?: React.ReactNode;\n}\n\ntype Child = ReturnType<typeof React.Children.toArray>[0];\n\n/** @internal */\nexport function ToolGroup({ children, className, ...props }: ToolGroupProps) {\n const context = React.useContext(ToolbarContext);\n const expandsTo = context?.expandsTo ?? \"bottom\";\n const panelAlignment = context?.panelAlignment ?? \"start\";\n const orientation = getOrientation(expandsTo);\n const childrenArray = React.Children.toArray(children);\n\n const keyToChildMap = childrenArray.reduce<Map<string, Child>>(\n (acc, child, index) => {\n const childKey = getChildKey(child, index);\n acc.set(childKey, child);\n return acc;\n },\n new Map()\n );\n const childrenKeys = Array.from(keyToChildMap.keys());\n const itemRefs = React.useRef<Map<string, Element>>(new Map());\n const overflowRef = React.useRef<HTMLButtonElement>(null);\n\n const getItemSize = React.useCallback((item: string) => {\n const element = itemRefs.current.get(item);\n if (!element) return { width: 0, height: 0 };\n return element.getBoundingClientRect();\n }, []);\n const getOverflowSize = React.useCallback(() => {\n const element = overflowRef.current;\n if (!element) return { width: 0, height: 0 };\n return element.getBoundingClientRect();\n }, []);\n\n const [containerRef, componentRef, visibleCount, renderOverflow] =\n useOverflow(childrenKeys, orientation, getItemSize, getOverflowSize);\n\n const keyToChildEntries = Array.from(keyToChildMap.entries());\n const visibleChildren = keyToChildEntries.slice(0, visibleCount);\n const overflown = keyToChildEntries.slice(visibleCount);\n return (\n <div\n className={classnames(\n \"uifw-toolbar-group-toolGroup_container\",\n `uifw-${orientation}`,\n `uifw-${panelAlignment}`,\n className\n )}\n ref={containerRef}\n >\n <Surface orientation={orientation} ref={componentRef} {...props}>\n {visibleChildren.map(([item, child]) => {\n if (!React.isValidElement<{ ref: React.Ref<Element> }>(child))\n return child;\n return React.cloneElement(child, {\n ref: (el: Element | null) => {\n if (!el) {\n itemRefs.current.delete(item);\n return;\n }\n itemRefs.current.set(item, el);\n },\n });\n })}\n {renderOverflow && (\n <OverflowButton ref={overflowRef}>\n {overflown.map(([_, child]) => child)}\n </OverflowButton>\n )}\n </Surface>\n </div>\n );\n}\n\nToolGroup.ActionItem = ActionItem;\nToolGroup.GroupItem = GroupItem;\nToolGroup.CustomItem = CustomItem;\n\ntype ToolbarContextProps = React.ContextType<typeof ToolbarContext>;\n\nfunction getOrientation(\n expandsTo: NonNullable<ToolbarContextProps>[\"expandsTo\"]\n) {\n switch (expandsTo) {\n case \"left\":\n case \"right\":\n return \"vertical\";\n case \"top\":\n case \"bottom\":\n return \"horizontal\";\n }\n}\n"]}
1
+ {"version":3,"file":"ToolGroup.js","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/ToolGroup.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK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,yDAAyD;AACzD,SAAS,cAAc,CAAC,WAAoB;IAC1C,MAAM,IAAI,GAAG,WAAW,CAAC,sBAAsB,CAAC;IAChD,IAAI,IAAI,EAAE,OAAO,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC7C,OAAO,IAAI,CAAC;AACd,CAAC;AAED,mEAAmE;AACnE,SAAS,WAAW,CAAC,WAAoB;IACvC,IAAI,EAAE,GAAG,WAAW,CAAC,kBAAkB,CAAC;IACxC,OAAO,EAAE,EAAE,CAAC;QACV,IAAI,EAAE,CAAC,OAAO,KAAK,QAAQ,IAAI,EAAE,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,CAAC;YAC/D,OAAO,KAAK,CAAC;QACf,CAAC;QACD,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC;IAC7B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,4EAA4E;AAC5E,SAAS,YAAY,CAAC,WAAoB;IACxC,IAAI,EAAE,GAAG,WAAW,CAAC,kBAAkB,CAAC;IACxC,OAAO,EAAE,EAAE,CAAC;QACV,IAAI,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,oCAAoC,CAAC,EAAE,CAAC;YAChE,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC;IAC7B,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Toolbar\n */\n\nimport \"./ToolGroup.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { OverflowButton } from \"./OverflowButton.js\";\nimport { useOverflow } from \"./useOverflow.js\";\nimport { getChildKey } from \"../../layout/tool-settings/Docked.js\";\nimport { ToolbarContext } from \"./Toolbar.js\";\nimport { Surface } from \"./Surface.js\";\nimport { useSafeContext } from \"../../hooks/useSafeContext.js\";\n\n// eslint-disable-next-line @typescript-eslint/no-deprecated\ninterface ToolGroupProps extends CommonProps {\n children?: React.ReactNode;\n}\n\ntype Child = ReturnType<typeof React.Children.toArray>[0];\n\n/** @internal */\nexport function ToolGroup({ children, className, ...props }: ToolGroupProps) {\n const { panelAlignment, orientation } = useSafeContext(ToolbarContext);\n const childrenArray = React.Children.toArray(children);\n\n const keyToChildMap = childrenArray.reduce<Map<string, Child>>(\n (acc, child, index) => {\n const childKey = getChildKey(child, index);\n acc.set(childKey, child);\n return acc;\n },\n new Map()\n );\n const childrenKeys = Array.from(keyToChildMap.keys());\n const itemRefs = React.useRef<Map<string, Element>>(new Map());\n const overflowRef = React.useRef<HTMLButtonElement>(null);\n\n const getItemSize = React.useCallback((item: string) => {\n const element = itemRefs.current.get(item);\n if (!element) return { width: 0, height: 0 };\n\n const elementSize = element.getBoundingClientRect();\n\n const separatorSize = getSeparatorSize(element);\n if (!separatorSize) return elementSize;\n\n return {\n width: elementSize.width + separatorSize.width,\n height: elementSize.height + separatorSize.height,\n };\n }, []);\n const getOverflowSize = React.useCallback(() => {\n const element = overflowRef.current;\n if (!element) return { width: 0, height: 0 };\n return element.getBoundingClientRect();\n }, []);\n\n const [containerRef, componentRef, visibleCount, renderOverflow] =\n useOverflow(childrenKeys, orientation, getItemSize, getOverflowSize);\n\n const keyToChildEntries = Array.from(keyToChildMap.entries());\n const visibleChildren = keyToChildEntries.slice(0, visibleCount);\n const overflown = keyToChildEntries.slice(visibleCount);\n return (\n <div\n className={classnames(\n \"uifw-toolbar-group-toolGroup_container\",\n `uifw-${orientation}`,\n `uifw-${panelAlignment}`,\n className\n )}\n ref={containerRef}\n >\n <Surface orientation={orientation} ref={componentRef} {...props}>\n {visibleChildren.map(([item, child]) => {\n if (!React.isValidElement<{ ref: React.Ref<Element> }>(child))\n return child;\n return React.cloneElement(child, {\n ref: (el: Element | null) => {\n if (!el) {\n itemRefs.current.delete(item);\n return;\n }\n itemRefs.current.set(item, el);\n },\n });\n })}\n {renderOverflow && (\n <OverflowButton ref={overflowRef}>\n {overflown.map(([_, child]) => child)}\n </OverflowButton>\n )}\n </Surface>\n </div>\n );\n}\n\n// First item in the group reserves space for the separator to correctly calculate the overflow.\nfunction getSeparatorSize(toolbarItem: Element) {\n const firstInGroup = isFirstInGroup(toolbarItem);\n if (!firstInGroup) return undefined;\n\n // Last group does not have a separator.\n if (isLastGroup(toolbarItem)) return undefined;\n\n const separator = getSeparator(toolbarItem);\n if (!separator) return undefined;\n\n return separator.getBoundingClientRect();\n}\n\n// Returns if the toolbar item is the first in its group.\nfunction isFirstInGroup(toolbarItem: Element) {\n const prev = toolbarItem.previousElementSibling;\n if (prev?.tagName === \"BUTTON\") return false;\n return true;\n}\n\n// Returns if the toolbar item is in the last group of the toolbar.\nfunction isLastGroup(toolbarItem: Element) {\n let el = toolbarItem.nextElementSibling;\n while (el) {\n if (el.tagName === \"BUTTON\" && el.hasAttribute(\"data-item-id\")) {\n return false;\n }\n el = el.nextElementSibling;\n }\n return true;\n}\n\n// Returns the first separator element after the toolbar item, if it exists.\nfunction getSeparator(toolbarItem: Element) {\n let el = toolbarItem.nextElementSibling;\n while (el) {\n if (el.classList.contains(\"uifw-toolbar-newToolbars-separator\")) {\n return el;\n }\n el = el.nextElementSibling;\n }\n return undefined;\n}\n"]}
@@ -19,8 +19,13 @@ export declare function Toolbar({ items, expandsTo, panelAlignment, onItemExecut
19
19
  interface ToolbarContextProps extends Pick<Required<ToolbarProps>, "expandsTo" | "panelAlignment">, Pick<ToolbarProps, "onItemExecuted"> {
20
20
  popoverOpen: boolean;
21
21
  setPopoverOpen: React.Dispatch<React.SetStateAction<boolean>>;
22
+ orientation: "horizontal" | "vertical";
22
23
  }
23
24
  /** @internal */
24
25
  export declare const ToolbarContext: React.Context<ToolbarContextProps | undefined>;
26
+ /** @internal */
27
+ export declare const ToolbarItemContext: React.Context<{
28
+ renderSeparator: boolean;
29
+ } | undefined>;
25
30
  export {};
26
31
  //# sourceMappingURL=Toolbar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Toolbar.d.ts","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/Toolbar.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAOhE,OAAO,KAAK,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,eAAe,CAAC;AAErE,oDAAoD;AACpD,KAAK,oBAAoB,GAAG,IAAI,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC;AAEpE,UAAU,YAAa,SAAQ,oBAAoB;IACjD,4CAA4C;IAC5C,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,gJAAgJ;IAChJ,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;IAChD,6DAA6D;IAC7D,cAAc,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;CAClC;AAED,gBAAgB;AAChB,wBAAgB,OAAO,CAAC,EACtB,KAAK,EACL,SAAoB,EACpB,cAAwB,EACxB,cAAc,GACf,EAAE,YAAY,qBA+Bd;AAED,UAAU,mBACR,SAAQ,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,WAAW,GAAG,gBAAgB,CAAC,EAClE,IAAI,CAAC,YAAY,EAAE,gBAAgB,CAAC;IACtC,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;CAC/D;AAED,gBAAgB;AAChB,eAAO,MAAM,cAAc,gDAEf,CAAC"}
1
+ {"version":3,"file":"Toolbar.d.ts","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/Toolbar.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAOhE,OAAO,KAAK,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,eAAe,CAAC;AAKrE,oDAAoD;AACpD,KAAK,oBAAoB,GAAG,IAAI,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC;AAEpE,UAAU,YAAa,SAAQ,oBAAoB;IACjD,4CAA4C;IAC5C,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,gJAAgJ;IAChJ,SAAS,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;IAChD,6DAA6D;IAC7D,cAAc,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;CAClC;AAED,gBAAgB;AAChB,wBAAgB,OAAO,CAAC,EACtB,KAAK,EACL,SAAoB,EACpB,cAAwB,EACxB,cAAc,GACf,EAAE,YAAY,qBA0Cd;AA2BD,UAAU,mBACR,SAAQ,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,WAAW,GAAG,gBAAgB,CAAC,EAClE,IAAI,CAAC,YAAY,EAAE,gBAAgB,CAAC;IACtC,WAAW,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9D,WAAW,EAAE,YAAY,GAAG,UAAU,CAAC;CACxC;AAED,gBAAgB;AAChB,eAAO,MAAM,cAAc,gDAEf,CAAC;AAGb,gBAAgB;AAChB,eAAO,MAAM,kBAAkB;qBAER,OAAO;cAGlB,CAAC"}
@@ -8,30 +8,63 @@
8
8
  import * as React from "react";
9
9
  import { isToolbarActionItem, isToolbarCustomItem, isToolbarGroupItem, } from "../../toolbar/ToolbarItem.js";
10
10
  import { ToolGroup } from "./ToolGroup.js";
11
+ import { ActionItem } from "./ActionItem.js";
12
+ import { GroupItem } from "./GroupItem.js";
13
+ import { CustomItem } from "./CustomItem.js";
11
14
  /** @internal */
12
15
  export function Toolbar({ items, expandsTo = "bottom", panelAlignment = "start", onItemExecuted, }) {
13
16
  const [popoverOpen, setPopoverOpen] = React.useState(false);
17
+ const orientation = getOrientation(expandsTo);
14
18
  return (React.createElement(ToolbarContext.Provider, { value: React.useMemo(() => ({
15
19
  expandsTo,
20
+ orientation,
16
21
  panelAlignment,
17
22
  popoverOpen,
18
23
  setPopoverOpen,
19
24
  onItemExecuted,
20
- }), [expandsTo, panelAlignment, popoverOpen, setPopoverOpen, onItemExecuted]) },
21
- React.createElement(ToolGroup, null, items.map((item) => {
22
- if (isToolbarActionItem(item)) {
23
- return React.createElement(ToolGroup.ActionItem, { key: item.id, item: item });
24
- }
25
- if (isToolbarGroupItem(item)) {
26
- return React.createElement(ToolGroup.GroupItem, { key: item.id, item: item });
27
- }
28
- if (isToolbarCustomItem(item)) {
29
- return React.createElement(ToolGroup.CustomItem, { key: item.id, item: item });
30
- }
31
- return null;
25
+ }), [
26
+ expandsTo,
27
+ orientation,
28
+ panelAlignment,
29
+ popoverOpen,
30
+ setPopoverOpen,
31
+ onItemExecuted,
32
+ ]) },
33
+ React.createElement(ToolGroup, null, items.map((item, index) => {
34
+ const nextItem = items.length > index + 1 ? items[index + 1] : undefined;
35
+ const renderSeparator = nextItem
36
+ ? item.groupPriority !== nextItem.groupPriority
37
+ : false;
38
+ return (React.createElement(ItemRenderer, { key: item.id, item: item, renderSeparator: renderSeparator }));
32
39
  }))));
33
40
  }
41
+ const ItemRenderer = React.forwardRef(function ItemRenderer({ item, renderSeparator }, forwardedRef) {
42
+ let itemElement;
43
+ if (isToolbarActionItem(item)) {
44
+ itemElement = React.createElement(ActionItem, { ref: forwardedRef, item: item });
45
+ }
46
+ if (isToolbarGroupItem(item)) {
47
+ itemElement = React.createElement(GroupItem, { ref: forwardedRef, item: item });
48
+ }
49
+ if (isToolbarCustomItem(item)) {
50
+ itemElement = React.createElement(CustomItem, { ref: forwardedRef, item: item });
51
+ }
52
+ return (React.createElement(ToolbarItemContext.Provider, { value: { renderSeparator } }, itemElement));
53
+ });
34
54
  /** @internal */
35
55
  export const ToolbarContext = React.createContext(undefined);
36
56
  ToolbarContext.displayName = "uifw:ToolbarContext";
57
+ /** @internal */
58
+ export const ToolbarItemContext = React.createContext(undefined);
59
+ ToolbarContext.displayName = "uifw:ToolbarContext";
60
+ function getOrientation(expandsTo) {
61
+ switch (expandsTo) {
62
+ case "left":
63
+ case "right":
64
+ return "vertical";
65
+ case "top":
66
+ case "bottom":
67
+ return "horizontal";
68
+ }
69
+ }
37
70
  //# sourceMappingURL=Toolbar.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Toolbar.js","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/Toolbar.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAe3C,gBAAgB;AAChB,MAAM,UAAU,OAAO,CAAC,EACtB,KAAK,EACL,SAAS,GAAG,QAAQ,EACpB,cAAc,GAAG,OAAO,EACxB,cAAc,GACD;IACb,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC5D,OAAO,CACL,oBAAC,cAAc,CAAC,QAAQ,IACtB,KAAK,EAAE,KAAK,CAAC,OAAO,CAClB,GAAG,EAAE,CAAC,CAAC;YACL,SAAS;YACT,cAAc;YACd,WAAW;YACX,cAAc;YACd,cAAc;SACf,CAAC,EACF,CAAC,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,CAAC,CACzE;QAED,oBAAC,SAAS,QACP,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YAClB,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC9B,OAAO,oBAAC,SAAS,CAAC,UAAU,IAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,GAAI,CAAC;YAC5D,CAAC;YACD,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC7B,OAAO,oBAAC,SAAS,CAAC,SAAS,IAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,GAAI,CAAC;YAC3D,CAAC;YACD,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC9B,OAAO,oBAAC,SAAS,CAAC,UAAU,IAAC,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,GAAI,CAAC;YAC5D,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CACQ,CACY,CAC3B,CAAC;AACJ,CAAC;AASD,gBAAgB;AAChB,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC,aAAa,CAE/C,SAAS,CAAC,CAAC;AACb,cAAc,CAAC,WAAW,GAAG,qBAAqB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Toolbar\n */\n\nimport * as React from \"react\";\nimport type { ToolbarItem } from \"../../toolbar/ToolbarItem.js\";\nimport {\n isToolbarActionItem,\n isToolbarCustomItem,\n isToolbarGroupItem,\n} from \"../../toolbar/ToolbarItem.js\";\nimport { ToolGroup } from \"./ToolGroup.js\";\nimport type { ToolbarProps as OldToolbarProps } from \"../Toolbar.js\";\n\n/** These exist for backwards compatibility only. */\ntype ToolbarInternalProps = Pick<OldToolbarProps, \"onItemExecuted\">;\n\ninterface ToolbarProps extends ToolbarInternalProps {\n /** Definitions for items of the toolbar. */\n items: ToolbarItem[];\n /** Describes direction to which the panels are expanded. Orientation of the toolbar is determined based on this prop. Defaults to `bottom`. */\n expandsTo?: \"top\" | \"bottom\" | \"left\" | \"right\";\n /** Describes how panels are aligned. Defaults to `start`. */\n panelAlignment?: \"start\" | \"end\";\n}\n\n/** @internal */\nexport function Toolbar({\n items,\n expandsTo = \"bottom\",\n panelAlignment = \"start\",\n onItemExecuted,\n}: ToolbarProps) {\n const [popoverOpen, setPopoverOpen] = React.useState(false);\n return (\n <ToolbarContext.Provider\n value={React.useMemo(\n () => ({\n expandsTo,\n panelAlignment,\n popoverOpen,\n setPopoverOpen,\n onItemExecuted,\n }),\n [expandsTo, panelAlignment, popoverOpen, setPopoverOpen, onItemExecuted]\n )}\n >\n <ToolGroup>\n {items.map((item) => {\n if (isToolbarActionItem(item)) {\n return <ToolGroup.ActionItem key={item.id} item={item} />;\n }\n if (isToolbarGroupItem(item)) {\n return <ToolGroup.GroupItem key={item.id} item={item} />;\n }\n if (isToolbarCustomItem(item)) {\n return <ToolGroup.CustomItem key={item.id} item={item} />;\n }\n return null;\n })}\n </ToolGroup>\n </ToolbarContext.Provider>\n );\n}\n\ninterface ToolbarContextProps\n extends Pick<Required<ToolbarProps>, \"expandsTo\" | \"panelAlignment\">,\n Pick<ToolbarProps, \"onItemExecuted\"> {\n popoverOpen: boolean;\n setPopoverOpen: React.Dispatch<React.SetStateAction<boolean>>;\n}\n\n/** @internal */\nexport const ToolbarContext = React.createContext<\n ToolbarContextProps | undefined\n>(undefined);\nToolbarContext.displayName = \"uifw:ToolbarContext\";\n"]}
1
+ {"version":3,"file":"Toolbar.js","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/Toolbar.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EACL,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OAAO;YACV,OAAO,UAAU,CAAC;QACpB,KAAK,KAAK,CAAC;QACX,KAAK,QAAQ;YACX,OAAO,YAAY,CAAC;IACxB,CAAC;AACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Toolbar\n */\n\nimport * as React from \"react\";\nimport type { ToolbarItem } from \"../../toolbar/ToolbarItem.js\";\nimport {\n isToolbarActionItem,\n isToolbarCustomItem,\n isToolbarGroupItem,\n} from \"../../toolbar/ToolbarItem.js\";\nimport { ToolGroup } from \"./ToolGroup.js\";\nimport type { ToolbarProps as OldToolbarProps } from \"../Toolbar.js\";\nimport { ActionItem } from \"./ActionItem.js\";\nimport { GroupItem } from \"./GroupItem.js\";\nimport { CustomItem } from \"./CustomItem.js\";\n\n/** These exist for backwards compatibility only. */\ntype ToolbarInternalProps = Pick<OldToolbarProps, \"onItemExecuted\">;\n\ninterface ToolbarProps extends ToolbarInternalProps {\n /** Definitions for items of the toolbar. */\n items: ToolbarItem[];\n /** Describes direction to which the panels are expanded. Orientation of the toolbar is determined based on this prop. Defaults to `bottom`. */\n expandsTo?: \"top\" | \"bottom\" | \"left\" | \"right\";\n /** Describes how panels are aligned. Defaults to `start`. */\n panelAlignment?: \"start\" | \"end\";\n}\n\n/** @internal */\nexport function Toolbar({\n items,\n expandsTo = \"bottom\",\n panelAlignment = \"start\",\n onItemExecuted,\n}: ToolbarProps) {\n const [popoverOpen, setPopoverOpen] = React.useState(false);\n const orientation = getOrientation(expandsTo);\n return (\n <ToolbarContext.Provider\n value={React.useMemo(\n () => ({\n expandsTo,\n orientation,\n panelAlignment,\n popoverOpen,\n setPopoverOpen,\n onItemExecuted,\n }),\n [\n expandsTo,\n orientation,\n panelAlignment,\n popoverOpen,\n setPopoverOpen,\n onItemExecuted,\n ]\n )}\n >\n <ToolGroup>\n {items.map((item, index) => {\n const nextItem =\n items.length > index + 1 ? items[index + 1] : undefined;\n const renderSeparator = nextItem\n ? item.groupPriority !== nextItem.groupPriority\n : false;\n return (\n <ItemRenderer\n key={item.id}\n item={item}\n renderSeparator={renderSeparator}\n />\n );\n })}\n </ToolGroup>\n </ToolbarContext.Provider>\n );\n}\n\ninterface ItemRendererProps {\n item: ToolbarItem;\n renderSeparator: boolean;\n}\n\nconst ItemRenderer = React.forwardRef<HTMLButtonElement, ItemRendererProps>(\n function ItemRenderer({ item, renderSeparator }, forwardedRef) {\n let itemElement: React.JSX.Element | undefined;\n if (isToolbarActionItem(item)) {\n itemElement = <ActionItem ref={forwardedRef} item={item} />;\n }\n if (isToolbarGroupItem(item)) {\n itemElement = <GroupItem ref={forwardedRef} item={item} />;\n }\n if (isToolbarCustomItem(item)) {\n itemElement = <CustomItem ref={forwardedRef} item={item} />;\n }\n return (\n <ToolbarItemContext.Provider value={{ renderSeparator }}>\n {itemElement}\n </ToolbarItemContext.Provider>\n );\n }\n);\n\ninterface ToolbarContextProps\n extends Pick<Required<ToolbarProps>, \"expandsTo\" | \"panelAlignment\">,\n Pick<ToolbarProps, \"onItemExecuted\"> {\n popoverOpen: boolean;\n setPopoverOpen: React.Dispatch<React.SetStateAction<boolean>>;\n orientation: \"horizontal\" | \"vertical\";\n}\n\n/** @internal */\nexport const ToolbarContext = React.createContext<\n ToolbarContextProps | undefined\n>(undefined);\nToolbarContext.displayName = \"uifw:ToolbarContext\";\n\n/** @internal */\nexport const ToolbarItemContext = React.createContext<\n | {\n renderSeparator: boolean;\n }\n | undefined\n>(undefined);\nToolbarContext.displayName = \"uifw:ToolbarContext\";\n\nfunction getOrientation(expandsTo: ToolbarContextProps[\"expandsTo\"]) {\n switch (expandsTo) {\n case \"left\":\n case \"right\":\n return \"vertical\";\n case \"top\":\n case \"bottom\":\n return \"horizontal\";\n }\n}\n"]}
@@ -43,12 +43,12 @@ export const useOverflow = (allItems, orientation, getItemSize, getOverflowSize)
43
43
  setVisible(itemSizes.length);
44
44
  return;
45
45
  }
46
- let totalSize = overflowSize;
47
- if (totalSize >= containerSize) {
46
+ if (overflowSize >= containerSize) {
48
47
  // Render only overflow.
49
48
  setVisible(0);
50
49
  return;
51
50
  }
51
+ let totalSize = overflowSize;
52
52
  let newVisible = 0;
53
53
  for (const size of itemSizes) {
54
54
  totalSize += size;
@@ -1 +1 @@
1
- {"version":3,"file":"useOverflow.js","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/useOverflow.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAK/D,gBAAgB;AAChB,MAAM,CAAC,MAAM,WAAW,GAAG,CAIzB,QAA+B,EAC/B,WAAwB,EACxB,WAAwC,EACxC,eAAgC,EAChC,EAAE;IACF,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9D,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxD,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,EAAa,CAAC;IACnD,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,EAAa,CAAC;IAEnD,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC1E,IAAI,eAAe,KAAK,WAAW,EAAE,CAAC;QACpC,kBAAkB,CAAC,WAAW,CAAC,CAAC;QAChC,YAAY,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,GAAG,EAAE;QACzB,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,IAAI,CAAC,SAAS;YAAE,OAA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AQ,GAAG,SAAS,IAAI,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC;IACxD,MAAM,YAAY,GAAG,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAC3D,OAAO,CAAC,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,QAAQ,CAAU,CAAC;AAC3E,CAAC,CAAC;AAEF,SAAS,SAAS,CAChB,IAAuC,EACvC,WAAwB;IAExB,OAAO,WAAW,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;AACjE,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Toolbar\n */\n\nimport * as React from \"react\";\nimport { useResizeObserver } from \"@itwin/core-react/internal\";\nimport type { SizeProps } from \"../../utils/SizeProps.js\";\n\ntype Orientation = \"horizontal\" | \"vertical\";\n\n/** @internal */\nexport const useOverflow = <\n TContainer extends HTMLElement,\n TComponent extends HTMLElement\n>(\n allItems: ReadonlyArray<string>,\n orientation: Orientation,\n getItemSize: (item: string) => SizeProps,\n getOverflowSize: () => SizeProps\n) => {\n const [visible, setVisible] = React.useState(allItems.length);\n const [calculate, setCalculate] = React.useState(false);\n const containerSizeRef = React.useRef<SizeProps>();\n const componentSizeRef = React.useRef<SizeProps>();\n\n const [prevOrientation, setPrevOrientation] = React.useState(orientation);\n if (prevOrientation !== orientation) {\n setPrevOrientation(orientation);\n setCalculate(true);\n }\n\n React.useLayoutEffect(() => {\n setCalculate(false);\n if (!calculate) return;\n\n const containerSize = containerSizeRef.current\n ? getLength(containerSizeRef.current, orientation)\n : undefined;\n if (containerSize === undefined) return;\n\n const componentSize = componentSizeRef.current\n ? getLength(componentSizeRef.current, orientation)\n : undefined;\n if (componentSize === undefined) return;\n\n const itemSizes = allItems.map((item) => {\n const size = getItemSize(item);\n return getLength(size, orientation);\n });\n const overflowSize = getLength(getOverflowSize(), orientation);\n\n const otherSize = itemSizes.reduce((acc, size) => acc + size, 0);\n if (otherSize < containerSize) {\n // No overflow.\n setVisible(itemSizes.length);\n return;\n }\n\n let totalSize = overflowSize;\n if (totalSize >= containerSize) {\n // Render only overflow.\n setVisible(0);\n return;\n }\n\n let newVisible = 0;\n for (const size of itemSizes) {\n totalSize += size;\n if (totalSize >= containerSize) {\n break;\n }\n newVisible++;\n }\n setVisible(newVisible);\n }, [calculate, allItems, getItemSize, getOverflowSize, orientation]);\n const containerRoRef = useResizeObserver<TContainer>(\n React.useCallback(\n (width: number, height: number) => {\n const length = containerSizeRef.current\n ? getLength(containerSizeRef.current, orientation)\n : undefined;\n containerSizeRef.current = { width, height };\n const newLength = getLength(containerSizeRef.current, orientation);\n\n if (newLength === length) return;\n setCalculate(true);\n },\n [orientation]\n )\n );\n const componentRoRef = useResizeObserver<TComponent>(\n React.useCallback(\n (width: number, height: number) => {\n const length = componentSizeRef.current\n ? getLength(componentSizeRef.current, orientation)\n : undefined;\n componentSizeRef.current = { width, height };\n const newLength = getLength(componentSizeRef.current, orientation);\n\n if (newLength === length) return;\n setCalculate(true);\n },\n [orientation]\n )\n );\n\n const overflow = calculate || visible < allItems.length;\n const visibleItems = calculate ? allItems.length : visible;\n return [containerRoRef, componentRoRef, visibleItems, overflow] as const;\n};\n\nfunction getLength(\n size: { width: number; height: number },\n orientation: Orientation\n) {\n return orientation === \"horizontal\" ? size.width : size.height;\n}\n"]}
1
+ {"version":3,"file":"useOverflow.js","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/useOverflow.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAK/D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EAAE,CAAC;QAC7C,MAAM,SAAS,GAAG,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAEnE,IAAI,SAAS,KAAK,MAAM;YAAE,OAAO;QACjC,YAAY,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC,EACD,CAAC,WAAW,CAAC,CACd,CACF,CAAC;IACF,MAAM,cAAc,GAAG,iBAAiB,CACtC,KAAK,CAAC,WAAW,CACf,CAAC,KAAa,EAAE,MAAc,EAAE,EAAE;QAChC,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO;YACrC,CAAC,CAAC,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC;YAClD,CAAC,CAAC,SAAS,CAAC;QACd,gBAAgB,CAAC,OAAO,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;QAC7C,MAAM,SAAS,GAAG,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;QAEnE,IAAI,SAAS,KAAK,MAAM;YAAE,OAAO;QACjC,YAAY,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC,EACD,CAAC,WAAW,CAAC,CACd,CACF,CAAC;IAEF,MAAM,QAAQ,GAAG,SAAS,IAAI,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC;IACxD,MAAM,YAAY,GAAG,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAC3D,OAAO,CAAC,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,QAAQ,CAAU,CAAC;AAC3E,CAAC,CAAC;AAEF,SAAS,SAAS,CAChB,IAAuC,EACvC,WAAwB;IAExB,OAAO,WAAW,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;AACjE,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Toolbar\n */\n\nimport * as React from \"react\";\nimport { useResizeObserver } from \"@itwin/core-react/internal\";\nimport type { SizeProps } from \"../../utils/SizeProps.js\";\n\ntype Orientation = \"horizontal\" | \"vertical\";\n\n/** @internal */\nexport const useOverflow = <\n TContainer extends HTMLElement,\n TComponent extends HTMLElement\n>(\n allItems: ReadonlyArray<string>,\n orientation: Orientation,\n getItemSize: (item: string) => SizeProps,\n getOverflowSize: () => SizeProps\n) => {\n const [visible, setVisible] = React.useState(allItems.length);\n const [calculate, setCalculate] = React.useState(false);\n const containerSizeRef = React.useRef<SizeProps>();\n const componentSizeRef = React.useRef<SizeProps>();\n\n const [prevOrientation, setPrevOrientation] = React.useState(orientation);\n if (prevOrientation !== orientation) {\n setPrevOrientation(orientation);\n setCalculate(true);\n }\n\n React.useLayoutEffect(() => {\n setCalculate(false);\n if (!calculate) return;\n\n const containerSize = containerSizeRef.current\n ? getLength(containerSizeRef.current, orientation)\n : undefined;\n if (containerSize === undefined) return;\n\n const componentSize = componentSizeRef.current\n ? getLength(componentSizeRef.current, orientation)\n : undefined;\n if (componentSize === undefined) return;\n\n const itemSizes = allItems.map((item) => {\n const size = getItemSize(item);\n return getLength(size, orientation);\n });\n const overflowSize = getLength(getOverflowSize(), orientation);\n\n const otherSize = itemSizes.reduce((acc, size) => acc + size, 0);\n if (otherSize < containerSize) {\n // No overflow.\n setVisible(itemSizes.length);\n return;\n }\n\n if (overflowSize >= containerSize) {\n // Render only overflow.\n setVisible(0);\n return;\n }\n\n let totalSize = overflowSize;\n let newVisible = 0;\n for (const size of itemSizes) {\n totalSize += size;\n if (totalSize >= containerSize) {\n break;\n }\n newVisible++;\n }\n setVisible(newVisible);\n }, [calculate, allItems, getItemSize, getOverflowSize, orientation]);\n const containerRoRef = useResizeObserver<TContainer>(\n React.useCallback(\n (width: number, height: number) => {\n const length = containerSizeRef.current\n ? getLength(containerSizeRef.current, orientation)\n : undefined;\n containerSizeRef.current = { width, height };\n const newLength = getLength(containerSizeRef.current, orientation);\n\n if (newLength === length) return;\n setCalculate(true);\n },\n [orientation]\n )\n );\n const componentRoRef = useResizeObserver<TComponent>(\n React.useCallback(\n (width: number, height: number) => {\n const length = componentSizeRef.current\n ? getLength(componentSizeRef.current, orientation)\n : undefined;\n componentSizeRef.current = { width, height };\n const newLength = getLength(componentSizeRef.current, orientation);\n\n if (newLength === length) return;\n setCalculate(true);\n },\n [orientation]\n )\n );\n\n const overflow = calculate || visible < allItems.length;\n const visibleItems = calculate ? allItems.length : visible;\n return [containerRoRef, componentRoRef, visibleItems, overflow] as const;\n};\n\nfunction getLength(\n size: { width: number; height: number },\n orientation: Orientation\n) {\n return orientation === \"horizontal\" ? size.width : size.height;\n}\n"]}
@@ -3,7 +3,7 @@
3
3
  */
4
4
  /** Returns widget direction.
5
5
  * I.e. "horizontal" when widget is in bottom/top stage panel.
6
- * @alpha
6
+ * @public
7
7
  */
8
8
  export declare function useWidgetDirection(): "horizontal" | "vertical";
9
9
  //# sourceMappingURL=useWidgetDirection.d.ts.map
@@ -13,7 +13,7 @@ import { isHorizontalPanelSide } from "../layout/widget-panels/Panel.js";
13
13
  import { TabIdContext } from "../layout/widget/ContentRenderer.js";
14
14
  /** Returns widget direction.
15
15
  * I.e. "horizontal" when widget is in bottom/top stage panel.
16
- * @alpha
16
+ * @public
17
17
  */
18
18
  export function useWidgetDirection() {
19
19
  const tabId = React.useContext(TabIdContext);
@@ -1 +1 @@
1
- {"version":3,"file":"useWidgetDirection.js","sourceRoot":"","sources":["../../../src/appui-react/widget-panels/useWidgetDirection.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAEnE;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IAC7C,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAChB,OAAO,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;QACzB,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACjD,IACE,WAAW;YACX,MAAM,IAAI,WAAW;YACrB,qBAAqB,CAAC,WAAW,CAAC,IAAI,CAAC,EACvC,CAAC;YACD,OAAO,YAAY,CAAC;QACtB,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Widget\n */\n\nimport { assert } from \"@itwin/core-bentley\";\nimport * as React from \"react\";\nimport { useLayout } from \"../layout/base/LayoutStore.js\";\nimport { getTabLocation } from \"../layout/state/TabLocation.js\";\nimport { isHorizontalPanelSide } from \"../layout/widget-panels/Panel.js\";\nimport { TabIdContext } from \"../layout/widget/ContentRenderer.js\";\n\n/** Returns widget direction.\n * I.e. \"horizontal\" when widget is in bottom/top stage panel.\n * @alpha\n */\nexport function useWidgetDirection(): \"horizontal\" | \"vertical\" {\n const tabId = React.useContext(TabIdContext);\n assert(!!tabId);\n return useLayout((state) => {\n const tabLocation = getTabLocation(state, tabId);\n if (\n tabLocation &&\n \"side\" in tabLocation &&\n isHorizontalPanelSide(tabLocation.side)\n ) {\n return \"horizontal\";\n }\n return \"vertical\";\n });\n}\n"]}
1
+ {"version":3,"file":"useWidgetDirection.js","sourceRoot":"","sources":["../../../src/appui-react/widget-panels/useWidgetDirection.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AAEnE;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IAChC,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IAC7C,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IAChB,OAAO,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;QACzB,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACjD,IACE,WAAW;YACX,MAAM,IAAI,WAAW;YACrB,qBAAqB,CAAC,WAAW,CAAC,IAAI,CAAC,EACvC,CAAC;YACD,OAAO,YAAY,CAAC;QACtB,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Widget\n */\n\nimport { assert } from \"@itwin/core-bentley\";\nimport * as React from \"react\";\nimport { useLayout } from \"../layout/base/LayoutStore.js\";\nimport { getTabLocation } from \"../layout/state/TabLocation.js\";\nimport { isHorizontalPanelSide } from \"../layout/widget-panels/Panel.js\";\nimport { TabIdContext } from \"../layout/widget/ContentRenderer.js\";\n\n/** Returns widget direction.\n * I.e. \"horizontal\" when widget is in bottom/top stage panel.\n * @public\n */\nexport function useWidgetDirection(): \"horizontal\" | \"vertical\" {\n const tabId = React.useContext(TabIdContext);\n assert(!!tabId);\n return useLayout((state) => {\n const tabLocation = getTabLocation(state, tabId);\n if (\n tabLocation &&\n \"side\" in tabLocation &&\n isHorizontalPanelSide(tabLocation.side)\n ) {\n return \"horizontal\";\n }\n return \"vertical\";\n });\n}\n"]}
@@ -1,8 +1,12 @@
1
+ /** @packageDocumentation
2
+ * @module Widget
3
+ */
1
4
  import type { WidgetState } from "./WidgetState.js";
2
5
  /** Hook that returns information about the Widget in the current context.
6
+ * @note This hook must be used within a widget.
3
7
  * @returns object that contains the WidgetLocation, WidgetState, and
4
8
  * the ability to set the state of the widget.
5
- * @alpha
9
+ * @public
6
10
  */
7
11
  export declare function useWidget(): {
8
12
  /** State of the Widget */
@@ -1 +1 @@
1
- {"version":3,"file":"useWidget.d.ts","sourceRoot":"","sources":["../../../src/appui-react/widgets/useWidget.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;GAIG;AACH,wBAAgB,SAAS;IA0CrB,0BAA0B;;IAE1B,sEAAsE;;IAEtE;;OAEG;4BAbW,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,QAAQ,CAAC;EAgBxD"}
1
+ {"version":3,"file":"useWidget.d.ts","sourceRoot":"","sources":["../../../src/appui-react/widgets/useWidget.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAeH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;GAKG;AACH,wBAAgB,SAAS;IA0CrB,0BAA0B;;IAE1B,sEAAsE;;IAEtE;;OAEG;4BAbW,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,QAAQ,CAAC;EAgBxD"}
@@ -2,6 +2,9 @@
2
2
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
+ /** @packageDocumentation
6
+ * @module Widget
7
+ */
5
8
  import { assert } from "@itwin/core-bentley";
6
9
  import * as React from "react";
7
10
  import { useActiveFrontstageDef } from "../frontstage/FrontstageDef.js";
@@ -10,9 +13,10 @@ import { getTabLocation, isFloatingTabLocation, isPanelTabLocation, isPopoutTabL
10
13
  import { TabIdContext } from "../layout/widget/ContentRenderer.js";
11
14
  import { useWidgetDef } from "../widget-panels/Content.js";
12
15
  /** Hook that returns information about the Widget in the current context.
16
+ * @note This hook must be used within a widget.
13
17
  * @returns object that contains the WidgetLocation, WidgetState, and
14
18
  * the ability to set the state of the widget.
15
- * @alpha
19
+ * @public
16
20
  */
17
21
  export function useWidget() {
18
22
  const tabId = React.useContext(TabIdContext);
@@ -1 +1 @@
1
- {"version":3,"file":"useWidget.js","sourceRoot":"","sources":["../../../src/appui-react/widgets/useWidget.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAG3D;;;;GAIG;AACH,MAAM,UAAU,SAAS;IACvB,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;IAC7C,MAAM,CAAC,CAAC,CAAC,KAAK,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C;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,aAAqB,EAAE,UAAyB;IACpE,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACnC,MAAM,WAAW,GAAG,cAAc,CAAC,UAAU,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IAE5E,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,qBAAqB,CAAC,WAAW,CAAC,EAAE,CAAC;YACvC,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,IAAI,mBAAmB,CAAC,WAAW,CAAC,EAAE,CAAC;YACrC,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,IAAI,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC;YACpC,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { assert } from \"@itwin/core-bentley\";\nimport * as React from \"react\";\nimport type { FrontstageDef } from \"../frontstage/FrontstageDef.js\";\nimport { useActiveFrontstageDef } from \"../frontstage/FrontstageDef.js\";\nimport { InternalFrontstageManager } from \"../frontstage/InternalFrontstageManager.js\";\nimport {\n getTabLocation,\n isFloatingTabLocation,\n isPanelTabLocation,\n isPopoutTabLocation,\n} from \"../layout/state/TabLocation.js\";\nimport { TabIdContext } from \"../layout/widget/ContentRenderer.js\";\nimport { useWidgetDef } from \"../widget-panels/Content.js\";\nimport type { WidgetState } from \"./WidgetState.js\";\n\n/** Hook that returns information about the Widget in the current context.\n * @returns object that contains the WidgetLocation, WidgetState, and\n * the ability to set the state of the widget.\n * @alpha\n */\nexport function useWidget() {\n const tabId = React.useContext(TabIdContext);\n assert(!!tabId);\n\n const frontstage = useActiveFrontstageDef();\n\n assert(!!frontstage);\n\n const widgetDef = useWidgetDef();\n\n assert(!!widgetDef);\n\n const [widgetLocation, setWidgetLocation] = React.useState<\n \"docked\" | \"floating\" | \"popout\"\n >(findLocation(tabId, frontstage));\n\n const [state, setState] = React.useState(widgetDef.state);\n\n React.useEffect(() => {\n return InternalFrontstageManager.onFrontstageNineZoneStateChangedEvent.addListener(\n () => {\n if (widgetDef) return setState(widgetDef.state);\n }\n );\n }, [frontstage, widgetDef]);\n\n React.useEffect(() => {\n return InternalFrontstageManager.onFrontstageNineZoneStateChangedEvent.addListener(\n () => {\n setWidgetLocation(findLocation(tabId, frontstage));\n }\n );\n }, [frontstage, tabId]);\n\n const setWidgetState = React.useCallback(\n (widgetState: Omit<WidgetState, WidgetState.Floating>) => {\n widgetDef?.setWidgetState(widgetState as WidgetState);\n },\n [widgetDef]\n );\n\n return {\n /** State of the Widget */\n state,\n /** Where the widget is located (\"docked\" | \"popout\" | \"floating\"). */\n widgetLocation,\n /** Set widget to different state\n * @param WidgetState that you want to set the widget to.\n */\n setState: setWidgetState,\n };\n}\n\nfunction findLocation(locationTabId: string, frontstage: FrontstageDef) {\n assert(!!frontstage.nineZoneState);\n const tabLocation = getTabLocation(frontstage.nineZoneState, locationTabId);\n\n if (tabLocation) {\n if (isFloatingTabLocation(tabLocation)) {\n return \"floating\";\n }\n\n if (isPopoutTabLocation(tabLocation)) {\n return \"popout\";\n }\n\n if (isPanelTabLocation(tabLocation)) {\n return \"docked\";\n }\n }\n\n return \"floating\";\n}\n"]}
1
+ {"version":3,"file":"useWidget.js","sourceRoot":"","sources":["../../../src/appui-react/widgets/useWidget.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AACvF,OAA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EAAE,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC;IAExB,MAAM,cAAc,GAAG,KAAK,CAAC,WAAW,CACtC,CAAC,WAAoD,EAAE,EAAE;QACvD,SAAS,EAAE,cAAc,CAAC,WAA0B,CAAC,CAAC;IACxD,CAAC,EACD,CAAC,SAAS,CAAC,CACZ,CAAC;IAEF,OAAO;QACL,0BAA0B;QAC1B,KAAK;QACL,sEAAsE;QACtE,cAAc;QACd;;WAEG;QACH,QAAQ,EAAE,cAAc;KACzB,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,aAAqB,EAAE,UAAyB;IACpE,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACnC,MAAM,WAAW,GAAG,cAAc,CAAC,UAAU,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC;IAE5E,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,qBAAqB,CAAC,WAAW,CAAC,EAAE,CAAC;YACvC,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,IAAI,mBAAmB,CAAC,WAAW,CAAC,EAAE,CAAC;YACrC,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,IAAI,kBAAkB,CAAC,WAAW,CAAC,EAAE,CAAC;YACpC,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Widget\n */\n\nimport { assert } from \"@itwin/core-bentley\";\nimport * as React from \"react\";\nimport type { FrontstageDef } from \"../frontstage/FrontstageDef.js\";\nimport { useActiveFrontstageDef } from \"../frontstage/FrontstageDef.js\";\nimport { InternalFrontstageManager } from \"../frontstage/InternalFrontstageManager.js\";\nimport {\n getTabLocation,\n isFloatingTabLocation,\n isPanelTabLocation,\n isPopoutTabLocation,\n} from \"../layout/state/TabLocation.js\";\nimport { TabIdContext } from \"../layout/widget/ContentRenderer.js\";\nimport { useWidgetDef } from \"../widget-panels/Content.js\";\nimport type { WidgetState } from \"./WidgetState.js\";\n\n/** Hook that returns information about the Widget in the current context.\n * @note This hook must be used within a widget.\n * @returns object that contains the WidgetLocation, WidgetState, and\n * the ability to set the state of the widget.\n * @public\n */\nexport function useWidget() {\n const tabId = React.useContext(TabIdContext);\n assert(!!tabId);\n\n const frontstage = useActiveFrontstageDef();\n\n assert(!!frontstage);\n\n const widgetDef = useWidgetDef();\n\n assert(!!widgetDef);\n\n const [widgetLocation, setWidgetLocation] = React.useState<\n \"docked\" | \"floating\" | \"popout\"\n >(findLocation(tabId, frontstage));\n\n const [state, setState] = React.useState(widgetDef.state);\n\n React.useEffect(() => {\n return InternalFrontstageManager.onFrontstageNineZoneStateChangedEvent.addListener(\n () => {\n if (widgetDef) return setState(widgetDef.state);\n }\n );\n }, [frontstage, widgetDef]);\n\n React.useEffect(() => {\n return InternalFrontstageManager.onFrontstageNineZoneStateChangedEvent.addListener(\n () => {\n setWidgetLocation(findLocation(tabId, frontstage));\n }\n );\n }, [frontstage, tabId]);\n\n const setWidgetState = React.useCallback(\n (widgetState: Omit<WidgetState, WidgetState.Floating>) => {\n widgetDef?.setWidgetState(widgetState as WidgetState);\n },\n [widgetDef]\n );\n\n return {\n /** State of the Widget */\n state,\n /** Where the widget is located (\"docked\" | \"popout\" | \"floating\"). */\n widgetLocation,\n /** Set widget to different state\n * @param WidgetState that you want to set the widget to.\n */\n setState: setWidgetState,\n };\n}\n\nfunction findLocation(locationTabId: string, frontstage: FrontstageDef) {\n assert(!!frontstage.nineZoneState);\n const tabLocation = getTabLocation(frontstage.nineZoneState, locationTabId);\n\n if (tabLocation) {\n if (isFloatingTabLocation(tabLocation)) {\n return \"floating\";\n }\n\n if (isPopoutTabLocation(tabLocation)) {\n return \"popout\";\n }\n\n if (isPanelTabLocation(tabLocation)) {\n return \"docked\";\n }\n }\n\n return \"floating\";\n}\n"]}
@@ -0,0 +1,32 @@
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
+ .uifw-toolbar-newToolbars-separator {
6
+ display: none;
7
+
8
+ &.uifw-horizontal {
9
+ border-right: var(--iui-surface-border);
10
+ border-color: var(--_uifw-toolbar-border-color);
11
+ }
12
+
13
+ &.uifw-vertical {
14
+ border-bottom: var(--iui-surface-border);
15
+ border-color: var(--_uifw-toolbar-border-color);
16
+ }
17
+
18
+ &:has(~ button) {
19
+ button + & {
20
+ display: block;
21
+ }
22
+ }
23
+
24
+ @supports not selector(:has(~ *)) {
25
+ button + & {
26
+ // This will display the last separator if there are multiple separators at the end of the toolbar.
27
+ &:not(:last-child) {
28
+ display: block;
29
+ }
30
+ }
31
+ }
32
+ }
@@ -3,10 +3,12 @@
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  .uifw-toolbar-group-surface {
6
+ --_uifw-toolbar-border-color: var(--iui-color-border-foreground);
7
+
6
8
  display: flex;
7
9
  width: fit-content;
8
10
  height: fit-content;
9
- border-color: var(--iui-color-border-foreground);
11
+ border-color: var(--_uifw-toolbar-border-color);
10
12
  transition: border-color var(--iui-duration-1) ease;
11
13
  // TODO: needed due to opacity on toolbar container (since pointer events are disabled for center content).
12
14
  pointer-events: all;
@@ -26,7 +28,7 @@
26
28
 
27
29
  &:hover,
28
30
  &:focus-within {
29
- border-color: var(--iui-color-border-foreground-hover);
31
+ --_uifw-toolbar-border-color: var(--iui-color-border-foreground-hover);
30
32
  }
31
33
 
32
34
  &:empty {
@@ -0,0 +1,32 @@
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
+ .uifw-toolbar-newToolbars-separator {
6
+ display: none;
7
+
8
+ &.uifw-horizontal {
9
+ border-right: var(--iui-surface-border);
10
+ border-color: var(--_uifw-toolbar-border-color);
11
+ }
12
+
13
+ &.uifw-vertical {
14
+ border-bottom: var(--iui-surface-border);
15
+ border-color: var(--_uifw-toolbar-border-color);
16
+ }
17
+
18
+ &:has(~ button) {
19
+ button + & {
20
+ display: block;
21
+ }
22
+ }
23
+
24
+ @supports not selector(:has(~ *)) {
25
+ button + & {
26
+ // This will display the last separator if there are multiple separators at the end of the toolbar.
27
+ &:not(:last-child) {
28
+ display: block;
29
+ }
30
+ }
31
+ }
32
+ }
@@ -3,10 +3,12 @@
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  .uifw-toolbar-group-surface {
6
+ --_uifw-toolbar-border-color: var(--iui-color-border-foreground);
7
+
6
8
  display: flex;
7
9
  width: fit-content;
8
10
  height: fit-content;
9
- border-color: var(--iui-color-border-foreground);
11
+ border-color: var(--_uifw-toolbar-border-color);
10
12
  transition: border-color var(--iui-duration-1) ease;
11
13
  // TODO: needed due to opacity on toolbar container (since pointer events are disabled for center content).
12
14
  pointer-events: all;
@@ -26,7 +28,7 @@
26
28
 
27
29
  &:hover,
28
30
  &:focus-within {
29
- border-color: var(--iui-color-border-foreground-hover);
31
+ --_uifw-toolbar-border-color: var(--iui-color-border-foreground-hover);
30
32
  }
31
33
 
32
34
  &:empty {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/appui-react",
3
- "version": "5.8.0",
3
+ "version": "5.9.0",
4
4
  "description": "A react component library for AppUI framework",
5
5
  "type": "module",
6
6
  "types": "./lib/appui-react.d.ts",
@@ -45,9 +45,9 @@
45
45
  "react-dom": "^18.0.0",
46
46
  "react-redux": "^7.2.2 || ^8.0.0 || ^9.0.0",
47
47
  "redux": "^4.1.0 || ^5.0.0",
48
- "@itwin/components-react": "5.8.0",
49
- "@itwin/core-react": "5.8.0",
50
- "@itwin/imodel-components-react": "5.8.0"
48
+ "@itwin/components-react": "5.9.0",
49
+ "@itwin/core-react": "5.9.0",
50
+ "@itwin/imodel-components-react": "5.9.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@itwin/appui-abstract": "rc",
@@ -60,7 +60,7 @@
60
60
  "@itwin/core-quantity": "rc",
61
61
  "@itwin/ecschema-metadata": "rc",
62
62
  "@itwin/eslint-plugin": "5.1.0",
63
- "@itwin/itwinui-react": "^3.17.0",
63
+ "@itwin/itwinui-react": "^3.18.3",
64
64
  "@itwin/webgl-compatibility": "rc",
65
65
  "@testing-library/dom": "^10.1.0",
66
66
  "@testing-library/react": "^15.0.7",
@@ -91,9 +91,9 @@
91
91
  "typescript": "~5.6.2",
92
92
  "upath": "^2.0.1",
93
93
  "vitest": "^3.0.6",
94
- "@itwin/core-react": "5.8.0",
95
- "@itwin/components-react": "5.8.0",
96
- "@itwin/imodel-components-react": "5.8.0"
94
+ "@itwin/core-react": "5.9.0",
95
+ "@itwin/components-react": "5.9.0",
96
+ "@itwin/imodel-components-react": "5.9.0"
97
97
  },
98
98
  "dependencies": {
99
99
  "@itwin/itwinui-icons-react": "^2.8.0",