Cloud Native BuildOpenSourceUIOpensource UI
GitHubTwitter/X
  1. Home
  2. Components
  3. Docks
  4. Presence Dock
Back to DocksComponents / Docks

Presence Dock

Free Docks React component — PresenceDock. MIT licensed, copy-paste ready for Next.js and Tailwind CSS.

Collaborator presence dock with MacDock-sized avatar tiles and expandable member list.

Preview

Setup

How to use

Free for personal and commercial use. No UI attribution required. Include the MIT copyright notice when copying component source into your project. Read the MIT license.

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge lucide-react
  2. 2

    Copy lib/cn.ts below. Skip if you already have cn().

  3. 3

    Copy the code below and create components/docks/presence-dock.tsx in your project.

  4. 4

    Import and render:

    Example

    import { PresenceDock } from "@/components/docks/presence-dock";

    <PresenceDock maxVisible={3} onSelect={(id) => console.log(id)} />

lib/cn.ts

1
2
3
4
5
6
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
 
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

components/docks/presence-dock.tsx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
"use client";
 
import {
forwardRef,
useState,
type ComponentPropsWithoutRef,
} from "react";
 
import { cn } from "@/lib/cn";
 
export type PresenceDockPerson = Readonly<{
id: string;
name: string;
initials?: string;
tone?: "rose" | "sky" | "amber" | "emerald" | "neutral";
online?: boolean;
}>;
 
export type PresenceDockProps = Readonly<
{
people?: readonly PresenceDockPerson[];
maxVisible?: number;
defaultOpen?: boolean;
label?: string;
onSelect?: (id: string) => void;
} & ComponentPropsWithoutRef<"div">
>;
 
const DEFAULT_PEOPLE: readonly PresenceDockPerson[] = [
{ id: "ava", name: "Ava Patel", initials: "AP", tone: "rose", online: true },
{ id: "noah", name: "Noah Kim", initials: "NK", tone: "sky", online: true },
{
id: "mia",
name: "Mia Johnson",
initials: "MJ",
tone: "amber",
online: false,
},
{
id: "leo",
name: "Leo Chen",
initials: "LC",
tone: "emerald",
online: true,
},
];
 
function avatarTone(tone: PresenceDockPerson["tone"]) {
switch (tone) {
case "rose":
return "bg-rose-400 text-white";
case "sky":
return "bg-sky-400 text-white";
case "amber":
return "bg-amber-400 text-neutral-900";
case "emerald":
return "bg-emerald-400 text-neutral-900";
default:
return "bg-neutral-800 text-white";
}
}
 
function getInitials(person: PresenceDockPerson) {
if (person.initials) return person.initials;
return person.name
.split(" ")
.filter(Boolean)
.slice(0, 2)
.map((part) => part[0]?.toUpperCase() ?? "")
.join("");
}
 
// Presence dock — collaborator stack in MacDock frosted shell.
export const PresenceDock = forwardRef<HTMLDivElement, PresenceDockProps>(
(
{
className,
people = DEFAULT_PEOPLE,
maxVisible = 3,
defaultOpen = false,
label,
onSelect,
...props
},
ref,
) => {
const [open, setOpen] = useState(defaultOpen);
const visible = people.slice(0, maxVisible);
const overflow = Math.max(0, people.length - maxVisible);
const onlineCount = people.filter((person) => person.online).length;
 
return (
<div
ref={ref}
data-slot="presence-dock"
className={cn("relative inline-flex font-sans", className)}
{...props}
>
<button
type="button"
aria-expanded={open}
aria-label={label ?? `${onlineCount} people online`}
onClick={() => setOpen((value) => !value)}
className="relative flex h-[3.75rem] items-center rounded-full border border-neutral-50 bg-white/50 px-2.5 py-2 shadow-xl shadow-black/10 backdrop-blur-md transition-transform duration-300 ease-smooth will-change-transform hover:scale-[1.02]"
>
<span className="flex items-center">
{visible.map((person, index) => (
<span
key={person.id}
className={cn(
"relative flex size-11 items-center justify-center rounded-full border-2 border-white text-[11px] font-semibold shadow-xs",
avatarTone(person.tone),
index > 0 && "-ml-2.5",
index === 0 && "z-30",
index === 1 && "z-20",
index === 2 && "z-10",
)}
>
{getInitials(person)}
{person.online ? (
<span className="absolute right-0 bottom-0 size-2.5 rounded-full border-2 border-white bg-emerald-400" />
) : null}
</span>
))}
{overflow > 0 ? (
<span className="-ml-2.5 flex size-11 items-center justify-center rounded-full border-2 border-white bg-neutral-900 text-[11px] font-semibold text-white">
+{overflow}
</span>
) : null}
</span>
<span className="ml-2.5 text-xs font-medium text-neutral-600">
{onlineCount} live
</span>
</button>
 
<ul
className={cn(
"absolute top-[calc(100%+0.5rem)] left-0 z-20 w-full origin-top overflow-hidden rounded-2xl border border-neutral-50 bg-white/90 p-2 shadow-xl shadow-black/10 backdrop-blur-md transition-[opacity,transform] duration-200 ease-smooth",
open
? "pointer-events-auto scale-100 opacity-100"
: "pointer-events-none scale-95 opacity-0",
)}
>
{people.map((person) => (
<li key={person.id}>
<button
type="button"
onClick={() => onSelect?.(person.id)}
className="flex w-full items-center gap-2.5 rounded-lg px-2 py-2 text-left transition-colors duration-150 ease-smooth hover:bg-neutral-50"
>
<span
className={cn(
"relative flex size-11 shrink-0 items-center justify-center rounded-full text-[11px] font-semibold",
avatarTone(person.tone),
)}
>
{getInitials(person)}
<span
className={cn(
"absolute right-0 bottom-0 size-2.5 rounded-full border-2 border-white",
person.online ? "bg-emerald-400" : "bg-neutral-300",
)}
/>
</span>
<span className="min-w-0 flex-1">
<span className="block truncate text-sm font-medium text-neutral-900">
{person.name}
</span>
<span className="text-xs text-neutral-500">
{person.online ? "Active now" : "Away"}
</span>
</span>
</button>
</li>
))}
</ul>
</div>
);
},
);
 
PresenceDock.displayName = "PresenceDock";
PreviousNext

On this

page

Jump to a section on this page.

  • lib/cn.ts
  • components/docks/presence-dock.tsx

Sponsor spot · demo preview

Logo

Your brand name

Your tagline or category

A short pitch about your product or service goes here. This is a preview of how sponsor cards will look in this sidebar.

Your call to action

This slot is available. Sponsor Opensource UI and reach developers browsing components every day.