-
-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathOptionsSelector.tsx
More file actions
75 lines (70 loc) · 2.16 KB
/
OptionsSelector.tsx
File metadata and controls
75 lines (70 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
import { t } from "@/i18n";
import { ObsidianIcon } from "@/ui/components/obsidian-icon";
import type { TaskCreationOptions } from "@/ui/createTaskModal";
import { Popover } from "@/ui/createTaskModal/Popover";
import cn from "classnames";
import type React from "react";
import { Button, type Key, Menu, MenuItem, MenuTrigger } from "react-aria-components";
type Props = {
selected: TaskCreationOptions;
setSelected: (selected: TaskCreationOptions) => void;
};
export const OptionsSelector: React.FC<Props> = ({ selected, setSelected }) => {
const i18n = t().createTaskModal.optionsSelector;
const onAction = (key: Key) => {
if (key === "add-link-to-content") {
setSelected({ ...selected, appendLinkTo: "content" });
} else if (key === "add-link-to-description") {
setSelected({ ...selected, appendLinkTo: "description" });
} else if (key === "do-not-add-link") {
setSelected({ ...selected, appendLinkTo: undefined });
}
};
const items: Array<{
key: string;
label: string;
isSelected: boolean;
}> = [
{
key: "add-link-to-content",
label: i18n.addLinkToContent,
isSelected: selected.appendLinkTo === "content",
},
{
key: "add-link-to-description",
label: i18n.addLinkToDescription,
isSelected: selected.appendLinkTo === "description",
},
{
key: "do-not-add-link",
label: i18n.doNotAddLink,
isSelected: selected.appendLinkTo === undefined,
},
];
return (
<MenuTrigger>
<Button className="options-selector" aria-label={i18n.buttonLabel}>
<ObsidianIcon size="m" id="ellipsis-vertical" />
</Button>
<Popover>
<Menu
className="task-option-dialog task-options-menu"
aria-label={i18n.optionsLabel}
onAction={onAction}
>
{items.map((item) => (
<MenuItem
key={item.key}
id={item.key}
className={cn("task-option-dialog-item", {
"is-selected": item.isSelected,
})}
>
{item.label}
</MenuItem>
))}
</Menu>
</Popover>
</MenuTrigger>
);
};