Skip to Content

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

  1. Mobile first. Write the layout for 360 px wide, then add md: and lg:. The desktop version must be as good: use the extra width for columns, tables and side panels, not for stretching a phone layout
  2. Tokens only, light only. Colors, radius, shadows and fonts come from the theme. No hex, rgb(), bg-white, text-black, no dark: classes, and no arbitrary values like w-[317px] or text-[10px] (the lint warns about them). Guest pages re-theme --primary with the hotel color, so a hard coded color breaks branding
  3. Logical properties only. Arabic is right to left. Use ms- me- ps- pe- start- end- text-start text-end border-s border-e rounded-s rounded-e inset-x. Never ml- mr- pl- pr- left- right- text-left text-right. Icons that point (arrows, chevrons) get rtl:rotate-180. Phone numbers, emails and codes are shown dir="ltr"
  4. 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
  5. 16 px inputs on mobile. Never set text-sm on a mobile input, iOS zooms the page
  6. Accessible by default. Every input has a visible Label (or FieldLabel), errors use FieldError so they are announced, icon only buttons have an aria-label, focus is visible (do not remove outlines), contrast is AA (4.5:1 body text), never use color alone to show state, honor prefers-reduced-motion (handled globally)
  7. Every string is translated. No literal text in components, use the next-intl messages in en, fr and ar. Labels for spinners and skeletons are passed by the caller
  8. Every async surface has states. Loading skeleton, empty state, error state. See below
  9. 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
  10. 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-display is for the landing, the logo and the auth panel
  11. 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-4 and gap-4 or gap-6; from md, a page header plus content in a max width container
  • primary action reachable by thumb: a full width Button at the bottom on guest pages, in the page header on desktop
  • dashboard navigation is the collapsible Sidebar on 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 the hotel switcher, every group, language, feedback and sign out. The palette (the Search button in the top bar, also on phones) finds guests by name or phone digits through guests.find for the hotel on screen, and offers add guest, redeem code, new campaign and new offer to roles that may do them. Add a page to NAV in apps/dashboard/lib/nav.ts once, with its group, and the sidebar, the More sheet, the top bar breadcrumb and the command palette (cmd+k, or g then the item's shortcut key) all pick it up. Every one of those, and the phone's bottom tabs, shows only what the viewer may open: give a NAV entry that works on the hotel on screen a hotel field (any, or the permission from packages/auth/src/access.ts that the api asks for)

Page building blocks

Exported from @ritorno/ui/components/*. They take already translated text, so they work in any app.

ComponentUse it for
page-header PageHeaderThe 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 SectionA titled block of a page. Sections are separated by space, not by boxes inside boxes
stat-card StatCardOne 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 ChartCardA chart with its title, a control slot for the period picker and an empty state shown when isEmpty
data-list DataListThe 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 NumA 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 DataTableThe 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 StatusBadgeA state chip: success, warning, danger, info, neutral on the soft token fills, each with an icon. The text carries the meaning
page-state PageStateWhat a page or a panel shows instead of content: loading (skeleton), empty (firstRun adds the pattern), error (an InlineAlert), forbidden
form-section FormSectionA group of fields with its title and help on the side from md, stacked on a phone
sticky-form-actions StickyFormActionsSave and cancel. Sticks above the tab bar on a phone, sits at the end of the form from md
inline-alert InlineAlertA message that stays on the page: info, success, warning, error (the error is announced). Never color only, each tone has an icon
confirm-dialog ConfirmDialogConfirm 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 EmptyStateNothing here yet: icon, one sentence, one next action. decorated adds the quiet zellige pattern, for first run screens only
zellige-pattern ZelligePatternThe 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

  • FieldGroup of fields, one column on mobile, two on md only when fields are short
  • every field is a FormField (@ritorno/ui/components/form-field): label, required marker or optional text, the control, then the hint or the inline error with its icon. It hands the control id, aria-invalid and aria-describedby, so errors are announced and look the same everywhere
  • one Select (@ritorno/ui/components/select) for every choice from a list: pass options, then value and onValueChange, or name and defaultValue in a plain server form (it posts a hidden input). No hand rolled <select>.
  • Input with type or inputMode email, tel or url is dir="ltr" by default. Slugs, promo codes and other codes set dir="ltr" themselves
  • SegmentedControl for 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 an href (and linkComponent={Link}) when the choice lives in the url, like the metrics period. Past five options, use Select
  • the submit button is <Button loading={pending}>, disabled while pending so a double tap cannot send twice
  • phone: PhoneInput with usePhoneNumber and its searchable country picker (loaded on open). Always starts on +216, never preselected from the browser (why). A typed or pasted + or 00 switches the country. Validate in the api and show the refused field on the field
  • consent: separate unchecked Checkbox per 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 an InlineAlert
  • while the analytics consent card is open on a phone, StickyFormActions stops sticking: the actions, the card and the tabs stacked would cover the form
  • on a phone the save button is a StickyFormActions at the bottom; long forms are split into FormSections

Lists and tables

  • mobile: a list of cards or Item rows, one tap target per row. Do not shrink a table to fit
  • desktop: a table with start aligned text, numbers end aligned. DataList does both layouts
  • a filter form with more than two fields starts folded behind a "Filters" button on a phone, so the list is on the first screen (AuditFilters)
  • search and filters above the list. Long lists load more on scroll with a "load more" button as the fallback (see below), never a page without one

Long lists and caching

Guests, messages, unhappy guest cases and redemptions page by cursor, hotel scoped:

  • api: limit and cursor in, nextCursor out (null at the end). Use packages/orpc/src/lib/cursor.ts, which keeps the timestamp's microseconds so rows are not skipped
  • dashboard: the query options live in apps/dashboard/lib/lists.ts. The server prefetches the first page, the browser uses useInfiniteQuery, and LoadMore (components/load-more.tsx) fetches the next one near the end of the list
  • the hotel is the one the data comes from: currentHotel() in lib/api.ts, not hotel.mine().activeId, which ignores the hotel an admin opened. These list keys end with it and every page sends it as x-hotel-id, so a switch in another tab fails the next page instead of mixing hotels (the proxy keeps a header the browser sent). The activity log does not send it yet
  • the app layout gives each hotel its own query cache, so no query shows another hotel's cached rows after a switch
  • a first page that fails shows LoadError with a retry. The audit logs use the same LoadMore
  • stale times: guests 60 s, unhappy guests and redemptions 30 s, messages 15 s (delivery statuses move)
  • a mutation that changes a guest or a case calls useRefreshLists()

Server pages and refused data

prefetchQuery swallows errors, and the client useSuspenseQuery then fetches during the server render, where there is no browser client: the page stays a skeleton for ever. When a role can be refused, use fetchQuery inside call, catch isForbidden and render PageState kind="forbidden" (see the campaigns page).

Text written by people

Offer titles and texts and guest comments can be in another language than the page. Wrap them in <bdi> so their punctuation stays on the right side in Arabic.

Overlays

  • Dialog for short focused tasks on desktop, Sheet side="bottom" for the same task on mobile; AlertDialog only for destructive confirmation (delete a guest, delete a hotel), with the consequence in the text
  • a Sheet that slides from a side uses start or end, never left or right
  • 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.

On this page