Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .changeset/roomy-forms-reflow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
"@tailor-platform/app-shell": minor
---

Add `FormLayout` for laying out form fields in a responsive grid that reflows by its container's width, so one form definition fits a Dialog, a Sheet or a page. It comes with `FormLayout.Section` (card or plain fieldset groups), `FormLayout.Item` and a sticky-capable `FormLayout.Actions`.

```tsx
<Form id="po-form" onFormSubmit={save}>
<FormLayout columns={2}>
<FormLayout.Section title="Supplier">
<Field.Root name="supplier">
<Field.Label required>Supplier</Field.Label>
<Combobox items={suppliers} required />
</Field.Root>
<Field.Root name="notes" span="full">
<Field.Label>Notes</Field.Label>
<Textarea />
</Field.Root>
</FormLayout.Section>
</FormLayout>
</Form>
```

Supporting additions:

- `Field.Root` and `Fieldset.Root` take `span` (`2 | 3 | "full"`) to widen a field inside `FormLayout`. A field holding a `Textarea` takes the full row unless it sets its own `span`.
- `Field.Label` takes `required` to show a visual-only required marker.
- `Field.Value` shows a read-only value in the control's place, at an input's height, so it lines up with editable fields.
- `Layout` takes `maxWidth` (`"md" | "lg" | "xl"`) to centre a page and cap its width, header included.
- `Dialog.Content` takes `size` (`"sm" | "md" | "lg" | "xl"`, default `"md"`, matching `Sheet.Content`, always leaving a 1rem margin on each side), and the new `Dialog.Body` scrolls long content while the header and footer stay in view.

Visual changes to existing components (snapshots of open dialogs and sheets will show the new classes):

- `Dialog.Content` is now a flex column instead of a grid, so `Dialog.Body` can scroll while the header and footer stay in view. Direct children other than `Dialog.Body` don't shrink, so a tall dialog without a `Body` still scrolls as a whole. Its height limit and default width are unchanged. If you made `Dialog.Content` a flex column yourself and gave a child `min-h-0 flex-1 overflow-y-auto`, wrap that content in `Dialog.Body` instead; see the migrations guide. `ActivityCard`'s "All activities" dialog now does this.
- `Dialog.Footer` and `Sheet.Footer` right-align their buttons at their natural width at every size. Previously `Sheet.Footer` stacked buttons full width, and `Dialog.Footer` did so below `sm`. Buttons now show in source order from left to right, so put the primary button last.
96 changes: 60 additions & 36 deletions docs-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,11 @@
"claims": [],
"symbols": ["Dialog"],
"hashes": {
"typeSurface": "b1614970f950ceb6",
"outline": "5ba9ca06b0385f80",
"snapshot": "86c672f1c58f27fd",
"outputMd": "cd9fa9c4b8ccb108",
"examples": "f5540beaf3f36609"
"typeSurface": "970c4f4b295f98ac",
"outline": "eebbc84b7a4c6ad5",
"snapshot": "7883d34cf5f88fe5",
"outputMd": "7117e72d36b059b0",
"examples": "815276da21f4140a"
}
},
"document-collection": {
Expand Down Expand Up @@ -739,9 +739,9 @@
"symbols": ["Form", "FormProps"],
"hashes": {
"typeSurface": "7b374d45d53d4535",
"outline": "fc23844ab3a67563",
"snapshot": "5d7a7904c5256f29",
"outputMd": "c97c3d6e426d8b29",
"outline": "297c00086c7f4894",
"snapshot": "3f1e5fb2bc4fce7a",
"outputMd": "75ba9388fea50563",
"examples": "c56460c1a93d532b"
}
},
Expand All @@ -762,6 +762,29 @@
"examples": "abd682c0980d1e21"
}
},
"form-layout": {
"slug": "form-layout",
"kind": "code-backed",
"outline": "docs-src/components/form-layout.docs.outline.md",
"output": "docs/components/form-layout.md",
"examples": "docs-src/components/form-layout.docs.examples.tsx",
"sources": ["packages/core/src/components/form-layout/**"],
"claims": [],
"symbols": [
"FormLayout",
"FormLayoutActionsProps",
"FormLayoutItemProps",
"FormLayoutProps",
"FormLayoutSectionProps"
],
"hashes": {
"typeSurface": "6210ea28649026a8",
"outline": "7c64761beea57d38",
"snapshot": "b222cdafb62c9883",
"outputMd": "bdbe2cece53829eb",
"examples": "56c8f6cc9667bb78"
}
},
"form-modal": {
"slug": "form-modal",
"kind": "prose",
Expand All @@ -773,10 +796,10 @@
"symbols": [],
"hashes": {
"typeSurface": null,
"outline": "8adb1ebff87dda10",
"outline": "648b627bff7d3515",
"snapshot": null,
"outputMd": "a0d3c952b0b10351",
"examples": "2d4e2f50bb0d2ef7"
"outputMd": "a075c90ec7cdced3",
"examples": "be70ebcbf100eacb"
}
},
"form-sectioned": {
Expand All @@ -790,10 +813,10 @@
"symbols": [],
"hashes": {
"typeSurface": null,
"outline": "af8e73b07f01cef4",
"outline": "3ce14475d1bf8029",
"snapshot": null,
"outputMd": "d31cd3ae6ad0790c",
"examples": "e66de48697da4786"
"outputMd": "a0f1f5c5de01e16b",
"examples": "abe3509c18a16dd3"
}
},
"form-single-page": {
Expand All @@ -807,10 +830,10 @@
"symbols": [],
"hashes": {
"typeSurface": null,
"outline": "828493750c9e7dbf",
"outline": "392846644fde9613",
"snapshot": null,
"outputMd": "10a0f4d91a120752",
"examples": "c160f4883aff98f3"
"outputMd": "4a39515f08e16dc4",
"examples": "71dd598170e178cb"
}
},
"form-wizard": {
Expand All @@ -824,10 +847,10 @@
"symbols": [],
"hashes": {
"typeSurface": null,
"outline": "fbc09ef9994494cb",
"outline": "fbad71e167b466f0",
"snapshot": null,
"outputMd": "851afb4672da6673",
"examples": "157ff03dc999d3d3"
"outputMd": "b082d3078b01563c",
"examples": "a00df2055b7095ec"
}
},
"global-header-layout": {
Expand Down Expand Up @@ -1079,9 +1102,9 @@
"symbols": ["Layout", "LayoutProps"],
"hashes": {
"typeSurface": "c7e8fec79020d657",
"outline": "b5f77b82d71d0eae",
"snapshot": "03dedb3cc14b1eaf",
"outputMd": "3b8bf269c15e2fa5",
"outline": "6a972f8849f5e805",
"snapshot": "7ca9322e311ae48a",
"outputMd": "5c81d60ef3fbd409",
"examples": "c34348bb6d088ad1"
}
},
Expand Down Expand Up @@ -1130,9 +1153,9 @@
"symbols": [],
"hashes": {
"typeSurface": null,
"outline": "e88bb360eb853c34",
"outline": "9b0cdbbc8a18b897",
"snapshot": null,
"outputMd": "19ca77c7802ca5f6",
"outputMd": "0bd27d80c5eff763",
"examples": null
}
},
Expand Down Expand Up @@ -1267,7 +1290,7 @@
"hashes": {
"typeSurface": "e760949efcbe4c38",
"outline": "3c51b0bd7cc290ab",
"snapshot": "8c75bb4dad18f7b8",
"snapshot": "c6018473d903f2af",
"outputMd": "0be1c6430a4b7ec1",
"examples": "8f93acd2d478616f"
}
Expand Down Expand Up @@ -1570,7 +1593,7 @@
"hashes": {
"typeSurface": "95d4d96e2c7cad05",
"outline": "1044541495fff6fd",
"snapshot": "e63b60420ec5113f",
"snapshot": "1e3e80f9664bcd2b",
"outputMd": "6010470f3c41538a",
"examples": "7e372a50c2939317"
}
Expand Down Expand Up @@ -1845,15 +1868,16 @@
"packages/core/skills/app-shell-patterns/references/components/default-header.md": "375e55f4b12fa2be",
"packages/core/skills/app-shell-patterns/references/components/default-sidebar.md": "9b1672c71b6db3ff",
"packages/core/skills/app-shell-patterns/references/components/description-card.md": "8930a410d7d45f89",
"packages/core/skills/app-shell-patterns/references/components/dialog.md": "cd9fa9c4b8ccb108",
"packages/core/skills/app-shell-patterns/references/components/dialog.md": "7117e72d36b059b0",
"packages/core/skills/app-shell-patterns/references/components/document-progress-card.md": "cabfb86627aefd6f",
"packages/core/skills/app-shell-patterns/references/components/filter-rail.md": "12021e27b57f45e9",
"packages/core/skills/app-shell-patterns/references/components/form.md": "c97c3d6e426d8b29",
"packages/core/skills/app-shell-patterns/references/components/form.md": "75ba9388fea50563",
"packages/core/skills/app-shell-patterns/references/components/form-layout.md": "bdbe2cece53829eb",
"packages/core/skills/app-shell-patterns/references/components/global-header-layout.md": "fe86450720c4d586",
"packages/core/skills/app-shell-patterns/references/components/grid.md": "d048e972ae8aba3e",
"packages/core/skills/app-shell-patterns/references/components/input.md": "876dca4c3b3bc9c5",
"packages/core/skills/app-shell-patterns/references/components/item-list.md": "0190e797cd8ed318",
"packages/core/skills/app-shell-patterns/references/components/layout.md": "3b8bf269c15e2fa5",
"packages/core/skills/app-shell-patterns/references/components/layout.md": "5c81d60ef3fbd409",
"packages/core/skills/app-shell-patterns/references/components/menu.md": "05e75c52c12c3c32",
"packages/core/skills/app-shell-patterns/references/components/metric-card.md": "4742120c07f00991",
"packages/core/skills/app-shell-patterns/references/components/select.md": "7e20d26620366d82",
Expand Down Expand Up @@ -1899,18 +1923,18 @@
"packages/core/skills/app-shell-patterns/references/api/use-time-zone.md": "717d6989930fb8c8",
"packages/core/skills/app-shell-patterns/references/api/use-toast.md": "3f763c8074704709",
"packages/core/skills/app-shell-patterns/references/patterns/form-composer.md": "ed187ac3a0773d3d",
"packages/core/skills/app-shell-patterns/references/patterns/form-modal.md": "a0d3c952b0b10351",
"packages/core/skills/app-shell-patterns/references/patterns/form-sectioned.md": "d31cd3ae6ad0790c",
"packages/core/skills/app-shell-patterns/references/patterns/form-single-page.md": "10a0f4d91a120752",
"packages/core/skills/app-shell-patterns/references/patterns/form-wizard.md": "851afb4672da6673",
"packages/core/skills/app-shell-patterns/references/patterns/form-modal.md": "a075c90ec7cdced3",
"packages/core/skills/app-shell-patterns/references/patterns/form-sectioned.md": "a0f1f5c5de01e16b",
"packages/core/skills/app-shell-patterns/references/patterns/form-single-page.md": "4a39515f08e16dc4",
"packages/core/skills/app-shell-patterns/references/patterns/form-wizard.md": "b082d3078b01563c",
"packages/core/skills/app-shell-patterns/references/patterns/i18n-labels.md": "d9f0851d9c98ecfe",
"packages/core/skills/app-shell-patterns/references/patterns/interaction-confirm.md": "2db70f423c6fdf97",
"packages/core/skills/app-shell-patterns/references/patterns/interaction-multi-select.md": "253fcea1c4e5a42c",
"packages/core/skills/app-shell-patterns/references/patterns/interaction-toast.md": "f68bdab855730f48",
"packages/core/skills/app-shell-patterns/references/pages/document-collection.md": "e79d9120d86db198",
"packages/core/skills/app-shell-patterns/references/pages/document-detail.md": "e07c7fee2478a21d",
"packages/core/skills/app-shell-patterns/SKILL.md": "18efee79280174e7",
"packages/core/skills/app-shell-upgrade/references/migrations.md": "9bd2735c34fd35e3",
"packages/core/skills/app-shell-patterns/SKILL.md": "63874609c07182d7",
"packages/core/skills/app-shell-upgrade/references/migrations.md": "85b8177b2b14f3f8",
"packages/core/skills/app-shell-upgrade/SKILL.md": "f9be942f3e596c00"
}
}
60 changes: 34 additions & 26 deletions docs-src/components/dialog.docs.examples.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from "react";

import { Button, Dialog, Field, Form, Text } from "@tailor-platform/app-shell";
import { Button, Dialog, Field, Form, FormLayout, Text } from "@tailor-platform/app-shell";

export function DeleteConfirmation() {
const [open, setOpen] = useState(false);
Expand Down Expand Up @@ -60,38 +60,46 @@ export function FormDialog() {
<Text.p role="status">Saved item name: {name}</Text.p>
<Dialog.Root open={open} onOpenChange={setOpen}>
<Dialog.Trigger render={<Button variant="outline" />}>Edit item</Dialog.Trigger>
<Dialog.Content>
<Dialog.Content size="lg">
<Dialog.Header>
<Dialog.Title>Edit item</Dialog.Title>
<Dialog.Description>
Save a new name, or cancel to keep the saved name.
</Dialog.Description>
</Dialog.Header>
<Form<{ name: string }>
noValidate
onFormSubmit={(values) => {
setName(values.name.trim());
setOpen(false);
}}
>
<Field.Root
name="name"
className="py-4"
validate={(value) =>
typeof value === "string" && value.trim() ? undefined : "Name is required."
}
<Dialog.Body>
<Form<{ name: string; sku: string }>
id="edit-item-form"
noValidate
onFormSubmit={(values) => {
setName(values.name.trim());
setOpen(false);
}}
>
<Field.Label>Item name</Field.Label>
<Field.Control defaultValue={name} required />
<Field.Error>Name is required.</Field.Error>
</Field.Root>
<Dialog.Footer>
<Dialog.Close render={<Button type="button" variant="outline" />}>
Cancel
</Dialog.Close>
<Button type="submit">Save item</Button>
</Dialog.Footer>
</Form>
<FormLayout columns={2}>
<Field.Root
name="name"
validate={(value) =>
typeof value === "string" && value.trim() ? undefined : "Name is required."
}
>
<Field.Label required>Item name</Field.Label>
<Field.Control defaultValue={name} required />
<Field.Error>Name is required.</Field.Error>
</Field.Root>
<Field.Root name="sku">
<Field.Label>SKU</Field.Label>
<Field.Control defaultValue="CTN-S-01" />
</Field.Root>
</FormLayout>
</Form>
</Dialog.Body>
<Dialog.Footer>
<Dialog.Close render={<Button type="button" variant="outline" />}>Cancel</Dialog.Close>
<Button type="submit" form="edit-item-form">
Save item
</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
</div>
Expand Down
15 changes: 11 additions & 4 deletions docs-src/components/dialog.docs.outline.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The runnable examples also import `useState` from `react`, and `Button`, `Field`
| `Dialog.Trigger` | Element that opens the dialog when clicked |
| `Dialog.Content` | The main dialog panel (includes overlay and close button automatically) |
| `Dialog.Header` | Layout wrapper for title and description |
| `Dialog.Body` | Scrollable middle section; long content scrolls here, not off-screen |
| `Dialog.Footer` | Layout wrapper for action buttons |
| `Dialog.Title` | Dialog title (announced by screen readers) |
| `Dialog.Description` | Additional context below the title |
Expand All @@ -50,15 +51,19 @@ The runnable examples also import `useState` from `react`, and `Button`, `Field`

### Dialog.Content Props

Accepts `className` and all standard HTML `<div>` props.
| Prop | Type | Default | Description |
| ------ | ------------------------------ | ------- | ----------------------------------------------------------------------------------------------- |
| `size` | `"sm" \| "md" \| "lg" \| "xl"` | `"md"` | Max width of the panel: 24rem, 32rem, 45rem or 60rem — the same steps as `Sheet.Content` `size` |

Also accepts `className` and all standard HTML `<div>` props. The panel never grows taller than the viewport; put long content in `Dialog.Body` so it scrolls while the header and footer stay in view.

## Tall Content

`Dialog.Content` is never taller than the viewport minus 2rem (16px above and below, the same margin as on the sides). When the content is taller, the whole dialog scrolls, including the title and the close button. `Escape` and a click on the backdrop still close it.
`Dialog.Content` is never taller than the viewport minus 2rem (16px above and below, the same margin as on the sides). Without a `Dialog.Body`, content that is taller makes the whole dialog scroll, including the title and the close button. `Escape` and a click on the backdrop still close it.

On open, focus moves to the first control in the dialog. In a dialog that scrolls, this happens only when that control is in view at the top. When it is below the fold (for example, a footer button after a long body), the dialog itself takes focus instead, so it opens at the top rather than scrolled to that control. `Tab` then moves to the control. Pass `initialFocus` to choose the element yourself.

To keep a header or footer in view while only the body scrolls, make `Dialog.Content` a flex column and give the body `min-h-0 flex-1 overflow-y-auto`. A `className` with its own `max-h-*` or `overflow-*` replaces the defaults.
To keep the header and footer in view while only the middle scrolls, wrap the middle in `Dialog.Body`. `Dialog.Content` is already a flex column, and `Dialog.Body` is the only child that shrinks; the header, footer and anything else placed directly in `Dialog.Content` keep their height. A `className` with its own `max-h-*` or `overflow-*` replaces the defaults.

### Dialog.Trigger / Dialog.Close Props

Expand All @@ -78,7 +83,9 @@ Open the confirmation and cancel to keep the order, or confirm to remove it from

### Form Dialog

Edit the item name and save to update the value outside the dialog. Empty or whitespace-only names are rejected through `Form` and `Field`. Cancel or close leaves the saved name unchanged; reopening restores it. Cancel is explicitly `type="button"` so it does not submit the form.
Put the `Form` inside `Dialog.Body` and submit it from the footer with `form="<id>"`, so the Save button stays visible however long the form gets. [`FormLayout`](./form-layout.md) lays the fields out in columns that fit the dialog's width.

In this example, empty or whitespace-only names are rejected through `Form` and `Field`. Cancel or close leaves the saved name unchanged; reopening restores it. Cancel is explicitly `type="button"` so it does not submit the form.

<!-- example: form-dialog -->

Expand Down
Loading
Loading