Skip to content

Commit d2acc15

Browse files
committed
Enhance schema types for data tables and forms
Added new properties to TableColumn (minWidth, align, fixed, type) and DataTableSchema (toolbar) to support richer data table configuration. Extended FormField with colSpan for grid layouts and FormSchema with mode and actions for improved form customization. Also added AI_GUIDE.md with detailed schema generation guidelines.
1 parent 28141ce commit d2acc15

File tree

3 files changed

+181
-0
lines changed

3 files changed

+181
-0
lines changed

docs/AI_GUIDE.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# AI Generation Guide: Object UI
2+
3+
**This document is optimized for LLMs.** Use this context to generate high-quality, bug-free Object UI JSON schemas.
4+
5+
## 1. Core Mental Model
6+
7+
* **You are a Schema Engine**: You do not write React code. You write **JSON** that describes a UI.
8+
* **Recursive Structure**: Every component is a node. `children` prop can contain arrays of other nodes.
9+
* **Tailwind Native**: Styling is done via `className`. Use standardized margins/padding (e.g., `p-4`, `gap-4`).
10+
11+
## 2. The Enterprise Component Palette
12+
13+
Use these strictly typed components. Do not hallucinate `type` names.
14+
15+
### Layout (The Skeleton)
16+
* **`page`**: Top-level container. Properties: `title`, `body[]`.
17+
* **`grid`**: CSS Grid. Properties: `columns` (number), `gap` (number), `children[]`.
18+
* **`flex`**: Flexbox. Properties: `direction` ('row'|'col'), `gap`, `justify`, `align`, `children[]`.
19+
* **`card`**: Content container. Properties: `title`, `description`, `header` (node), `children` (body), `footer` (node).
20+
* **`tabs`**: Tabbed interface. Properties: `items: [{ label, value, content }]`.
21+
* **`resizable`**: Split pane. Properties: `direction`, `panels: [{ defaultSize, content }]`.
22+
23+
### Form (The Input)
24+
* **`form`**: Data context wrapper. Properties: `mode` ('edit'|'read'), `layout`, `actions` (toolbar), `body[]`. **Crucial**: Inputs must be inside a form to bind data.
25+
* **`input`**: Text/Number. Properties: `name` (key), `label`, `inputType`, `required`, `colSpan` (grid width).
26+
* **`select`**: Dropdown. Properties: `name`, `label`, `options: [{ label, value }]`, `colSpan`.
27+
* **`date-picker`**: Date/Time. Properties: `name`, `label`, `mode`, `colSpan`.
28+
* **`checkbox` / `switch`**: Boolean.
29+
* **`upload`**: File handling.
30+
31+
### Data (The Output)
32+
* **`data-table`**: Enterprise Grid. Properties: `data` (array), `toolbar`, `columns: [{ header, accessorKey, fixed, align, width, type }]`.
33+
* **`statistic`**: KPI Metrics. Properties: `label`, `value`, `trend`.
34+
* **`tag`** / **`badge`**: Status indicators.
35+
36+
## 3. Golden Rules for Generation
37+
38+
1. **Always use `name` in Inputs**: Without `name`, the form cannot save data.
39+
2. **Combine Layouts**: Don't just dump fields. Wrap them in `grid` -> `card` for structure.
40+
3. **Strict Types**:
41+
* `className` is always a STRING.
42+
* `children` is an ARRAY of objects.
43+
4. **Data Binding**:
44+
* In `table`, `field` matches the data key.
45+
* In `form`, `name` matches the submission key.
46+
47+
## 4. One-Shot Examples
48+
49+
### Scenario: CRM Customer Detail Page
50+
*Pattern: Header + Sidebar Layout + Tabbed Content*
51+
52+
```json
53+
{
54+
"type": "page",
55+
"title": "Customer: Acme Corp",
56+
"body": [
57+
{
58+
"type": "grid",
59+
"columns": 12,
60+
"gap": 6,
61+
"children": [
62+
{
63+
"type": "div",
64+
"className": "col-span-12 md:col-span-4",
65+
"children": [
66+
{
67+
"type": "card",
68+
"title": "Contact Info",
69+
"children": [
70+
{ "type": "text", "value": "[email protected]", "className": "text-sm" },
71+
{ "type": "text", "value": "+1 555 0199", "className": "text-sm" }
72+
]
73+
}
74+
]
75+
},
76+
{
77+
"type": "div",
78+
"className": "col-span-12 md:col-span-8",
79+
"children": [
80+
{
81+
"type": "tabs",
82+
"defaultValue": "activity",
83+
"items": [
84+
{
85+
"label": "Activity",
86+
"value": "activity",
87+
"content": { "type": "timeline", "items": [] }
88+
},
89+
{
90+
"label": "Opportunities",
91+
"value": "opportunities",
92+
"content": {
93+
"type": "table",
94+
"columns": [
95+
{ "title": "Deal Name", "field": "name" },
96+
{ "title": "Amount", "field": "amount" }
97+
]
98+
}
99+
}
100+
]
101+
}
102+
]
103+
}
104+
]
105+
}
106+
]
107+
}
108+
```
109+
110+
### Scenario: Enterprise Settings Form
111+
*Pattern: Card-based Sections + Form Context*
112+
113+
```json
114+
{
115+
"type": "form",
116+
"submitLabel": "Save Changes",
117+
"layout": "vertical",
118+
"body": [
119+
{
120+
"type": "card",
121+
"title": "General Settings",
122+
"description": "Basic account configuration",
123+
"children": [
124+
{
125+
"type": "grid",
126+
"columns": 2,
127+
"gap": 4,
128+
"children": [
129+
{ "type": "input", "name": "companyName", "label": "Company Name", "required": true },
130+
{ "type": "select", "name": "industry", "label": "Industry", "options": [{"label": "Tech", "value": "tech"}] }
131+
]
132+
}
133+
]
134+
},
135+
{
136+
"type": "card",
137+
"title": "Notifications",
138+
"className": "mt-4",
139+
"children": [
140+
{ "type": "switch", "name": "emailAlerts", "label": "Email Alerts" },
141+
{ "type": "switch", "name": "smsAlerts", "label": "SMS Alerts" }
142+
]
143+
}
144+
]
145+
}
146+
```

packages/types/src/data-display.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,23 @@ export interface TableColumn {
186186
* Column width
187187
*/
188188
width?: string | number;
189+
/**
190+
* Column minimum width
191+
*/
192+
minWidth?: string | number;
193+
/**
194+
* Text alignment
195+
* @default 'left'
196+
*/
197+
align?: 'left' | 'center' | 'right';
198+
/**
199+
* Pin column to side
200+
*/
201+
fixed?: 'left' | 'right';
202+
/**
203+
* Data type for formatting
204+
*/
205+
type?: 'text' | 'number' | 'date' | 'datetime' | 'currency' | 'percent' | 'boolean' | 'action';
189206
/**
190207
* Whether column is sortable
191208
* @default true
@@ -249,6 +266,10 @@ export interface DataTableSchema extends BaseSchema {
249266
* Table caption
250267
*/
251268
caption?: string;
269+
/**
270+
* Table toolbar actions/content
271+
*/
272+
toolbar?: SchemaNode[];
252273
/**
253274
* Table columns
254275
*/

packages/types/src/form.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,11 @@ export interface FormField {
814814
* Additional field-specific props
815815
*/
816816
[key: string]: any;
817+
/**
818+
* Column span for grid layouts
819+
* @default 1
820+
*/
821+
colSpan?: number;
817822
}
818823

819824
/**
@@ -868,6 +873,15 @@ export interface FormSchema extends BaseSchema {
868873
* Whether form is disabled
869874
*/
870875
disabled?: boolean;
876+
/**
877+
* Form mode
878+
* @default 'edit'
879+
*/
880+
mode?: 'edit' | 'read' | 'disabled';
881+
/**
882+
* Custom action buttons (replaces default submit/cancel)
883+
*/
884+
actions?: SchemaNode[];
871885
/**
872886
* Submit handler
873887
*/

0 commit comments

Comments
 (0)