Hooks

useFullscreen

Media viewers, charts, code panels, and kiosk views that expand to fullscreen and track Esc-key exits correctly.

Import

import { useFullscreen } from "@zentauri-ui/zentauri-components/hooks/useFullscreen";

Demo source

Full client component used for this preview (same JSX as below). Adjust paths if you copy outside this app.

"use client";

import { useFullscreen } from "@zentauri-ui/zentauri-components/hooks/useFullscreen";
import { Button } from "@zentauri-ui/zentauri-components/ui/buttons";
import { HookDemoPanel } from "@/components/preview/hooks/demo-panel";
import { useRef } from "react";

export default function HookDemo() {
  const fullscreenTargetRef = useRef<HTMLDivElement>(null);
  const { isFullscreen, isSupported, toggle } = useFullscreen(fullscreenTargetRef);
  return (
    <HookDemoPanel title="Interactive demo">
      <p className="mb-4 text-sm text-slate-400">
        {isSupported
          ? "Expand the panel below to fullscreen — pressing Esc exits and the state stays correct."
          : "The Fullscreen API is not available in this browser."}
      </p>
      <div ref={fullscreenTargetRef} className="mt-4 flex h-48 flex-col items-center justify-center gap-3 rounded-lg border border-white/10 bg-slate-900/50 text-slate-300">
        <p className="text-sm">
          {isFullscreen ? "You are viewing this panel in fullscreen." : "This panel goes fullscreen."}
        </p>
        <Button type="button" onClick={() => toggle()} disabled={!isSupported}>
          {isFullscreen ? "Exit fullscreen" : "Enter fullscreen"}
        </Button>
      </div>
    </HookDemoPanel>
  );
}

Interactive demo

The Fullscreen API is not available in this browser (e.g. iOS Safari only supports fullscreen video).

This panel goes fullscreen — not the whole page.

What it does

useFullscreen ships as a small client module you can import from @zentauri-ui/zentauri-components/hooks/useFullscreen. Use it when the behavior matches your integration without copying utility code.

API notes

Read the interactive demo on this page for the parameters used in typical flows. Refer to TypeScript types exported next to the hook for exhaustive options.

Common use cases

  • Reuse the same hook in client components across Next.js App Router routes.
  • Keep server components free of browser APIs; colocate interactive demos in client files.
  • Compose hooks with Zentauri UI primitives for overlays, forms, and data views.
  • Align documentation with published @zentauri-ui/zentauri-components/hooks/* paths.

Accessibility

Hooks manipulate behavior, not roles. Pair them with appropriate elements, ARIA attributes, and keyboard handlers so assistive technologies receive a coherent experience.

Next.js integration notes

Keep interactive subtrees in client components. When you only need static copy, leave it in the server layout and pass children into a client boundary that calls the hook.

FAQ

Can I import this hook from a server component?

No. These hooks rely on browser APIs or React client lifecycle. Import them from a file marked with the "use client" directive or from a client child component.

Does the preview site bundle the same code as npm?

The component library app depends on the workspace package. Published builds resolve the same export paths under @zentauri-ui/zentauri-components.

Where should I validate accessibility for hook-driven UI?

Hooks do not replace semantics. Test focus order, labels, and keyboard flows in your real layout with assistive technologies you support.