Skip to content

Commit c806140

Browse files
committed
Add gallery view support in ListView and refactor ViewSwitcher to use buttons for view selection
1 parent 583ddc4 commit c806140

File tree

2 files changed

+33
-22
lines changed

2 files changed

+33
-22
lines changed

packages/plugin-list/src/ListView.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ export const ListView: React.FC<ListViewProps> = ({
299299
if (schema.options?.kanban?.groupField) {
300300
views.push('kanban');
301301
}
302+
303+
// Check for Gallery capabilities
304+
if (schema.options?.gallery?.imageField) {
305+
views.push('gallery');
306+
}
302307

303308
// Check for Calendar capabilities
304309
if (schema.options?.calendar?.startDateField) {

packages/plugin-list/src/ViewSwitcher.tsx

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import * as React from 'react';
10-
import { cn, ToggleGroup, ToggleGroupItem } from '@object-ui/components';
10+
import { cn } from '@object-ui/components';
1111
import {
1212
Grid,
1313
LayoutGrid,
@@ -61,26 +61,32 @@ export const ViewSwitcher: React.FC<ViewSwitcherProps> = ({
6161
className,
6262
}) => {
6363
return (
64-
<ToggleGroup
65-
type="single"
66-
value={currentView}
67-
onValueChange={(value) => value && onViewChange(value as ViewType)}
68-
className={cn("bg-transparent gap-1", className)}
69-
>
70-
{availableViews.map((view) => (
71-
<ToggleGroupItem
72-
key={view}
73-
value={view}
74-
aria-label={VIEW_LABELS[view]}
75-
title={VIEW_LABELS[view]}
76-
className="gap-2 px-3 data-[state=on]:bg-background data-[state=on]:shadow-sm border-transparent border data-[state=on]:border-border/50"
77-
>
78-
{VIEW_ICONS[view]}
79-
<span className="hidden sm:inline-block text-xs font-medium">
80-
{VIEW_LABELS[view]}
81-
</span>
82-
</ToggleGroupItem>
83-
))}
84-
</ToggleGroup>
64+
<div className={cn("flex items-center gap-1 bg-transparent", className)}>
65+
{availableViews.map((view) => {
66+
const isActive = currentView === view;
67+
return (
68+
<button
69+
key={view}
70+
type="button"
71+
onClick={() => onViewChange(view)}
72+
aria-label={VIEW_LABELS[view]}
73+
title={VIEW_LABELS[view]}
74+
aria-pressed={isActive}
75+
data-state={isActive ? 'on' : 'off'}
76+
className={cn(
77+
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
78+
"hover:bg-muted hover:text-muted-foreground",
79+
"gap-2 px-3 py-2",
80+
"data-[state=on]:bg-background data-[state=on]:text-foreground data-[state=on]:shadow-sm border-transparent border data-[state=on]:border-border/50",
81+
)}
82+
>
83+
{VIEW_ICONS[view]}
84+
<span className="hidden sm:inline-block text-xs font-medium">
85+
{VIEW_LABELS[view]}
86+
</span>
87+
</button>
88+
);
89+
})}
90+
</div>
8591
);
8692
};

0 commit comments

Comments
 (0)