screenshot button in fullscreen

This commit is contained in:
tresabhi committed 2026-12-03 23:35:07 -06:00
1 parent 4c2c1c82ca
commit cac2c4e7b2
7 files changed
+46 -36

No files matched your search

@@ -29,6 +29,10 @@
box-shadow: var(--shadow-subtle); box-shadow: var(--shadow-subtle);
border-radius: var(--space-4); border-radius: var(--space-4);
outline: var(--outline-interactive) !important; outline: var(--outline-interactive) !important;
&[data-size="minor"] {
max-width: min(25rem, 100%);
}
} }
.Title { .Title {
@@ -43,4 +47,3 @@
color: var(--gray-11); color: var(--gray-11);
text-align: left; text-align: left;
} }
@@ -62,7 +62,7 @@ export function ScreenshotButton({ canvas, name, children, ...props }: Props) {
<Dialog.Portal> <Dialog.Portal>
<Dialog.Overlay> <Dialog.Overlay>
<Dialog.Content> <Dialog.Content data-size="minor">
<Dialog.Header> <Dialog.Header>
<Dialog.Title>{strings.common.screenshot.title}</Dialog.Title> <Dialog.Title>{strings.common.screenshot.title}</Dialog.Title>
<Dialog.Description> <Dialog.Description>
@@ -38,7 +38,7 @@ export const SettingsDialog = withLocale(
<Dialog.Portal> <Dialog.Portal>
<Dialog.Overlay> <Dialog.Overlay>
<Dialog.Content> <Dialog.Content data-size="minor">
<Dialog.Header> <Dialog.Header>
<Dialog.Title>{strings.navbar.settings}</Dialog.Title> <Dialog.Title>{strings.navbar.settings}</Dialog.Title>
</Dialog.Header> </Dialog.Header>
@@ -1,5 +1,6 @@
import { EnterFullScreenIcon, ExitFullScreenIcon } from "@radix-ui/react-icons"; import { EnterFullScreenIcon, ExitFullScreenIcon } from "@radix-ui/react-icons";
import { useCallback, useEffect, useState, type RefObject } from "react"; import { useCallback, type RefObject } from "react";
import { useFullScreen } from "../../hooks/useFullScreen";
import { IconButton } from "../IconButton"; import { IconButton } from "../IconButton";
import styles from "./index.module.css"; import styles from "./index.module.css";
@@ -8,19 +9,7 @@ interface TankopediaFullscreenProps {
} }
export function TankopediaFullscreen({ target }: TankopediaFullscreenProps) { export function TankopediaFullscreen({ target }: TankopediaFullscreenProps) {
const [isFullscreen, setIsFullscreen] = useState(false); const isFullscreen = useFullScreen();
useEffect(() => {
function handleFullscreenChange() {
setIsFullscreen(document.fullscreenElement === target.current);
}
document.addEventListener("fullscreenchange", handleFullscreenChange);
return () => {
document.removeEventListener("fullscreenchange", handleFullscreenChange);
};
}, []);
const handleClick = useCallback(() => { const handleClick = useCallback(() => {
if (isFullscreen) { if (isFullscreen) {
+2 -18
View File
@@ -1,21 +1,5 @@
import { useEffect, useState } from 'react'; import { useFullscreenElement } from "./useFullscreenElement";
export function useFullScreen() { export function useFullScreen() {
const [isFullScreen, setIsFullScreen] = useState( return useFullscreenElement() !== null;
typeof document !== 'undefined' && document.fullscreenElement !== null,
);
useEffect(() => {
function handleFullScreenChange() {
setIsFullScreen(document.fullscreenElement !== null);
}
document.addEventListener('fullscreenchange', handleFullScreenChange);
return () => {
document.removeEventListener('fullscreenchange', handleFullScreenChange);
};
}, []);
return isFullScreen;
} }
@@ -0,0 +1,21 @@
import { useEffect, useState } from "react";
export function useFullscreenElement() {
const [fullscreenElement, setFullscreenElement] = useState(
typeof document === "undefined" ? null : document.fullscreenElement,
);
useEffect(() => {
function handleFullscreenChange() {
setFullscreenElement(document.fullscreenElement);
}
document.addEventListener("fullscreenchange", handleFullscreenChange);
return () => {
document.removeEventListener("fullscreenchange", handleFullscreenChange);
};
}, []);
return fullscreenElement;
}
+14 -1
View File
@@ -1,4 +1,5 @@
import type { ComponentProps, ComponentType } from "react"; import type { ComponentProps, ComponentType } from "react";
import { useFullscreenElement } from "../hooks/useFullscreenElement";
import { classNames } from "./classNames"; import { classNames } from "./classNames";
function composeRadixComponent<Props extends object>( function composeRadixComponent<Props extends object>(
@@ -38,11 +39,23 @@ export function composeRadixComponents<Module extends Record<string, unknown>>(
for (const key in components) { for (const key in components) {
if (key[0].toLowerCase() === key[0]) continue; if (key[0].toLowerCase() === key[0]) continue;
mapped[key] = composeRadixComponent( const Composed = composeRadixComponent(
components[key] as ComponentType<any>, components[key] as ComponentType<any>,
styles[key], styles[key],
propsByName[key], propsByName[key],
); );
if (key !== "Portal") {
mapped[key] = Composed;
continue;
}
// Fullscreen only shows the fullscreen element's subtree, so portals mount
// inside it rather than in the body while something is fullscreen
mapped[key] = function (props: ComponentProps<typeof Composed>) {
const fullscreenElement = useFullscreenElement();
return <Composed container={fullscreenElement ?? undefined} {...props} />;
};
} }
return mapped as PickComponents<Module>; return mapped as PickComponents<Module>;