quicker switching between different popovers

This commit is contained in:
Ryan Di
2025-08-26 23:46:20 +10:00
parent 6448c4b6a1
commit 2f31911b0d
2 changed files with 36 additions and 3 deletions

View File

@@ -380,7 +380,13 @@ export const CompactShapeActions = ({
<div className="compact-action-item"> <div className="compact-action-item">
<Popover.Root <Popover.Root
open={strokePopoverOpen} open={strokePopoverOpen}
onOpenChange={setStrokePopoverOpen} onOpenChange={(open) => {
setStrokePopoverOpen(open);
if (open) {
setOtherActionsPopoverOpen(false);
setAppState({ openPopup: null });
}
}}
> >
<Popover.Trigger asChild> <Popover.Trigger asChild>
<button <button
@@ -435,6 +441,10 @@ export const CompactShapeActions = ({
open={appState.openPopup === "arrowProperties"} open={appState.openPopup === "arrowProperties"}
onOpenChange={(open) => { onOpenChange={(open) => {
setAppState({ openPopup: open ? "arrowProperties" : null }); setAppState({ openPopup: open ? "arrowProperties" : null });
if (open) {
setStrokePopoverOpen(false);
setOtherActionsPopoverOpen(false);
}
}} }}
> >
<Popover.Trigger asChild> <Popover.Trigger asChild>
@@ -507,6 +517,10 @@ export const CompactShapeActions = ({
open={appState.openPopup === "textAlign"} open={appState.openPopup === "textAlign"}
onOpenChange={(open) => { onOpenChange={(open) => {
setAppState({ openPopup: open ? "textAlign" : null }); setAppState({ openPopup: open ? "textAlign" : null });
if (open) {
setStrokePopoverOpen(false);
setOtherActionsPopoverOpen(false);
}
}} }}
> >
<Popover.Trigger asChild> <Popover.Trigger asChild>
@@ -561,7 +575,13 @@ export const CompactShapeActions = ({
<div className="compact-action-item"> <div className="compact-action-item">
<Popover.Root <Popover.Root
open={otherActionsPopoverOpen} open={otherActionsPopoverOpen}
onOpenChange={setOtherActionsPopoverOpen} onOpenChange={(open) => {
setOtherActionsPopoverOpen(open);
if (open) {
setStrokePopoverOpen(false);
setAppState({ openPopup: null });
}
}}
> >
<Popover.Trigger asChild> <Popover.Trigger asChild>
<button <button

View File

@@ -191,12 +191,14 @@ const ColorPickerTrigger = ({
type, type,
compactMode = false, compactMode = false,
mode = "background", mode = "background",
onToggle,
}: { }: {
color: string | null; color: string | null;
label: string; label: string;
type: ColorPickerType; type: ColorPickerType;
compactMode?: boolean; compactMode?: boolean;
mode?: "background" | "stroke"; mode?: "background" | "stroke";
onToggle: () => void;
}) => { }) => {
return ( return (
<Popover.Trigger <Popover.Trigger
@@ -213,6 +215,7 @@ const ColorPickerTrigger = ({
? t("labels.showStroke") ? t("labels.showStroke")
: t("labels.showBackground") : t("labels.showBackground")
} }
onClick={onToggle}
> >
<div className="color-picker__button-outline">{!color && slashIcon}</div> <div className="color-picker__button-outline">{!color && slashIcon}</div>
{compactMode && color && ( {compactMode && color && (
@@ -279,7 +282,11 @@ export const ColorPicker = ({
<Popover.Root <Popover.Root
open={appState.openPopup === type} open={appState.openPopup === type}
onOpenChange={(open) => { onOpenChange={(open) => {
updateData({ openPopup: open ? type : null }); if (open) {
updateData({ openPopup: type });
} else if (appState.openPopup === type) {
updateData({ openPopup: null });
}
}} }}
> >
{/* serves as an active color indicator as well */} {/* serves as an active color indicator as well */}
@@ -289,6 +296,12 @@ export const ColorPicker = ({
type={type} type={type}
compactMode={compactMode} compactMode={compactMode}
mode={type === "elementStroke" ? "stroke" : "background"} mode={type === "elementStroke" ? "stroke" : "background"}
onToggle={() => {
// toggle to this type (if already open, close; if another is open, switch)
updateData({
openPopup: appState.openPopup === type ? null : type,
});
}}
/> />
{/* popup content */} {/* popup content */}
{appState.openPopup === type && ( {appState.openPopup === type && (