Components
Loading preview...
a flexible, context-based solution to manage and display multiple workspaces in your app. It uses Radix Popover, supports avatars, search, and customizable rendering—perfect for SaaS dashboards with multi-tenant support.
npx shadcn@latest add https://21st.dev/r/sshahaider/workspaces'use client';
import * as React from 'react';
import {
Workspaces,
WorkspaceTrigger,
WorkspaceContent,
type Workspace,
} from '@/components/ui/workspaces';
import { Button } from '@/components/ui/button';
import { PlusIcon } from 'lucide-react';
// Extended workspace interface for this specific use case
interface MyWorkspace extends Workspace {
logo: string;
plan: string;
slug: string;
}
const workspaces: MyWorkspace[] = [
{
id: '1',
name: 'Asme Inc.',
logo: 'https://avatar.vercel.sh/asme',
plan: 'Free',
slug: 'asme',
},
{
id: '2',
name: 'Bilux Labs',
logo: 'https://avatar.vercel.sh/bilux',
plan: 'Pro',
slug: 'bilux',
},
{
id: '3',
name: 'Zentra Ltd.',
logo: 'https://avatar.vercel.sh/zentra',
plan: 'Team',
slug: 'zentra',
},
{
id: '4',
name: 'Nuvex Group',
logo: 'https://avatar.vercel.sh/nuvex',
plan: 'Free',
slug: 'nuvex',
},
{
id: '5',
name: 'Cortexia',
logo: 'https://avatar.vercel.sh/cortexia',
plan: 'Pro',
slug: 'cortexia',
},
];
export default function Default() {
const [activeWorkspaceId, setActiveWorkspaceId] = React.useState('1');
const handleWorkspaceChange = (workspace: MyWorkspace) => {
setActiveWorkspaceId(workspace.id);
console.log('Selected workspace:', workspace);
};
return (
<div className="flex min-h-screen items-start justify-center gap-8 px-4 py-24">
<Workspaces
workspaces={workspaces}
selectedWorkspaceId={activeWorkspaceId}
onWorkspaceChange={handleWorkspaceChange}
>
<WorkspaceTrigger className="min-w-72" />
<WorkspaceContent>
<Button
variant="ghost"
size="sm"
className="text-muted-foreground w-full justify-start"
>
<PlusIcon className="mr-2 h-4 w-4" />
Create workspace
</Button>
</WorkspaceContent>
</Workspaces>
</div>
);
}