feat(inspector): extend shared floating-inspector dismissal to background color

Dismiss and single-active the background color picker, matching the
other inspectors.

- Replace the local open signal with useActiveInspector("background")
  keyed by a fixed sentinel id (the background has no entity), so the
  picker dismisses on outside interaction and joins the single-active
  model.
- Wrap the section in a contents-only trigger boundary and move the
  picker into a FloatingInspectorLayer; the data-row-control swatch is
  excluded so re-clicking it toggles the picker closed.
This commit is contained in:
Doruk Kavcioglu 2026-07-21 17:13:32 +03:00
parent d4c349a570
commit 45eb63d93f
No known key found for this signature in database

View File

@ -8,6 +8,7 @@ import {
FloatingInspectorContent,
FloatingInspectorHeader,
FloatingInspectorTitle,
FloatingInspectorLayer,
} from "@/components/ui/floating-inspector";
import { Icon } from "@/components/ui/icon";
import { PanelSection } from "@/components/ui/panel-section";
@ -16,17 +17,24 @@ import { ColorOpacityRow } from "@/components/ui/color-opacity-row";
import { useEngine } from "@/context/engine";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { createSignal } from "solid-js";
import { createUniqueId, Show } from "solid-js";
import { DEFAULT_BACKGROUND, persistWorldState, useWorldState } from "@/components/engine";
import { useActiveInspector } from "./active-inspector";
const OWNER = "background";
// The background has no entity; a fixed id keys its single picker in the shared model.
const SLOT = 1;
export function BackgroundSettings() {
const { world } = useEngine();
const [isPickerOpen, setIsPickerOpen] = createSignal(false);
const titleId = createUniqueId();
const inspectors = useActiveInspector();
const isPickerOpen = () => inspectors.currentId(OWNER) !== undefined;
const color = useWorldState(w => w.background, DEFAULT_BACKGROUND);
let anchorRef: HTMLDivElement | undefined;
let sectionRef: HTMLDivElement | undefined;
const assignColor = (next: number) => {
world.background = next;
@ -34,47 +42,57 @@ export function BackgroundSettings() {
};
return (
<PanelSection title="Background" ref={anchorRef}>
<ControlRow label="Color">
<ColorOpacityRow
color={color()}
onChangeColor={assignColor}
onClick={() => setIsPickerOpen(true)}
/>
</ControlRow>
<FloatingInspector
open={isPickerOpen}
anchorRef={anchorRef}
>
<FloatingInspectorHeader>
<FloatingInspectorTitle>Color</FloatingInspectorTitle>
<div class="ml-auto">
<Tooltip>
<TooltipTrigger
as={Button}
size="icon"
variant="ghost"
class="text-muted-foreground"
onClick={() => setIsPickerOpen(false)}
>
<Icon name="close-remove" class="size-6" />
</TooltipTrigger>
<TooltipContent>Close</TooltipContent>
</Tooltip>
</div>
</FloatingInspectorHeader>
<FloatingInspectorContent class="p-0">
<ColorOpacityPicker
<>
<div ref={sectionRef} class="contents">
<PanelSection title="Background" ref={anchorRef}>
<ControlRow label="Color">
<ColorOpacityRow
color={color()}
opacity={1}
onColorChange={assignColor}
onBeginChange={(label) => world.history.startTransaction(label)}
onEndChange={() => world.history.commitTransaction()}
withoutOpacity
onChangeColor={assignColor}
onClick={() => inspectors.toggle(OWNER, SLOT)}
/>
</FloatingInspectorContent>
</FloatingInspector>
</PanelSection>
</ControlRow>
</PanelSection>
</div>
<Show when={isPickerOpen()}>
<FloatingInspectorLayer
onDismiss={() => inspectors.close(OWNER)}
triggerRef={sectionRef}
triggerControlSelector="[data-row-control]"
labelledBy={titleId}
>
<FloatingInspector open anchorRef={anchorRef}>
<FloatingInspectorHeader>
<FloatingInspectorTitle id={titleId}>Color</FloatingInspectorTitle>
<div class="ml-auto">
<Tooltip>
<TooltipTrigger
as={Button}
size="icon"
variant="ghost"
class="text-muted-foreground"
onClick={() => inspectors.close(OWNER)}
>
<Icon name="close-remove" class="size-6" />
</TooltipTrigger>
<TooltipContent>Close</TooltipContent>
</Tooltip>
</div>
</FloatingInspectorHeader>
<FloatingInspectorContent class="p-0">
<ColorOpacityPicker
color={color()}
opacity={1}
onColorChange={assignColor}
onBeginChange={(label) => world.history.startTransaction(label)}
onEndChange={() => world.history.commitTransaction()}
withoutOpacity
/>
</FloatingInspectorContent>
</FloatingInspector>
</FloatingInspectorLayer>
</Show>
</>
);
}