src/examples/account-panel/Headless.tsx
src/examples/account-panel/Headless.tsx'use client'
import { useAccountPanel, useSession, useSignInMethods } from '@synqauth/react'
// The same panel headless: useAccountPanel() keeps it open in ?panel=account
// (so Back closes it), keeps the focus inside, closes on Escape or a click
// outside, and says which view to show. Spread its props on your own button
// and dialog, and draw each view your way.
export function AccountPanelHeadless() {
const panel = useAccountPanel()
const { user } = useSession()
const { data: methods } = useSignInMethods()
return (
<>
<button {...panel.triggerProps}>
{user ? `Your profile, ${user.name ?? user.sub}` : 'Sign in'}
</button>
{panel.open && (
<div {...panel.panelProps} className="mt-4 space-y-3 rounded-2xl border border-plum p-4">
<h2 id={panel.titleId}>
{panel.view === 'onboarding' ? 'Welcome!' : user ? 'Your profile' : 'Sign in'}
</h2>
{panel.view === 'sign-in' &&
methods
?.filter((method) => !method.in_place)
.map((method) => (
<button key={method.id} onClick={() => void panel.signIn(method.id)}>
Continue with {method.name}
</button>
))}
{panel.view === 'progress' && (
<p>
Finish with {panel.pending?.name}… <button onClick={panel.cancel}>Cancel</button>
</p>
)}
{panel.problem && <p role="alert">{panel.problem.message}</p>}
{user && <button onClick={() => void panel.signOut()}>Sign out</button>}
<button onClick={() => panel.setOpen(false)}>Close</button>
</div>
)}
</>
)
}