@itwin/appui-react 5.8.0 → 5.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/lib/appui-react/content/ContentLayout.d.ts.map +1 -1
- package/lib/appui-react/content/ContentLayout.js +3 -2
- package/lib/appui-react/content/ContentLayout.js.map +1 -1
- package/lib/appui-react/hooks/useSafeContext.d.ts +7 -0
- package/lib/appui-react/hooks/useSafeContext.d.ts.map +1 -0
- package/lib/appui-react/hooks/useSafeContext.js +17 -0
- package/lib/appui-react/hooks/useSafeContext.js.map +1 -0
- package/lib/appui-react/toolbar/new-toolbars/ActionItem.d.ts +2 -2
- package/lib/appui-react/toolbar/new-toolbars/ActionItem.d.ts.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/ActionItem.js +2 -1
- package/lib/appui-react/toolbar/new-toolbars/ActionItem.js.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/CustomItem.d.ts +2 -2
- package/lib/appui-react/toolbar/new-toolbars/CustomItem.d.ts.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/CustomItem.js +3 -2
- package/lib/appui-react/toolbar/new-toolbars/CustomItem.js.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/GroupItem.d.ts +2 -3
- package/lib/appui-react/toolbar/new-toolbars/GroupItem.d.ts.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/GroupItem.js +6 -7
- package/lib/appui-react/toolbar/new-toolbars/GroupItem.js.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/Item.d.ts +3 -5
- package/lib/appui-react/toolbar/new-toolbars/Item.d.ts.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/Item.js +15 -19
- package/lib/appui-react/toolbar/new-toolbars/Item.js.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/OverflowButton.d.ts +0 -1
- package/lib/appui-react/toolbar/new-toolbars/OverflowButton.d.ts.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/OverflowButton.js +3 -2
- package/lib/appui-react/toolbar/new-toolbars/OverflowButton.js.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/Separator.d.ts +8 -0
- package/lib/appui-react/toolbar/new-toolbars/Separator.d.ts.map +1 -0
- package/lib/appui-react/toolbar/new-toolbars/Separator.js +19 -0
- package/lib/appui-react/toolbar/new-toolbars/Separator.js.map +1 -0
- package/lib/appui-react/toolbar/new-toolbars/Separator.scss +32 -0
- package/lib/appui-react/toolbar/new-toolbars/Surface.d.ts +5 -3
- package/lib/appui-react/toolbar/new-toolbars/Surface.d.ts.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/Surface.js.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/Surface.scss +4 -2
- package/lib/appui-react/toolbar/new-toolbars/ToolGroup.d.ts +0 -5
- package/lib/appui-react/toolbar/new-toolbars/ToolGroup.d.ts.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/ToolGroup.js +50 -19
- package/lib/appui-react/toolbar/new-toolbars/ToolGroup.js.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/Toolbar.d.ts +5 -0
- package/lib/appui-react/toolbar/new-toolbars/Toolbar.d.ts.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/Toolbar.js +45 -12
- package/lib/appui-react/toolbar/new-toolbars/Toolbar.js.map +1 -1
- package/lib/appui-react/toolbar/new-toolbars/useOverflow.js +2 -2
- package/lib/appui-react/toolbar/new-toolbars/useOverflow.js.map +1 -1
- package/lib/appui-react/widget-panels/useWidgetDirection.d.ts +1 -1
- package/lib/appui-react/widget-panels/useWidgetDirection.js +1 -1
- package/lib/appui-react/widget-panels/useWidgetDirection.js.map +1 -1
- package/lib/appui-react/widgets/useWidget.d.ts +5 -1
- package/lib/appui-react/widgets/useWidget.d.ts.map +1 -1
- package/lib/appui-react/widgets/useWidget.js +5 -1
- package/lib/appui-react/widgets/useWidget.js.map +1 -1
- package/lib/cjs/appui-react/toolbar/new-toolbars/Separator.scss +32 -0
- package/lib/cjs/appui-react/toolbar/new-toolbars/Surface.scss +4 -2
- package/lib/esm/appui-react/toolbar/new-toolbars/Separator.scss +32 -0
- package/lib/esm/appui-react/toolbar/new-toolbars/Surface.scss +4 -2
- package/package.json +8 -8
|
@@ -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,
|
|
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;I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AS;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"]}
|
|
@@ -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;
|
|
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
|
|
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
|
-
|
|
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;
|
|
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 @@
|
|
|
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
|
|
8
|
-
|
|
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;
|
|
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,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;
|
|
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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,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(--
|
|
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;
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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,
|
|
1
|
+
{"version":3,"file":"ToolGroup.js","sourceRoot":"","sources":["../../../../src/appui-react/toolbar/new-toolb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AAY,CAAC,WAAW,CAAC,CAAC;IAC5C,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC;IAEjC,OAAO,SAAS,CAAC,qBAAqB,EAAE,CAAC;AAC3C,CAAC;AAED,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;
|
|
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
|
-
}), [
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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;
|
|
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,EACpB,cAAc,GAAG,OAAO,EACxB,cAAc,GACD;IACb,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC5D,MAAM,WAAW,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,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
|
-
|
|
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,O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,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"]}
|
|
@@ -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
|
-
* @
|
|
16
|
+
* @public
|
|
17
17
|
*/
|
|
18
18
|
export function useWidgetDirection() {
|
|
19
19
|
const tabId = React.useContext(TabIdContext);
|