-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSettingsDialog.tsx
More file actions
85 lines (81 loc) · 2.16 KB
/
SettingsDialog.tsx
File metadata and controls
85 lines (81 loc) · 2.16 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
import React from "react";
import {
Dialog,
Button,
Classes,
IconName,
MaybeElement,
} from "@blueprintjs/core";
import renderOverlay from "roamjs-components/util/renderOverlay";
type SelectItem = {
id: string;
text: string;
icon?: IconName | MaybeElement;
onClick: () => void;
};
type SelectDialogProps = {
isOpen: boolean;
onClose: () => void;
title: string;
items: SelectItem[];
errorMessage?: string;
width?: string;
};
const SelectDialog = ({
isOpen,
onClose,
title,
items,
errorMessage,
width = "20rem",
}: SelectDialogProps) => {
return (
<Dialog
isOpen={isOpen}
onClose={onClose}
canOutsideClickClose
canEscapeKeyClose
className="roamjs-canvas-dialog"
style={{ width }}
>
<div className={`${Classes.DIALOG_BODY} py-4 px-0 m-0`}>
<div className="flex flex-col">
<div className="text-lg font-bold p-2 mb-2 mx-5 mt-0">{title}</div>
<button
// Visually hidden button to catch initial focus
// this allows the Dialog to be called via command palette WITH the keyboard
// then use keyboard arrow keys to navigate
className="sr-only"
tabIndex={0}
aria-hidden="true"
/>
{items.length > 0 ? (
items.map((item, i) => (
<div key={item.id} className="flex items-center">
<Button
minimal
text={item.text}
className="p-2 px-7 focus:outline-none focus:bg-gray-300 justify-start flex-grow"
icon={item.icon}
style={{
caretColor: "transparent",
}}
onClick={() => {
item.onClick();
onClose();
}}
/>
</div>
))
) : (
<div className="p-4 text-center">
{errorMessage || "No items available"}
</div>
)}
</div>
</div>
</Dialog>
);
};
export const renderSelectDialog = (props: SelectDialogProps) =>
renderOverlay({ Overlay: SelectDialog, props });