LogoutButton
Sign out: a real form post to url (works without JS state), or a button calling onLogout.
import { LogoutButton } from '@ergasti/bricks';Examples
Sign out
Renders a real form that POSTs to url with the CSRF token (csrfToken, field name csrfField), so it works without JavaScript; onLogout runs first.
Code
import { LogoutButton } from '@ergasti/bricks';
function SignOut() {
return <LogoutButton url="/logout" csrfToken="demo-token" onLogout={() => {}}>Sign out</LogoutButton>;
}Props
Prop
Type
Design guidance
How the BRICKS design system uses LogoutButton. Written in docs/content/components/LogoutButton.md; the props above are read from the code, which wins where the two disagree.
The sign-out control: a real form POST to the server's sign-out URL (with the CSRF field), or a button calling onLogout; use it in the user menu, the sidebar's user row or the phone sheet's footer.
The mocks show "Sign out" in the user menu; the library makes it work without client state: with url it renders a <form method="post">, so the session ends server-side like any web form (Laravel's _token by default). Without url it is a plain button.
Anatomy
- Form (
.kit-shell-logout-form, withurl):method="post",actionthroughsafeHref, a hidden CSRF input. - Button (
.kit-shell-logoutby default): full width, 40px min, red (--bad) 14px 600 text,--rasp-50on hover. PassclassNamefor another look (kit-shell-me-outfor the sidebar's icon button).
Variants
| Props | Renders | Use when |
|---|---|---|
url (+ csrfToken) | <form> + submit button | Server sessions (Laravel). |
onLogout only | <button type="button"> | API sign-out, then the app redirects. |
className="kit-shell-me-out" + icon child | Grey icon button | The PR sidebar's user row. |
States
Default, hover (--rasp-50), focus-visible (inset ring). No loading state: the POST navigates away.
Usage
// Server sign-out from the user menu
const csrf = document.querySelector<HTMLMetaElement>('meta[name="csrf-token"]')?.content;
<UserMenu name="Nour Hassan" detail="HushUp" avatar={<Avatar name="Nour Hassan" seed={3} size="sm" />}
logout={<LogoutButton url="/logout" csrfToken={csrf}>Sign out</LogoutButton>} />// PR sidebar: an icon button
<LogoutButton className="kit-shell-me-out" onLogout={signOut}>
<Icon name="logout" /><span className="kit-sr">Sign out</span>
</LogoutButton>Where it appears
- Library shell: the header's
UserMenufooter ("Sign out"); the v3 brand mock has no sign-out. - PR Portal › sidebar › Mona Adel's user row, sign-out icon (the v3 PR mock). Screens:
Pr*. - Library shell: the phone nav sheet footer (not in the desktop mocks).
Guidelines
Do
- Prefer
url+csrfTokenfor server sessions. - Name icon-only buttons with screen-reader text.
Don't
- Don't use a link (GET) for sign-out.
- Don't style it as a primary button.
RTL and Arabic
- Text aligns to the start; "تسجيل الخروج". The icon variant's arrow mirrors.
Tokens
--bad, --rasp-50, --focus-ring-inset; in the phone sheet, white outlined (--shell-nav-hover hover).
Accessibility
- A real
<button>(submit inside the form); the visible words are its name. - 40px minimum height on desktop, 44px on touch tiers (≤1024px); inset focus ring.
Found in the source
- No roles, ARIA attributes or key handling are set in this component's own source; it renders native elements and the components it composes.
Read from the component's source and tests. See Accessibility for the patterns the library follows.
Related
UserMenu,TopbarMenu(footer): where it usually sits.SidebarUser(action),MobileNavSheet(footer).
See also: AppHeader · HeaderSearch · LanguageToggle
Source
src/shell/LogoutButton.tsx (line 20) on GitHub.