@itwin/appui-react 5.7.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 (76) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/lib/appui-react/editors/CustomNumberEditor.d.ts.map +1 -1
  3. package/lib/appui-react/editors/CustomNumberEditor.js +3 -1
  4. package/lib/appui-react/editors/CustomNumberEditor.js.map +1 -1
  5. package/lib/appui-react/editors/NumericEditor.d.ts.map +1 -1
  6. package/lib/appui-react/editors/NumericEditor.js +3 -1
  7. package/lib/appui-react/editors/NumericEditor.js.map +1 -1
  8. package/lib/appui-react/editors/TextEditor.d.ts.map +1 -1
  9. package/lib/appui-react/editors/TextEditor.js +3 -1
  10. package/lib/appui-react/editors/TextEditor.js.map +1 -1
  11. package/lib/appui-react/hooks/useSafeContext.d.ts +7 -0
  12. package/lib/appui-react/hooks/useSafeContext.d.ts.map +1 -0
  13. package/lib/appui-react/hooks/useSafeContext.js +17 -0
  14. package/lib/appui-react/hooks/useSafeContext.js.map +1 -0
  15. package/lib/appui-react/preview/PreviewFeatures.d.ts +4 -0
  16. package/lib/appui-react/preview/PreviewFeatures.d.ts.map +1 -1
  17. package/lib/appui-react/preview/PreviewFeatures.js +1 -0
  18. package/lib/appui-react/preview/PreviewFeatures.js.map +1 -1
  19. package/lib/appui-react/preview/tool-settings-key-press-commit/useToolSettingsKeyPressCommit.d.ts +6 -0
  20. package/lib/appui-react/preview/tool-settings-key-press-commit/useToolSettingsKeyPressCommit.d.ts.map +1 -0
  21. package/lib/appui-react/preview/tool-settings-key-press-commit/useToolSettingsKeyPressCommit.js +15 -0
  22. package/lib/appui-react/preview/tool-settings-key-press-commit/useToolSettingsKeyPressCommit.js.map +1 -0
  23. package/lib/appui-react/toolbar/new-toolbars/ActionItem.d.ts +2 -2
  24. package/lib/appui-react/toolbar/new-toolbars/ActionItem.d.ts.map +1 -1
  25. package/lib/appui-react/toolbar/new-toolbars/ActionItem.js +2 -1
  26. package/lib/appui-react/toolbar/new-toolbars/ActionItem.js.map +1 -1
  27. package/lib/appui-react/toolbar/new-toolbars/CustomItem.d.ts +2 -2
  28. package/lib/appui-react/toolbar/new-toolbars/CustomItem.d.ts.map +1 -1
  29. package/lib/appui-react/toolbar/new-toolbars/CustomItem.js +3 -2
  30. package/lib/appui-react/toolbar/new-toolbars/CustomItem.js.map +1 -1
  31. package/lib/appui-react/toolbar/new-toolbars/GroupItem.d.ts +2 -3
  32. package/lib/appui-react/toolbar/new-toolbars/GroupItem.d.ts.map +1 -1
  33. package/lib/appui-react/toolbar/new-toolbars/GroupItem.js +6 -7
  34. package/lib/appui-react/toolbar/new-toolbars/GroupItem.js.map +1 -1
  35. package/lib/appui-react/toolbar/new-toolbars/Item.d.ts +3 -5
  36. package/lib/appui-react/toolbar/new-toolbars/Item.d.ts.map +1 -1
  37. package/lib/appui-react/toolbar/new-toolbars/Item.js +15 -19
  38. package/lib/appui-react/toolbar/new-toolbars/Item.js.map +1 -1
  39. package/lib/appui-react/toolbar/new-toolbars/OverflowButton.d.ts +0 -1
  40. package/lib/appui-react/toolbar/new-toolbars/OverflowButton.d.ts.map +1 -1
  41. package/lib/appui-react/toolbar/new-toolbars/OverflowButton.js +3 -2
  42. package/lib/appui-react/toolbar/new-toolbars/OverflowButton.js.map +1 -1
  43. package/lib/appui-react/toolbar/new-toolbars/Separator.d.ts +8 -0
  44. package/lib/appui-react/toolbar/new-toolbars/Separator.d.ts.map +1 -0
  45. package/lib/appui-react/toolbar/new-toolbars/Separator.js +19 -0
  46. package/lib/appui-react/toolbar/new-toolbars/Separator.js.map +1 -0
  47. package/lib/appui-react/toolbar/new-toolbars/Separator.scss +32 -0
  48. package/lib/appui-react/toolbar/new-toolbars/Surface.d.ts +5 -3
  49. package/lib/appui-react/toolbar/new-toolbars/Surface.d.ts.map +1 -1
  50. package/lib/appui-react/toolbar/new-toolbars/Surface.js.map +1 -1
  51. package/lib/appui-react/toolbar/new-toolbars/Surface.scss +4 -2
  52. package/lib/appui-react/toolbar/new-toolbars/ToolGroup.d.ts +0 -5
  53. package/lib/appui-react/toolbar/new-toolbars/ToolGroup.d.ts.map +1 -1
  54. package/lib/appui-react/toolbar/new-toolbars/ToolGroup.js +50 -19
  55. package/lib/appui-react/toolbar/new-toolbars/ToolGroup.js.map +1 -1
  56. package/lib/appui-react/toolbar/new-toolbars/Toolbar.d.ts +5 -0
  57. package/lib/appui-react/toolbar/new-toolbars/Toolbar.d.ts.map +1 -1
  58. package/lib/appui-react/toolbar/new-toolbars/Toolbar.js +45 -12
  59. package/lib/appui-react/toolbar/new-toolbars/Toolbar.js.map +1 -1
  60. package/lib/appui-react/toolbar/new-toolbars/useOverflow.js +2 -2
  61. package/lib/appui-react/toolbar/new-toolbars/useOverflow.js.map +1 -1
  62. package/lib/appui-react/widget-panels/ToolSettings.d.ts.map +1 -1
  63. package/lib/appui-react/widget-panels/ToolSettings.js +10 -7
  64. package/lib/appui-react/widget-panels/ToolSettings.js.map +1 -1
  65. package/lib/appui-react/widget-panels/useWidgetDirection.d.ts +1 -1
  66. package/lib/appui-react/widget-panels/useWidgetDirection.js +1 -1
  67. package/lib/appui-react/widget-panels/useWidgetDirection.js.map +1 -1
  68. package/lib/appui-react/widgets/useWidget.d.ts +5 -1
  69. package/lib/appui-react/widgets/useWidget.d.ts.map +1 -1
  70. package/lib/appui-react/widgets/useWidget.js +5 -1
  71. package/lib/appui-react/widgets/useWidget.js.map +1 -1
  72. package/lib/cjs/appui-react/toolbar/new-toolbars/Separator.scss +32 -0
  73. package/lib/cjs/appui-react/toolbar/new-toolbars/Surface.scss +4 -2
  74. package/lib/esm/appui-react/toolbar/new-toolbars/Separator.scss +32 -0
  75. package/lib/esm/appui-react/toolbar/new-toolbars/Surface.scss +4 -2
  76. package/package.json +8 -8
@@ -6,43 +6,39 @@
6
6
  * @module Toolbar
7
7
  */
8
8
  import * as React from "react";
9
- import { assert } from "@itwin/core-bentley";
10
9
  import { Icon } from "@itwin/core-react";
11
10
  import { IconButton } from "@itwin/itwinui-react";
12
11
  import { useConditionalProp } from "../../hooks/useConditionalProp.js";
13
12
  import { Badge } from "./Badge.js";
14
- import { ToolbarContext } from "./Toolbar.js";
13
+ import { ToolbarContext, ToolbarItemContext } from "./Toolbar.js";
14
+ import { useSafeContext } from "../../hooks/useSafeContext.js";
15
+ import { Separator } from "./Separator.js";
15
16
  /** @internal */
16
17
  export const Item = React.forwardRef(function Item(props, ref) {
17
18
  const { item, ...other } = props;
19
+ const { renderSeparator } = useSafeContext(ToolbarItemContext);
18
20
  const label = useConditionalProp(item.label);
19
21
  const isDisabled = useConditionalProp(item.isDisabled);
20
22
  const isHidden = useConditionalProp(item.isHidden);
21
23
  // eslint-disable-next-line @typescript-eslint/no-deprecated
22
24
  const iconSpec = useConditionalProp(item.icon);
23
25
  const labelProps = useLabelProps();
24
- if (isHidden)
25
- return null;
26
- return (React.createElement(IconButton, { className: props.className, styleType: "borderless", disabled: isDisabled, isActive: item.isActive, label: label, labelProps: labelProps, style: props.style, ref: ref, "data-item-id": item.id, ...other },
27
- item.iconNode ?? React.createElement(Icon, { iconSpec: iconSpec }),
28
- React.createElement(Badge, { badge: item.badge, badgeKind: item.badgeKind }),
29
- props.children));
26
+ return (React.createElement(React.Fragment, null,
27
+ isHidden ? undefined : (React.createElement(IconButton, { styleType: "borderless", disabled: isDisabled, isActive: item.isActive, label: label, labelProps: labelProps, style: props.style, ref: ref, "data-item-id": item.id, ...other },
28
+ item.iconNode ?? (
29
+ /* eslint-disable-next-line @typescript-eslint/no-deprecated */
30
+ React.createElement(Icon, { iconSpec: iconSpec })),
31
+ React.createElement(Badge, { badge: item.badge, badgeKind: item.badgeKind }),
32
+ props.children)),
33
+ renderSeparator && React.createElement(Separator, null)));
30
34
  });
31
35
  /** @internal */
32
- export function useExpandsTo() {
33
- const context = React.useContext(ToolbarContext);
34
- assert(!!context);
35
- const { expandsTo } = context;
36
- return expandsTo;
37
- }
38
- /** @internal */
39
36
  export function useLabelProps() {
40
- const context = React.useContext(ToolbarContext);
37
+ const { popoverOpen, expandsTo } = useSafeContext(ToolbarContext);
41
38
  const [internalVisible, setInternalVisible] = React.useState(false);
42
- const visible = context?.popoverOpen ? false : internalVisible;
43
- const placement = useExpandsTo();
39
+ const visible = popoverOpen ? false : internalVisible;
44
40
  return {
45
- placement,
41
+ placement: expandsTo,
46
42
  visible,
47
43
  onVisibleChange: setInternalVisible,
48
44
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Item.js","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/Item.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAQ9C,gBAAgB;AAChB,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAClC,SAAS,IAAI,CAAC,KAAK,EAAE,GAAG;IACtB,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC;IACjC,MAAM,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7C,MAAM,UAAU,GAAG,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnD,4DAA4D;IAC5D,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;I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OAAO;QACP,eAAe,EAAE,kBAAkB;KAC3B,CAAC;AACb,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 { assert } from \"@itwin/core-bentley\";\nimport { Icon } from \"@itwin/core-react\";\nimport { IconButton } from \"@itwin/itwinui-react\";\nimport type { ToolbarItem } from \"../../toolbar/ToolbarItem.js\";\nimport { useConditionalProp } from \"../../hooks/useConditionalProp.js\";\nimport { Badge } from \"./Badge.js\";\nimport { ToolbarContext } from \"./Toolbar.js\";\n\n/** @internal */\nexport interface ItemProps\n extends Partial<React.ComponentProps<typeof IconButton>> {\n item: ToolbarItem;\n}\n\n/** @internal */\nexport const Item = React.forwardRef<HTMLButtonElement, ItemProps>(\n function Item(props, ref) {\n const { item, ...other } = props;\n const label = useConditionalProp(item.label);\n const isDisabled = useConditionalProp(item.isDisabled);\n const isHidden = useConditionalProp(item.isHidden);\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const iconSpec = useConditionalProp(item.icon);\n const labelProps = useLabelProps();\n\n if (isHidden) return null;\n return (\n <IconButton\n className={props.className}\n styleType=\"borderless\"\n disabled={isDisabled}\n isActive={item.isActive}\n label={label}\n labelProps={labelProps}\n style={props.style}\n ref={ref}\n data-item-id={item.id}\n {...other}\n >\n {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}\n {item.iconNode ?? <Icon iconSpec={iconSpec} />}\n {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}\n <Badge badge={item.badge} badgeKind={item.badgeKind} />\n {props.children}\n </IconButton>\n );\n }\n);\n\n/** @internal */\nexport function useExpandsTo() {\n const context = React.useContext(ToolbarContext);\n assert(!!context);\n\n const { expandsTo } = context;\n return expandsTo;\n}\n\n/** @internal */\nexport function useLabelProps() {\n const context = React.useContext(ToolbarContext);\n const [internalVisible, setInternalVisible] = React.useState(false);\n const visible = context?.popoverOpen ? false : internalVisible;\n const placement = useExpandsTo();\n return {\n placement,\n visible,\n onVisibleChange: setInternalVisible,\n } as const;\n}\n"]}
1
+ {"version":3,"file":"Item.js","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/Item.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAM3C,gBAAgB;AAChB,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,CAAC,UAAU,CAClC,SAAS,IAAI,CAAC,KAAK,EAAE,GAAG;IACtB,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,EAAE,GAAG,KAAK,CAAC;IACjC,MAAM,EAAE,eAAe,EAAE,GAAG,cAAc,CAAC,kBAAkB,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,kBAAkB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC7C,MAAM,UAAU,GAAG,kBAAkB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnD,4DAA4D;IAC5D,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IAEnC,OAAO,CACL;QACG,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CACtB,oBAAC,UAAU,IACT,SAAS,EAAC,YAAY,EACtB,QAAQ,EAAE,UAAU,EACpB,QAAQ,EAAE,IAAI,CAAC,QAAQ,EACvB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,GAAG,EAAE,GAAG,kBACM,IAAI,CAAC,EAAE,KACjB,KAAK;YAER,IAAI,CAAC,QAAQ,IAAI;YAChB,+DAA+D;YAC/D,oBAAC,IAAI,IAAC,QAAQ,EAAE,QAAQ,GAAI,CAC7B;YAED,oBAAC,KAAK,IAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,GAAI;YACtD,KAAK,CAAC,QAAQ,CACJ,CACd;QACA,eAAe,IAAI,oBAAC,SAAS,OAAG,CAChC,CACJ,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,gBAAgB;AAChB,MAAM,UAAU,aAAa;IAC3B,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;IAClE,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACpE,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,eAAe,CAAC;IACtD,OAAO;QACL,SAAS,EAAE,SAAS;QACpB,OAAO;QACP,eAAe,EAAE,kBAAkB;KAC3B,CAAC;AACb,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 { Icon } from \"@itwin/core-react\";\nimport { IconButton } from \"@itwin/itwinui-react\";\nimport type { ToolbarItem } from \"../../toolbar/ToolbarItem.js\";\nimport { useConditionalProp } from \"../../hooks/useConditionalProp.js\";\nimport { Badge } from \"./Badge.js\";\nimport { ToolbarContext, ToolbarItemContext } from \"./Toolbar.js\";\nimport { useSafeContext } from \"../../hooks/useSafeContext.js\";\nimport { Separator } from \"./Separator.js\";\n\ninterface ItemProps extends Partial<React.ComponentProps<typeof IconButton>> {\n item: ToolbarItem;\n}\n\n/** @internal */\nexport const Item = React.forwardRef<HTMLButtonElement, ItemProps>(\n function Item(props, ref) {\n const { item, ...other } = props;\n const { renderSeparator } = useSafeContext(ToolbarItemContext);\n const label = useConditionalProp(item.label);\n const isDisabled = useConditionalProp(item.isDisabled);\n const isHidden = useConditionalProp(item.isHidden);\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n const iconSpec = useConditionalProp(item.icon);\n const labelProps = useLabelProps();\n\n return (\n <>\n {isHidden ? undefined : (\n <IconButton\n styleType=\"borderless\"\n disabled={isDisabled}\n isActive={item.isActive}\n label={label}\n labelProps={labelProps}\n style={props.style}\n ref={ref}\n data-item-id={item.id}\n {...other}\n >\n {item.iconNode ?? (\n /* eslint-disable-next-line @typescript-eslint/no-deprecated */\n <Icon iconSpec={iconSpec} />\n )}\n {/* eslint-disable-next-line @typescript-eslint/no-deprecated */}\n <Badge badge={item.badge} badgeKind={item.badgeKind} />\n {props.children}\n </IconButton>\n )}\n {renderSeparator && <Separator />}\n </>\n );\n }\n);\n\n/** @internal */\nexport function useLabelProps() {\n const { popoverOpen, expandsTo } = useSafeContext(ToolbarContext);\n const [internalVisible, setInternalVisible] = React.useState(false);\n const visible = popoverOpen ? false : internalVisible;\n return {\n placement: expandsTo,\n visible,\n onVisibleChange: setInternalVisible,\n } as const;\n}\n"]}
@@ -2,7 +2,6 @@
2
2
  * @module Toolbar
3
3
  */
4
4
  import * as React from "react";
5
- /** @internal */
6
5
  interface ToolGroupOverflow {
7
6
  onClose?: () => void;
8
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"OverflowButton.d.ts","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/OverflowButton.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,gBAAgB;AAChB,UAAU,iBAAiB;IACzB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,gBAAgB;AAChB,eAAO,MAAM,wBAAwB,8CAEzB,CAAC;AAEb,UAAU,mBAAmB;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,gBAAgB;AAChB,eAAO,MAAM,cAAc,+FAgCzB,CAAC"}
1
+ {"version":3,"file":"OverflowButton.d.ts","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/OverflowButton.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B,UAAU,iBAAiB;IACzB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,gBAAgB;AAChB,eAAO,MAAM,wBAAwB,8CAEzB,CAAC;AAEb,UAAU,mBAAmB;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,gBAAgB;AAChB,eAAO,MAAM,cAAc,+FAgCzB,CAAC"}
@@ -11,19 +11,20 @@ import { SvgMore } from "@itwin/itwinui-icons-react";
11
11
  import { useLabelProps } from "./Item.js";
12
12
  import { usePopoverPlacement } from "./GroupItem.js";
13
13
  import { ToolbarContext } from "./Toolbar.js";
14
+ import { useSafeContext } from "../../hooks/useSafeContext.js";
14
15
  /** @internal */
15
16
  export const ToolGroupOverflowContext = React.createContext(undefined);
16
17
  /** @internal */
17
18
  export const OverflowButton = React.forwardRef(function OverflowButton(props, ref) {
18
19
  const placement = usePopoverPlacement();
19
20
  const labelProps = useLabelProps();
20
- const context = React.useContext(ToolbarContext);
21
+ const { setPopoverOpen } = useSafeContext(ToolbarContext);
21
22
  return (React.createElement(DropdownMenu, { menuItems: (close) => {
22
23
  return [
23
24
  React.createElement(OverflowMenu, { key: 0, onClose: close }, props.children),
24
25
  ];
25
26
  }, placement: placement, onVisibleChange: (newVisible) => {
26
- context?.setPopoverOpen(newVisible);
27
+ setPopoverOpen(newVisible);
27
28
  } },
28
29
  React.createElement(IconButton, { ref: ref, label: "More", labelProps: labelProps, styleType: "borderless" },
29
30
  React.createElement(SvgMore, null))));
@@ -1 +1 @@
1
- {"version":3,"file":"OverflowButton.js","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/OverflowButton.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAO9C,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC,aAAa,CAEzD,SAAS,CAAC,CAAC;AAMb,gBAAgB;AAChB,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC,UAAU,CAG5C,SAAS,cAAc,CAAC,KAAK,EAAE,GAAG;IAClC,MAAM,SAAS,GAAG,mBAAmB,EAAE,CAAC;IACxC,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IACnC,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,cAAc,CAAC,CAAC;IAEjD,OAAO,CACL,oBAAC,YAAY,IACX,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;YACnB,OAAO;gBACL,oBAAC,YAAY,IAAC,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,IACjC,KAAK,CAAC,QAAQ,CACF;aAChB,CAAC;QACJ,CAAC,EACD,SAAS,EAAE,SAAS,EACpB,eAAe,EAAE,CAAC,UAAU,EAAE,EAAE;YAC9B,OAAO,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;QACtC,CAAC;QAED,oBAAC,UAAU,IACT,GAAG,EAAE,GAAG,EACR,KAAK,EAAC,MAAM,EACZ,UAAU,EAAE,UAAU,EACtB,SAAS,EAAC,YAAY;YAEtB,oBAAC,OAAO,OAAG,CACA,CACA,CAChB,CAAC;AACJ,CAAC,CAAC,CAAC;AAOH,SAAS,YAAY,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAqB;IAC5D,OAAO,CACL,oBAAC,wBAAwB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,OAAO,EAAE,IAClD,QAAQ,CACyB,CACrC,CAAC;AACJ,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 { DropdownMenu, IconButton } from \"@itwin/itwinui-react\";\nimport { SvgMore } from \"@itwin/itwinui-icons-react\";\nimport { useLabelProps } from \"./Item.js\";\nimport { usePopoverPlacement } from \"./GroupItem.js\";\nimport { ToolbarContext } from \"./Toolbar.js\";\n\n/** @internal */\ninterface ToolGroupOverflow {\n onClose?: () => void;\n}\n\n/** @internal */\nexport const ToolGroupOverflowContext = React.createContext<\n ToolGroupOverflow | undefined\n>(undefined);\n\ninterface OverflowButtonProps {\n children?: React.ReactNode;\n}\n\n/** @internal */\nexport const OverflowButton = React.forwardRef<\n HTMLButtonElement,\n OverflowButtonProps\n>(function OverflowButton(props, ref) {\n const placement = usePopoverPlacement();\n const labelProps = useLabelProps();\n const context = React.useContext(ToolbarContext);\n\n return (\n <DropdownMenu\n menuItems={(close) => {\n return [\n <OverflowMenu key={0} onClose={close}>\n {props.children}\n </OverflowMenu>,\n ];\n }}\n placement={placement}\n onVisibleChange={(newVisible) => {\n context?.setPopoverOpen(newVisible);\n }}\n >\n <IconButton\n ref={ref}\n label=\"More\"\n labelProps={labelProps}\n styleType=\"borderless\"\n >\n <SvgMore />\n </IconButton>\n </DropdownMenu>\n );\n});\n\ninterface OverflowMenuProps {\n children?: React.ReactNode;\n onClose?: () => void;\n}\n\nfunction OverflowMenu({ children, onClose }: OverflowMenuProps) {\n return (\n <ToolGroupOverflowContext.Provider value={{ onClose }}>\n {children}\n </ToolGroupOverflowContext.Provider>\n );\n}\n"]}
1
+ {"version":3,"file":"OverflowButton.js","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/OverflowButton.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAM/D,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,CAAC,aAAa,CAEzD,SAAS,CAAC,CAAC;AAMb,gBAAgB;AAChB,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC,UAAU,CAG5C,SAAS,cAAc,CAAC,KAAK,EAAE,GAAG;IAClC,MAAM,SAAS,GAAG,mBAAmB,EAAE,CAAC;IACxC,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IACnC,MAAM,EAAE,cAAc,EAAE,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;IAE1D,OAAO,CACL,oBAAC,YAAY,IACX,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;YACnB,OAAO;gBACL,oBAAC,YAAY,IAAC,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,KAAK,IACjC,KAAK,CAAC,QAAQ,CACF;aAChB,CAAC;QACJ,CAAC,EACD,SAAS,EAAE,SAAS,EACpB,eAAe,EAAE,CAAC,UAAU,EAAE,EAAE;YAC9B,cAAc,CAAC,UAAU,CAAC,CAAC;QAC7B,CAAC;QAED,oBAAC,UAAU,IACT,GAAG,EAAE,GAAG,EACR,KAAK,EAAC,MAAM,EACZ,UAAU,EAAE,UAAU,EACtB,SAAS,EAAC,YAAY;YAEtB,oBAAC,OAAO,OAAG,CACA,CACA,CAChB,CAAC;AACJ,CAAC,CAAC,CAAC;AAOH,SAAS,YAAY,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAqB;IAC5D,OAAO,CACL,oBAAC,wBAAwB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,OAAO,EAAE,IAClD,QAAQ,CACyB,CACrC,CAAC;AACJ,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 { DropdownMenu, IconButton } from \"@itwin/itwinui-react\";\nimport { SvgMore } from \"@itwin/itwinui-icons-react\";\nimport { useLabelProps } from \"./Item.js\";\nimport { usePopoverPlacement } from \"./GroupItem.js\";\nimport { ToolbarContext } from \"./Toolbar.js\";\nimport { useSafeContext } from \"../../hooks/useSafeContext.js\";\n\ninterface ToolGroupOverflow {\n onClose?: () => void;\n}\n\n/** @internal */\nexport const ToolGroupOverflowContext = React.createContext<\n ToolGroupOverflow | undefined\n>(undefined);\n\ninterface OverflowButtonProps {\n children?: React.ReactNode;\n}\n\n/** @internal */\nexport const OverflowButton = React.forwardRef<\n HTMLButtonElement,\n OverflowButtonProps\n>(function OverflowButton(props, ref) {\n const placement = usePopoverPlacement();\n const labelProps = useLabelProps();\n const { setPopoverOpen } = useSafeContext(ToolbarContext);\n\n return (\n <DropdownMenu\n menuItems={(close) => {\n return [\n <OverflowMenu key={0} onClose={close}>\n {props.children}\n </OverflowMenu>,\n ];\n }}\n placement={placement}\n onVisibleChange={(newVisible) => {\n setPopoverOpen(newVisible);\n }}\n >\n <IconButton\n ref={ref}\n label=\"More\"\n labelProps={labelProps}\n styleType=\"borderless\"\n >\n <SvgMore />\n </IconButton>\n </DropdownMenu>\n );\n});\n\ninterface OverflowMenuProps {\n children?: React.ReactNode;\n onClose?: () => void;\n}\n\nfunction OverflowMenu({ children, onClose }: OverflowMenuProps) {\n return (\n <ToolGroupOverflowContext.Provider value={{ onClose }}>\n {children}\n </ToolGroupOverflowContext.Provider>\n );\n}\n"]}
@@ -0,0 +1,8 @@
1
+ /** @packageDocumentation
2
+ * @module Toolbar
3
+ */
4
+ import "./Separator.scss";
5
+ import * as React from "react";
6
+ /** @internal */
7
+ export declare function Separator(): React.JSX.Element;
8
+ //# sourceMappingURL=Separator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Separator.d.ts","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/Separator.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,kBAAkB,CAAC;AAE1B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,gBAAgB;AAChB,wBAAgB,SAAS,sBAWxB"}
@@ -0,0 +1,19 @@
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
+ /** @packageDocumentation
6
+ * @module Toolbar
7
+ */
8
+ import "./Separator.scss";
9
+ import classnames from "classnames";
10
+ import * as React from "react";
11
+ import { ToolbarContext } from "./Toolbar.js";
12
+ import { useSafeContext } from "../../hooks/useSafeContext.js";
13
+ /** @internal */
14
+ export function Separator() {
15
+ const context = useSafeContext(ToolbarContext);
16
+ const { orientation } = context;
17
+ return (React.createElement("div", { className: classnames("uifw-toolbar-newToolbars-separator", `uifw-${orientation}`) }));
18
+ }
19
+ //# sourceMappingURL=Separator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Separator.js","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/Separator.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,kBAAkB,CAAC;AAC1B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,gBAAgB;AAChB,MAAM,UAAU,SAAS;IACvB,MAAM,OAAO,GAAG,cAAc,CAAC,cAAc,CAAC,CAAC;IAC/C,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,OAAO,CACL,6BACE,SAAS,EAAE,UAAU,CACnB,oCAAoC,EACpC,QAAQ,WAAW,EAAE,CACtB,GACD,CACH,CAAC;AACJ,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 \"./Separator.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { ToolbarContext } from \"./Toolbar.js\";\nimport { useSafeContext } from \"../../hooks/useSafeContext.js\";\n\n/** @internal */\nexport function Separator() {\n const context = useSafeContext(ToolbarContext);\n const { orientation } = context;\n return (\n <div\n className={classnames(\n \"uifw-toolbar-newToolbars-separator\",\n `uifw-${orientation}`\n )}\n />\n );\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
+ }
@@ -4,9 +4,11 @@
4
4
  import "./Surface.scss";
5
5
  import * as React from "react";
6
6
  import { Surface as IUI_Surface } from "@itwin/itwinui-react";
7
- type SurfaceProps = React.ComponentProps<typeof IUI_Surface> & {
8
- orientation: "horizontal" | "vertical";
9
- };
7
+ import type { ToolbarContext } from "./Toolbar.js";
8
+ type ToolbarContextProps = NonNullable<React.ContextType<typeof ToolbarContext>>;
9
+ interface SurfaceProps extends React.ComponentProps<typeof IUI_Surface> {
10
+ orientation: ToolbarContextProps["orientation"];
11
+ }
10
12
  /** @internal */
11
13
  export declare const Surface: React.ForwardRefExoticComponent<Omit<SurfaceProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
12
14
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"Surface.d.ts","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/Surface.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,gBAAgB,CAAC;AACxB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAY9D,KAAK,YAAY,GAAG,KAAK,CAAC,cAAc,CAAC,OAAO,WAAW,CAAC,GAAG;IAC7D,WAAW,EAAE,YAAY,GAAG,UAAU,CAAC;CACxC,CAAC;AAEF,gBAAgB;AAChB,eAAO,MAAM,OAAO,kGAiCnB,CAAC"}
1
+ {"version":3,"file":"Surface.d.ts","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/Surface.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,gBAAgB,CAAC;AACxB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAW9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,KAAK,mBAAmB,GAAG,WAAW,CACpC,KAAK,CAAC,WAAW,CAAC,OAAO,cAAc,CAAC,CACzC,CAAC;AAEF,UAAU,YAAa,SAAQ,KAAK,CAAC,cAAc,CAAC,OAAO,WAAW,CAAC;IACrE,WAAW,EAAE,mBAAmB,CAAC,aAAa,CAAC,CAAC;CACjD;AAED,gBAAgB;AAChB,eAAO,MAAM,OAAO,kGAiCnB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Surface.js","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/Surface.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,gBAAgB,CAAC;AACxB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAC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K,EAAE;YACL,eAAe;YACf,GAAG,KAAK;SACT,EACD,SAAS,EAAE,UAAU,CACnB,4BAA4B,EAC5B,QAAQ,WAAW,EAAE,EACrB,SAAS,CACV,EACD,GAAG,EAAE,IAAI,GACT,CACH,CAAC;AACJ,CAAC,CACF,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 \"./Surface.scss\";\nimport * as React from \"react\";\nimport classnames from \"classnames\";\nimport { Surface as IUI_Surface } from \"@itwin/itwinui-react\";\nimport {\n calculateToolbarOpacity,\n getToolbarBackgroundColor,\n useRefs,\n useWidgetOpacityContext,\n} from \"@itwin/core-react/internal\";\nimport { UiFramework } from \"../../UiFramework.js\";\nimport { ProcessDetector } from \"@itwin/core-bentley\";\nimport { useConditionalValue } from \"../../hooks/useConditionalValue.js\";\nimport { SyncUiEventId } from \"../../syncui/SyncUiEventDispatcher.js\";\n\ntype SurfaceProps = React.ComponentProps<typeof IUI_Surface> & {\n orientation: \"horizontal\" | \"vertical\";\n};\n\n/** @internal */\nexport const Surface = React.forwardRef<HTMLDivElement, SurfaceProps>(\n function Surface({ className, style, orientation, ...rest }, forwardedRed) {\n const { ref, proximityScale } = useWidgetOpacityContext<HTMLDivElement>();\n const refs = useRefs(ref, forwardedRed);\n\n const calculateOpacity = useConditionalValue(() => {\n if (ProcessDetector.isMobileBrowser) return false;\n if (UiFramework.visibility.snapWidgetOpacity) return true;\n return false;\n }, [SyncUiEventId.ShowHideManagerSettingChange]);\n const opacity = React.useMemo(() => {\n if (!calculateOpacity) return undefined;\n return calculateToolbarOpacity(proximityScale);\n }, [proximityScale, calculateOpacity]);\n const backgroundColor =\n opacity === undefined ? undefined : getToolbarBackgroundColor(opacity);\n\n return (\n <IUI_Surface\n {...rest}\n style={{\n backgroundColor,\n ...style,\n }}\n className={classnames(\n \"uifw-toolbar-group-surface\",\n `uifw-${orientation}`,\n className\n )}\n ref={refs}\n />\n );\n }\n);\n"]}
1
+ {"version":3,"file":"Surface.js","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolbars/Surface.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,gBAAgB,CAAC;AACxB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,OAAO,EACP,uBAAuB,GACxB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAWtE,gBAAgB;AAChB,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CACrC,SAAS,OAAO,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,GAAG,IAAI,EAAE,EAAE,YAAY;IACvE,MAAM,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,uBAAuB,EAAkB,CAAC;IAC1E,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IAExC,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,GAAG,EAAE;QAChD,IAAI,eAAe,CAAC,eAAe;YAAE,OAAO,KAAK,CAAC;QAClD,IAAI,WAAW,CAAC,UAAU,CAAC,iBAAiB;YAAE,OAAO,IAAI,CAAC;QAC1D,OAAO,KAAK,CAAC;IACf,CAAC,EAAE,CAAC,aAAa,CAAC,4BAA4B,CAAC,CAAC,CAAC;IACjD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QACjC,IAAI,CAAC,gBAAgB;YAAE,OAAO,SAAS,CAAC;QACxC,OAAO,uBAAuB,CAAC,cAAc,CAAC,CAAC;IACjD,CAAC,EAAE,CAAC,cAAc,EAAE,gBAAgB,CAAC,CAAC,CAAC;IACvC,MAAM,eAAe,GACnB,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC;IAEzE,OAAO,CACL,oBAAC,WAAW,OACN,IAAI,EACR,KAAK,EAAE;YACL,eAAe;YACf,GAAG,KAAK;SACT,EACD,SAAS,EAAE,UAAU,CACnB,4BAA4B,EAC5B,QAAQ,WAAW,EAAE,EACrB,SAAS,CACV,EACD,GAAG,EAAE,IAAI,GACT,CACH,CAAC;AACJ,CAAC,CACF,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 \"./Surface.scss\";\nimport * as React from \"react\";\nimport classnames from \"classnames\";\nimport { Surface as IUI_Surface } from \"@itwin/itwinui-react\";\nimport {\n calculateToolbarOpacity,\n getToolbarBackgroundColor,\n useRefs,\n useWidgetOpacityContext,\n} from \"@itwin/core-react/internal\";\nimport { UiFramework } from \"../../UiFramework.js\";\nimport { ProcessDetector } from \"@itwin/core-bentley\";\nimport { useConditionalValue } from \"../../hooks/useConditionalValue.js\";\nimport { SyncUiEventId } from \"../../syncui/SyncUiEventDispatcher.js\";\nimport type { ToolbarContext } from \"./Toolbar.js\";\n\ntype ToolbarContextProps = NonNullable<\n React.ContextType<typeof ToolbarContext>\n>;\n\ninterface SurfaceProps extends React.ComponentProps<typeof IUI_Surface> {\n orientation: ToolbarContextProps[\"orientation\"];\n}\n\n/** @internal */\nexport const Surface = React.forwardRef<HTMLDivElement, SurfaceProps>(\n function Surface({ className, style, orientation, ...rest }, forwardedRed) {\n const { ref, proximityScale } = useWidgetOpacityContext<HTMLDivElement>();\n const refs = useRefs(ref, forwardedRed);\n\n const calculateOpacity = useConditionalValue(() => {\n if (ProcessDetector.isMobileBrowser) return false;\n if (UiFramework.visibility.snapWidgetOpacity) return true;\n return false;\n }, [SyncUiEventId.ShowHideManagerSettingChange]);\n const opacity = React.useMemo(() => {\n if (!calculateOpacity) return undefined;\n return calculateToolbarOpacity(proximityScale);\n }, [proximityScale, calculateOpacity]);\n const backgroundColor =\n opacity === undefined ? undefined : getToolbarBackgroundColor(opacity);\n\n return (\n <IUI_Surface\n {...rest}\n style={{\n backgroundColor,\n ...style,\n }}\n className={classnames(\n \"uifw-toolbar-group-surface\",\n `uifw-${orientation}`,\n className\n )}\n ref={refs}\n />\n );\n }\n);\n"]}
@@ -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 {
@@ -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
  //# sourceMappingURL=ToolGroup.js.map
@@ -1 +1 @@
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,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,SA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AW,EAAE,GAAG,EAAE,YAAY,KAAM,KAAK;YAC5D,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE;gBACrC,IAAI,CAAC,KAAK,CAAC,cAAc,CAA8B,KAAK,CAAC;oBAC3D,OAAO,KAAK,CAAC;gBACf,OAAO,KAAK,CAAC,YAAY,CAAC,KAAK,EAAE;oBAC/B,GAAG,EAAE,CAAC,EAAkB,EAAE,EAAE;wBAC1B,IAAI,CAAC,EAAE,EAAE,CAAC;4BACR,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;4BAC9B,OAAO;wBACT,CAAC;wBACD,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;oBACjC,CAAC;iBACF,CAAC,CAAC;YACL,CAAC,CAAC;YACD,cAAc,IAAI,CACjB,oBAAC,cAAc,IAAC,GAAG,EAAE,WAAW,IAC7B,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CACtB,CAClB,CACO,CACN,CACP,CAAC;AACJ,CAAC;AAED,SAAS,CAAC,UAAU,GAAG,UAAU,CAAC;AAClC,SAAS,CAAC,SAAS,GAAG,SAAS,CAAC;AAChC,SAAS,CAAC,UAAU,GAAG,UAAU,CAAC;AAIlC,SAAS,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,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,sCAAsC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAS/D,gBAAgB;AAChB,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,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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E,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,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAc7C,gBAAgB;AAChB,MAAM,UAAU,OAAO,CAAC,EACtB,KAAK,EACL,SAAS,GAAG,QAAQ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AAE,YAAY,EAAE,IAAI,EAAE,IAAI,GAAI,CAAC;IAC9D,CAAC;IACD,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7B,WAAW,GAAG,oBAAC,SAAS,IAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,GAAI,CAAC;IAC7D,CAAC;IACD,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,WAAW,GAAG,oBAAC,UAAU,IAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,GAAI,CAAC;IAC9D,CAAC;IACD,OAAO,CACL,oBAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,eAAe,EAAE,IACpD,WAAW,CACgB,CAC/B,CAAC;AACJ,CAAC,CACF,CAAC;AAUF,gBAAgB;AAChB,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,CAAC,aAAa,CAE/C,SAAS,CAAC,CAAC;AACb,cAAc,CAAC,WAAW,GAAG,qBAAqB,CAAC;AAEnD,gBAAgB;AAChB,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC,aAAa,CAKnD,SAAS,CAAC,CAAC;AACb,cAAc,CAAC,WAAW,GAAG,qBAAqB,CAAC;AAEnD,SAAS,cAAc,CAAC,SAA2C;IACjE,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 * 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;