Skip to content

Commit 7e6e6dd

Browse files
Copilothotlong
andcommitted
Add ConnectionStatusIndicator to CollaborationProvider, expand user color palette to 16 colors
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent d432acb commit 7e6e6dd

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

packages/plugin-designer/src/CollaborationProvider.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,43 @@ export function useCollaboration(): CollaborationContextValue | null {
200200
return useContext(CollabCtx);
201201
}
202202

203+
/**
204+
* Connection status indicator component.
205+
* Shows the current collaboration connection state with a colored dot and label.
206+
*/
207+
export function ConnectionStatusIndicator({ className }: { className?: string }) {
208+
const ctx = useContext(CollabCtx);
209+
if (!ctx) return null;
210+
211+
const { connectionState, users } = ctx;
212+
const stateConfig: Record<string, { color: string; label: string }> = {
213+
connected: { color: 'bg-green-500', label: 'Connected' },
214+
connecting: { color: 'bg-yellow-500 animate-pulse', label: 'Connecting…' },
215+
disconnected: { color: 'bg-gray-400', label: 'Disconnected' },
216+
error: { color: 'bg-red-500', label: 'Connection error' },
217+
};
218+
const { color, label } = stateConfig[connectionState] ?? stateConfig.disconnected;
219+
220+
return (
221+
<div className={`flex items-center gap-2 text-xs ${className ?? ''}`} role="status" aria-live="polite" aria-label={`Collaboration: ${label}`}>
222+
<span className={`inline-block h-2 w-2 rounded-full ${color}`} />
223+
<span>{label}</span>
224+
{connectionState === 'connected' && users.length > 1 && (
225+
<span className="text-muted-foreground">({users.length} users)</span>
226+
)}
227+
</div>
228+
);
229+
}
230+
203231
/**
204232
* Generate a consistent color for a user ID.
205233
*/
206234
function generateColor(userId: string): string {
207235
const colors = [
208236
'#3b82f6', '#ef4444', '#22c55e', '#f59e0b',
209237
'#8b5cf6', '#ec4899', '#06b6d4', '#f97316',
238+
'#14b8a6', '#f43f5e', '#a855f7', '#84cc16',
239+
'#0ea5e9', '#e879f9', '#fb923c', '#facc15',
210240
];
211241
let hash = 0;
212242
for (let i = 0; i < userId.length; i++) {

packages/plugin-designer/src/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { PageDesigner } from './PageDesigner';
1111
import { DataModelDesigner } from './DataModelDesigner';
1212
import { ProcessDesigner } from './ProcessDesigner';
1313
import { ReportDesigner } from './ReportDesigner';
14-
import { CollaborationProvider } from './CollaborationProvider';
14+
import { CollaborationProvider, ConnectionStatusIndicator } from './CollaborationProvider';
1515
import { ViewDesigner } from './ViewDesigner';
1616

1717
export {
@@ -20,6 +20,7 @@ export {
2020
ProcessDesigner,
2121
ReportDesigner,
2222
CollaborationProvider,
23+
ConnectionStatusIndicator,
2324
ViewDesigner,
2425
};
2526

0 commit comments

Comments
 (0)