Skip to content

Commit 66be06e

Browse files
committed
feat: refine message reaction chips
1 parent 4c3ecc0 commit 66be06e

1 file changed

Lines changed: 77 additions & 124 deletions

File tree

‎apps/web/src/components/messages/ReactionsBar.svelte‎

Lines changed: 77 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { tick } from "svelte";
2+
import EmojiPicker from "./EmojiPicker.svelte";
33
import type { ReactionSummary } from "../../lib/types";
44
55
let {
@@ -25,18 +25,13 @@
2525
);
2626
2727
let showPicker = $state(false);
28-
let pickerRef = $state<HTMLDivElement>();
28+
let pickerWrapRef = $state<HTMLDivElement>();
2929
let addButtonRef = $state<HTMLButtonElement>();
3030
let pickerId = $derived(`reaction-picker-${messageId}`);
3131
32-
const QUICK_EMOJIS = ["👍", "❤️", "😂", "😮", "😢", "🙏", "🎉", "🔥", "💯", "👀", "🚀", "✅"];
33-
34-
async function togglePicker() {
32+
function togglePicker() {
3533
if (disabled || pending) return;
3634
showPicker = !showPicker;
37-
if (!showPicker) return;
38-
await tick();
39-
pickerRef?.querySelector<HTMLButtonElement>(".emoji-option")?.focus();
4035
}
4136
4237
function chooseReaction(emoji: string) {
@@ -45,19 +40,17 @@
4540
showPicker = false;
4641
}
4742
43+
function closePicker() {
44+
showPicker = false;
45+
addButtonRef?.focus();
46+
}
47+
4848
function handleClickOutside(e: MouseEvent) {
49-
if (pickerRef && !pickerRef.contains(e.target as Node)) {
49+
if (pickerWrapRef && !pickerWrapRef.contains(e.target as Node)) {
5050
showPicker = false;
5151
}
5252
}
5353
54-
function handlePickerKeydown(event: KeyboardEvent) {
55-
if (event.key !== "Escape") return;
56-
event.preventDefault();
57-
showPicker = false;
58-
addButtonRef?.focus();
59-
}
60-
6154
$effect(() => {
6255
if (showPicker) {
6356
document.addEventListener("click", handleClickOutside);
@@ -70,89 +63,81 @@
7063
});
7164
</script>
7265

73-
<div class="reactions-bar">
74-
{#each groupedEntries as { emoji, count, reacted_by_me }}
75-
<button
76-
class="reaction-btn"
77-
class:me={reacted_by_me}
78-
onclick={() => onToggle(emoji)}
79-
disabled={disabled || pending}
80-
aria-pressed={reacted_by_me}
81-
aria-label="{emoji} — {count} reaction{count !== 1 ? 's' : ''}"
82-
title="{emoji}"
83-
>
84-
<span class="reaction-emoji">{emoji}</span>
85-
{#if count > 1}
86-
<span class="reaction-count">{count}</span>
87-
{/if}
88-
</button>
89-
{/each}
90-
91-
<div class="picker-wrapper" bind:this={pickerRef}>
92-
<button
93-
bind:this={addButtonRef}
94-
class="reaction-btn add-btn"
95-
onclick={togglePicker}
96-
aria-label="Add reaction"
97-
aria-controls={pickerId}
98-
aria-expanded={showPicker}
99-
disabled={disabled || pending}
100-
>
101-
<svg width="16" height="16" viewBox="0 0 16 16" fill="none">
102-
<path d="M8 3v10M3 8h10" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
103-
</svg>
104-
</button>
105-
106-
{#if showPicker}
107-
<div
108-
class="emoji-grid"
109-
id={pickerId}
110-
role="group"
111-
aria-label="Choose a reaction"
66+
{#if groupedEntries.length > 0 || error}
67+
<div class="reactions-bar">
68+
{#each groupedEntries as { emoji, count, reacted_by_me }}
69+
<button
70+
class="reaction-btn"
71+
class:me={reacted_by_me}
72+
onclick={() => onToggle(emoji)}
73+
disabled={disabled || pending}
74+
aria-pressed={reacted_by_me}
75+
aria-label="{emoji} — {count} reaction{count !== 1 ? 's' : ''}"
76+
title="{emoji}"
11277
>
113-
{#each QUICK_EMOJIS as emoji}
114-
<button
115-
class="emoji-option"
116-
onclick={() => {
117-
chooseReaction(emoji);
118-
}}
119-
aria-label={`React with ${emoji}`}
120-
title={emoji}
78+
<span class="reaction-emoji">{emoji}</span>
79+
{#if count > 1}
80+
<span class="reaction-count">{count}</span>
81+
{/if}
82+
</button>
83+
{/each}
84+
85+
{#if groupedEntries.length > 0 && !disabled}
86+
<div class="picker-wrapper" bind:this={pickerWrapRef}>
87+
<button
88+
bind:this={addButtonRef}
89+
class="reaction-btn add-btn"
90+
onclick={togglePicker}
91+
aria-label="Add another reaction"
92+
aria-controls={pickerId}
93+
aria-expanded={showPicker}
94+
disabled={disabled || pending}
95+
>
96+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true">
97+
<circle cx="12" cy="12" r="9"/>
98+
<path d="M8 14s1.5 2 4 2 4-2 4-2M9 9h.01M15 9h.01"/>
99+
</svg>
100+
<svg width="10" height="10" viewBox="0 0 16 16" fill="none" aria-hidden="true">
101+
<path d="M8 3v10M3 8h10" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/>
102+
</svg>
103+
</button>
104+
105+
{#if showPicker}
106+
<EmojiPicker
107+
id={pickerId}
121108
disabled={disabled || pending}
122-
onkeydown={handlePickerKeydown}
123-
>
124-
{emoji}
125-
</button>
126-
{/each}
109+
onPick={chooseReaction}
110+
onEscape={closePicker}
111+
/>
112+
{/if}
127113
</div>
128114
{/if}
115+
{#if error}<span class="reaction-error" role="status">{error}</span>{/if}
129116
</div>
130-
{#if error}<span class="reaction-error" role="status">{error}</span>{/if}
131-
</div>
117+
{/if}
132118

133119
<style>
134120
.reactions-bar {
135121
display: flex;
136122
flex-wrap: wrap;
137123
gap: 4px;
138124
align-items: center;
139-
margin-top: 4px;
140-
min-height: 28px;
125+
margin-top: 5px;
141126
}
142127
143128
.reaction-btn {
144129
display: inline-flex;
145130
align-items: center;
146-
gap: 3px;
147-
padding: 2px 6px;
148-
border: 1px solid var(--border, color-mix(in srgb, var(--line, #e0e0e0) 50%, transparent));
149-
border-radius: var(--radius, 8px);
150-
background: transparent;
131+
gap: 4px;
132+
padding: 2px 8px;
133+
border: 1px solid var(--line-strong, rgba(16, 21, 29, 0.17));
134+
border-radius: 999px;
135+
background: var(--panel, #fff);
151136
cursor: pointer;
152-
font-size: 13px;
137+
font-size: 12.5px;
153138
line-height: 1.4;
154139
transition: background 0.1s, border-color 0.1s;
155-
color: var(--text-muted, #666);
140+
color: var(--muted, #666);
156141
}
157142
158143
.reaction-btn:hover {
@@ -166,8 +151,9 @@
166151
}
167152
168153
.reaction-btn.me {
169-
background: color-mix(in srgb, var(--accent, #5865f2) 15%, transparent);
170-
border-color: color-mix(in srgb, var(--accent, #5865f2) 40%, transparent);
154+
background: var(--accent-soft, rgba(0, 128, 196, 0.13));
155+
border-color: var(--accent, #0080c4);
156+
color: var(--text-strong, #10151d);
171157
}
172158
173159
.reaction-emoji {
@@ -176,65 +162,32 @@
176162
}
177163
178164
.reaction-count {
179-
font-size: 12px;
180-
font-weight: 600;
181-
color: var(--text-muted, #666);
165+
font-size: 11.5px;
166+
font-weight: 700;
167+
color: var(--muted, #666);
182168
}
183169
184170
.reaction-btn.me .reaction-count {
185171
color: var(--accent, #5865f2);
186172
}
187173
174+
/* The add-chip only appears next to existing chips (Slack model): dashed,
175+
quiet, and never rendered under a message without reactions. */
188176
.add-btn {
189-
opacity: 0.6;
190-
padding: 2px 4px;
177+
padding: 2px 7px;
178+
border-style: dashed;
179+
background: transparent;
180+
color: var(--muted-2, #8b94a3);
191181
}
192182
193183
.add-btn:hover {
194-
opacity: 1;
184+
color: var(--muted, #666);
195185
}
196186
197187
.picker-wrapper {
198188
position: relative;
199189
}
200190
201-
.emoji-grid {
202-
position: absolute;
203-
bottom: 100%;
204-
left: 0;
205-
margin-bottom: 4px;
206-
display: grid;
207-
grid-template-columns: repeat(6, 1fr);
208-
gap: 2px;
209-
padding: 6px;
210-
background: var(--panel, #fff);
211-
border: 1px solid var(--border, #e0e0e0);
212-
border-radius: var(--radius, 8px);
213-
box-shadow: 0 4px 12px rgba(0,0,0,0.12);
214-
z-index: 100;
215-
min-width: 200px;
216-
}
217-
218-
.emoji-option {
219-
display: flex;
220-
align-items: center;
221-
justify-content: center;
222-
width: 32px;
223-
height: 32px;
224-
padding: 0;
225-
border: none;
226-
border-radius: 4px;
227-
background: transparent;
228-
cursor: pointer;
229-
font-size: 18px;
230-
line-height: 1;
231-
transition: background 0.1s;
232-
}
233-
234-
.emoji-option:hover {
235-
background: color-mix(in srgb, var(--accent, #5865f2) 12%, transparent);
236-
}
237-
238191
.reaction-error {
239192
color: var(--danger, #b42318);
240193
font-size: 12px;

0 commit comments

Comments
 (0)