Skip to content

Commit c165cad

Browse files
committed
feat: add DashboardRenderer component and related types for dashboard functionality
1 parent ad2fdfb commit c165cad

File tree

7 files changed

+122
-7
lines changed

7 files changed

+122
-7
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
import { ComponentRegistry } from '@object-ui/core';
10+
import type { DashboardSchema } from '@object-ui/types';
11+
import { SchemaRenderer } from '@object-ui/react';
12+
import { forwardRef } from 'react';
13+
import { cn } from '../../lib/utils';
14+
15+
const DashboardRenderer = forwardRef<HTMLDivElement, { schema: DashboardSchema; className?: string; [key: string]: any }>(
16+
({ schema, className, ...props }, ref) => {
17+
const columns = schema.columns || 3;
18+
const gap = schema.gap || 4;
19+
20+
return (
21+
<div
22+
ref={ref}
23+
className={cn("grid", className)}
24+
style={{
25+
gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
26+
gap: gap * 4 // Assuming tailwind scale
27+
}}
28+
{...props}
29+
>
30+
{schema.widgets?.map((widget) => (
31+
<div
32+
key={widget.id}
33+
className={cn("border rounded-lg p-4 bg-card text-card-foreground shadow-sm")}
34+
style={widget.layout ? {
35+
gridColumn: `span ${widget.layout.w}`,
36+
gridRow: `span ${widget.layout.h}`
37+
}: undefined}
38+
>
39+
{widget.title && <h3 className="font-semibold mb-2">{widget.title}</h3>}
40+
<SchemaRenderer schema={widget.component} />
41+
</div>
42+
))}
43+
</div>
44+
);
45+
}
46+
);
47+
48+
ComponentRegistry.register(
49+
'dashboard',
50+
DashboardRenderer,
51+
{
52+
label: 'Dashboard',
53+
category: 'Complex',
54+
icon: 'layout-dashboard',
55+
inputs: [
56+
{ name: 'columns', type: 'number', label: 'Columns', defaultValue: 3 },
57+
{ name: 'gap', type: 'number', label: 'Gap', defaultValue: 4 },
58+
{ name: 'className', type: 'string', label: 'CSS Class' }
59+
],
60+
defaultProps: {
61+
columns: 3,
62+
widgets: []
63+
}
64+
}
65+
);

packages/components/src/renderers/complex/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ import './scroll-area';
1212
import './resizable';
1313
import './table';
1414
import './data-table';
15+
import './dashboard';
1516

1617

packages/components/src/renderers/disclosure/toggle-group.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ ComponentRegistry.register('toggle-group',
2121

2222
return (
2323
<ToggleGroup
24-
type={schema.selectionType || 'single'}
24+
type={(schema.selectionType || 'single') as any}
2525
variant={schema.variant}
2626
size={schema.size}
27-
value={schema.value}
27+
value={schema.value as any}
2828
className={schema.className}
2929
{...toggleGroupProps}
3030
{...{ 'data-obj-id': dataObjId, 'data-obj-type': dataObjType, style }}

packages/components/src/renderers/feedback/sonner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ComponentRegistry.register('sonner',
2626
};
2727

2828
return (
29-
<Button onClick={showToast} variant={schema.buttonVariant} className={schema.className}>
29+
<Button onClick={showToast} variant={schema.buttonVariant} className={schema.className} {...props}>
3030
{schema.buttonLabel || 'Show Toast'}
3131
</Button>
3232
);

packages/core/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export * from './types';
1010
export * from './registry/Registry';
1111
export * from './validation/schema-validator';
1212
export * from './builder/schema-builder';
13-
export * from './adapters';
1413
export * from './utils/filter-converter';
1514
// export * from './data-scope'; // TODO
1615
// export * from './evaluator'; // TODO

packages/types/src/complex.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,36 @@ export interface ChatbotSchema extends BaseSchema {
491491
height?: string | number;
492492
}
493493

494+
/**
495+
* Dashboard Widget Layout
496+
*/
497+
export interface DashboardWidgetLayout {
498+
x: number;
499+
y: number;
500+
w: number;
501+
h: number;
502+
}
503+
504+
/**
505+
* Dashboard Widget
506+
*/
507+
export interface DashboardWidgetSchema {
508+
id: string;
509+
title?: string;
510+
component: SchemaNode;
511+
layout?: DashboardWidgetLayout;
512+
}
513+
514+
/**
515+
* Dashboard Schema
516+
*/
517+
export interface DashboardSchema extends BaseSchema {
518+
type: 'dashboard';
519+
columns?: number;
520+
gap?: number;
521+
widgets: DashboardWidgetSchema[];
522+
}
523+
494524
/**
495525
* Union type of all complex schemas
496526
*/

packages/types/src/index.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export type {
9191
ScrollAreaSchema,
9292
ResizableSchema,
9393
ResizablePanel,
94+
AspectRatioSchema,
9495
LayoutSchema,
9596
PageSchema,
9697
} from './layout';
@@ -108,15 +109,17 @@ export type {
108109
RadioGroupSchema,
109110
RadioOption,
110111
SwitchSchema,
111-
ToggleSchema,
112112
SliderSchema,
113113
FileUploadSchema,
114114
DatePickerSchema,
115115
CalendarSchema,
116-
InputOTPSchema,
117116
ValidationRule,
118117
FieldCondition,
119118
FormField,
119+
ComboboxSchema,
120+
CommandSchema,
121+
InputOTPSchema,
122+
ToggleSchema,
120123
FormSchema,
121124
LabelSchema,
122125
FormComponentSchema,
@@ -142,6 +145,7 @@ export type {
142145
ChartSchema,
143146
TimelineEvent,
144147
TimelineSchema,
148+
KbdSchema,
145149
HtmlSchema,
146150
StatisticSchema,
147151
DataDisplaySchema,
@@ -151,10 +155,13 @@ export type {
151155
// Feedback Components - Status & Progress Indication
152156
// ============================================================================
153157
export type {
158+
SpinnerSchema,
154159
LoadingSchema,
155160
ProgressSchema,
156161
SkeletonSchema,
157162
ToastSchema,
163+
EmptySchema,
164+
SonnerSchema,
158165
ToasterSchema,
159166
FeedbackSchema,
160167
} from './feedback';
@@ -164,6 +171,7 @@ export type {
164171
// ============================================================================
165172
export type {
166173
AccordionItem,
174+
ToggleGroupSchema,
167175
AccordionSchema,
168176
CollapsibleSchema,
169177
DisclosureSchema,
@@ -183,6 +191,7 @@ export type {
183191
TooltipSchema,
184192
HoverCardSchema,
185193
MenuItem,
194+
MenubarSchema,
186195
DropdownMenuSchema,
187196
ContextMenuSchema,
188197
OverlaySchema,
@@ -197,8 +206,10 @@ export type {
197206
SidebarSchema,
198207
BreadcrumbItem,
199208
BreadcrumbSchema,
200-
PaginationSchema,
209+
ButtonGroupSchema,
210+
NavigationMenuSchema,
201211
NavigationSchema,
212+
PaginationSchema,
202213
} from './navigation';
203214

204215
// ============================================================================
@@ -218,6 +229,9 @@ export type {
218229
FilterField,
219230
CarouselItem,
220231
CarouselSchema,
232+
DashboardWidgetLayout,
233+
DashboardWidgetSchema,
234+
DashboardSchema,
221235
ChatMessage,
222236
ChatbotSchema,
223237
ComplexSchema,
@@ -268,6 +282,12 @@ export type {
268282
GanttConfig,
269283
SortConfig,
270284
// Component schemas
285+
ObjectMapSchema,
286+
ObjectGanttSchema,
287+
ObjectCalendarSchema,
288+
ObjectKanbanSchema,
289+
ObjectChartSchema,
290+
ListViewSchema,
271291
ObjectGridSchema,
272292
ObjectFormSchema,
273293
ObjectViewSchema,

0 commit comments

Comments
 (0)