Skip to content

Commit

Permalink
Add close button.
Browse files Browse the repository at this point in the history
  • Loading branch information
phulin committed Feb 13, 2025
1 parent 03e0bfc commit 19ecc3d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RefreshContext } from "tome-kolmafia-react";

import BrandHeading from "./components/BrandHeading";
import ChatButton from "./components/ChatButton";
import CloseIconButton from "./components/CloseIconButton";
import LocationBar from "./components/LocationBar";
import PrefsButton from "./components/PrefsButton";
import RefreshButton from "./components/RefreshButton";
Expand All @@ -15,7 +16,12 @@ import NagSection from "./sections/NagSection";
import QuestSection from "./sections/QuestSection";
import ResourceSection from "./sections/ResourceSection";
import { inDevMode } from "./util/env";
import { setup3Frames, setup4Frames, visibleFrameCount } from "./util/frames";
import {
close,
setup3Frames,
setup4Frames,
visibleFrameCount,
} from "./util/frames";

const Layout = () => {
const { triggerHardRefresh } = useContext(RefreshContext);
Expand Down Expand Up @@ -76,6 +82,16 @@ const Layout = () => {
onMouseLeave={() => setButtonsVisible(false)}
>
<Flex position="relative" minH={0} flexGrow={1}>
<Stack
direction="row"
position="absolute"
top={1}
left={1}
zIndex={200}
{...(!buttonsVisible && { display: "none" })}
>
<CloseIconButton onClick={close} />
</Stack>
<Stack
direction="row"
gap={1}
Expand Down
20 changes: 20 additions & 0 deletions src/components/CloseIconButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ButtonProps, IconButton } from "@chakra-ui/react";
import { XIcon } from "lucide-react";
import { FC } from "react";

const CloseIconButton: FC<ButtonProps> = (props) => (
<IconButton
asChild
aria-label="Close"
size="2xs"
_hover={{ bgColor: "bg.emphasized" }}
bgColor="bg"
p={1}
variant="outline"
{...props}
>
<XIcon />
</IconButton>
);

export default CloseIconButton;
10 changes: 10 additions & 0 deletions src/util/frames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,13 @@ export function setup3Frames(): void {
const cols = rootset.cols.split(",");
rootset.cols = [...cols.slice(0, 2), "25%"].join(",");
}

export function close(): void {
if (getFrames().length === 0) return;

setup3Frames();

const allFrames = getFrames();
allFrames.yorickpane?.frameElement?.remove();
delete allFrames.yorickpane;
}

0 comments on commit 19ecc3d

Please sign in to comment.