-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCard.tsx
37 lines (32 loc) · 942 Bytes
/
Card.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
import { TFile } from "obsidian";
import React from "preact/compat";
import { ComponentChildren, Key } from "preact";
import { useAppMount } from "~/react/context/app-mount-provider";
interface WithKeyProps {
key?: Key;
}
interface CardPropsI {
file?: TFile;
children: ComponentChildren;
}
type CardProps = CardPropsI & React.HTMLAttributes<HTMLDivElement> & WithKeyProps;
export default function Card(props: CardProps) {
const { file, ...rest } = props;
const { app, sourcePath } = useAppMount();
const handleClick = (event: MouseEvent): void => {
const newLeaf =
event.altKey && (event.ctrlKey || event.metaKey)
? "split"
: event.ctrlKey || event.metaKey
? "tab"
: false;
if (file) {
app.workspace.openLinkText(file.path, sourcePath, newLeaf);
}
};
return (
<div {...rest} className="note-card" onClick={handleClick}>
{props.children}
</div>
);
}