@object-ui/fields 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +5 -5
- package/dist/index.js +140 -114
- package/package.json +4 -4
- package/src/__tests__/cell-renderers.test.tsx +90 -0
- package/src/index.tsx +30 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@object-ui/fields",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Field renderers and registry for Object UI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"clsx": "^2.1.1",
|
|
26
26
|
"lucide-react": "^0.576.0",
|
|
27
27
|
"tailwind-merge": "^3.5.0",
|
|
28
|
-
"@object-ui/components": "3.1.
|
|
29
|
-
"@object-ui/core": "3.1.
|
|
30
|
-
"@object-ui/types": "3.1.
|
|
28
|
+
"@object-ui/components": "3.1.1",
|
|
29
|
+
"@object-ui/core": "3.1.1",
|
|
30
|
+
"@object-ui/types": "3.1.1"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"react": "^18.0.0 || ^19.0.0",
|
|
@@ -205,6 +205,96 @@ describe('SelectCellRenderer', () => {
|
|
|
205
205
|
expect(container.querySelector('[class*="bg-gray-100"]')).toBeInTheDocument();
|
|
206
206
|
});
|
|
207
207
|
|
|
208
|
+
it('should auto-detect status semantic colors (Paid → green)', () => {
|
|
209
|
+
const { container } = render(
|
|
210
|
+
<SelectCellRenderer
|
|
211
|
+
value="Paid"
|
|
212
|
+
field={{ name: 'status', type: 'select', options: [] } as any}
|
|
213
|
+
/>
|
|
214
|
+
);
|
|
215
|
+
expect(container.querySelector('[class*="bg-green-100"]')).toBeInTheDocument();
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('should auto-detect status semantic colors (Pending → yellow)', () => {
|
|
219
|
+
const { container } = render(
|
|
220
|
+
<SelectCellRenderer
|
|
221
|
+
value="Pending"
|
|
222
|
+
field={{ name: 'status', type: 'select', options: [] } as any}
|
|
223
|
+
/>
|
|
224
|
+
);
|
|
225
|
+
expect(container.querySelector('[class*="bg-yellow-100"]')).toBeInTheDocument();
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('should auto-detect status semantic colors (Shipped → blue)', () => {
|
|
229
|
+
const { container } = render(
|
|
230
|
+
<SelectCellRenderer
|
|
231
|
+
value="Shipped"
|
|
232
|
+
field={{ name: 'status', type: 'select', options: [] } as any}
|
|
233
|
+
/>
|
|
234
|
+
);
|
|
235
|
+
expect(container.querySelector('[class*="bg-blue-100"]')).toBeInTheDocument();
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('should auto-detect status semantic colors (Draft → gray)', () => {
|
|
239
|
+
const { container } = render(
|
|
240
|
+
<SelectCellRenderer
|
|
241
|
+
value="Draft"
|
|
242
|
+
field={{ name: 'status', type: 'select', options: [] } as any}
|
|
243
|
+
/>
|
|
244
|
+
);
|
|
245
|
+
expect(container.querySelector('[class*="bg-gray-100"]')).toBeInTheDocument();
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('should auto-detect status semantic colors (Cancelled → red)', () => {
|
|
249
|
+
const { container } = render(
|
|
250
|
+
<SelectCellRenderer
|
|
251
|
+
value="Cancelled"
|
|
252
|
+
field={{ name: 'status', type: 'select', options: [] } as any}
|
|
253
|
+
/>
|
|
254
|
+
);
|
|
255
|
+
expect(container.querySelector('[class*="bg-red-100"]')).toBeInTheDocument();
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('should auto-detect status semantic colors (Delivered → purple)', () => {
|
|
259
|
+
const { container } = render(
|
|
260
|
+
<SelectCellRenderer
|
|
261
|
+
value="Delivered"
|
|
262
|
+
field={{ name: 'status', type: 'select', options: [] } as any}
|
|
263
|
+
/>
|
|
264
|
+
);
|
|
265
|
+
expect(container.querySelector('[class*="bg-purple-100"]')).toBeInTheDocument();
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('should auto-detect status semantic colors with snake_case (in_progress → blue)', () => {
|
|
269
|
+
const { container } = render(
|
|
270
|
+
<SelectCellRenderer
|
|
271
|
+
value="in_progress"
|
|
272
|
+
field={{ name: 'status', type: 'select', options: [] } as any}
|
|
273
|
+
/>
|
|
274
|
+
);
|
|
275
|
+
expect(container.querySelector('[class*="bg-blue-100"]')).toBeInTheDocument();
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('should auto-detect status semantic colors with hyphen (in-progress → blue)', () => {
|
|
279
|
+
const { container } = render(
|
|
280
|
+
<SelectCellRenderer
|
|
281
|
+
value="in-progress"
|
|
282
|
+
field={{ name: 'status', type: 'select', options: [] } as any}
|
|
283
|
+
/>
|
|
284
|
+
);
|
|
285
|
+
expect(container.querySelector('[class*="bg-blue-100"]')).toBeInTheDocument();
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it('should auto-detect status semantic colors with spaces (in progress → blue)', () => {
|
|
289
|
+
const { container } = render(
|
|
290
|
+
<SelectCellRenderer
|
|
291
|
+
value="in progress"
|
|
292
|
+
field={{ name: 'status', type: 'select', options: [] } as any}
|
|
293
|
+
/>
|
|
294
|
+
);
|
|
295
|
+
expect(container.querySelector('[class*="bg-blue-100"]')).toBeInTheDocument();
|
|
296
|
+
});
|
|
297
|
+
|
|
208
298
|
it('should render dash for null/empty value', () => {
|
|
209
299
|
render(
|
|
210
300
|
<SelectCellRenderer
|
package/src/index.tsx
CHANGED
|
@@ -368,8 +368,10 @@ export function DateTimeCellRenderer({ value }: CellRendererProps): React.ReactE
|
|
|
368
368
|
);
|
|
369
369
|
}
|
|
370
370
|
|
|
371
|
-
//
|
|
372
|
-
|
|
371
|
+
// Semantic color mapping (auto-detect from value text for priority & status fields)
|
|
372
|
+
// Keys use underscore notation; lookup normalizes spaces/hyphens to underscores automatically.
|
|
373
|
+
const SEMANTIC_COLOR_MAP: Record<string, string> = {
|
|
374
|
+
// Priority values
|
|
373
375
|
critical: 'red',
|
|
374
376
|
urgent: 'red',
|
|
375
377
|
high: 'orange',
|
|
@@ -377,6 +379,31 @@ const PRIORITY_COLOR_MAP: Record<string, string> = {
|
|
|
377
379
|
normal: 'blue',
|
|
378
380
|
low: 'gray',
|
|
379
381
|
none: 'gray',
|
|
382
|
+
// Status values
|
|
383
|
+
paid: 'green',
|
|
384
|
+
completed: 'green',
|
|
385
|
+
done: 'green',
|
|
386
|
+
active: 'green',
|
|
387
|
+
approved: 'green',
|
|
388
|
+
resolved: 'green',
|
|
389
|
+
pending: 'yellow',
|
|
390
|
+
waiting: 'yellow',
|
|
391
|
+
on_hold: 'yellow',
|
|
392
|
+
shipped: 'blue',
|
|
393
|
+
in_progress: 'blue',
|
|
394
|
+
open: 'blue',
|
|
395
|
+
processing: 'blue',
|
|
396
|
+
draft: 'gray',
|
|
397
|
+
new: 'gray',
|
|
398
|
+
inactive: 'gray',
|
|
399
|
+
closed: 'gray',
|
|
400
|
+
cancelled: 'red',
|
|
401
|
+
canceled: 'red',
|
|
402
|
+
rejected: 'red',
|
|
403
|
+
failed: 'red',
|
|
404
|
+
overdue: 'red',
|
|
405
|
+
delivered: 'purple',
|
|
406
|
+
archived: 'indigo',
|
|
380
407
|
};
|
|
381
408
|
|
|
382
409
|
// Color to Tailwind class mapping for custom Badge styling
|
|
@@ -394,7 +421,7 @@ const BADGE_COLOR_MAP: Record<string, string> = {
|
|
|
394
421
|
|
|
395
422
|
function getBadgeColorClasses(color?: string, val?: string): string {
|
|
396
423
|
const resolvedColor = color
|
|
397
|
-
|| (val ?
|
|
424
|
+
|| (val ? SEMANTIC_COLOR_MAP[String(val).toLowerCase().replace(/[\s-]/g, '_')] : undefined);
|
|
398
425
|
return BADGE_COLOR_MAP[resolvedColor || ''] || 'bg-muted text-muted-foreground border-border';
|
|
399
426
|
}
|
|
400
427
|
|