Documentation / Feedback & overlays
AdvanceDetachable
The advanced version of Detachable: it also opens a separate window through createPortal, but adds two modes and value synchronisation.
mode="detach"moves the content into the window (nothing stays in the page);mode="clone"duplicates it: it stays in the page and also shows in the window.
id names a BroadcastChannel (falling back to postMessage): instances sharing the same id — in other tabs or windows — exchange their value serialised as JSON (serialize / deserialize for another format) and receive the others’ in onValueChange. readOnly stops the exchange, disabled prevents opening, and name adds a hidden field so a form submits the value.
Opening is controlled (isDetached + onDetachedChange) or uncontrolled (defaultDetached, the ref’s open() / close() / toggle()). The children can be a function that receives these commands and the detached state. A "use client" component, generic over the value type.
Examples
Render-prop children
The function receives toggle and detached: the detach button lives inside the content itself.
import { AdvanceDetachable, Button } from "@synertech/ui";
export function RenderProp() {
return (
<AdvanceDetachable mode="detach" id="notes" title="Notes" features="width=480,height=360">
{({ toggle, detached }) => (
<div className="space-y-2 rounded-lg border border-gray-200 p-4">
<p className="text-sm">Bloc-notes de la réunion du jour.</p>
<Button size="sm" onClick={toggle}>
{detached ? "Rattacher" : "Détacher"}
</Button>
</div>
)}
</AdvanceDetachable>
);
}Clone mode
The content stays in the page and also shows in the window: handy for a presentation screen.
import { useRef } from "react";
import { AdvanceDetachable, Button, type AdvanceDetachableRef } from "@synertech/ui";
export function CloneMode() {
const ref = useRef<AdvanceDetachableRef>(null);
return (
<div className="space-y-3">
<Button onClick={() => ref.current?.toggle()}>Projeter sur un second écran</Button>
<AdvanceDetachable
ref={ref}
mode="clone"
id="slide"
title="Présentation"
detachedBodyClassName="bg-gray-900 p-8"
>
<div className="rounded-lg bg-indigo-600 p-6 text-white">
Diapositive 3 / 12 — Résultats du trimestre
</div>
</AdvanceDetachable>
</div>
);
}Controlled opening
isDetached drives the window and onDetachedChange also reports when the user closes it.
import { useState } from "react";
import { AdvanceDetachable, Button } from "@synertech/ui";
export function ControlledWindow() {
const [detached, setDetached] = useState(false);
return (
<div className="space-y-3">
<p className="text-sm text-gray-600">Fenêtre {detached ? "ouverte" : "fermée"}</p>
<Button onClick={() => setDetached((value) => !value)}>
{detached ? "Fermer" : "Ouvrir"} la console
</Button>
<AdvanceDetachable
mode="detach"
id="console"
isDetached={detached}
onDetachedChange={setDetached}
title="Console"
>
<pre className="rounded bg-gray-900 p-3 text-xs text-green-400">
$ build terminé en 2,3 s
</pre>
</AdvanceDetachable>
</div>
);
}Value synchronised across windows
Every tab rendering this component with the same id receives the others’ value in onValueChange.
import { useState } from "react";
import { AdvanceDetachable, Button } from "@synertech/ui";
export function SyncedValue() {
const [note, setNote] = useState("");
return (
<AdvanceDetachable<string> mode="clone" id="shared-note" value={note} onValueChange={setNote}>
{({ toggle }) => (
<div className="space-y-2">
<textarea
value={note}
onChange={(event) => setNote(event.target.value)}
placeholder="Ouvrez cette page dans deux onglets et écrivez…"
className="w-full rounded-md border border-gray-300 p-2 text-sm"
/>
<Button size="sm" onClick={toggle}>
Ouvrir à part
</Button>
</div>
)}
</AdvanceDetachable>
);
}Form integration
name renders a hidden field with the serialised value; defaultValue lets the component manage the value.
import { AdvanceDetachable, Button } from "@synertech/ui";
interface Filters {
status: string;
owner: string;
}
export function InForm() {
return (
<form
onSubmit={(event) => {
event.preventDefault();
console.log(new FormData(event.currentTarget).get("filters"));
}}
className="space-y-3"
>
<AdvanceDetachable<Filters>
mode="detach"
id="filters"
name="filters"
defaultValue={{ status: "ouvert", owner: "moi" }}
>
<p className="text-sm">Filtres : tickets ouverts, assignés à moi</p>
</AdvanceDetachable>
<Button type="submit">Appliquer</Button>
</form>
);
}API reference
Components
import { AdvanceDetachable } from "@synertech/ui";Props — AdvanceDetachableProps
| Prop | Type | Default | Description |
|---|---|---|---|
children• |
ReactNode | ((ctx: AdvanceDetachableRenderContext) => ReactNode) |
— | |
id• |
string |
— | Names the channel the value is shared on. Every instance with the same |
mode• |
"detach" | "clone" |
— | |
autoFocus |
boolean |
true |
|
className |
string |
— | |
closeOnMainWindowUnload |
boolean |
true |
|
defaultDetached |
boolean |
false |
|
defaultValue |
T |
— | |
deserialize |
(raw: string) => T |
— | |
detachedBodyClassName |
string |
— | |
disabled |
boolean |
false |
|
features |
string |
— | |
isDetached |
boolean |
— | |
name |
string |
— | |
onDetachedChange |
(detached: boolean) => void |
— | |
onPopupBlocked |
() => void |
— | The browser refused to open the window (a popup blocker: expected with |
onValueChange |
(next: T) => void |
— | |
placeholderClassName |
string |
— | |
readOnly |
boolean |
false |
|
serialize |
(value: T) => string |
— | |
target |
string |
— | |
title |
string |
"" |
|
value |
T |
— |
+ 2 inherited native attributes from RefAttributes, Attributes (className, id, aria-*, event handlers…).
Types
AdvanceDetachableRef
Interfaceinterface AdvanceDetachableRef| Field | Type | Default | Description |
|---|---|---|---|
close• |
() => void |
— | |
isDetached• |
boolean |
— | |
open• |
() => void |
— | |
toggle• |
() => void |
— | |
window• |
Window | null |
— |
AdvanceDetachableRenderContext
Interfaceinterface AdvanceDetachableRenderContext| Field | Type | Default | Description |
|---|---|---|---|
close• |
() => void |
— | |
detached• |
boolean |
— | |
open• |
() => void |
— | |
toggle• |
() => void |
— | |
windowRef• |
Window | null |
— |