Skip to content

Commit 8555f6e

Browse files
committed
feat: expand field stories with additional components and improve layout
1 parent 16a89db commit 8555f6e

File tree

1 file changed

+190
-17
lines changed

1 file changed

+190
-17
lines changed

packages/components/src/stories-json/fields.stories.tsx

Lines changed: 190 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import {
55
CurrencyField,
66
SelectField,
77
DateField,
8+
DateTimeField,
9+
TimeField,
810
BooleanField,
911
NumberField,
1012
PercentField,
@@ -14,7 +16,12 @@ import {
1416
PasswordField,
1517
TextAreaField,
1618
AutoNumberField,
17-
LookupField
19+
LookupField,
20+
UserField,
21+
FileField,
22+
LocationField,
23+
FormulaField,
24+
SummaryField
1825
} from '@object-ui/fields';
1926
import { FieldMetadata } from '@object-ui/types';
2027

@@ -60,10 +67,10 @@ const FieldWrapper = ({
6067
} as FieldMetadata;
6168

6269
return (
63-
<div className="w-[300px] space-y-2 p-4 border rounded-lg">
64-
<div className="flex justify-between items-center">
65-
<label className="text-sm font-medium">{fullField.label}</label>
66-
{readonly && <span className="text-[10px] bg-gray-100 px-1 rounded">Read Only</span>}
70+
<div className="w-[350px] space-y-2 p-4 border rounded-lg shadow-sm bg-white">
71+
<div className="flex justify-between items-center mb-2">
72+
<label className="text-sm font-semibold text-gray-700">{fullField.label}</label>
73+
{readonly && <span className="text-[10px] bg-slate-100 px-2 py-0.5 rounded text-slate-500 font-medium">Read Only</span>}
6774
</div>
6875

6976
<Component
@@ -77,14 +84,16 @@ const FieldWrapper = ({
7784
/>
7885

7986
{!readonly && (
80-
<div className="text-xs text-muted-foreground mt-4 pt-2 border-t font-mono">
87+
<div className="text-xs text-muted-foreground mt-4 pt-2 border-t font-mono overflow-hidden text-ellipsis">
8188
Value: {JSON.stringify(value)}
8289
</div>
8390
)}
8491
</div>
8592
);
8693
};
8794

95+
// --- Text Based ---
96+
8897
export const Text: Story = {
8998
render: () => (
9099
<FieldWrapper
@@ -105,6 +114,59 @@ export const TextArea: Story = {
105114
)
106115
};
107116

117+
export const Email: Story = {
118+
render: () => (
119+
<FieldWrapper
120+
Component={EmailField}
121+
field={{ label: 'Email', type: 'email' }}
122+
initialValue="contact@example.com"
123+
/>
124+
)
125+
};
126+
127+
export const Phone: Story = {
128+
render: () => (
129+
<FieldWrapper
130+
Component={PhoneField}
131+
field={{ label: 'Phone', type: 'phone' }}
132+
initialValue="+1 (555) 123-4567"
133+
/>
134+
)
135+
};
136+
137+
export const Url: Story = {
138+
render: () => (
139+
<FieldWrapper
140+
Component={UrlField}
141+
field={{ label: 'Website', type: 'url' }}
142+
initialValue="https://objectui.org"
143+
/>
144+
)
145+
};
146+
147+
export const Password: Story = {
148+
render: () => (
149+
<FieldWrapper
150+
Component={PasswordField}
151+
field={{ label: 'Secret Key', type: 'password' }}
152+
initialValue="supersecret"
153+
/>
154+
)
155+
};
156+
157+
export const AutoNumber: Story = {
158+
render: () => (
159+
<FieldWrapper
160+
Component={AutoNumberField}
161+
field={{ label: 'Order Number', type: 'autonumber' }}
162+
initialValue="ORD-2024-001"
163+
readonly={true}
164+
/>
165+
)
166+
};
167+
168+
// --- Numbers ---
169+
108170
export const Number: Story = {
109171
render: () => (
110172
<FieldWrapper
@@ -135,26 +197,50 @@ export const Percent: Story = {
135197
)
136198
};
137199

138-
export const Boolean: Story = {
200+
// --- Date & Time ---
201+
202+
export const Date: Story = {
139203
render: () => (
140204
<FieldWrapper
141-
Component={BooleanField}
142-
field={{ label: 'Is Active?', type: 'boolean' }}
143-
initialValue={true}
205+
Component={DateField}
206+
field={{ label: 'Close Date', type: 'date' }}
207+
initialValue={new Date().toISOString()}
144208
/>
145209
)
146210
};
147211

148-
export const Date: Story = {
212+
export const DateTime: Story = {
149213
render: () => (
150214
<FieldWrapper
151-
Component={DateField}
152-
field={{ label: 'Close Date', type: 'date' }}
215+
Component={DateTimeField}
216+
field={{ label: 'Meeting Time', type: 'datetime' }}
153217
initialValue={new Date().toISOString()}
154218
/>
155219
)
156220
};
157221

222+
export const Time: Story = {
223+
render: () => (
224+
<FieldWrapper
225+
Component={TimeField}
226+
field={{ label: 'Start Time', type: 'time' }}
227+
initialValue="14:30"
228+
/>
229+
)
230+
};
231+
232+
// --- Selection ---
233+
234+
export const Boolean: Story = {
235+
render: () => (
236+
<FieldWrapper
237+
Component={BooleanField}
238+
field={{ label: 'Is Active?', type: 'boolean' }}
239+
initialValue={true}
240+
/>
241+
)
242+
};
243+
158244
export const Select: Story = {
159245
render: () => (
160246
<FieldWrapper
@@ -175,12 +261,93 @@ export const Select: Story = {
175261
)
176262
};
177263

178-
export const Password: Story = {
264+
export const Lookup: Story = {
179265
render: () => (
180266
<FieldWrapper
181-
Component={PasswordField}
182-
field={{ label: 'Secret Key', type: 'password' }}
183-
initialValue="supersecret"
267+
Component={LookupField}
268+
field={{
269+
label: 'Account',
270+
type: 'lookup',
271+
options: [
272+
{ label: 'Acme Corp', value: 'acme' },
273+
{ label: 'Globex', value: 'globex' },
274+
{ label: 'Soylent Corp', value: 'soylent' },
275+
] as any
276+
}}
277+
initialValue="acme"
278+
/>
279+
)
280+
};
281+
282+
export const MultiSelectLookup: Story = {
283+
render: () => (
284+
<FieldWrapper
285+
Component={LookupField}
286+
field={{
287+
label: 'Related Accounts',
288+
type: 'lookup',
289+
multiple: true,
290+
options: [
291+
{ label: 'Acme Corp', value: 'acme' },
292+
{ label: 'Globex', value: 'globex' },
293+
{ label: 'Soylent Corp', value: 'soylent' },
294+
] as any
295+
}}
296+
initialValue={['acme', 'soylent']}
297+
/>
298+
)
299+
};
300+
301+
// --- Special ---
302+
303+
export const User: Story = {
304+
render: () => (
305+
<FieldWrapper
306+
Component={UserField}
307+
field={{ label: 'Assigned To', type: 'user' }}
308+
initialValue={{ name: 'John Doe', username: 'jdoe' }}
309+
/>
310+
)
311+
};
312+
313+
export const File: Story = {
314+
render: () => (
315+
<FieldWrapper
316+
Component={FileField}
317+
field={{ label: 'Attachment', type: 'file' }}
318+
initialValue={{ name: 'report.pdf', size: 1024000 }}
319+
/>
320+
)
321+
};
322+
323+
export const Location: Story = {
324+
render: () => (
325+
<FieldWrapper
326+
Component={LocationField}
327+
field={{ label: 'Coordinates', type: 'location' }}
328+
initialValue={{ latitude: 37.7749, longitude: -122.4194 }}
329+
/>
330+
)
331+
};
332+
333+
export const Formula: Story = {
334+
render: () => (
335+
<FieldWrapper
336+
Component={FormulaField}
337+
field={{ label: 'Net Profit', type: 'formula' }}
338+
initialValue={5000}
339+
readonly
340+
/>
341+
)
342+
};
343+
344+
export const Summary: Story = {
345+
render: () => (
346+
<FieldWrapper
347+
Component={SummaryField}
348+
field={{ label: 'Total Sales', type: 'summary' }}
349+
initialValue={100000}
350+
readonly
184351
/>
185352
)
186353
};
@@ -200,6 +367,12 @@ export const ReadOnly: Story = {
200367
initialValue={9999.99}
201368
readonly={true}
202369
/>
370+
<FieldWrapper
371+
Component={UserField}
372+
field={{ label: 'Read Only User', type: 'user' }}
373+
initialValue={{ name: 'Jane Smith' }}
374+
readonly={true}
375+
/>
203376
</div>
204377
)
205378
};

0 commit comments

Comments
 (0)