# The site toolkit (React)

> The hooks and components every Vorjo site uses for its shop, blog, content, forms, bookings, reviews and SEO.

Every website has `src/lib/vorjo.jsx`. It wraps the [Shop and content API](/developers/commerce-api) in React hooks and ready-made components. Vorjo replaces this file on every build, so don't edit it; build on top of it.

```jsx
import { useProducts, AddToCartButton, Price, Seo } from "./lib/vorjo";

export default function Shop() {
  const { products, loading } = useProducts({ sort: "newest", limit: 12 });
  if (loading) return <p>Loading…</p>;
  return (
    <>
      <Seo title="Shop" description="Fresh cakes, baked to order." />
      {products.map((p) => (
        <article key={p.id}>
          <h2>{p.title}</h2>
          <Price product={p} />
          <AddToCartButton product={p} />
        </article>
      ))}
    </>
  );
}
```

## Shop

| Export | Returns or does |
| --- | --- |
| `useStore()` | Store settings: currency, payments, pickup |
| `useProducts({ collection, q, tag, sort, limit })` | `{ products, total, loading, error }` |
| `useProduct(handle)` | `{ product, loading, error }` |
| `useCollections()` | `{ collections, loading }` |
| `useVariant(product)` | `{ chosen, variant, choose }` for option pickers |
| `findVariant(product, chosen)` | The variant matching the chosen options, or `null` when that combination does not exist (then `<AddToCartButton variant={null}>` shows "Unavailable" and is disabled) |
| `useCart()` | `{ items, count, subtotal, add, setQty, remove, clear, open, checkoutUrl }` |
| `openCart()`, `openSearch(q)` | Open Vorjo's cart drawer or search |
| `useSearch(q, { limit })` | `{ results, loading }` (2+ characters) |
| `useCustomer()` | `{ customer, loading, accounts }` |
| `useOrder(ref)`, `lookupOrder(number, email)` | Read an order |
| `formatPrice(value, currency)` | A formatted price |
| `usePolicies()` | `[{ key, label, url }]` for live policy pages |
| `cartUrl`, `checkoutUrl`, `trackOrderUrl`, `accountUrl`, `loginUrl`, `signupUrl`, `searchUrl` | Addresses of Vorjo's pages |

Components: `AddToCartButton`, `BuyNowButton`, `Price`, `VariantPicker`, `QuantityPicker`, `StockBadge`, `CartButton`, `SearchButton`, `SearchBox`, `AccountButton` (hidden when accounts are off). Their default looks take the site's colours: set `--vorjo-accent`, `--vorjo-accent-text`, `--vorjo-radius`, `--vorjo-border` and `--vorjo-surface` in `:root` (or fill in `vorjo.json` `theme`), then refine with `className` (`QuantityPicker` also takes `buttonClassName` and `inputClassName`, `ProductReviews` takes `classNames: { head, summary, list, item, form, field, button }`).

## Blog and content

| Export | Returns or does |
| --- | --- |
| `usePosts({ tag, category, limit, offset })` | `{ posts, total, tags, categories, loading, error }` |
| `usePost(slug)` | `{ post, loading, error }` |
| `useCollection(name)` / `getCollection(name)` | A content collection's items (shown at once from `vorjo.json`, then refreshed) |
| `Markdown({ text })`, `markdownToHtml(md)` | Safe Markdown rendering |

## Forms and bookings

| Export | Returns or does |
| --- | --- |
| `useForm(name)` | `{ submit, status, error, sending, sent, reset }` |
| `submitForm(name, data)` | Sends an object, `FormData` or a `<form>` |
| `Honeypot()` | A hidden spam-trap field to put in every form. Every request also carries the page's stamp (`_vt`) and, with a captcha Gear on, its token (`_captcha`), added by the toolkit; Vorjo's spam shield checks them |
| `NewsletterForm({ placeholder, buttonLabel, withName, doneText, pendingText, note, className, inputClassName, buttonClassName, messageClassName })` | A complete newsletter signup form (email, optional name, button, thank-you, errors, honeypot). Subscribers are saved to the owner's Contacts tagged Newsletter, with double opt-in if the owner turned it on, and sent to their email Gear (Mailchimp, Klaviyo, Brevo, MailerLite, Kit). No `vorjo.json` entry needed. |
| `BookingPicker({ service \| serviceId, onSelect, value, onChange, staffId, withForm, labels, className, classNames })` | The booking date and time picker: a month calendar (free days highlighted, full, closed and past days greyed, Next available), the day's times grouped Morning, Afternoon and Evening as start – end, places left for classes, a With chooser when several people do the service, and a note when the visitor's time zone differs (times are always the business's). `onSelect` gets `{ date, time, start, end, staffId, service }`; pass `start` and `staffId` to `book()`. `withForm` adds the details form, payment choice and confirmation. Style it with `--vorjo-accent`, `--vorjo-accent-text`, `--vorjo-radius`, `--vorjo-surface` and `--vorjo-border`. Loads a month in one request (`GET bookings/days`). |
| `useNewsletter()` | `{ subscribe(email, name?), status, error, sending, done, pending, reset }` for a signup form of your own. `status` is `"subscribed"`, or `"pending"` when the subscriber must confirm by email first. Posts to `/_vorjo/newsletter`. |
| `useBooking()` | `{ services, staff, staffChoice, payments, days, timezone, currency, slots(service, date, staff), freeDays(service, from, to, staff), book({ service, start, staff, name, email, phone, note, pay }) }`. Each service has `payNow`, `payText` (for example "$20 deposit, $60 at your visit") and `rule` (the cancellation rule). When a service takes money, `book()` sends the customer on to pay; the time is held for 10 minutes and Vorjo shows the confirmation. Customers get a link to change or cancel (`/_vorjo/booking/<link>`, hosted by Vorjo). Older sites keep calling `book()` without paying and their bookings are paid at the visit. |

## Reviews and Gears

`Stars`, `ReviewStars({ product })`, `ProductReviews({ product })`, `ReviewsCarousel()`, and `GearSlot({ name, product })`, where installed widget Gears appear (`home`, `product`, `footer`, `checkout`, and on product pages `product.price.after`, `product.stock.after`, `product.cart.before`, `product.cart.after`; pass the `product` there). `SaleCountdown({ product, variant })` shows a sale's "Sale ends in" timer; `Price` shows it on its own on product pages (`countdown={false}` hides it). `trackEvent(event, data)` passes shop events to tracking Gears.

## Pages and SEO

| Export | Does |
| --- | --- |
| `VorjoPage()` | Shows one of Vorjo's locked pages (cart, account, login, track, search, policies) inside the site's layout |
| `Seo({ title, description, image, type, noindex, jsonLd })` | The page's head tags and structured data |
| `faqJsonLd(items)`, `howToJsonLd(name, steps)` | Structured data helpers |
| `productPath`, `collectionPath`, `postPath` | Standard addresses |
| `ErrorBoundary` | Catches errors in part of a page |

Sites must link to Vorjo's checkout (`checkoutUrl`) and never build their own checkout page.

Vorjo's pages (cart drawer, cart, checkout, login, sign-up, account, order and tracking) take their colours from vorjo.json `"theme"`: `{ "mode": "light" | "dark", "background", "surface" (panels and cards), "text", "muted", "border", "accent" (buttons), "accentText", "font", "radius" }`, colours as `#rrggbb`. `shop.checkout` can carry the same tokens in `"colors"`. Only colours change: the layout of these pages is fixed, and text, muted text and button text are kept at a contrast of at least 4.5:1 (adjusted automatically). The owner's choice in Settings › Checkout wins.

## Accessible UI pieces

New sites also have `src/components/ui/`: a mobile menu, modal, accordion and tabs built on the browser's own `<dialog>` and `<details>` elements and ARIA tabs. They have no dependencies (about 2 KB gzipped) and add behaviour only, so you style everything with `className`. Usage notes are at the top of each file.

```jsx
import { Sheet, Accordion, AccordionItem, Tabs, TabList, Tab, TabPanel } from "./components/ui";

<Sheet side="right" title="Menu" trigger={<button aria-label="Open menu">☰</button>} className="bg-white p-8">…links…</Sheet>

<Accordion single className="divide-y">
  <AccordionItem title="Do you take walk-ins?" className="py-4">Yes, until 6 pm.</AccordionItem>
</Accordion>

<Tabs defaultValue="starters">
  <TabList label="Menu"><Tab value="starters">Starters</Tab><Tab value="mains">Mains</Tab></TabList>
  <TabPanel value="starters">…</TabPanel><TabPanel value="mains">…</TabPanel>
</Tabs>
```

| Export | Does |
| --- | --- |
| `Dialog({ open, onOpenChange, trigger, title, side })` | A modal on `<dialog>`: focus moves in and stays in, the page behind can't scroll, Escape, the backdrop, a link click or a page change closes it, and focus returns to the trigger |
| `Sheet`, `Drawer` | The same, sliding in from a side (`side`: `left`, `right`, `top` or `bottom`; `right` by default) |
| `Accordion({ single })`, `AccordionItem({ title, defaultOpen })` | FAQs on `<details>`; `single` keeps one open at a time. Answers stay in the HTML, so search engines read them |
| `Tabs({ defaultValue })`, `TabList({ label })`, `Tab({ value })`, `TabPanel({ value })` | ARIA tabs with arrow keys, Home and End. Every panel stays in the HTML; only the chosen one shows |
