@itwin/core-react 5.19.0 → 5.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/lib/core-react/UiCore.js +2 -1
- package/lib/core-react/UiCore.js.map +1 -1
- package/lib/core-react/autosuggest/AutoSuggest.js +86 -86
- package/lib/core-react/autosuggest/AutoSuggest.js.map +1 -1
- package/lib/core-react/contextmenu/ContextMenu.js +272 -269
- package/lib/core-react/contextmenu/ContextMenu.js.map +1 -1
- package/lib/core-react/contextmenu/ContextMenuItem.js +57 -55
- package/lib/core-react/contextmenu/ContextMenuItem.js.map +1 -1
- package/lib/core-react/contextmenu/ContextSubMenu.js +70 -67
- package/lib/core-react/contextmenu/ContextSubMenu.js.map +1 -1
- package/lib/core-react/contextmenu/GlobalContextMenu.js +23 -22
- package/lib/core-react/contextmenu/GlobalContextMenu.js.map +1 -1
- package/lib/core-react/contextmenu/TildeFinder.js +52 -52
- package/lib/core-react/contextmenu/TildeFinder.js.map +1 -1
- package/lib/core-react/dialog/Dialog.js +29 -29
- package/lib/core-react/dialog/Dialog.js.map +1 -1
- package/lib/core-react/dialog/GlobalDialog.js +24 -23
- package/lib/core-react/dialog/GlobalDialog.js.map +1 -1
- package/lib/core-react/expandable/ExpandableList.js +15 -15
- package/lib/core-react/expandable/ExpandableList.js.map +1 -1
- package/lib/core-react/focus/ItemKeyboardNavigator.js +7 -3
- package/lib/core-react/focus/ItemKeyboardNavigator.js.map +1 -1
- package/lib/core-react/hocs/withIsPressed.js +14 -17
- package/lib/core-react/hocs/withIsPressed.js.map +1 -1
- package/lib/core-react/hocs/withOnOutsideClick.js +38 -41
- package/lib/core-react/hocs/withOnOutsideClick.js.map +1 -1
- package/lib/core-react/hocs/withTimeout.js +2 -5
- package/lib/core-react/hocs/withTimeout.js.map +1 -1
- package/lib/core-react/icons/ConditionalIconItem.js +3 -0
- package/lib/core-react/icons/ConditionalIconItem.js.map +1 -1
- package/lib/core-react/imagecheckbox/ImageCheckBox.js +15 -18
- package/lib/core-react/imagecheckbox/ImageCheckBox.js.map +1 -1
- package/lib/core-react/loading/LoadingBar.js +3 -3
- package/lib/core-react/loading/LoadingBar.js.map +1 -1
- package/lib/core-react/loading/LoadingPrompt.js +9 -9
- package/lib/core-react/loading/LoadingPrompt.js.map +1 -1
- package/lib/core-react/loading/LoadingSpinner.js +3 -3
- package/lib/core-react/loading/LoadingSpinner.js.map +1 -1
- package/lib/core-react/loading/LoadingStatus.js +4 -4
- package/lib/core-react/loading/LoadingStatus.js.map +1 -1
- package/lib/core-react/messagebox/MessageBox.js +6 -6
- package/lib/core-react/messagebox/MessageBox.js.map +1 -1
- package/lib/core-react/popup/Popup.js +209 -209
- package/lib/core-react/popup/Popup.js.map +1 -1
- package/lib/core-react/radialmenu/Annulus.js +19 -2
- package/lib/core-react/radialmenu/Annulus.js.map +1 -1
- package/lib/core-react/radialmenu/RadialMenu.js +56 -56
- package/lib/core-react/radialmenu/RadialMenu.js.map +1 -1
- package/lib/core-react/searchbox/SearchBox.js +60 -60
- package/lib/core-react/searchbox/SearchBox.js.map +1 -1
- package/lib/core-react/settings/SettingsManager.js +20 -22
- package/lib/core-react/settings/SettingsManager.js.map +1 -1
- package/lib/core-react/tabs/Tabs.js +14 -13
- package/lib/core-react/tabs/Tabs.js.map +1 -1
- package/lib/core-react/tree/Node.js +18 -18
- package/lib/core-react/tree/Node.js.map +1 -1
- package/lib/core-react/tree/Tree.js +1 -4
- package/lib/core-react/tree/Tree.js.map +1 -1
- package/lib/core-react/uistate/LocalStateStorage.js +1 -0
- package/lib/core-react/uistate/LocalStateStorage.js.map +1 -1
- package/lib/core-react/uistate/UiStateEntry.js +5 -0
- package/lib/core-react/uistate/UiStateEntry.js.map +1 -1
- package/lib/core-react/utils/Point.js +2 -0
- package/lib/core-react/utils/Point.js.map +1 -1
- package/lib/core-react/utils/Rectangle.js +4 -0
- package/lib/core-react/utils/Rectangle.js.map +1 -1
- package/lib/core-react/utils/ScrollPositionMaintainer.js +1 -0
- package/lib/core-react/utils/ScrollPositionMaintainer.js.map +1 -1
- package/lib/core-react/utils/Timer.js +5 -2
- package/lib/core-react/utils/Timer.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageBox.js","sourceRoot":"","sources":["../../../src/core-react/messagebox/MessageBox.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,mBAAmB,CAAC;AAC3B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AA6C7C;;;GAGG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK,CAAC,aAA8B;IAQlD,MAAM;QACpB,OAAO,CACL,oBAAC,MAAM,IACL,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EACvB,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,EACvC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EACzB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,EAC3B,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,EAC7B,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EACvB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,EAC/B,KAAK,EAAE,IAAI,CAAC,KAAK,CAA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C,CAAC,CAAC,oBAAC,eAAe,OAAG,CAAC;QAClE,KAAK,eAAe,CAAC,QAAQ;YAC3B,OAAO,MAAM,CAAC,CAAC,CAAC,oBAAC,qBAAqB,OAAG,CAAC,CAAC,CAAC,oBAAC,eAAe,OAAG,CAAC;QAClE,KAAK,eAAe,CAAC,OAAO;YAC1B,OAAO,oBAAC,gBAAgB,OAAG,CAAC,CAAC,8CAA8C;QAC7E,KAAK,eAAe,CAAC,KAAK;YACxB,OAAO,MAAM,CAAC,CAAC,CAAC,oBAAC,oBAAoB,OAAG,CAAC,CAAC,CAAC,oBAAC,cAAc,OAAG,CAAC;YAC9D,MAAM;QACR,KAAK,eAAe,CAAC,KAAK;YACxB,OAAO,MAAM,CAAC,CAAC,CAAC,oBAAC,uBAAuB,OAAG,CAAC,CAAC,CAAC,oBAAC,iBAAiB,OAAG,CAAC;IACxE,CAAC;AACH,CAAC;AAID,SAAS,MAAM,CAAC,QAAyB;IACvC,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,eAAe,CAAC,IAAI;YACvB,OAAO,SAAS,CAAC;QACnB,KAAK,eAAe,CAAC,OAAO;YAC1B,OAAO,UAAU,CAAC;QACpB,KAAK,eAAe,CAAC,WAAW,CAAC;QACjC,KAAK,eAAe,CAAC,QAAQ;YAC3B,OAAO,eAAe,CAAC;QACzB,KAAK,eAAe,CAAC,OAAO;YAC1B,OAAO,SAAS,CAAC;QACnB,KAAK,eAAe,CAAC,KAAK,CAAC;QAC3B,KAAK,eAAe,CAAC,KAAK;YACxB,OAAO,UAAU,CAAC;IACtB,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 Dialog\n */\n\nimport \"./MessageBox.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { DialogButtonDef } from \"@itwin/appui-abstract\";\nimport { MessageSeverity } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"../utils/Props.js\";\nimport {\n SvgHelpCircular,\n SvgHelpCircularHollow,\n SvgInfoCircular,\n SvgInfoCircularHollow,\n SvgStatusError,\n SvgStatusErrorHollow,\n SvgStatusRejected,\n SvgStatusRejectedHollow,\n SvgStatusSuccess,\n SvgStatusSuccessHollow,\n SvgStatusWarning,\n} from \"@itwin/itwinui-icons-react\";\nimport { Icon } from \"@itwin/itwinui-react\";\nimport type { IconSpec } from \"../icons/IconComponent.js\";\nimport { Dialog } from \"../dialog/Dialog.js\";\n\n/* eslint-disable @typescript-eslint/no-deprecated */\n\n/** Properties for the [[MessageBox]] component\n * @public\n * @deprecated in 4.15.0. Props of deprecated {@link MessageBox} component.\n */\nexport interface MessageBoxProps extends CommonProps {\n /** Severity of MessageBox */\n severity: MessageSeverity;\n /** whether to show dialog or not */\n opened: boolean;\n /** List of [[DialogButtonDef]] objects specifying buttons and associated onClick events */\n buttonCluster: DialogButtonDef[];\n /** Title to show in title bar of dialog */\n title?: string | React.ReactElement;\n /** onClick event for X button for dialog */\n onClose?: () => void;\n /** 'keyup' event for <Esc> key */\n onEscape?: () => void;\n /** minimum width that the dialog may be resized to. Default: 400 */\n minWidth?: number;\n /** minimum height that the dialog may be resized to. Default: 400 */\n minHeight?: number;\n /** initial width of dialog.\n * Displayed in px if value is a number, otherwise displayed in specified CSS unit.\n * Default: \"50%\"\n */\n width?: string | number;\n /** initial height of dialog.\n * Displayed in px if value is a number, otherwise displayed in specified CSS unit.\n * Default: \"\"\n */\n height?: string | number;\n /** Whether to show background overlay. Default: true */\n modal?: boolean;\n /** Custom CSS class name for the content */\n contentClassName?: string;\n /** Custom CSS Style for the content */\n contentStyle?: React.CSSProperties;\n /** Message content */\n children?: React.ReactNode;\n}\n\n/** Message Box React component.\n * @public\n * @deprecated in 4.15.0. Use {@link https://itwinui.bentley.com/docs/dialog iTwinUI Dialog} instead.\n */\nexport class MessageBox extends React.PureComponent<MessageBoxProps> {\n public static defaultProps: Partial<MessageBoxProps> = {\n minWidth: 400,\n minHeight: 400,\n width: \"512px\",\n modal: true,\n };\n\n public override render(): React.ReactElement {\n return (\n <Dialog\n title={this.props.title}\n buttonCluster={this.props.buttonCluster}\n opened={this.props.opened}\n onClose={this.props.onClose}\n onEscape={this.props.onEscape}\n modal={this.props.modal}\n className={this.props.className}\n style={this.props.style}\n width={this.props.width}\n >\n <MessageContainer\n severity={this.props.severity}\n className={this.props.contentClassName}\n style={this.props.contentStyle}\n >\n {this.props.children}\n </MessageContainer>\n </Dialog>\n );\n }\n}\n\n/** Properties for the [[MessageContainer]] component\n * @public\n * @deprecated in 4.15.0. Props of deprecated {@link MessageContainer} component.\n */\nexport interface MessageContainerProps extends CommonProps {\n severity: MessageSeverity;\n /** Message Content */\n children?: React.ReactNode;\n}\n\n/** Message Container React component.\n * @public\n * @deprecated in 4.15.0. Use {@link https://itwinui.bentley.com/docs/dialog iTwinUI Dialog} instead.\n */\nexport class MessageContainer extends React.PureComponent<MessageContainerProps> {\n /** Returns the class name corresponding to the MessageSeverity.\n * @param severity MessageSeverity\n */\n public static getIconClassName(severity: MessageSeverity): string;\n /** Returns the class name associated with the WebFont icon corresponding to the MessageSeverity.\n * @param severity MessageSeverity\n * @param hollow Should the icon be hollow\n * @deprecated in 4.0.0. Hollow parameter ignored, WebFont is not returned, only the color.\n */\n public static getIconClassName(\n severity: MessageSeverity,\n // eslint-disable-next-line @typescript-eslint/unified-signatures\n hollow?: boolean\n ): string;\n\n public static getIconClassName(\n severity: MessageSeverity,\n _hollow?: boolean\n ): string {\n let iconClassName = \"\";\n\n switch (severity) {\n case MessageSeverity.None:\n iconClassName = \"\";\n break;\n case MessageSeverity.Success:\n iconClassName = \"core-message-box-success\";\n break;\n case MessageSeverity.Information:\n iconClassName = \"core-message-box-information\";\n break;\n case MessageSeverity.Question:\n iconClassName = \"core-message-box-question\";\n break;\n case MessageSeverity.Warning:\n iconClassName = \"core-message-box-warning\";\n break;\n case MessageSeverity.Error:\n iconClassName = \"core-message-box-error\";\n break;\n case MessageSeverity.Fatal:\n iconClassName = \"core-message-box-fatal\";\n break;\n }\n\n return iconClassName;\n }\n\n /** Returns the React icon corresponding to the MessageSeverity.\n * @param severity MessageSeverity\n * @param hollow set to true to return the hollow form of the icon.\n * @returns IconSpec\n */\n /* ignore for unit tests and replace with visual testing */\n\n public static getIcon(severity: MessageSeverity, hollow?: boolean): IconSpec {\n const icon = getIcon(severity, hollow);\n return icon ?? \"\";\n }\n\n public override render(): React.ReactElement {\n const iconClassName = classnames(\n \"icon\",\n \"core-message-box-icon\",\n MessageContainer.getIconClassName(this.props.severity)\n );\n\n const icon = getIcon(this.props.severity);\n return (\n <div className=\"core-message-box-container\">\n {icon ? (\n <Icon\n className={iconClassName}\n size=\"large\"\n fill={toFill(this.props.severity)}\n >\n {icon}\n </Icon>\n ) : undefined}\n <div\n className={classnames(\n \"core-message-box-content\",\n this.props.className\n )}\n style={this.props.style}\n >\n {this.props.children}\n </div>\n </div>\n );\n }\n}\n\nfunction getIcon(\n severity: MessageSeverity,\n hollow?: boolean\n): React.ReactElement | undefined {\n switch (severity) {\n case MessageSeverity.None:\n return undefined;\n case MessageSeverity.Success:\n return hollow ? <SvgStatusSuccessHollow /> : <SvgStatusSuccess />;\n case MessageSeverity.Information:\n return hollow ? <SvgInfoCircularHollow /> : <SvgInfoCircular />;\n case MessageSeverity.Question:\n return hollow ? <SvgHelpCircularHollow /> : <SvgHelpCircular />;\n case MessageSeverity.Warning:\n return <SvgStatusWarning />; // TODO - need icon-status-warning-hollow icon\n case MessageSeverity.Error:\n return hollow ? <SvgStatusErrorHollow /> : <SvgStatusError />;\n break;\n case MessageSeverity.Fatal:\n return hollow ? <SvgStatusRejectedHollow /> : <SvgStatusRejected />;\n }\n}\n\ntype IconProps = React.ComponentProps<typeof Icon>;\n\nfunction toFill(severity: MessageSeverity): IconProps[\"fill\"] {\n switch (severity) {\n case MessageSeverity.None:\n return undefined;\n case MessageSeverity.Success:\n return \"positive\";\n case MessageSeverity.Information:\n case MessageSeverity.Question:\n return \"informational\";\n case MessageSeverity.Warning:\n return \"warning\";\n case MessageSeverity.Error:\n case MessageSeverity.Fatal:\n return \"negative\";\n }\n return undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MessageBox.js","sourceRoot":"","sources":["../../../src/core-react/messagebox/MessageBox.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAChG;;GAEG;AAEH,OAAO,mBAAmB,CAAC;AAC3B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACvB,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,GACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AA6C7C;;;GAGG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK,CAAC,aAA8B;IAC3D,MAAM,CAAC,YAAY,GAA6B;QACrD,QAAQ,EAAE,GAAG;QACb,SAAS,EAAE,GAAG;QACd,KAAK,EAAE,OAAO;QACd,KAAK,EAAE,IAAI;KACZ,CAAC;IAEc,MAAM;QACpB,OAAO,CACL,oBAAC,MAAM,IACL,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,EACvB,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,aAAa,EACvC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EACzB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,EAC3B,QAAQ,EAAE,I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CAAC,CAAC,oBAAC,qBAAqB,OAAG,CAAC,CAAC,CAAC,oBAAC,eAAe,OAAG,CAAC;QAClE,KAAK,eAAe,CAAC,QAAQ;YAC3B,OAAO,MAAM,CAAC,CAAC,CAAC,oBAAC,qBAAqB,OAAG,CAAC,CAAC,CAAC,oBAAC,eAAe,OAAG,CAAC;QAClE,KAAK,eAAe,CAAC,OAAO;YAC1B,OAAO,oBAAC,gBAAgB,OAAG,CAAC,CAAC,8CAA8C;QAC7E,KAAK,eAAe,CAAC,KAAK;YACxB,OAAO,MAAM,CAAC,CAAC,CAAC,oBAAC,oBAAoB,OAAG,CAAC,CAAC,CAAC,oBAAC,cAAc,OAAG,CAAC;YAC9D,MAAM;QACR,KAAK,eAAe,CAAC,KAAK;YACxB,OAAO,MAAM,CAAC,CAAC,CAAC,oBAAC,uBAAuB,OAAG,CAAC,CAAC,CAAC,oBAAC,iBAAiB,OAAG,CAAC;IACxE,CAAC;AACH,CAAC;AAID,SAAS,MAAM,CAAC,QAAyB;IACvC,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,eAAe,CAAC,IAAI;YACvB,OAAO,SAAS,CAAC;QACnB,KAAK,eAAe,CAAC,OAAO;YAC1B,OAAO,UAAU,CAAC;QACpB,KAAK,eAAe,CAAC,WAAW,CAAC;QACjC,KAAK,eAAe,CAAC,QAAQ;YAC3B,OAAO,eAAe,CAAC;QACzB,KAAK,eAAe,CAAC,OAAO;YAC1B,OAAO,SAAS,CAAC;QACnB,KAAK,eAAe,CAAC,KAAK,CAAC;QAC3B,KAAK,eAAe,CAAC,KAAK;YACxB,OAAO,UAAU,CAAC;IACtB,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 Dialog\n */\n\nimport \"./MessageBox.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport type { DialogButtonDef } from \"@itwin/appui-abstract\";\nimport { MessageSeverity } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"../utils/Props.js\";\nimport {\n SvgHelpCircular,\n SvgHelpCircularHollow,\n SvgInfoCircular,\n SvgInfoCircularHollow,\n SvgStatusError,\n SvgStatusErrorHollow,\n SvgStatusRejected,\n SvgStatusRejectedHollow,\n SvgStatusSuccess,\n SvgStatusSuccessHollow,\n SvgStatusWarning,\n} from \"@itwin/itwinui-icons-react\";\nimport { Icon } from \"@itwin/itwinui-react\";\nimport type { IconSpec } from \"../icons/IconComponent.js\";\nimport { Dialog } from \"../dialog/Dialog.js\";\n\n/* eslint-disable @typescript-eslint/no-deprecated */\n\n/** Properties for the [[MessageBox]] component\n * @public\n * @deprecated in 4.15.0. Props of deprecated {@link MessageBox} component.\n */\nexport interface MessageBoxProps extends CommonProps {\n /** Severity of MessageBox */\n severity: MessageSeverity;\n /** whether to show dialog or not */\n opened: boolean;\n /** List of [[DialogButtonDef]] objects specifying buttons and associated onClick events */\n buttonCluster: DialogButtonDef[];\n /** Title to show in title bar of dialog */\n title?: string | React.ReactElement;\n /** onClick event for X button for dialog */\n onClose?: () => void;\n /** 'keyup' event for <Esc> key */\n onEscape?: () => void;\n /** minimum width that the dialog may be resized to. Default: 400 */\n minWidth?: number;\n /** minimum height that the dialog may be resized to. Default: 400 */\n minHeight?: number;\n /** initial width of dialog.\n * Displayed in px if value is a number, otherwise displayed in specified CSS unit.\n * Default: \"50%\"\n */\n width?: string | number;\n /** initial height of dialog.\n * Displayed in px if value is a number, otherwise displayed in specified CSS unit.\n * Default: \"\"\n */\n height?: string | number;\n /** Whether to show background overlay. Default: true */\n modal?: boolean;\n /** Custom CSS class name for the content */\n contentClassName?: string;\n /** Custom CSS Style for the content */\n contentStyle?: React.CSSProperties;\n /** Message content */\n children?: React.ReactNode;\n}\n\n/** Message Box React component.\n * @public\n * @deprecated in 4.15.0. Use {@link https://itwinui.bentley.com/docs/dialog iTwinUI Dialog} instead.\n */\nexport class MessageBox extends React.PureComponent<MessageBoxProps> {\n public static defaultProps: Partial<MessageBoxProps> = {\n minWidth: 400,\n minHeight: 400,\n width: \"512px\",\n modal: true,\n };\n\n public override render(): React.ReactElement {\n return (\n <Dialog\n title={this.props.title}\n buttonCluster={this.props.buttonCluster}\n opened={this.props.opened}\n onClose={this.props.onClose}\n onEscape={this.props.onEscape}\n modal={this.props.modal}\n className={this.props.className}\n style={this.props.style}\n width={this.props.width}\n >\n <MessageContainer\n severity={this.props.severity}\n className={this.props.contentClassName}\n style={this.props.contentStyle}\n >\n {this.props.children}\n </MessageContainer>\n </Dialog>\n );\n }\n}\n\n/** Properties for the [[MessageContainer]] component\n * @public\n * @deprecated in 4.15.0. Props of deprecated {@link MessageContainer} component.\n */\nexport interface MessageContainerProps extends CommonProps {\n severity: MessageSeverity;\n /** Message Content */\n children?: React.ReactNode;\n}\n\n/** Message Container React component.\n * @public\n * @deprecated in 4.15.0. Use {@link https://itwinui.bentley.com/docs/dialog iTwinUI Dialog} instead.\n */\nexport class MessageContainer extends React.PureComponent<MessageContainerProps> {\n /** Returns the class name corresponding to the MessageSeverity.\n * @param severity MessageSeverity\n */\n public static getIconClassName(severity: MessageSeverity): string;\n /** Returns the class name associated with the WebFont icon corresponding to the MessageSeverity.\n * @param severity MessageSeverity\n * @param hollow Should the icon be hollow\n * @deprecated in 4.0.0. Hollow parameter ignored, WebFont is not returned, only the color.\n */\n public static getIconClassName(\n severity: MessageSeverity,\n // eslint-disable-next-line @typescript-eslint/unified-signatures\n hollow?: boolean\n ): string;\n\n public static getIconClassName(\n severity: MessageSeverity,\n _hollow?: boolean\n ): string {\n let iconClassName = \"\";\n\n switch (severity) {\n case MessageSeverity.None:\n iconClassName = \"\";\n break;\n case MessageSeverity.Success:\n iconClassName = \"core-message-box-success\";\n break;\n case MessageSeverity.Information:\n iconClassName = \"core-message-box-information\";\n break;\n case MessageSeverity.Question:\n iconClassName = \"core-message-box-question\";\n break;\n case MessageSeverity.Warning:\n iconClassName = \"core-message-box-warning\";\n break;\n case MessageSeverity.Error:\n iconClassName = \"core-message-box-error\";\n break;\n case MessageSeverity.Fatal:\n iconClassName = \"core-message-box-fatal\";\n break;\n }\n\n return iconClassName;\n }\n\n /** Returns the React icon corresponding to the MessageSeverity.\n * @param severity MessageSeverity\n * @param hollow set to true to return the hollow form of the icon.\n * @returns IconSpec\n */\n /* ignore for unit tests and replace with visual testing */\n\n public static getIcon(severity: MessageSeverity, hollow?: boolean): IconSpec {\n const icon = getIcon(severity, hollow);\n return icon ?? \"\";\n }\n\n public override render(): React.ReactElement {\n const iconClassName = classnames(\n \"icon\",\n \"core-message-box-icon\",\n MessageContainer.getIconClassName(this.props.severity)\n );\n\n const icon = getIcon(this.props.severity);\n return (\n <div className=\"core-message-box-container\">\n {icon ? (\n <Icon\n className={iconClassName}\n size=\"large\"\n fill={toFill(this.props.severity)}\n >\n {icon}\n </Icon>\n ) : undefined}\n <div\n className={classnames(\n \"core-message-box-content\",\n this.props.className\n )}\n style={this.props.style}\n >\n {this.props.children}\n </div>\n </div>\n );\n }\n}\n\nfunction getIcon(\n severity: MessageSeverity,\n hollow?: boolean\n): React.ReactElement | undefined {\n switch (severity) {\n case MessageSeverity.None:\n return undefined;\n case MessageSeverity.Success:\n return hollow ? <SvgStatusSuccessHollow /> : <SvgStatusSuccess />;\n case MessageSeverity.Information:\n return hollow ? <SvgInfoCircularHollow /> : <SvgInfoCircular />;\n case MessageSeverity.Question:\n return hollow ? <SvgHelpCircularHollow /> : <SvgHelpCircular />;\n case MessageSeverity.Warning:\n return <SvgStatusWarning />; // TODO - need icon-status-warning-hollow icon\n case MessageSeverity.Error:\n return hollow ? <SvgStatusErrorHollow /> : <SvgStatusError />;\n break;\n case MessageSeverity.Fatal:\n return hollow ? <SvgStatusRejectedHollow /> : <SvgStatusRejected />;\n }\n}\n\ntype IconProps = React.ComponentProps<typeof Icon>;\n\nfunction toFill(severity: MessageSeverity): IconProps[\"fill\"] {\n switch (severity) {\n case MessageSeverity.None:\n return undefined;\n case MessageSeverity.Success:\n return \"positive\";\n case MessageSeverity.Information:\n case MessageSeverity.Question:\n return \"informational\";\n case MessageSeverity.Warning:\n return \"warning\";\n case MessageSeverity.Error:\n case MessageSeverity.Fatal:\n return \"negative\";\n }\n return undefined;\n}\n"]}
|
|
@@ -23,206 +23,12 @@ export const PopupContext = React.createContext(undefined);
|
|
|
23
23
|
*/
|
|
24
24
|
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
25
25
|
export class Popup extends React.Component {
|
|
26
|
+
_popup = null;
|
|
27
|
+
/** @internal */
|
|
28
|
+
static contextType = PopupContext;
|
|
26
29
|
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
27
30
|
constructor(props) {
|
|
28
31
|
super(props);
|
|
29
|
-
this._popup = null;
|
|
30
|
-
this._bindWindowEvents = () => {
|
|
31
|
-
const activeWindow = this.getParentWindow();
|
|
32
|
-
activeWindow.addEventListener("pointerdown", this._handleOutsideClick);
|
|
33
|
-
activeWindow.addEventListener("resize", this._resize);
|
|
34
|
-
activeWindow.addEventListener("contextmenu", this._handleContextMenu);
|
|
35
|
-
activeWindow.addEventListener("scroll", this._hide);
|
|
36
|
-
activeWindow.addEventListener("wheel", this._handleWheel);
|
|
37
|
-
activeWindow.addEventListener("keydown", this._handleKeyboard);
|
|
38
|
-
};
|
|
39
|
-
this._unBindWindowEvents = () => {
|
|
40
|
-
const activeWindow = this.getParentWindow();
|
|
41
|
-
activeWindow.removeEventListener("pointerdown", this._handleOutsideClick);
|
|
42
|
-
activeWindow.removeEventListener("resize", this._resize);
|
|
43
|
-
activeWindow.removeEventListener("contextmenu", this._handleContextMenu);
|
|
44
|
-
activeWindow.removeEventListener("scroll", this._hide);
|
|
45
|
-
activeWindow.removeEventListener("wheel", this._handleWheel);
|
|
46
|
-
activeWindow.removeEventListener("keydown", this._handleKeyboard);
|
|
47
|
-
};
|
|
48
|
-
this._handleWheel = (event) => {
|
|
49
|
-
if (this._popup && this._popup.contains(event.target))
|
|
50
|
-
return;
|
|
51
|
-
if (this.props.onWheel)
|
|
52
|
-
return this.props.onWheel(event);
|
|
53
|
-
const closeOnWheel = this.props.closeOnWheel !== undefined ? this.props.closeOnWheel : true;
|
|
54
|
-
if (closeOnWheel)
|
|
55
|
-
this._hide();
|
|
56
|
-
};
|
|
57
|
-
this._handleOutsideClick = (event) => {
|
|
58
|
-
if (this._popup && this._popup.contains(event.target))
|
|
59
|
-
return;
|
|
60
|
-
if (this.props.isPinned)
|
|
61
|
-
return;
|
|
62
|
-
if (!this.props.closeOnNestedPopupOutsideClick &&
|
|
63
|
-
this.isInCorePopup(event.target))
|
|
64
|
-
return;
|
|
65
|
-
if (this.props.onOutsideClick)
|
|
66
|
-
return this.props.onOutsideClick(event);
|
|
67
|
-
if (this.props.target && this.props.target.contains(event.target))
|
|
68
|
-
return;
|
|
69
|
-
this._onClose();
|
|
70
|
-
};
|
|
71
|
-
this._handleContextMenu = (event) => {
|
|
72
|
-
if (this._popup && this._popup.contains(event.target))
|
|
73
|
-
return;
|
|
74
|
-
if (this.props.onContextMenu)
|
|
75
|
-
return this.props.onContextMenu(event);
|
|
76
|
-
const closeOnContextMenu = this.props.closeOnContextMenu !== undefined
|
|
77
|
-
? this.props.closeOnContextMenu
|
|
78
|
-
: true;
|
|
79
|
-
if (closeOnContextMenu)
|
|
80
|
-
this._hide();
|
|
81
|
-
};
|
|
82
|
-
this._handleKeyboard = (event) => {
|
|
83
|
-
if (this.props.isPinned)
|
|
84
|
-
return;
|
|
85
|
-
if (event.key === Key.Escape.valueOf() ||
|
|
86
|
-
event.key === Key.Enter.valueOf()) {
|
|
87
|
-
const closeOnEnter = this.props.closeOnEnter !== undefined ? this.props.closeOnEnter : true;
|
|
88
|
-
if (event.key === Key.Enter.valueOf()) {
|
|
89
|
-
if (closeOnEnter)
|
|
90
|
-
this._onClose(true);
|
|
91
|
-
else
|
|
92
|
-
this.props.onEnter && this.props.onEnter();
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
this._onClose(false);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
this._resize = () => {
|
|
100
|
-
if (this.props.repositionOnResize) {
|
|
101
|
-
const position = this._toggleRelativePosition();
|
|
102
|
-
const point = this._fitPopup(this._getPosition(position));
|
|
103
|
-
this.setState({ left: point.x, top: point.y, position });
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
this._hide(); // legacy behavior
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
this._hide = () => {
|
|
110
|
-
if (this.props.isPinned)
|
|
111
|
-
return;
|
|
112
|
-
this._onClose();
|
|
113
|
-
};
|
|
114
|
-
this._getPosition = (position) => {
|
|
115
|
-
const activeWindow = this.getParentWindow();
|
|
116
|
-
const { target, offset, top, left } = this.props;
|
|
117
|
-
const offsetArrow = this.props.showArrow ? 6 : 0;
|
|
118
|
-
// absolute position
|
|
119
|
-
if (this._isPositionAbsolute())
|
|
120
|
-
return { x: left, y: top };
|
|
121
|
-
// sanity check
|
|
122
|
-
const point = { x: 0, y: 0 };
|
|
123
|
-
if (!this._popup || !target)
|
|
124
|
-
return point;
|
|
125
|
-
// relative position
|
|
126
|
-
const scrollY = activeWindow.scrollY;
|
|
127
|
-
const scrollX = activeWindow.scrollX;
|
|
128
|
-
const container = this.getContainer();
|
|
129
|
-
const containerBounds = container.getBoundingClientRect();
|
|
130
|
-
const targetRect = Rectangle.create(target.getBoundingClientRect()).offset({
|
|
131
|
-
x: -containerBounds.left,
|
|
132
|
-
y: -containerBounds.top,
|
|
133
|
-
});
|
|
134
|
-
const { popupWidth, popupHeight } = this._getPopupDimensions();
|
|
135
|
-
switch (position) {
|
|
136
|
-
case RelativePosition.Top:
|
|
137
|
-
point.y = scrollY + targetRect.top - popupHeight - offset - offsetArrow;
|
|
138
|
-
point.x =
|
|
139
|
-
scrollX +
|
|
140
|
-
targetRect.left +
|
|
141
|
-
targetRect.getWidth() / 2 -
|
|
142
|
-
popupWidth / 2;
|
|
143
|
-
break;
|
|
144
|
-
case RelativePosition.TopLeft:
|
|
145
|
-
point.y = scrollY + targetRect.top - popupHeight - offset - offsetArrow;
|
|
146
|
-
point.x = scrollX + targetRect.left;
|
|
147
|
-
break;
|
|
148
|
-
case RelativePosition.TopRight:
|
|
149
|
-
point.y = scrollY + targetRect.top - popupHeight - offset - offsetArrow;
|
|
150
|
-
point.x = scrollX + targetRect.right - popupWidth;
|
|
151
|
-
break;
|
|
152
|
-
case RelativePosition.Bottom:
|
|
153
|
-
point.y = scrollY + targetRect.bottom + offset + offsetArrow;
|
|
154
|
-
point.x =
|
|
155
|
-
scrollX +
|
|
156
|
-
targetRect.left +
|
|
157
|
-
targetRect.getWidth() / 2 -
|
|
158
|
-
popupWidth / 2;
|
|
159
|
-
break;
|
|
160
|
-
case RelativePosition.BottomLeft:
|
|
161
|
-
point.y = scrollY + targetRect.bottom + offset + offsetArrow;
|
|
162
|
-
point.x = scrollX + targetRect.left;
|
|
163
|
-
break;
|
|
164
|
-
case RelativePosition.BottomRight:
|
|
165
|
-
point.y = scrollY + targetRect.bottom + offset + offsetArrow;
|
|
166
|
-
point.x = scrollX + targetRect.right - popupWidth;
|
|
167
|
-
break;
|
|
168
|
-
case RelativePosition.Left:
|
|
169
|
-
point.y =
|
|
170
|
-
scrollY +
|
|
171
|
-
targetRect.top +
|
|
172
|
-
targetRect.getHeight() / 2 -
|
|
173
|
-
popupHeight / 2;
|
|
174
|
-
point.x = scrollX + targetRect.left - popupWidth - offset - offsetArrow;
|
|
175
|
-
break;
|
|
176
|
-
case RelativePosition.LeftTop:
|
|
177
|
-
point.y = scrollY + targetRect.top;
|
|
178
|
-
point.x = scrollX + targetRect.left - popupWidth - offset - offsetArrow;
|
|
179
|
-
break;
|
|
180
|
-
case RelativePosition.Right:
|
|
181
|
-
point.y =
|
|
182
|
-
scrollY +
|
|
183
|
-
targetRect.top +
|
|
184
|
-
targetRect.getHeight() / 2 -
|
|
185
|
-
popupHeight / 2;
|
|
186
|
-
point.x = scrollX + targetRect.right + offset + offsetArrow;
|
|
187
|
-
break;
|
|
188
|
-
case RelativePosition.RightTop:
|
|
189
|
-
point.y = scrollY + targetRect.top;
|
|
190
|
-
point.x = scrollX + targetRect.right + offset + offsetArrow;
|
|
191
|
-
break;
|
|
192
|
-
}
|
|
193
|
-
return point;
|
|
194
|
-
};
|
|
195
|
-
// fit the popup within the extents of the view port
|
|
196
|
-
this._fitPopup = (point) => {
|
|
197
|
-
const fittedPoint = point;
|
|
198
|
-
if (!this._popup) {
|
|
199
|
-
return fittedPoint;
|
|
200
|
-
}
|
|
201
|
-
const { popupWidth, popupHeight } = this._getPopupDimensions();
|
|
202
|
-
const container = this.getContainer();
|
|
203
|
-
const containerBounds = container.getBoundingClientRect();
|
|
204
|
-
if (fittedPoint.y + popupHeight > containerBounds.height) {
|
|
205
|
-
fittedPoint.y = containerBounds.height - popupHeight;
|
|
206
|
-
}
|
|
207
|
-
if (fittedPoint.x + popupWidth > containerBounds.width) {
|
|
208
|
-
fittedPoint.x = containerBounds.width - popupWidth;
|
|
209
|
-
}
|
|
210
|
-
if (fittedPoint.y < 0) {
|
|
211
|
-
fittedPoint.y = 0;
|
|
212
|
-
}
|
|
213
|
-
if (fittedPoint.x < 0) {
|
|
214
|
-
fittedPoint.x = 0;
|
|
215
|
-
}
|
|
216
|
-
return fittedPoint;
|
|
217
|
-
};
|
|
218
|
-
this._handleAnimationEnd = (event) => {
|
|
219
|
-
if (event.target === this._popup) {
|
|
220
|
-
this.setState({ animationEnded: true });
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
this._handleThemeProviderRef = (el) => {
|
|
224
|
-
this.setState({ portalContainer: el ?? undefined });
|
|
225
|
-
};
|
|
226
32
|
const parentDocument = this.props.target?.ownerDocument ?? document;
|
|
227
33
|
this.state = {
|
|
228
34
|
animationEnded: false,
|
|
@@ -233,6 +39,16 @@ export class Popup extends React.Component {
|
|
|
233
39
|
parentDocument,
|
|
234
40
|
};
|
|
235
41
|
}
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
43
|
+
static defaultProps = {
|
|
44
|
+
position: RelativePosition.Bottom,
|
|
45
|
+
showShadow: true,
|
|
46
|
+
showArrow: false,
|
|
47
|
+
isOpen: false,
|
|
48
|
+
offset: 4,
|
|
49
|
+
top: -1,
|
|
50
|
+
left: -1,
|
|
51
|
+
};
|
|
236
52
|
componentDidMount() {
|
|
237
53
|
if (this.props.isOpen) {
|
|
238
54
|
this._onShow();
|
|
@@ -282,6 +98,33 @@ export class Popup extends React.Component {
|
|
|
282
98
|
componentWillUnmount() {
|
|
283
99
|
this._unBindWindowEvents();
|
|
284
100
|
}
|
|
101
|
+
_bindWindowEvents = () => {
|
|
102
|
+
const activeWindow = this.getParentWindow();
|
|
103
|
+
activeWindow.addEventListener("pointerdown", this._handleOutsideClick);
|
|
104
|
+
activeWindow.addEventListener("resize", this._resize);
|
|
105
|
+
activeWindow.addEventListener("contextmenu", this._handleContextMenu);
|
|
106
|
+
activeWindow.addEventListener("scroll", this._hide);
|
|
107
|
+
activeWindow.addEventListener("wheel", this._handleWheel);
|
|
108
|
+
activeWindow.addEventListener("keydown", this._handleKeyboard);
|
|
109
|
+
};
|
|
110
|
+
_unBindWindowEvents = () => {
|
|
111
|
+
const activeWindow = this.getParentWindow();
|
|
112
|
+
activeWindow.removeEventListener("pointerdown", this._handleOutsideClick);
|
|
113
|
+
activeWindow.removeEventListener("resize", this._resize);
|
|
114
|
+
activeWindow.removeEventListener("contextmenu", this._handleContextMenu);
|
|
115
|
+
activeWindow.removeEventListener("scroll", this._hide);
|
|
116
|
+
activeWindow.removeEventListener("wheel", this._handleWheel);
|
|
117
|
+
activeWindow.removeEventListener("keydown", this._handleKeyboard);
|
|
118
|
+
};
|
|
119
|
+
_handleWheel = (event) => {
|
|
120
|
+
if (this._popup && this._popup.contains(event.target))
|
|
121
|
+
return;
|
|
122
|
+
if (this.props.onWheel)
|
|
123
|
+
return this.props.onWheel(event);
|
|
124
|
+
const closeOnWheel = this.props.closeOnWheel !== undefined ? this.props.closeOnWheel : true;
|
|
125
|
+
if (closeOnWheel)
|
|
126
|
+
this._hide();
|
|
127
|
+
};
|
|
285
128
|
isInCorePopup(element) {
|
|
286
129
|
if (element.nodeName === "DIV") {
|
|
287
130
|
if (element.classList && element.classList.contains("core-popup"))
|
|
@@ -295,6 +138,63 @@ export class Popup extends React.Component {
|
|
|
295
138
|
}
|
|
296
139
|
return false;
|
|
297
140
|
}
|
|
141
|
+
_handleOutsideClick = (event) => {
|
|
142
|
+
if (this._popup && this._popup.contains(event.target))
|
|
143
|
+
return;
|
|
144
|
+
if (this.props.isPinned)
|
|
145
|
+
return;
|
|
146
|
+
if (!this.props.closeOnNestedPopupOutsideClick &&
|
|
147
|
+
this.isInCorePopup(event.target))
|
|
148
|
+
return;
|
|
149
|
+
if (this.props.onOutsideClick)
|
|
150
|
+
return this.props.onOutsideClick(event);
|
|
151
|
+
if (this.props.target && this.props.target.contains(event.target))
|
|
152
|
+
return;
|
|
153
|
+
this._onClose();
|
|
154
|
+
};
|
|
155
|
+
_handleContextMenu = (event) => {
|
|
156
|
+
if (this._popup && this._popup.contains(event.target))
|
|
157
|
+
return;
|
|
158
|
+
if (this.props.onContextMenu)
|
|
159
|
+
return this.props.onContextMenu(event);
|
|
160
|
+
const closeOnContextMenu = this.props.closeOnContextMenu !== undefined
|
|
161
|
+
? this.props.closeOnContextMenu
|
|
162
|
+
: true;
|
|
163
|
+
if (closeOnContextMenu)
|
|
164
|
+
this._hide();
|
|
165
|
+
};
|
|
166
|
+
_handleKeyboard = (event) => {
|
|
167
|
+
if (this.props.isPinned)
|
|
168
|
+
return;
|
|
169
|
+
if (event.key === Key.Escape.valueOf() ||
|
|
170
|
+
event.key === Key.Enter.valueOf()) {
|
|
171
|
+
const closeOnEnter = this.props.closeOnEnter !== undefined ? this.props.closeOnEnter : true;
|
|
172
|
+
if (event.key === Key.Enter.valueOf()) {
|
|
173
|
+
if (closeOnEnter)
|
|
174
|
+
this._onClose(true);
|
|
175
|
+
else
|
|
176
|
+
this.props.onEnter && this.props.onEnter();
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
this._onClose(false);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
_resize = () => {
|
|
184
|
+
if (this.props.repositionOnResize) {
|
|
185
|
+
const position = this._toggleRelativePosition();
|
|
186
|
+
const point = this._fitPopup(this._getPosition(position));
|
|
187
|
+
this.setState({ left: point.x, top: point.y, position });
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
this._hide(); // legacy behavior
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
_hide = () => {
|
|
194
|
+
if (this.props.isPinned)
|
|
195
|
+
return;
|
|
196
|
+
this._onClose();
|
|
197
|
+
};
|
|
298
198
|
_onShow() {
|
|
299
199
|
this._bindWindowEvents();
|
|
300
200
|
const position = this._toggleRelativePosition();
|
|
@@ -361,6 +261,87 @@ export class Popup extends React.Component {
|
|
|
361
261
|
}
|
|
362
262
|
return { popupWidth, popupHeight };
|
|
363
263
|
}
|
|
264
|
+
_getPosition = (position) => {
|
|
265
|
+
const activeWindow = this.getParentWindow();
|
|
266
|
+
const { target, offset, top, left } = this.props;
|
|
267
|
+
const offsetArrow = this.props.showArrow ? 6 : 0;
|
|
268
|
+
// absolute position
|
|
269
|
+
if (this._isPositionAbsolute())
|
|
270
|
+
return { x: left, y: top };
|
|
271
|
+
// sanity check
|
|
272
|
+
const point = { x: 0, y: 0 };
|
|
273
|
+
if (!this._popup || !target)
|
|
274
|
+
return point;
|
|
275
|
+
// relative position
|
|
276
|
+
const scrollY = activeWindow.scrollY;
|
|
277
|
+
const scrollX = activeWindow.scrollX;
|
|
278
|
+
const container = this.getContainer();
|
|
279
|
+
const containerBounds = container.getBoundingClientRect();
|
|
280
|
+
const targetRect = Rectangle.create(target.getBoundingClientRect()).offset({
|
|
281
|
+
x: -containerBounds.left,
|
|
282
|
+
y: -containerBounds.top,
|
|
283
|
+
});
|
|
284
|
+
const { popupWidth, popupHeight } = this._getPopupDimensions();
|
|
285
|
+
switch (position) {
|
|
286
|
+
case RelativePosition.Top:
|
|
287
|
+
point.y = scrollY + targetRect.top - popupHeight - offset - offsetArrow;
|
|
288
|
+
point.x =
|
|
289
|
+
scrollX +
|
|
290
|
+
targetRect.left +
|
|
291
|
+
targetRect.getWidth() / 2 -
|
|
292
|
+
popupWidth / 2;
|
|
293
|
+
break;
|
|
294
|
+
case RelativePosition.TopLeft:
|
|
295
|
+
point.y = scrollY + targetRect.top - popupHeight - offset - offsetArrow;
|
|
296
|
+
point.x = scrollX + targetRect.left;
|
|
297
|
+
break;
|
|
298
|
+
case RelativePosition.TopRight:
|
|
299
|
+
point.y = scrollY + targetRect.top - popupHeight - offset - offsetArrow;
|
|
300
|
+
point.x = scrollX + targetRect.right - popupWidth;
|
|
301
|
+
break;
|
|
302
|
+
case RelativePosition.Bottom:
|
|
303
|
+
point.y = scrollY + targetRect.bottom + offset + offsetArrow;
|
|
304
|
+
point.x =
|
|
305
|
+
scrollX +
|
|
306
|
+
targetRect.left +
|
|
307
|
+
targetRect.getWidth() / 2 -
|
|
308
|
+
popupWidth / 2;
|
|
309
|
+
break;
|
|
310
|
+
case RelativePosition.BottomLeft:
|
|
311
|
+
point.y = scrollY + targetRect.bottom + offset + offsetArrow;
|
|
312
|
+
point.x = scrollX + targetRect.left;
|
|
313
|
+
break;
|
|
314
|
+
case RelativePosition.BottomRight:
|
|
315
|
+
point.y = scrollY + targetRect.bottom + offset + offsetArrow;
|
|
316
|
+
point.x = scrollX + targetRect.right - popupWidth;
|
|
317
|
+
break;
|
|
318
|
+
case RelativePosition.Left:
|
|
319
|
+
point.y =
|
|
320
|
+
scrollY +
|
|
321
|
+
targetRect.top +
|
|
322
|
+
targetRect.getHeight() / 2 -
|
|
323
|
+
popupHeight / 2;
|
|
324
|
+
point.x = scrollX + targetRect.left - popupWidth - offset - offsetArrow;
|
|
325
|
+
break;
|
|
326
|
+
case RelativePosition.LeftTop:
|
|
327
|
+
point.y = scrollY + targetRect.top;
|
|
328
|
+
point.x = scrollX + targetRect.left - popupWidth - offset - offsetArrow;
|
|
329
|
+
break;
|
|
330
|
+
case RelativePosition.Right:
|
|
331
|
+
point.y =
|
|
332
|
+
scrollY +
|
|
333
|
+
targetRect.top +
|
|
334
|
+
targetRect.getHeight() / 2 -
|
|
335
|
+
popupHeight / 2;
|
|
336
|
+
point.x = scrollX + targetRect.right + offset + offsetArrow;
|
|
337
|
+
break;
|
|
338
|
+
case RelativePosition.RightTop:
|
|
339
|
+
point.y = scrollY + targetRect.top;
|
|
340
|
+
point.x = scrollX + targetRect.right + offset + offsetArrow;
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
return point;
|
|
344
|
+
};
|
|
364
345
|
_toggleRelativePosition() {
|
|
365
346
|
const { target, position, offset } = this.props;
|
|
366
347
|
if (!this._popup || !target)
|
|
@@ -418,6 +399,37 @@ export class Popup extends React.Component {
|
|
|
418
399
|
}
|
|
419
400
|
return newPosition;
|
|
420
401
|
}
|
|
402
|
+
// fit the popup within the extents of the view port
|
|
403
|
+
_fitPopup = (point) => {
|
|
404
|
+
const fittedPoint = point;
|
|
405
|
+
if (!this._popup) {
|
|
406
|
+
return fittedPoint;
|
|
407
|
+
}
|
|
408
|
+
const { popupWidth, popupHeight } = this._getPopupDimensions();
|
|
409
|
+
const container = this.getContainer();
|
|
410
|
+
const containerBounds = container.getBoundingClientRect();
|
|
411
|
+
if (fittedPoint.y + popupHeight > containerBounds.height) {
|
|
412
|
+
fittedPoint.y = containerBounds.height - popupHeight;
|
|
413
|
+
}
|
|
414
|
+
if (fittedPoint.x + popupWidth > containerBounds.width) {
|
|
415
|
+
fittedPoint.x = containerBounds.width - popupWidth;
|
|
416
|
+
}
|
|
417
|
+
if (fittedPoint.y < 0) {
|
|
418
|
+
fittedPoint.y = 0;
|
|
419
|
+
}
|
|
420
|
+
if (fittedPoint.x < 0) {
|
|
421
|
+
fittedPoint.x = 0;
|
|
422
|
+
}
|
|
423
|
+
return fittedPoint;
|
|
424
|
+
};
|
|
425
|
+
_handleAnimationEnd = (event) => {
|
|
426
|
+
if (event.target === this._popup) {
|
|
427
|
+
this.setState({ animationEnded: true });
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
_handleThemeProviderRef = (el) => {
|
|
431
|
+
this.setState({ portalContainer: el ?? undefined });
|
|
432
|
+
};
|
|
421
433
|
render() {
|
|
422
434
|
const animate = this.props.animate !== undefined ? this.props.animate : true;
|
|
423
435
|
const className = classnames("core-popup", this._getClassNameByPosition(this.state.position), this.props.showShadow && "core-popup-shadow", this.props.showArrow && "arrow", !animate && "core-popup-animation-none", this.props.className, this.state.animationEnded && "core-animation-ended", !this.props.isOpen &&
|
|
@@ -445,18 +457,6 @@ export class Popup extends React.Component {
|
|
|
445
457
|
this.state.parentDocument.body);
|
|
446
458
|
}
|
|
447
459
|
}
|
|
448
|
-
/** @internal */
|
|
449
|
-
Popup.contextType = PopupContext;
|
|
450
|
-
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
451
|
-
Popup.defaultProps = {
|
|
452
|
-
position: RelativePosition.Bottom,
|
|
453
|
-
showShadow: true,
|
|
454
|
-
showArrow: false,
|
|
455
|
-
isOpen: false,
|
|
456
|
-
offset: 4,
|
|
457
|
-
top: -1,
|
|
458
|
-
left: -1,
|
|
459
|
-
};
|
|
460
460
|
function parsePxString(pxStr) {
|
|
461
461
|
const parsed = parseInt(pxStr, 10);
|
|
462
462
|
return parsed || 0;
|