---
title: "Component patterns"
description: "Mobile first patterns and the UI rules every agent follows."
url: https://pr-194-docs.preview-lehoetel.findmalek.engineer/docs/component-patterns
markdown: https://pr-194-docs.preview-lehoetel.findmalek.engineer/docs/component-patterns.md
---

# Component patterns

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](https://pr-194-docs.preview-lehoetel.findmalek.engineer/docs/design-system.md).

## 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.** Colors, radius and fonts come from the theme. No hex, `rgb()`, `bg-white`, `text-black`, and no arbitrary values like `w-[317px]` or `text-[10px]` (the lint warns about them). Hotels re-theme `--primary`, 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. **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-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 (hotel switcher on top, user menu at the bottom) and a bottom tab bar on phones (the tabbed pages from `apps/dashboard/lib/nav.ts`, then a "More" sheet with the rest, theme, language and sign out). Add a page to `NAV` once 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

- `FieldGroup` of `Field`s, one column on mobile, two on `md` only when fields are short
- each `Field` has `FieldLabel`, the control, optional `FieldDescription`, and `FieldError` bound to the validation error. Set `data-invalid` on the field and `aria-invalid` on the control
- the submit button is `<Button loading={pending}>`, disabled while pending so a double tap cannot send twice
- phone: `PhoneInput` with the dial code select. Default `+216`. Normalize and validate in the api
- 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`
- on a phone the save button is a `StickyFormActions` at the bottom; long forms are split into `FormSection`s

### 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. `DataTable` does both layouts
- search and filters above the list. Pagination or "load more", not infinite scroll without a way to the footer

### 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

```tsx
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.
