# Ynch screens and styling

How to lay out a screen and style it with theme tokens.

Full docs: https://docs.ynch.ai/llms.txt (every page is markdown at its address plus `.md`).

## Rules

1. Edit only files inside `.ynch`. Never change `projectId` in `project.json`, and never edit `ynch.lock`.
2. Use only the components, props, style options and icons listed here. There are no custom components, no CSS, no JavaScript and no SQL. An unknown property is an error.
3. Every JSON file starts with `"schemaVersion": "1.0.0"`. Strict JSON: no comments, no trailing commas.
4. Ids are lowercase letters, digits and hyphens, starting with a letter. A file's name is its id.
5. After every change run `npx ynch check` and fix everything it reports. Do not remove a requested feature to silence an error.
6. Never write passwords, keys or tokens into any file.
7. Do not run `ynch upload`. The person uploads and approves each version in Ynch Studio.

## Layout

- A screen file is `{"schemaVersion":"1.0.0","id":"<file name>","root":{...Screen}}`.
- `Screen` and `Stack` lay children out top to bottom, `Row` side by side, `Grid` in 1 or 2 columns. `Card` groups content.
- Nest at most 12 levels. Component ids are unique within a screen.

## Style options (the only ones)

- `color`: $color.background, $color.surface, $color.primary, $color.secondary, $color.text, $color.muted, $color.border, $color.error, $color.success
- `backgroundColor`: $color.background, $color.surface, $color.primary, $color.secondary, $color.text, $color.muted, $color.border, $color.error, $color.success
- `typography`: $typography.body, $typography.title, $typography.caption
- `padding`: $spacing.none, $spacing.xs, $spacing.sm, $spacing.md, $spacing.lg, $spacing.xl
- `margin`: $spacing.none, $spacing.xs, $spacing.sm, $spacing.md, $spacing.lg, $spacing.xl
- `gap`: $spacing.none, $spacing.xs, $spacing.sm, $spacing.md, $spacing.lg, $spacing.xl
- `borderColor`: $color.background, $color.surface, $color.primary, $color.secondary, $color.text, $color.muted, $color.border, $color.error, $color.success
- `borderWidth`: whole number, 0 to 4
- `radius`: $radius.none, $radius.sm, $radius.md, $radius.lg
- `shadow`: none, subtle, medium
- `width`: auto, fill, half
- `height`: auto, fill
- `align`: start, center, end, stretch
- `justify`: start, center, end, space-between
- `flex`: whole number, 0 to 1
- `textAlign`: left, center, right

Token references: `$color.<name>` (background, surface, primary, secondary, text, muted, border, error, success), `$spacing.<none|xs|sm|md|lg|xl>`, `$radius.<none|sm|md|lg>`, `$typography.<body|title|caption>`. No raw colors or pixel values in `style`.

## Presets

Define repeated looks once in `theme.json` under `presets` and use them with `"preset": "name"`. A component's `style` is applied after its preset.

## Components (18)

- `Screen` (layout; children: many): The root of every screen file. It sets the title, whether the content scrolls and whether it stays inside the safe area. Props: `title`? (text, up to 200 characters), `safeArea`? (true or false), `scroll`? (true or false).
- `Stack` (layout; children: many): Lays its children out top to bottom. Props: none.
- `Row` (layout; children: many): Lays its children out side by side. Props: none.
- `Grid` (layout; children: many): Arranges its children in one or two equal columns. Props: `columns` (whole number, 1 to 2).
- `Card` (layout; children: many): A container, usually styled as a raised panel. Props: none.
- `Divider` (layout; children: none): A thin line between sections. Props: none.
- `Text` (visual; children: none): Shows text: either fixed text or a value from your data. Props: `text`? (text, up to 2000 characters).
- `Image` (visual; children: none): Shows an image bundled with the app. Props: `asset` (text in a fixed format), `alt` (text, up to 200 characters), `fit` (contain, cover).
- `Icon` (visual; children: none): Shows one of the built-in icons. Props: `name` (activity, plus, check, chevron-right, trash, home, edit), `label` (text, up to 200 characters).
- `Badge` (visual; children: none): A short label in a pill. Props: `text`? (text, up to 200 characters).
- `Button` (visual; children: none): A button that goes to another screen or runs an operation. Props: `label` (text, up to 200 characters), `disabled`? (true or false).
- `Input` (input; children: none): A single-line field for text, a number or an email address. Props: `label` (text, up to 200 characters), `required`? (true or false), `disabled`? (true or false), `inputType` (text, number, email), `placeholder`? (text, up to 200 characters).
- `TextArea` (input; children: none): A multi-line text field. Props: `label` (text, up to 200 characters), `required`? (true or false), `disabled`? (true or false), `maxLength`? (whole number, 1 to 10000).
- `Select` (input; children: none): Lets the user pick one option from a list. Props: `label` (text, up to 200 characters), `required`? (true or false), `disabled`? (true or false), `options` (list of 1 to 50 items).
- `Switch` (input; children: none): An on/off switch. Props: `label` (text, up to 200 characters), `required`? (true or false), `disabled`? (true or false).
- `DatePicker` (input; children: none): Lets the user pick a date. Props: `label` (text, up to 200 characters), `required`? (true or false), `disabled`? (true or false).
- `RecordList` (data; children: one): Loads rows with a list operation and draws its one child once per row. Props: `pageSize` (whole number, 1 to 100), `emptyText` (text, up to 200 characters).
- `Form` (data; children: many): Collects values for one model and saves them with an insert or update operation. Props: `model` (text in a fixed format), `submitLabel` (text, up to 200 characters).
