@linktr.ee/messaging-react 1.6.2 → 1.6.3

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@linktr.ee/messaging-react",
3
- "version": "1.6.2",
3
+ "version": "1.6.3",
4
4
  "description": "React messaging components built on messaging-core for web applications",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -1,34 +1,9 @@
1
1
  /**
2
2
  * Generate avatar background and text colors based on a string
3
- * Uses the ID to deterministically select from design system colors
3
+ * Returns a consistent background color
4
4
  */
5
- export function getAvatarColor(id: string): {
5
+ export function getAvatarColor(_id: string): {
6
6
  color: string
7
7
  } {
8
- // Map of color combinations from Linktree design system
9
- // Selected for good contrast at 20% opacity
10
- const colors = [
11
- { color: '#8129D9' }, // purple
12
- { color: '#254f1a' }, // dark green
13
- { color: '#061492' }, // dark blue
14
- { color: '#1e2330' }, // dark blue-gray
15
- { color: '#502274' }, // dark purple
16
- { color: '#d717e7' }, // magenta
17
- { color: '#780016' }, // dark red
18
- { color: '#c41500' }, // red
19
- { color: '#fc3e4b' }, // pink
20
- { color: '#4c2e05' }, // brown
21
- { color: '#ff6c02' }, // orange
22
- { color: '#70764d' }, // olive green
23
- ]
24
-
25
- // Simple hash function to get consistent index
26
- let hash = 0
27
- for (let i = 0; i < id.length; i++) {
28
- hash = (hash << 5) - hash + id.charCodeAt(i)
29
- hash = hash & hash // Convert to 32bit integer
30
- }
31
-
32
- const index = Math.abs(hash) % colors.length
33
- return colors[index]
8
+ return { color: '#FBFAF9' }
34
9
  }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Generate a fruit emoji based on a string id
3
+ * Returns a consistent fruit emoji for the same id
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
19
+ ]
20
+
21
+ /**
22
+ * Simple hash function to convert string to number
23
+ */
24
+ function hashString(str: string): number {
25
+ let hash = 0
26
+ for (let i = 0; i < str.length; i++) {
27
+ const char = str.charCodeAt(i)
28
+ hash = (hash << 5) - hash + char
29
+ hash = hash & hash // Convert to 32-bit integer
30
+ }
31
+ return Math.abs(hash)
32
+ }
33
+
34
+ /**
35
+ * Get a fruit emoji based on an id string
36
+ * @param id - The string id to generate emoji from
37
+ * @returns A fruit emoji string
38
+ */
39
+ export function getAvatarEmoji(id: string): string {
40
+ const hash = hashString(id)
41
+ const index = hash % EMOJIS.length
42
+ return EMOJIS[index]
43
+ }
44
+
@@ -1,7 +1,7 @@
1
1
  import classNames from 'classnames'
2
2
  import React from 'react'
3
3
 
4
- import { getAvatarColor } from './avatarColors'
4
+ import { getAvatarEmoji } from './getAvatarEmoji'
5
5
 
6
6
  export interface AvatarProps {
7
7
  id: string
@@ -16,14 +16,13 @@ export interface AvatarProps {
16
16
  */
17
17
  export const Avatar: React.FC<AvatarProps> = ({
18
18
  id,
19
- name,
20
19
  image,
21
20
  size = 40,
22
21
  className,
23
22
  }) => {
24
- const { color } = getAvatarColor(id)
25
- const initial = name.charAt(0).toUpperCase()
23
+ const emoji = getAvatarEmoji(id)
26
24
 
25
+ const DEFAULT_COLOR = '#FBFAF9'
27
26
  // Determine font size based on avatar size
28
27
  const getFontSizeClass = () => {
29
28
  if (size < 32) return 'text-xs'
@@ -36,7 +35,7 @@ export const Avatar: React.FC<AvatarProps> = ({
36
35
  return (
37
36
  <div
38
37
  className={classNames(
39
- 'flex-shrink-0 overflow-hidden rounded-full',
38
+ 'flex-shrink-0 overflow-hidden rounded-lg',
40
39
  className
41
40
  )}
42
41
  style={{ width: `${size}px`, height: `${size}px` }}
@@ -51,15 +50,15 @@ export const Avatar: React.FC<AvatarProps> = ({
51
50
  <div
52
51
  aria-hidden="true"
53
52
  className={classNames(
54
- 'flex h-full w-full items-center justify-center font-semibold',
53
+ 'flex h-full w-full items-center justify-center font-semibold rounded-sm',
55
54
  fontSizeClass
56
55
  )}
57
56
  style={{
58
- color,
59
- backgroundColor: `color-mix(in srgb, ${color} 20%, transparent)`,
57
+ color: DEFAULT_COLOR,
58
+ backgroundColor: `color-mix(in srgb, ${DEFAULT_COLOR} 60%, solid)`,
60
59
  }}
61
60
  >
62
- {initial}
61
+ {emoji}
63
62
  </div>
64
63
  )}
65
64
  </div>