Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions packages/ui/src/components/reactions/reactions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ function name(reaction: Event.Message.Reaction, me?: CurrentUser): string {
const SIZE = {
wide: "w-14 px-2",
mid: "w-12 px-2",
pair: "w-9 px-1.5",
single: "size-5.5 p-0",
digit: "w-9 px-1.5",
} as const;
const STACK = {
right: { wide: "-mr-10", mid: "-mr-8", pair: "-mr-5", single: "-mr-2.5" },
left: { wide: "-ml-10", mid: "-ml-8", pair: "-ml-5", single: "-ml-2.5" },
right: { wide: "-mr-10", mid: "-mr-8", digit: "-mr-5" },
left: { wide: "-ml-10", mid: "-ml-8", digit: "-ml-5" },
} as const;
const SLIDE = {
right: "group-hover/reactions:mr-0.5 group-data-[popup-open]/reactions:mr-0.5",
Expand All @@ -114,8 +113,7 @@ const SLIDE = {
function tier(count: number): keyof typeof SIZE {
if (count > 99) return "wide";
if (count > 9) return "mid";
if (count > 1) return "pair";
return "single";
return "digit";
}

function size(count: number): string {
Expand Down Expand Up @@ -178,9 +176,7 @@ function Reactions(
}
>
<EmojiGlyph emoji={emoji} />
{count > 1 && (
<span className="text-foreground/70 font-semibold tabular-nums">{count}</span>
)}
<span className="text-foreground/70 font-semibold tabular-nums">{count}</span>
</TooltipTrigger>
<TooltipContent>{reactors(users, currentUser)}</TooltipContent>
</Tooltip>
Expand Down
15 changes: 10 additions & 5 deletions packages/ui/src/ui/emoji-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ const TONES = [
{ emoji: "馃憢馃徔", label: "Dark skin tone" },
] as const;

/** Converts a CSS color value to an "R, G, B" triplet string for emoji-mart's --rgb-* vars. */
function toRGB(color: string) {
/**
* Paints CSS colors over each other into an "R, G, B" triplet for emoji-mart's --rgb-* vars, which
* take no alpha: a translucent token alone would read as its opaque base color.
*/
function toRGB(...colors: string[]) {
let ctx = document.createElement("canvas").getContext("2d")!;
ctx.fillStyle = color;
ctx.fillRect(0, 0, 1, 1);
for (let color of colors) {
ctx.fillStyle = color;
ctx.fillRect(0, 0, 1, 1);
}
let [r, g, b] = ctx.getImageData(0, 0, 1, 1).data;
return `${r}, ${g}, ${b}`;
}
Expand All @@ -37,7 +42,7 @@ function resolveVars(el: HTMLElement) {
let get = (name: string) => s.getPropertyValue(name).trim();
return {
"--rgb-background": toRGB(get("--popover")),
"--rgb-input": toRGB(get("--input")),
"--rgb-input": toRGB(get("--popover"), get("--input")),
"--rgb-color": toRGB(get("--popover-foreground")),
"--rgb-accent": toRGB(get("--accent")),
"--color-border": get("--border"),
Expand Down