Skip to content

Commit 941a53c

Browse files
Copilothotlong
andcommitted
Add documentation and examples for all field types
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 15b66d0 commit 941a53c

2 files changed

Lines changed: 526 additions & 0 deletions

File tree

examples/FIELD_TYPES.md

Lines changed: 306 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,306 @@
1+
# Field Types Implementation
2+
3+
This document describes all field type components implemented according to the ObjectStack specification protocol.
4+
5+
## Overview
6+
7+
All field types defined in `@object-ui/types/field-types.ts` are now implemented with corresponding widget components in `@object-ui/fields`.
8+
9+
## Field Type Categories
10+
11+
### Text Fields
12+
13+
#### Text Field
14+
- **Type**: `text`
15+
- **Component**: `TextField`
16+
- **Description**: Single-line text input
17+
- **Props**: `min_length`, `max_length`, `pattern`
18+
19+
#### Textarea Field
20+
- **Type**: `textarea`
21+
- **Component**: `TextAreaField`
22+
- **Description**: Multi-line text input
23+
- **Props**: `rows`, `min_length`, `max_length`
24+
25+
#### Markdown Field
26+
- **Type**: `markdown`
27+
- **Component**: `RichTextField`
28+
- **Description**: Markdown editor
29+
- **Props**: `max_length`
30+
31+
#### HTML Field
32+
- **Type**: `html`
33+
- **Component**: `RichTextField`
34+
- **Description**: Rich text HTML editor
35+
- **Props**: `max_length`
36+
37+
### Numeric Fields
38+
39+
#### Number Field
40+
- **Type**: `number`
41+
- **Component**: `NumberField`
42+
- **Description**: Numeric input with precision
43+
- **Props**: `min`, `max`, `precision`, `step`
44+
45+
#### Currency Field
46+
- **Type**: `currency`
47+
- **Component**: `CurrencyField`
48+
- **Description**: Currency input with symbol and formatting
49+
- **Props**: `currency`, `precision`, `min`, `max`
50+
- **Features**: Auto-formats on blur, shows currency symbol
51+
52+
#### Percent Field ✨ NEW
53+
- **Type**: `percent`
54+
- **Component**: `PercentField`
55+
- **Description**: Percentage input (stores 0-1, displays 0-100)
56+
- **Props**: `precision`, `min`, `max`
57+
- **Features**: Automatic % conversion and display
58+
59+
### Boolean Field
60+
61+
#### Boolean Field
62+
- **Type**: `boolean`
63+
- **Component**: `BooleanField`
64+
- **Description**: Switch or checkbox toggle
65+
- **Props**: `widget` (switch or checkbox)
66+
67+
### Date/Time Fields
68+
69+
#### Date Field
70+
- **Type**: `date`
71+
- **Component**: `DateField`
72+
- **Description**: Date picker
73+
- **Props**: `format`, `min_date`, `max_date`
74+
75+
#### DateTime Field ✨ NEW
76+
- **Type**: `datetime`
77+
- **Component**: `DateTimeField`
78+
- **Description**: Date and time picker
79+
- **Props**: `format`, `min_date`, `max_date`
80+
81+
#### Time Field ✨ NEW
82+
- **Type**: `time`
83+
- **Component**: `TimeField`
84+
- **Description**: Time-only picker
85+
- **Props**: `format`
86+
87+
### Selection Fields
88+
89+
#### Select Field
90+
- **Type**: `select`
91+
- **Component**: `SelectField`
92+
- **Description**: Dropdown select with options
93+
- **Props**: `options`, `multiple`, `searchable`
94+
- **Features**: Badge display with colors
95+
96+
#### Lookup Field
97+
- **Type**: `lookup` or `master_detail`
98+
- **Component**: `LookupField`
99+
- **Description**: Reference to another object
100+
- **Props**: `reference_to`, `reference_field`, `multiple`, `searchable`
101+
102+
### Contact Fields
103+
104+
#### Email Field
105+
- **Type**: `email`
106+
- **Component**: `EmailField`
107+
- **Description**: Email input with validation
108+
- **Props**: `max_length`
109+
- **Features**: Auto-validation, mailto: links
110+
111+
#### Phone Field
112+
- **Type**: `phone`
113+
- **Component**: `PhoneField`
114+
- **Description**: Phone number input
115+
- **Props**: `format`
116+
- **Features**: tel: links
117+
118+
#### URL Field
119+
- **Type**: `url`
120+
- **Component**: `UrlField`
121+
- **Description**: URL input with validation
122+
- **Props**: `max_length`
123+
- **Features**: Opens in new tab
124+
125+
#### Password Field ✨ NEW
126+
- **Type**: `password`
127+
- **Component**: `PasswordField`
128+
- **Description**: Password input with show/hide toggle
129+
- **Props**: `min_length`, `max_length`
130+
- **Features**: Toggle visibility button
131+
132+
### File Fields
133+
134+
#### File Field ✨ NEW
135+
- **Type**: `file`
136+
- **Component**: `FileField`
137+
- **Description**: File upload with preview
138+
- **Props**: `multiple`, `accept`, `max_size`, `max_files`
139+
- **Features**: File list, remove files, size display
140+
141+
#### Image Field ✨ NEW
142+
- **Type**: `image`
143+
- **Component**: `ImageField`
144+
- **Description**: Image upload with thumbnails
145+
- **Props**: `multiple`, `accept`, `max_size`, `max_files`, `max_width`, `max_height`
146+
- **Features**: Thumbnail grid, hover to remove
147+
148+
### Location Field
149+
150+
#### Location Field ✨ NEW
151+
- **Type**: `location`
152+
- **Component**: `LocationField`
153+
- **Description**: Geographic coordinates input
154+
- **Props**: `default_zoom`
155+
- **Format**: Stores as `{ latitude: number, longitude: number }`
156+
- **Display**: "latitude, longitude" format
157+
158+
### Computed/Read-only Fields
159+
160+
#### Formula Field ✨ NEW
161+
- **Type**: `formula`
162+
- **Component**: `FormulaField`
163+
- **Description**: Computed field from formula
164+
- **Props**: `formula`, `return_type`
165+
- **Features**: Read-only, formatted by return type
166+
167+
#### Summary Field ✨ NEW
168+
- **Type**: `summary`
169+
- **Component**: `SummaryField`
170+
- **Description**: Aggregation from related records
171+
- **Props**: `summary_object`, `summary_field`, `summary_type` (count, sum, avg, min, max)
172+
- **Features**: Read-only, tabular number display
173+
174+
#### AutoNumber Field ✨ NEW
175+
- **Type**: `auto_number`
176+
- **Component**: `AutoNumberField`
177+
- **Description**: Auto-generated sequence number
178+
- **Props**: `format`, `starting_number`
179+
- **Features**: Read-only, monospace display
180+
181+
### User Fields
182+
183+
#### User Field ✨ NEW
184+
- **Type**: `user` or `owner`
185+
- **Component**: `UserField`
186+
- **Description**: User/owner selector
187+
- **Props**: `multiple`
188+
- **Features**: Avatar display, badge list
189+
190+
### Complex Data Types
191+
192+
#### Object Field ✨ NEW
193+
- **Type**: `object`
194+
- **Component**: `ObjectField`
195+
- **Description**: JSON object editor
196+
- **Props**: `schema`
197+
- **Features**: Textarea with JSON validation, syntax highlighting
198+
199+
#### Vector Field ✨ NEW
200+
- **Type**: `vector`
201+
- **Component**: `VectorField`
202+
- **Description**: Vector embeddings display
203+
- **Props**: `dimensions`
204+
- **Features**: Read-only, shows preview of first values and dimensions
205+
206+
#### Grid Field ✨ NEW
207+
- **Type**: `grid`
208+
- **Component**: `GridField`
209+
- **Description**: Sub-table/inline grid
210+
- **Props**: `columns`
211+
- **Features**: Table view, pagination preview
212+
213+
## Usage
214+
215+
### Registration
216+
217+
All field types are automatically registered when you call `registerFields()`:
218+
219+
\`\`\`typescript
220+
import { registerFields } from '@object-ui/fields';
221+
222+
registerFields();
223+
\`\`\`
224+
225+
### Using Field Types
226+
227+
Define fields in your object schema:
228+
229+
\`\`\`typescript
230+
import { ObjectSchemaMetadata } from '@object-ui/types';
231+
232+
const schema: ObjectSchemaMetadata = {
233+
name: 'contact',
234+
label: 'Contact',
235+
fields: {
236+
name: {
237+
name: 'name',
238+
label: 'Full Name',
239+
type: 'text',
240+
required: true,
241+
},
242+
email: {
243+
name: 'email',
244+
label: 'Email',
245+
type: 'email',
246+
required: true,
247+
},
248+
percentage: {
249+
name: 'percentage',
250+
label: 'Completion',
251+
type: 'percent',
252+
precision: 1,
253+
},
254+
// ... more fields
255+
},
256+
};
257+
\`\`\`
258+
259+
### Custom Styling
260+
261+
All field components accept `className` prop for custom Tailwind styling:
262+
263+
\`\`\`typescript
264+
<TextField
265+
field={fieldMetadata}
266+
value={value}
267+
onChange={onChange}
268+
className="custom-class"
269+
/>
270+
\`\`\`
271+
272+
## Implementation Notes
273+
274+
### File Upload
275+
- File and Image fields create object URLs for preview
276+
- Actual file upload requires backend integration
277+
- File metadata structure: `{ name, original_name, size, mime_type, url }`
278+
279+
### User Selection
280+
- UserField displays avatars with initials
281+
- Actual user selection requires integration with user management system
282+
283+
### Read-only Fields
284+
- Formula, Summary, AutoNumber, and Vector fields are display-only
285+
- Values must be computed/generated by the backend
286+
287+
### Data Format Standards
288+
- **Location**: Always stores as `{ latitude: number, longitude: number }`
289+
- **Percent**: Stores as decimal (0-1), displays as percentage (0-100)
290+
- **Currency**: Stores as number, formats according to currency code
291+
- **DateTime**: Stores as ISO 8601 string
292+
293+
## Testing
294+
295+
Build the fields package:
296+
297+
\`\`\`bash
298+
pnpm --filter @object-ui/fields build
299+
\`\`\`
300+
301+
All 26+ field types are now available and registered!
302+
303+
## See Also
304+
305+
- [ObjectStack Field Types Specification](../../packages/types/src/field-types.ts)
306+
- [Example Schema](./field-types-example.ts)

0 commit comments

Comments
 (0)