add note page

This commit is contained in:
Ren Amamiya
2023-07-04 15:40:18 +07:00
parent a30cf66c2e
commit 6590ea29e2
11 changed files with 99 additions and 134 deletions

View File

@@ -81,12 +81,7 @@ export function NoteMetadata({
});
const openThread = (thread: string) => {
const selection = window.getSelection();
if (selection.toString().length === 0) {
block.mutate({ kind: 2, title: 'Thread', content: thread });
} else {
event.stopPropagation();
}
block.mutate({ kind: 2, title: 'Thread', content: thread });
};
if (status === 'loading') {

View File

@@ -1,58 +0,0 @@
import {
autoUpdate,
offset,
shift,
useFloating,
useFocus,
useHover,
useInteractions,
} from '@floating-ui/react';
import { useState } from 'react';
export function Tooltip({
children,
message,
}: {
children: React.ReactNode;
message: string;
}) {
const [isOpen, setIsOpen] = useState(false);
const { x, y, strategy, refs, context } = useFloating({
open: isOpen,
onOpenChange: setIsOpen,
placement: 'top',
middleware: [offset(8), shift()],
whileElementsMounted(...args) {
const cleanup = autoUpdate(...args, { animationFrame: true });
return cleanup;
},
});
const hover = useHover(context);
const focus = useFocus(context);
const { getReferenceProps, getFloatingProps } = useInteractions([hover, focus]);
return (
<>
<div ref={refs.setReference} {...getReferenceProps()}>
{children}
</div>
{isOpen && (
<div
ref={refs.setFloating}
className="w-max select-none rounded-md border border-zinc-700 bg-zinc-800 px-4 py-2 text-sm font-medium leading-none text-zinc-100"
style={{
position: strategy,
top: y ?? 0,
left: x ?? 0,
}}
{...getFloatingProps()}
>
{message}
</div>
)}
</>
);
}