@haatlabs-core/ui
React components the apps share. Fonts, theme and colours stay with each app: the components carry class names, and each app's stylesheet styles them.
import { Drawer, EmptyState, FullScreen, Loading, SearchBox } from '@haatlabs-core/ui';
| Component | What it is | Class names it uses |
|---|---|---|
EmptyState | What a list shows when it has nothing: a title and what to do next | .empty |
Loading | Placeholder rows (rows) or a spinner, labelled for assistive technology | .skeleton, .skeleton-row, .skeleton-box, .skeleton-line, .short, .loading, .spinner |
Drawer | A card's detail beside its list, with a link to its full page; Escape closes it | .drawer, .drawer-bar, .drawer-body, .row, .spread |
FullScreen | A picture over the whole screen; Escape or a click outside closes it | .full-screen, .full-screen-close |
SearchBox | Calls onSearch with the trimmed phrase once typing pauses for 300 ms | .search-box |
react, react-dom and react-router-dom are peers: the app's own copies are used.
Install
pnpm add @haatlabs-core/ui
It leaves these packages to your app, so the app holds one copy: react, react-dom, react-router-dom, @tanstack/react-query, zod.
The dashboard look
One look for every Haatlabs dashboard: a sidebar app shell, light and dark themes, an accent per product.
import '@fontsource-variable/plus-jakarta-sans/index.css';
import '@fontsource/jetbrains-mono/500.css';
import { AppShell, ThemeStyles } from '@haatlabs-core/ui';
<ThemeStyles accent="indigo" /> // indigo, coral, teal, green, or { solid, textLight, … }
<AppShell
brand={<Logo />}
nav={[{ items: [{ label: 'Home', to: '/home' }] }, { label: 'Billing', items: [...] }]}
account={{ name, detail: email, onSignOut, signingOut }}
statusChip={<StatusChip to="/credits">₹480.00</StatusChip>}
>
<Routes>…</Routes>
</AppShell>
- Theme: follows the computer's setting until someone picks dark or light in the sidebar's
switch; the choice is kept in the browser (
haatlabs:theme). ServeTHEME_BOOT_SCRIPTaspublic/theme-boot.jsand load it in<head>(<script src="/theme-boot.js"></script>): the pages' CSP forbids inline scripts, and without it a dark page flashes light. - Tokens:
--hl-*CSS variables (--hl-surface,--hl-text,--hl-accent, …), every accent tested for 4.5:1 contrast in both themes. - Pieces:
PageHeader,Card,Callout,Checklist,StatusChip,ShellSearch. - The shell leaves
<main>to the pages; its content area is#main, the skip link's target. - Adopting it in an app: drop
LoginPage'saccent/glowprops (the theme's accent and link colour apply), and point the app's own colour variables at the theme (--surface: var(--hl-surface, #fff)), so its pages follow the dark theme.
@haatlabs-core/ui/client
What an app's pages use to talk to its API, and the sign-in pages:
createTransport({ baseUrl, credentials, fetch, envelope }):call,adminCall,send,queryOf. Writes carry the CSRF header (x-csrf-token); administrators' writes carryx-admin-csrf. A failure is anApiErrorwith the API's code and status.cookieCredentials(appName): the dashboard's session cookie and its CSRF cookie<appName>_csrf. Inside Shopify admin, pass{ kind: 'bearer', getToken }.createQueryClient(): reads and writes that fail on the network or with a 5xx are tried again, twice at most; a 401 asks formeagain.LoginPage({ client, aside })andEmailSignInPanel({ client }): signing in with a code, and giving a store installed from Shopify an email to sign in with.
@tanstack/react-query and zod are peers.