Component patterns
Mobile first patterns and the UI rules every agent follows.
These are the rules for any UI change. They are also summarized in the agent rules (.ruler/AGENTS.md). The numbers behind them are in the design system.
Rules
- Mobile first. Write the layout for 360 px wide, then add
md:andlg:. The desktop version must be as good: use the extra width for columns, tables and side panels, not for stretching a phone layout - Tokens only. Colors, radius and fonts come from the theme. No hex,
rgb(),bg-white,text-black, and no arbitrary values likew-[317px]ortext-[10px](the lint warns about them). Hotels re-theme--primary, so a hard coded color breaks branding - Logical properties only. Arabic is right to left. Use
ms-me-ps-pe-start-end-text-starttext-endborder-sborder-erounded-srounded-einset-x. Neverml-mr-pl-pr-left-right-text-lefttext-right. Icons that point (arrows, chevrons) getrtl:rotate-180. Phone numbers, emails and codes are showndir="ltr" - 44 px touch targets. Anything tappable is 44 px tall and wide, or becomes so on touch (
coarse:variant), with 8 px between targets. Use the shared components, they already follow it - 16 px inputs on mobile. Never set
text-smon a mobile input, iOS zooms the page - Accessible by default. Every input has a visible
Label(orFieldLabel), errors useFieldErrorso they are announced, icon only buttons have anaria-label, focus is visible (do not remove outlines), contrast is AA (4.5:1 body text), never use color alone to show state, honorprefers-reduced-motion(handled globally) - Every string is translated. No literal text in components, use the
next-intlmessages in en, fr and ar. Labels for spinners and skeletons are passed by the caller - Every async surface has states. Loading skeleton, empty state, error state. See below
- Fast. Server components by default, no client component for static content, images sized and lazy, no extra font. Think about a 3G phone with a cheap CPU
- Test both themes and both directions (light, dark, ltr, rtl) before you hand off a UI change
Patterns
Page layout
- one column on mobile with
px-4andgap-4orgap-6; frommd, a page header plus content in a max width container - primary action reachable by thumb: a full width
Buttonat the bottom on guest pages, in the page header on desktop - dashboard navigation is the collapsible
Sidebaron desktop (hotel switcher on top, user menu at the bottom) and a bottom tab bar on phones (the tabbed pages fromapps/dashboard/lib/nav.ts, then a "More" sheet with the rest, theme, language and sign out). Add a page toNAVonce and the sidebar, the tab bar, the top bar title and the command palette (cmd+k) all pick it up
Page building blocks
Exported from @le-hoetel/ui/components/*. They take already translated text, so they work in any app.
| Component | Use it for |
|---|---|
page-header PageHeader | The one title of a page, a quiet description and the page actions (full width buttons on a phone) |
section Section | A titled block of a page. Sections are separated by space, not by boxes inside boxes |
stat-card StatCard | One number with a label and a hint. Numbers are tabular |
data-table DataTable | A list of rows. Table from md up with a sticky header, a list of cards on a phone (pass card for a custom card, else the first column is the title). Pass empty for the empty state |
form-section FormSection | A group of fields with its title and help on the side from md, stacked on a phone |
sticky-form-actions StickyFormActions | Save and cancel. Sticks above the tab bar on a phone, sits at the end of the form from md |
inline-alert InlineAlert | A message that stays on the page: info, success, warning, error (the error is announced). Never color only, each tone has an icon |
confirm-dialog ConfirmDialog | Confirm a destructive or irreversible action, with the consequence in the text |
empty-state EmptyState | Nothing here yet: icon, one sentence, one next action. decorated adds the quiet zellige pattern, for first run screens only |
zellige-pattern ZelligePattern | The one Tunisian detail: a khatim tile in the text color at 7% opacity. Auth pages, 404 and first run empty states, nowhere else |
In the dashboard, PageHeader from @/components/page-header adds the page padding, and the single primary action of a page can go in the top bar with <TopBarAction href label icon /> (icon and label on desktop, icon only on a phone). Put page content in a p-4 md:p-6 wrapper.
Auth pages
Sign in, sign up, forgot password, reset password and accept invitation share one layout (apps/dashboard/app/(auth)/layout.tsx): a brand panel with the zellige pattern from lg, the form on a phone. Fields validate on blur, errors have an icon and are linked with aria-describedby, inputs have the right autocomplete, inputmode and enterkeyhint. ?next= keeps the page a signed out visitor wanted (an invitation link) through sign in and sign up, only same site paths are followed. Password reset uses better-auth with the notification module: outside live messaging the email is only logged, so locally read the token from the verification table (reset-password:<token>) and open /reset-password?token=<token>.
Forms
FieldGroupofFields, one column on mobile, two onmdonly when fields are short- each
FieldhasFieldLabel, the control, optionalFieldDescription, andFieldErrorbound to the validation error. Setdata-invalidon the field andaria-invalidon the control - the submit button is
<Button loading={pending}>, disabled while pending so a double tap cannot send twice - phone:
PhoneInputwith the dial code select. Default+216. Normalize and validate in the api - consent: separate unchecked
Checkboxper channel (email, whatsapp), each with its own wording, never pre checked - success and failure use a toast (
toast.success,toast.error) unless the user must act, then anInlineAlert - on a phone the save button is a
StickyFormActionsat the bottom; long forms are split intoFormSections
Lists and tables
- mobile: a list of cards or
Itemrows, one tap target per row. Do not shrink a table to fit - desktop: a table with start aligned text, numbers end aligned.
DataTabledoes both layouts - search and filters above the list. Pagination or "load more", not infinite scroll without a way to the footer
Overlays
Dialogfor short focused tasks on desktop,Sheet side="bottom"for the same task on mobile;AlertDialogonly for destructive confirmation (delete a guest, delete a hotel), with the consequence in the text- a
Sheetthat slides from a side usesstartorend, neverleftorright - every overlay has a title and a way to close it that is at least 44 px
Loading, empty and error
if (isPending) return <ListSkeleton rows={5} label={t("loading")} />
if (error) return <Alert variant="destructive">...</Alert>
if (!items.length)
return (
<EmptyState
icon={<UsersIcon />}
title={t("guests.empty.title")}
description={t("guests.empty.description")}
action={<Button>{t("guests.add")}</Button>}
/>
)Hotel branding
Hotel colors only change --primary (and one accent). Use bg-primary text-primary-foreground pairs, never bg-primary with a fixed text color. The admin panel warns when a hotel color fails contrast.