2023-11-22 07:02:49 +00:00
|
|
|
import { useState } from "react";
|
|
|
|
import { Editor } from "@tiptap/react";
|
|
|
|
import { usePopper } from "react-popper";
|
|
|
|
import { List } from "lucide-react";
|
|
|
|
// components
|
|
|
|
import { ContentBrowser } from "./content-browser";
|
|
|
|
// types
|
|
|
|
import { IMarking } from "..";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
editor: Editor;
|
|
|
|
markings: IMarking[];
|
|
|
|
sidePeekVisible: boolean;
|
|
|
|
setSidePeekVisible: (sidePeekState: boolean) => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const SummaryPopover: React.FC<Props> = (props) => {
|
|
|
|
const { editor, markings, sidePeekVisible, setSidePeekVisible } = props;
|
|
|
|
|
2023-12-10 10:18:10 +00:00
|
|
|
const [referenceElement, setReferenceElement] = useState<HTMLButtonElement | null>(null);
|
|
|
|
const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);
|
2023-11-22 07:02:49 +00:00
|
|
|
|
2023-12-10 10:18:10 +00:00
|
|
|
const { styles: summaryPopoverStyles, attributes: summaryPopoverAttributes } = usePopper(
|
|
|
|
referenceElement,
|
|
|
|
popperElement,
|
|
|
|
{
|
2023-11-22 07:02:49 +00:00
|
|
|
placement: "bottom-start",
|
2023-12-10 10:18:10 +00:00
|
|
|
}
|
|
|
|
);
|
2023-11-22 07:02:49 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="group/summary-popover w-min whitespace-nowrap">
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
ref={setReferenceElement}
|
2023-12-10 10:18:10 +00:00
|
|
|
className={`grid h-7 w-7 place-items-center rounded ${
|
|
|
|
sidePeekVisible ? "bg-custom-primary-100/20 text-custom-primary-100" : "text-custom-text-300"
|
2023-11-22 07:02:49 +00:00
|
|
|
}`}
|
|
|
|
onClick={() => setSidePeekVisible(!sidePeekVisible)}
|
|
|
|
>
|
|
|
|
<List className="h-4 w-4" />
|
|
|
|
</button>
|
|
|
|
{!sidePeekVisible && (
|
|
|
|
<div
|
2023-12-10 10:18:10 +00:00
|
|
|
className="z-10 hidden max-h-80 w-64 overflow-y-auto rounded border-[0.5px] border-custom-border-200 bg-custom-background-100 p-3 shadow-custom-shadow-rg group-hover/summary-popover:block"
|
2023-11-22 07:02:49 +00:00
|
|
|
ref={setPopperElement}
|
|
|
|
style={summaryPopoverStyles.popper}
|
|
|
|
{...summaryPopoverAttributes.popper}
|
|
|
|
>
|
|
|
|
<ContentBrowser editor={editor} markings={markings} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|