Skip to content

Commit

Permalink
fix: select tool popover
Browse files Browse the repository at this point in the history
  • Loading branch information
slotDumpling committed Aug 25, 2024
1 parent 461b480 commit 7eaa7f0
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions src/pages/reader/tools/DrawTools.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
/// <reference types="paper" />
import { CSSProperties, FC, RefObject, useMemo, useState } from "react";
import {
CSSProperties,
FC,
RefObject,
useEffect,
useMemo,
useState,
} from "react";
import {
CopyOutlined,
BoldOutlined,
Expand Down Expand Up @@ -39,6 +46,7 @@ export const SelectTool: FC<{
clickPoint?: paper.Point;
}> = ({ drawRef, visible, clickPoint }) => {
const [currDrawCtrl, setCurrDrawCtrl] = useState<Partial<DrawCtrl>>({});
useEffect(() => setCurrDrawCtrl({}), [visible]);
if (!clickPoint) return null;
const { x, y } = clickPoint;
return (
Expand All @@ -47,24 +55,26 @@ export const SelectTool: FC<{
data-visible={visible}
style={getPosVars(x, y)}
>
<Popover
trigger="click"
placement="bottom"
overlayClassName="style-pop"
getPopupContainer={(e) => e.parentElement!}
destroyTooltipOnHide
content={
<PenPanel
updateDrawCtrl={(updated) => {
setCurrDrawCtrl((prev) => ({ ...prev, ...updated }));
drawRef.current?.mutateStyle(updated);
}}
drawCtrl={currDrawCtrl}
/>
}
>
<Button icon={<BgColorsOutlined />} {...btnProps} />
</Popover>
{visible && (
<Popover
trigger="click"
placement="bottom"
overlayClassName="style-pop"
getPopupContainer={(e) => e.parentElement!}
destroyTooltipOnHide
content={
<PenPanel
updateDrawCtrl={(updated) => {
setCurrDrawCtrl((prev) => ({ ...prev, ...updated }));
drawRef.current?.mutateStyle(updated);
}}
drawCtrl={currDrawCtrl}
/>
}
>
<Button icon={<BgColorsOutlined />} {...btnProps} />
</Popover>
)}
<Button
icon={<CopyOutlined />}
onClick={() => drawRef.current?.duplicateSelected()}
Expand Down

0 comments on commit 7eaa7f0

Please sign in to comment.