@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). Serve THEME_BOOT_SCRIPT as
public/theme-boot.js and 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,
NavIcon (page icons for NavItem.icon: icon: <NavIcon name="home" />).
- The shell leaves
<main> to the pages; its content area is #main, the skip link's target.
- Phones and tablets (below 1024px,
NARROW_QUERY): no sidebar; a bottom bar has the pages
marked bottom: true (at most 4; with none marked, the first 4) and More, a sheet with the
rest, the theme switch and the account with Sign out. The top bar is one row: the brand mark,
a search button that opens the search over the page, notifications and statusChip. An
app's own frame (the embedded Shopify app) renders <MobileNav nav={…} search={search} /> and
<style>{BOTTOM_NAV_CSS}</style> itself.
- Links have no underline, a pointer and the accent on hover; drop the app's own
text-decoration: underline rules.
- Adopting it in an app: drop
LoginPage's accent/glow props (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 carry
x-admin-csrf. A failure is an ApiError with 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 for me again.
LoginPage({ client, aside, brand }) and EmailSignInPanel({ client }): signing in with a
code, and giving a store installed from Shopify an email to sign in with. Below 1024px the
aside panel is left out and brand (the product's mark and name, drawn for the panel's
dark ground; by default a SignInAside's logo) sits in a slim row above the card.
@tanstack/react-query and zod are peers.