@linktr.ee/messaging-react 3.5.5-rc-1782987115 → 3.5.5-rc-1782988006

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/{Card-rMhzAqC4.js → Card-BBZvkjL_.js} +2 -2
  2. package/dist/{Card-rMhzAqC4.js.map → Card-BBZvkjL_.js.map} +1 -1
  3. package/dist/{Card-CH1lN2DQ.cjs → Card-BXE8pJ79.cjs} +2 -2
  4. package/dist/{Card-CH1lN2DQ.cjs.map → Card-BXE8pJ79.cjs.map} +1 -1
  5. package/dist/{Card-jw-FEk_j.cjs → Card-C6Wa9-kl.cjs} +2 -2
  6. package/dist/{Card-jw-FEk_j.cjs.map → Card-C6Wa9-kl.cjs.map} +1 -1
  7. package/dist/{Card-CwENIQHI.cjs → Card-D53qZLHI.cjs} +2 -2
  8. package/dist/{Card-CwENIQHI.cjs.map → Card-D53qZLHI.cjs.map} +1 -1
  9. package/dist/{Card-hIM2Pu2w.js → Card-DIZQPGVQ.js} +3 -3
  10. package/dist/{Card-hIM2Pu2w.js.map → Card-DIZQPGVQ.js.map} +1 -1
  11. package/dist/{Card-B6Jplpgi.js → Card-Dq01YelX.js} +2 -2
  12. package/dist/{Card-B6Jplpgi.js.map → Card-Dq01YelX.js.map} +1 -1
  13. package/dist/{LockedThumbnail-NSvs1btu.cjs → LockedThumbnail-Bm2UNwLs.cjs} +2 -2
  14. package/dist/{LockedThumbnail-NSvs1btu.cjs.map → LockedThumbnail-Bm2UNwLs.cjs.map} +1 -1
  15. package/dist/{LockedThumbnail-C68EUgjg.js → LockedThumbnail-DTLtL7Xc.js} +2 -2
  16. package/dist/{LockedThumbnail-C68EUgjg.js.map → LockedThumbnail-DTLtL7Xc.js.map} +1 -1
  17. package/dist/index-CWpqzddu.cjs +2 -0
  18. package/dist/index-CWpqzddu.cjs.map +1 -0
  19. package/dist/{index-Bo9wjHNl.js → index-DX6U0xNB.js} +582 -575
  20. package/dist/index-DX6U0xNB.js.map +1 -0
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +1 -1
  23. package/package.json +2 -2
  24. package/src/components/Avatar/getAvatarEmoji.test.ts +32 -0
  25. package/src/components/Avatar/getAvatarEmoji.ts +32 -19
  26. package/src/components/Avatar/index.tsx +6 -3
  27. package/dist/index-Bo9wjHNl.js.map +0 -1
  28. package/dist/index-Bt9H9JKb.cjs +0 -2
  29. package/dist/index-Bt9H9JKb.cjs.map +0 -1
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-Bt9H9JKb.cjs");exports.ActionButton=e.ActionButton;exports.Avatar=e.Avatar;exports.ChannelEmptyState=e.ChannelEmptyState;exports.ChannelList=e.ChannelList;exports.ChannelView=e.ChannelView;exports.CustomMessageProvider=e.CustomMessageProvider;exports.FaqList=e.FaqList;exports.FaqListItem=e.FaqListItem;exports.LinkAttachment=e.LinkAttachment;exports.LockedAttachment=e.LockedAttachment;exports.MediaMessage=e.MediaMessage;exports.MessageAttachment=e.MessageAttachment;exports.MessageVoteButtons=e.MessageVoteButtons;exports.MessagingProvider=e.MessagingProvider;exports.MessagingShell=e.MessagingShell;exports.buildCompactMetaLabel=e.buildCompactMetaLabel;exports.formatFileSize=e.formatFileSize;exports.formatRelativeTime=e.formatRelativeTime;exports.getFileExtensionLabel=e.getFileExtensionLabel;exports.getMessageDisplayText=e.getMessageDisplayText;exports.isLinkAttachment=e.isLinkAttachment;exports.isUuidLike=e.isUuidLike;exports.messageAttachmentGroupPositionFromStream=e.bubbleGroupPositionFromStream;exports.normalizeLanguageCode=e.normalizeLanguageCode;exports.resolveConversationParticipant=e.resolveConversationParticipant;exports.resolveLinkAttachment=e.resolveLinkAttachment;exports.resolveMediaFromMessage=e.resolveMediaFromMessage;exports.resolveParticipantDisplayName=e.resolveParticipantDisplayName;exports.useComposerLocked=e.useComposerLocked;exports.useCustomMessage=e.useCustomMessage;exports.useMessageVote=e.useMessageVote;exports.useMessaging=e.useMessaging;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-CWpqzddu.cjs");exports.ActionButton=e.ActionButton;exports.Avatar=e.Avatar;exports.ChannelEmptyState=e.ChannelEmptyState;exports.ChannelList=e.ChannelList;exports.ChannelView=e.ChannelView;exports.CustomMessageProvider=e.CustomMessageProvider;exports.FaqList=e.FaqList;exports.FaqListItem=e.FaqListItem;exports.LinkAttachment=e.LinkAttachment;exports.LockedAttachment=e.LockedAttachment;exports.MediaMessage=e.MediaMessage;exports.MessageAttachment=e.MessageAttachment;exports.MessageVoteButtons=e.MessageVoteButtons;exports.MessagingProvider=e.MessagingProvider;exports.MessagingShell=e.MessagingShell;exports.buildCompactMetaLabel=e.buildCompactMetaLabel;exports.formatFileSize=e.formatFileSize;exports.formatRelativeTime=e.formatRelativeTime;exports.getFileExtensionLabel=e.getFileExtensionLabel;exports.getMessageDisplayText=e.getMessageDisplayText;exports.isLinkAttachment=e.isLinkAttachment;exports.isUuidLike=e.isUuidLike;exports.messageAttachmentGroupPositionFromStream=e.bubbleGroupPositionFromStream;exports.normalizeLanguageCode=e.normalizeLanguageCode;exports.resolveConversationParticipant=e.resolveConversationParticipant;exports.resolveLinkAttachment=e.resolveLinkAttachment;exports.resolveMediaFromMessage=e.resolveMediaFromMessage;exports.resolveParticipantDisplayName=e.resolveParticipantDisplayName;exports.useComposerLocked=e.useComposerLocked;exports.useCustomMessage=e.useCustomMessage;exports.useMessageVote=e.useMessageVote;exports.useMessaging=e.useMessaging;
2
2
  //# sourceMappingURL=index.cjs.map
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as e, b as t, C as i, c as o, d as n, e as m, F as r, f as g, L as l, h as M, M as c, i as u, j as L, k as h, l as d, m as p, n as v, o as C, p as A, q as k, s as F, t as P, u as b, v as f, w as x, x as y, y as S, z as q, B as z, D as B, E as D, G as E } from "./index-Bo9wjHNl.js";
1
+ import { a as e, b as t, C as i, c as o, d as n, e as m, F as r, f as g, L as l, h as M, M as c, i as u, j as L, k as h, l as d, m as p, n as v, o as C, p as A, q as k, s as F, t as P, u as b, v as f, w as x, x as y, y as S, z as q, B as z, D as B, E as D, G as E } from "./index-DX6U0xNB.js";
2
2
  export {
3
3
  e as ActionButton,
4
4
  t as Avatar,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linktr.ee/messaging-react",
3
- "version": "3.5.5-rc-1782987115",
3
+ "version": "3.5.5-rc-1782988006",
4
4
  "description": "React messaging components built on messaging-core for web applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -38,7 +38,7 @@
38
38
  },
39
39
  "dependencies": {
40
40
  "@linktr.ee/component-library": "11.8.6",
41
- "@linktr.ee/messaging-core": "2.3.0-rc-1782987115",
41
+ "@linktr.ee/messaging-core": "2.3.0-rc-1782988006",
42
42
  "@phosphor-icons/react": "^2.1.10"
43
43
  },
44
44
  "devDependencies": {
@@ -0,0 +1,32 @@
1
+ import { describe, expect, it } from 'vitest'
2
+
3
+ import { getAvatarBgColor, getAvatarEmoji } from './getAvatarEmoji'
4
+
5
+ const emojiBgColors: Record<string, string> = {
6
+ '🍉': '#D6EBFF',
7
+ '🍎': '#FFD1DD',
8
+ '🍓': '#FFE0AE',
9
+ '🍋': '#CAEEB5',
10
+ '🍌': '#FFF1C9',
11
+ '🍇': '#E6D9FF',
12
+ '🍊': '#D6F4FF',
13
+ '🥥': '#F7E7D8',
14
+ '🍒': '#DFF4D8',
15
+ '🥭': '#FFD8C2',
16
+ '🥝': '#FFE7C7',
17
+ '🫒': '#F6E3B4',
18
+ '🍈': '#D9F7E1',
19
+ }
20
+
21
+ describe('getAvatarBgColor', () => {
22
+ it('returns the mapped color for the avatar emoji and stays consistent for the same id', () => {
23
+ const id = 'user-123'
24
+
25
+ const emoji = getAvatarEmoji(id)
26
+ const color = getAvatarBgColor(id)
27
+
28
+ expect(getAvatarEmoji(id)).toBe(emoji)
29
+ expect(color).toBe(emojiBgColors[emoji])
30
+ expect(getAvatarBgColor(id)).toBe(color)
31
+ })
32
+ })
@@ -1,21 +1,21 @@
1
1
  /**
2
- * Generate a fruit emoji based on a string id
3
- * Returns a consistent fruit emoji for the same id
2
+ * Fruit emojis paired with their avatar background color.
3
+ * Single source of truth for both `getAvatarEmoji` and `getAvatarBgColor`.
4
4
  */
5
- const EMOJIS = [
6
- '🍎', // Apple
7
- '🍌', // Banana
8
- '🍇', // Grape
9
- '🍊', // Orange
10
- '🍓', // Strawberry
11
- '🥥', // Coconut
12
- '🍒', // Cherry
13
- '🥭', // Mango
14
- '🍉', // Watermelon
15
- '🍋', // Lemon
16
- '🥝', // Kiwi
17
- '🫒', // Olive
18
- '🍈', // Melon
5
+ const FRUITS = [
6
+ { emoji: '🍎', bgColor: '#FFD1DD' }, // Apple
7
+ { emoji: '🍌', bgColor: '#FFF1C9' }, // Banana
8
+ { emoji: '🍇', bgColor: '#E6D9FF' }, // Grape
9
+ { emoji: '🍊', bgColor: '#D6F4FF' }, // Orange
10
+ { emoji: '🍓', bgColor: '#FFE0AE' }, // Strawberry
11
+ { emoji: '🥥', bgColor: '#F7E7D8' }, // Coconut
12
+ { emoji: '🍒', bgColor: '#DFF4D8' }, // Cherry
13
+ { emoji: '🥭', bgColor: '#FFD8C2' }, // Mango
14
+ { emoji: '🍉', bgColor: '#D6EBFF' }, // Watermelon
15
+ { emoji: '🍋', bgColor: '#CAEEB5' }, // Lemon
16
+ { emoji: '🥝', bgColor: '#FFE7C7' }, // Kiwi
17
+ { emoji: '🫒', bgColor: '#F6E3B4' }, // Olive
18
+ { emoji: '🍈', bgColor: '#D9F7E1' }, // Melon
19
19
  ]
20
20
 
21
21
  /**
@@ -31,14 +31,27 @@ function hashString(str: string): number {
31
31
  return Math.abs(hash)
32
32
  }
33
33
 
34
+ /**
35
+ * Pick a consistent fruit for an id string
36
+ */
37
+ function getFruit(id: string) {
38
+ return FRUITS[hashString(id) % FRUITS.length]
39
+ }
40
+
34
41
  /**
35
42
  * Get a fruit emoji based on an id string
36
43
  * @param id - The string id to generate emoji from
37
44
  * @returns A fruit emoji string
38
45
  */
39
46
  export function getAvatarEmoji(id: string): string {
40
- const hash = hashString(id)
41
- const index = hash % EMOJIS.length
42
- return EMOJIS[index]
47
+ return getFruit(id).emoji
43
48
  }
44
49
 
50
+ /**
51
+ * Get the background color paired with an id's fruit emoji
52
+ * @param id - The string id to generate the color from
53
+ * @returns A hex color string
54
+ */
55
+ export function getAvatarBgColor(id: string): string {
56
+ return getFruit(id).bgColor
57
+ }
@@ -2,7 +2,7 @@ import { StarIcon } from '@phosphor-icons/react'
2
2
  import classNames from 'classnames'
3
3
  import React from 'react'
4
4
 
5
- import { getAvatarEmoji } from './getAvatarEmoji'
5
+ import { getAvatarBgColor, getAvatarEmoji } from './getAvatarEmoji'
6
6
 
7
7
  export interface AvatarProps {
8
8
  id: string
@@ -28,6 +28,7 @@ export const Avatar = ({
28
28
  dmAgentEnabled = false,
29
29
  }: AvatarProps) => {
30
30
  const emoji = getAvatarEmoji(id)
31
+ const bgColor = getAvatarBgColor(id)
31
32
 
32
33
  // Small avatars scale the emoji with the avatar so it doesn't overpower a
33
34
  // tiny circle — a fixed floor read ~60% of a 17px avatar vs ~35% at 40px.
@@ -62,7 +63,7 @@ export const Avatar = ({
62
63
  <div
63
64
  aria-hidden="true"
64
65
  className={classNames(
65
- 'avatar-fallback flex h-full w-full items-center justify-center bg-[#E6E5E3] font-semibold select-none transition-colors'
66
+ 'avatar-fallback flex h-full w-full items-center justify-center font-semibold select-none transition-colors'
66
67
  )}
67
68
  style={{ fontSize, lineHeight: 1 }}
68
69
  >
@@ -75,13 +76,15 @@ export const Avatar = ({
75
76
  return (
76
77
  <div
77
78
  className={classNames(
78
- 'relative flex-shrink-0 !bg-transparent',
79
+ 'relative flex-shrink-0',
79
80
  className
80
81
  )}
81
82
  style={{
82
83
  '--str-chat__avatar-size': `${size}px`,
83
84
  width: `${size}px`,
84
85
  height: `${size}px`,
86
+ backgroundColor: image ? undefined : bgColor,
87
+ ...borderStyle,
85
88
  } as React.CSSProperties}
86
89
  >
87
90
  {starred && (