Files
lume/src/app/note/components/wrapper.tsx
2023-05-14 18:20:27 +07:00

31 lines
600 B
TypeScript

import { navigate } from "vite-plugin-ssr/client/router";
export function NoteWrapper({
children,
href,
className,
}: {
children: React.ReactNode;
href: string;
className: string;
}) {
const openThread = (event: any, href: string) => {
const selection = window.getSelection();
if (selection.toString().length === 0) {
navigate(href, { keepScrollPosition: true });
} else {
event.stopPropagation();
}
};
return (
<div
onClick={(event) => openThread(event, href)}
onKeyDown={(event) => openThread(event, href)}
className={className}
>
{children}
</div>
);
}