Synertech Web/ui v0.57.5 Site Storybook

Documentation / Feedback & overlays

Detachable

Client@synertech/uiOpen in Storybook

Detaches a piece of interface into a separate browser window (window.open + createPortal): a player, a dashboard or notes you want to keep on a second screen. The children stay in the page’s React tree: they keep their state, their context and their handlers; only their rendering moves to another window. While detached, nothing is rendered in their original place. What they open opens in their window: the list of a Select, the menu of a Dropdown, a Modal or a Drawer.

The page’s stylesheets are copied into the window (copyStyles, on by default), then tracked if new ones appear. The user closing the window is detected and reported through onClose. The component is controlled (detached) or uncontrolled (defaultDetached and the detach() / attach() ref). To sync a value between windows or to clone instead of moving, see AdvanceDetachable. A "use client" component.

Examples

Controlled mode

detached opens the window; onClose sets the state back to false when the user closes it.

Open in a tab
import { useState } from "react";
import { Button, Detachable } from "@synertech/ui";

export function Controlled() {
  const [detached, setDetached] = useState(false);

  return (
    <div className="space-y-3">
      <Button onClick={() => setDetached((value) => !value)}>
        {detached ? "Rattacher" : "Détacher"}
      </Button>
      <Detachable
        detached={detached}
        onClose={() => setDetached(false)}
        title="Notes de réunion"
        width={480}
        height={360}
      >
        <div className="rounded-lg border border-gray-200 p-4">
          <h3 className="font-semibold">Notes de réunion</h3>
          <p className="text-sm text-gray-600">Ce bloc peut vivre dans sa propre fenêtre.</p>
        </div>
      </Detachable>
    </div>
  );
}

Driving it through a ref

Without detached, the ref exposes detach(), attach(), isDetached and the open window.

Open in a tab
import { useRef } from "react";
import { Button, Detachable, type DetachableRef } from "@synertech/ui";

export function WithRef() {
  const ref = useRef<DetachableRef>(null);

  return (
    <div className="space-y-3">
      <div className="flex gap-2">
        <Button size="sm" onClick={() => ref.current?.detach()}>
          Ouvrir à part
        </Button>
        <Button size="sm" onClick={() => ref.current?.attach()}>
          Rattacher
        </Button>
      </div>
      <Detachable ref={ref} title="Chronomètre" onDetach={() => console.log("Fenêtre ouverte")}>
        <p className="text-3xl font-mono">00:42</p>
      </Detachable>
    </div>
  );
}

State survives detaching

The counter keeps changing in the window: it is the same component, rendered elsewhere.

Open in a tab
import { useState } from "react";
import { Button, Detachable } from "@synertech/ui";

export function SharedState() {
  const [detached, setDetached] = useState(false);
  const [count, setCount] = useState(0);

  return (
    <div className="space-y-3">
      <p className="text-sm">Valeur dans la page : {count}</p>
      <Button size="sm" onClick={() => setDetached(true)} disabled={detached}>
        Détacher le compteur
      </Button>
      <Detachable
        detached={detached}
        onClose={() => setDetached(false)}
        title="Compteur"
        width={320}
        height={200}
        windowClassName="p-6"
      >
        <Button onClick={() => setCount((value) => value + 1)}>Incrémenter ({count})</Button>
      </Detachable>
    </div>
  );
}

Blocked popup and positioning

onPopupBlocked warns when the browser refuses to open the window; left / top place the window instead of centring it.

Open in a tab
import { useState } from "react";
import { Button, Detachable } from "@synertech/ui";

export function PopupBlocked() {
  const [detached, setDetached] = useState(false);
  const [blocked, setBlocked] = useState(false);

  return (
    <div className="space-y-3">
      <Button
        onClick={() => {
          setBlocked(false);
          setDetached(true);
        }}
      >
        Ouvrir le tableau de bord
      </Button>
      {blocked && (
        <p className="text-sm text-red-600">Autorisez les fenêtres surgissantes pour ce site.</p>
      )}
      <Detachable
        detached={detached}
        left={40}
        top={40}
        onClose={() => setDetached(false)}
        onPopupBlocked={() => {
          setBlocked(true);
          setDetached(false);
        }}
      >
        <p className="p-4">Indicateurs du jour</p>
      </Detachable>
    </div>
  );
}

API reference

Components

Detachable

ComponentClient
import { Detachable } from "@synertech/ui";

Props — DetachableProps

PropTypeDefaultDescription
children• ReactNode —
center boolean true
className string —
closeOnParentUnmount boolean true
copyStyles boolean true
defaultDetached boolean false
detached boolean —
height number 600
left number —
onClose () => void —
onDetach () => void —
onPopupBlocked () => void —

The browser refused to open the window (a popup blocker: expected with defaultDetached, which opens it without a click). The content stays in the page; uncontrolled, the component is attached again, and a controlled parent sets detached back to false here.

title string ""
top number —
width number 800
windowClassName string —

+ 2 inherited native attributes from RefAttributes, Attributes (className, id, aria-*, event handlers…).

Types

DetachableRef

Interface
interface DetachableRef
FieldTypeDefaultDescription
attach• () => void —
detach• () => void —
isDetached• boolean —
window• Window | null —