@object-ui/plugin-view 3.0.2 → 3.1.0

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.
@@ -26,10 +26,17 @@ import {
26
26
  Activity,
27
27
  Calendar,
28
28
  FileText,
29
+ GanttChartSquare,
29
30
  Grid,
31
+ Images,
30
32
  LayoutGrid,
31
33
  List,
32
34
  Map,
35
+ Plus,
36
+ Share2,
37
+ Settings,
38
+ Copy,
39
+ Trash2,
33
40
  icons,
34
41
  type LucideIcon,
35
42
  } from 'lucide-react';
@@ -40,6 +47,9 @@ export type ViewSwitcherProps = {
40
47
  schema: ViewSwitcherSchema;
41
48
  className?: string;
42
49
  onViewChange?: (view: ViewType) => void;
50
+ onCreateView?: () => void;
51
+ onViewAction?: (action: string, view: ViewType) => void;
52
+ createViewLabel?: string;
43
53
  [key: string]: any;
44
54
  };
45
55
 
@@ -51,6 +61,8 @@ const DEFAULT_VIEW_LABELS: Record<ViewType, string> = {
51
61
  calendar: 'Calendar',
52
62
  timeline: 'Timeline',
53
63
  map: 'Map',
64
+ gallery: 'Gallery',
65
+ gantt: 'Gantt',
54
66
  };
55
67
 
56
68
  const DEFAULT_VIEW_ICONS: Record<ViewType, LucideIcon> = {
@@ -61,6 +73,8 @@ const DEFAULT_VIEW_ICONS: Record<ViewType, LucideIcon> = {
61
73
  calendar: Calendar,
62
74
  timeline: Activity,
63
75
  map: Map,
76
+ gallery: Images,
77
+ gantt: GanttChartSquare,
64
78
  };
65
79
 
66
80
  const viewSwitcherLayout = cva('flex gap-4', {
@@ -149,10 +163,27 @@ function getInitialView(schema: ViewSwitcherSchema): ViewType | undefined {
149
163
  return schema.views?.[0]?.type;
150
164
  }
151
165
 
166
+ const DEFAULT_VIEW_ACTION_ICONS: Record<string, LucideIcon> = {
167
+ share: Share2,
168
+ settings: Settings,
169
+ duplicate: Copy,
170
+ delete: Trash2,
171
+ };
172
+
173
+ const DEFAULT_VIEW_ACTION_LABELS: Record<string, string> = {
174
+ share: 'Share',
175
+ settings: 'Settings',
176
+ duplicate: 'Duplicate',
177
+ delete: 'Delete',
178
+ };
179
+
152
180
  export const ViewSwitcher: React.FC<ViewSwitcherProps> = ({
153
181
  schema,
154
182
  className,
155
183
  onViewChange,
184
+ onCreateView,
185
+ onViewAction,
186
+ createViewLabel = 'Create view',
156
187
  ...props
157
188
  }) => {
158
189
  const storageKey = React.useMemo(() => {
@@ -219,8 +250,42 @@ export const ViewSwitcher: React.FC<ViewSwitcherProps> = ({
219
250
  const isVertical = position === 'left' || position === 'right';
220
251
  const orientation = isVertical ? 'vertical' : 'horizontal';
221
252
 
253
+ const viewActionButtons = schema.viewActions && schema.viewActions.length > 0 ? (
254
+ <div className="flex items-center gap-1">
255
+ {schema.viewActions.map((action, idx) => {
256
+ const ActionIcon = action.icon
257
+ ? resolveIcon(action.icon) || DEFAULT_VIEW_ACTION_ICONS[action.type]
258
+ : DEFAULT_VIEW_ACTION_ICONS[action.type];
259
+ return (
260
+ <Button
261
+ key={`action-${action.type}-${idx}`}
262
+ type="button"
263
+ variant="ghost"
264
+ size="icon-sm"
265
+ onClick={() => onViewAction?.(action.type, currentView!)}
266
+ title={DEFAULT_VIEW_ACTION_LABELS[action.type] || action.type}
267
+ >
268
+ {ActionIcon ? <ActionIcon className="h-3.5 w-3.5" /> : null}
269
+ </Button>
270
+ );
271
+ })}
272
+ </div>
273
+ ) : null;
274
+
275
+ const createViewButton = schema.allowCreateView ? (
276
+ <Button
277
+ type="button"
278
+ variant="ghost"
279
+ size="icon-sm"
280
+ onClick={() => onCreateView?.()}
281
+ title={createViewLabel}
282
+ >
283
+ <Plus className="h-3.5 w-3.5" />
284
+ </Button>
285
+ ) : null;
286
+
222
287
  const switcher = (
223
- <div className={cn(viewSwitcherWidth({ orientation }))}>
288
+ <div className={cn(viewSwitcherWidth({ orientation }), 'flex items-center gap-1')}>
224
289
  {variant === 'dropdown' && (
225
290
  <Select value={currentViewValue} onValueChange={(value) => handleViewChange(value as ViewType)}>
226
291
  <SelectTrigger className={cn('w-full', isVertical ? 'h-10' : 'h-9')}>
@@ -278,6 +343,9 @@ export const ViewSwitcher: React.FC<ViewSwitcherProps> = ({
278
343
  </TabsList>
279
344
  </Tabs>
280
345
  )}
346
+
347
+ {viewActionButtons}
348
+ {createViewButton}
281
349
  </div>
282
350
  );
283
351