-
Notifications
You must be signed in to change notification settings - Fork 2
/
AccuDrawDialog.tsx
73 lines (65 loc) · 2.38 KB
/
AccuDrawDialog.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module AccuDraw
*/
import "./AccuDrawDialog.scss";
import classnames from "classnames";
import * as React from "react";
import type { CommonProps } from "@itwin/core-react";
import { Orientation } from "@itwin/core-react";
import { UiFramework } from "../UiFramework";
import { ModelessDialog } from "../dialog/ModelessDialog";
import { AccuDrawFieldContainer } from "./AccuDrawFieldContainer";
import { useTranslation } from "../hooks/useTranslation";
/** Properties for [[AccuDrawDialog]]
* @beta */
export interface AccuDrawDialogProps extends CommonProps {
/** Indicates whether the dialog is open */
opened: boolean;
/** Unique id for the dialog */
dialogId: string;
/** Orientation of the fields */
orientation?: Orientation;
/** Callback for when the dialog closes */
onClose?: () => void;
}
/** Dialog displays [[AccuDrawFieldContainer]] for AccuDraw Ui
* @beta */
export function AccuDrawDialog(props: AccuDrawDialogProps) {
const { translate } = useTranslation();
const [opened, setOpened] = React.useState(props.opened);
const closeDialog = React.useCallback(() => {
setOpened(false);
props.onClose && props.onClose();
}, [props]);
const handleClose = React.useCallback(() => {
closeDialog();
}, [closeDialog]);
const handleEscape = React.useCallback(() => {
UiFramework.keyboardShortcuts.setFocusToHome();
}, []);
const classNames = classnames("uifw-accudraw-dialog", props.className);
const orientation =
props.orientation !== undefined ? props.orientation : Orientation.Vertical;
const dialogWidth = orientation === Orientation.Horizontal ? 500 : 250;
return (
<ModelessDialog
className={classNames}
style={props.style}
title={translate("accuDraw.dialogTitle")}
opened={opened}
dialogId={props.dialogId}
width={dialogWidth}
minHeight={75}
inset={false}
movable={true}
onClose={handleClose}
onEscape={handleEscape}
>
<AccuDrawFieldContainer orientation={orientation} />
</ModelessDialog>
);
}