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, light only. Colors, radius, shadows and fonts come from the theme. No hex,
rgb(),bg-white,text-black, nodark:classes, and no arbitrary values likew-[317px]ortext-[10px](the lint warns about them). Guest pages re-theme--primarywith the hotel color, 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
- Ink actions, one blue. The primary action is the black pill (
bg-primary), blue is for links (text-blue-700), focus and accents, never a button fill. No serif inside the app:font-displayis for the landing, the logo and the auth panel - Test both directions (ltr in en or fr, rtl in ar) at phone and desktop width 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 (logo and hotel switcher on top, the Today, Guests, Grow and Insights groups, then Settings and Platform pinned at the bottom, feedback and the user menu in the footer) and on phones a bottom tab bar (Home, Guests, a center Add guest, Redeem, Inbox) plus a "More" sheet from the top bar with every group, language, feedback and sign out. Add a page toNAVinapps/dashboard/lib/nav.tsonce, with its group, and the sidebar, the More sheet, the top bar breadcrumb and the command palette (cmd+k, orgthen the item'sshortcutkey) all pick it up
Page building blocks
Exported from @ritorno/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, breadcrumbs, one primary action at the inline end and optional secondaryActions before it (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 caption label, a hint, a delta chip (arrow, signed value from formatDelta, context words and tone, never color only) and a link to the full list. Numbers are tabular |
chart-card ChartCard | A chart with its title, a control slot for the period picker and an empty state shown when isEmpty |
data-list DataList | The list of a page: filters slot, DataTable underneath (table from md up, cards on a phone), loading skeleton rows, empty, and pagination with previous and next as links or handlers. Page mode passes range (from pageWindow in @ritorno/ui/lib/pagination) and the numbers are isolated left to right inside the translated sentence, cursor mode just passes the targets it has |
num Num | A number inside text: formatted with formatNumber from @ritorno/ui/lib/number (locale marks, Western digits in every language) and isolated in a bdi dir="ltr", so +12% never reads 12%+ in Arabic. Use it for counts in badges and sentences |
data-table DataTable | The table part of DataList, for a list without filters or paging. Pass card for a custom phone card, else the first column is the title |
status-badge StatusBadge | A state chip: success, warning, danger, info, neutral on the soft token fills, each with an icon. The text carries the meaning |
page-state PageState | What a page or a panel shows instead of content: loading (skeleton), empty (firstRun adds the pattern), error (an InlineAlert), forbidden |
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. typedConfirmation={{ label, expected }} keeps the button disabled until the slug or name is typed (case and outer spaces ignored) |
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 is the only place a page title lives: the top bar shows a breadcrumb, never the title. The single primary action goes in its action prop. Put page content in a p-4 md:p-6 wrapper. app/(app)/loading.tsx, error.tsx and not-found.tsx render inside the shell, and sticky table headers sit under --app-header so they clear the top bar and the admin viewing banner.
Auth pages
Sign in, sign up, forgot password, reset password and accept invitation share one layout (apps/dashboard/app/(auth)/layout.tsx): a PixelSky brand panel with the italic headline from lg, a short sky band above 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. Sign up is for invited emails only: anyone else gets the notInvited error. 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
FieldGroupof fields, one column on mobile, two onmdonly when fields are short- every field is a
FormField(@ritorno/ui/components/form-field): label,requiredmarker oroptionaltext, the control, then thehintor the inlineerrorwith its icon. It hands the controlid,aria-invalidandaria-describedby, so errors are announced and look the same everywhere - one
Select(@ritorno/ui/components/select) for every choice from a list: passoptions, thenvalueandonValueChange, ornameanddefaultValuein a plain server form (it posts a hidden input). No hand rolled<select>. The only native select left is the dial code insidePhoneInput, where the picker sits inside the input and the native wheel is the expected phone control InputwithtypeorinputModeemail,telorurlisdir="ltr"by default. Slugs, promo codes and other codes setdir="ltr"themselvesSegmentedControlfor two to five options that should stay visible (period, language, a preference). Native radios underneath, so it works in a plain form. Give every option anhref(andlinkComponent={Link}) when the choice lives in the url, like the metrics period. Past five options, useSelect- 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.
DataListdoes 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 <PageState kind="loading" label={t("loading")} />
if (error) return <PageState kind="error" title={t("error.title")} action={<Button onClick={retry}>{t("retry")}</Button>} />
if (!items.length)
return (
<PageState
kind="empty"
icon={<UsersIcon />}
title={t("guests.empty.title")}
description={t("guests.empty.description")}
action={<Button>{t("guests.add")}</Button>}
/>
)Examples
<FormField id="channel" label={t("channel")} hint={t("channelHint")} error={form.error("channel")} required>
{(aria) => (
<Select
{...aria}
value={values.channel}
onValueChange={(channel) => form.set("channel", channel)}
options={CHANNELS.map((value) => ({ value, label: t(`channel.${value}`) }))}
/>
)}
</FormField>
<SegmentedControl
label={t("periodLabel")}
value={String(days)}
linkComponent={Link}
options={PERIODS.map((period) => ({ value: String(period), label: t("period.days", { count: period }), href: `?days=${period}` }))}
/>
const page = pageWindow({ page: Number(params.page), pageSize: 20, total })
<DataList
caption={t("title")}
filters={<Input type="search" aria-label={t("search")} />}
rows={rows}
columns={columns}
getRowKey={(row) => row.id}
empty={<PageState kind="empty" title={t("empty")} />}
linkComponent={Link}
pagination={{
previousLabel: t("previous"),
nextLabel: t("next"),
range: { ...page, total, locale, label: (n) => t.rich("range", { from: () => n.from, to: () => n.to, total: () => n.total }) },
previous: page.hasPrevious ? { href: `?page=${page.page - 1}` } : undefined,
next: page.hasNext ? { href: `?page=${page.page + 1}` } : undefined,
}}
/>
<StatCard
label={t("captured")}
value={formatNumber(total, locale)}
delta={{ direction: "up", value: formatDelta(change, locale, { style: "percent" }), context: t("vsLast") }}
/>
<StatusBadge tone="warning">{t("status.scheduled")}</StatusBadge>Hotel branding
Hotel colors only change --primary (and one accent), and only on guest pages, emails and the dashboard previews; the dashboard shell stays ink. 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 on the page or a surface.