@fluentui-react-native/experimental-avatar 0.14.43 → 0.15.0

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 (112) hide show
  1. package/CHANGELOG.json +46 -1
  2. package/CHANGELOG.md +26 -2
  3. package/{lib-commonjs/Avatar.d.ts → lib/NativeAvatar.d.ts} +6 -6
  4. package/lib/NativeAvatar.d.ts.map +1 -0
  5. package/lib/{Avatar.js → NativeAvatar.js} +3 -3
  6. package/lib/NativeAvatar.js.map +1 -0
  7. package/lib/index.d.ts +1 -3
  8. package/lib/index.d.ts.map +1 -1
  9. package/lib/index.js +1 -3
  10. package/lib/index.js.map +1 -1
  11. package/{lib/Avatar.d.ts → lib-commonjs/NativeAvatar.d.ts} +6 -6
  12. package/lib-commonjs/NativeAvatar.d.ts.map +1 -0
  13. package/lib-commonjs/{Avatar.js → NativeAvatar.js} +4 -4
  14. package/lib-commonjs/NativeAvatar.js.map +1 -0
  15. package/lib-commonjs/index.d.ts +1 -3
  16. package/lib-commonjs/index.d.ts.map +1 -1
  17. package/lib-commonjs/index.js +1 -3
  18. package/lib-commonjs/index.js.map +1 -1
  19. package/package.json +2 -10
  20. package/src/{Avatar.tsx → NativeAvatar.tsx} +11 -11
  21. package/src/__tests__/{JSAvatar.test.jsx → Avatar.test.jsx} +2 -2
  22. package/src/__tests__/__snapshots__/Avatar.test.jsx.snap +93 -0
  23. package/src/index.ts +1 -3
  24. package/MIGRATION.md +0 -158
  25. package/SPEC.md +0 -305
  26. package/jest.config.js +0 -2
  27. package/lib/Avatar.d.ts.map +0 -1
  28. package/lib/Avatar.js.map +0 -1
  29. package/lib/JSAvatar.d.ts +0 -12
  30. package/lib/JSAvatar.d.ts.map +0 -1
  31. package/lib/JSAvatar.helpers.d.ts +0 -7
  32. package/lib/JSAvatar.helpers.d.ts.map +0 -1
  33. package/lib/JSAvatar.helpers.js +0 -28
  34. package/lib/JSAvatar.helpers.js.map +0 -1
  35. package/lib/JSAvatar.js +0 -75
  36. package/lib/JSAvatar.js.map +0 -1
  37. package/lib/JSAvatar.styling.d.ts +0 -5
  38. package/lib/JSAvatar.styling.d.ts.map +0 -1
  39. package/lib/JSAvatar.styling.js +0 -114
  40. package/lib/JSAvatar.styling.js.map +0 -1
  41. package/lib/JSAvatar.types.d.ts +0 -192
  42. package/lib/JSAvatar.types.d.ts.map +0 -1
  43. package/lib/JSAvatar.types.js +0 -56
  44. package/lib/JSAvatar.types.js.map +0 -1
  45. package/lib/JSAvatarTokens.d.ts +0 -5
  46. package/lib/JSAvatarTokens.d.ts.map +0 -1
  47. package/lib/JSAvatarTokens.js +0 -200
  48. package/lib/JSAvatarTokens.js.map +0 -1
  49. package/lib/JSAvatarTokens.win32.d.ts +0 -5
  50. package/lib/JSAvatarTokens.win32.d.ts.map +0 -1
  51. package/lib/JSAvatarTokens.win32.js +0 -203
  52. package/lib/JSAvatarTokens.win32.js.map +0 -1
  53. package/lib/getHashCode.d.ts +0 -8
  54. package/lib/getHashCode.d.ts.map +0 -1
  55. package/lib/getHashCode.js +0 -16
  56. package/lib/getHashCode.js.map +0 -1
  57. package/lib/titles.d.ts +0 -2
  58. package/lib/titles.d.ts.map +0 -1
  59. package/lib/titles.js +0 -109
  60. package/lib/titles.js.map +0 -1
  61. package/lib/useAvatar.d.ts +0 -33
  62. package/lib/useAvatar.d.ts.map +0 -1
  63. package/lib/useAvatar.js +0 -105
  64. package/lib/useAvatar.js.map +0 -1
  65. package/lib-commonjs/Avatar.d.ts.map +0 -1
  66. package/lib-commonjs/Avatar.js.map +0 -1
  67. package/lib-commonjs/JSAvatar.d.ts +0 -12
  68. package/lib-commonjs/JSAvatar.d.ts.map +0 -1
  69. package/lib-commonjs/JSAvatar.helpers.d.ts +0 -7
  70. package/lib-commonjs/JSAvatar.helpers.d.ts.map +0 -1
  71. package/lib-commonjs/JSAvatar.helpers.js +0 -32
  72. package/lib-commonjs/JSAvatar.helpers.js.map +0 -1
  73. package/lib-commonjs/JSAvatar.js +0 -79
  74. package/lib-commonjs/JSAvatar.js.map +0 -1
  75. package/lib-commonjs/JSAvatar.styling.d.ts +0 -5
  76. package/lib-commonjs/JSAvatar.styling.d.ts.map +0 -1
  77. package/lib-commonjs/JSAvatar.styling.js +0 -117
  78. package/lib-commonjs/JSAvatar.styling.js.map +0 -1
  79. package/lib-commonjs/JSAvatar.types.d.ts +0 -192
  80. package/lib-commonjs/JSAvatar.types.d.ts.map +0 -1
  81. package/lib-commonjs/JSAvatar.types.js +0 -59
  82. package/lib-commonjs/JSAvatar.types.js.map +0 -1
  83. package/lib-commonjs/JSAvatarTokens.d.ts +0 -5
  84. package/lib-commonjs/JSAvatarTokens.d.ts.map +0 -1
  85. package/lib-commonjs/JSAvatarTokens.js +0 -204
  86. package/lib-commonjs/JSAvatarTokens.js.map +0 -1
  87. package/lib-commonjs/JSAvatarTokens.win32.d.ts +0 -5
  88. package/lib-commonjs/JSAvatarTokens.win32.d.ts.map +0 -1
  89. package/lib-commonjs/JSAvatarTokens.win32.js +0 -207
  90. package/lib-commonjs/JSAvatarTokens.win32.js.map +0 -1
  91. package/lib-commonjs/getHashCode.d.ts +0 -8
  92. package/lib-commonjs/getHashCode.d.ts.map +0 -1
  93. package/lib-commonjs/getHashCode.js +0 -20
  94. package/lib-commonjs/getHashCode.js.map +0 -1
  95. package/lib-commonjs/titles.d.ts +0 -2
  96. package/lib-commonjs/titles.d.ts.map +0 -1
  97. package/lib-commonjs/titles.js +0 -112
  98. package/lib-commonjs/titles.js.map +0 -1
  99. package/lib-commonjs/useAvatar.d.ts +0 -33
  100. package/lib-commonjs/useAvatar.d.ts.map +0 -1
  101. package/lib-commonjs/useAvatar.js +0 -112
  102. package/lib-commonjs/useAvatar.js.map +0 -1
  103. package/src/JSAvatar.helpers.ts +0 -35
  104. package/src/JSAvatar.styling.ts +0 -159
  105. package/src/JSAvatar.tsx +0 -80
  106. package/src/JSAvatar.types.ts +0 -259
  107. package/src/JSAvatarTokens.ts +0 -203
  108. package/src/JSAvatarTokens.win32.ts +0 -206
  109. package/src/__tests__/__snapshots__/JSAvatar.test.jsx.snap +0 -96
  110. package/src/getHashCode.ts +0 -16
  111. package/src/titles.ts +0 -108
  112. package/src/useAvatar.ts +0 -122
package/src/useAvatar.ts DELETED
@@ -1,122 +0,0 @@
1
- import { JSAvatarProps, AvatarInfo, JSAvatarState, AvatarColors } from './JSAvatar.types';
2
- import { PresenceBadgeProps } from '@fluentui-react-native/badge';
3
- import { titles } from './titles';
4
- import { getHashCodeWeb } from './getHashCode';
5
- /**
6
- * Re-usable hook for FURN Avatar.
7
- * This hook configures Avatar props and state for FURN Avatar.
8
- *
9
- * @param props user props sent to FURN Avatar
10
- * @returns configured props and state for FURN Avatar
11
- */
12
- export const useAvatar = (props: JSAvatarProps): AvatarInfo => {
13
- const {
14
- avatarColor,
15
- active,
16
- accessibilityLabel,
17
- accessibilityRole,
18
- activeAppearance,
19
- badge,
20
- idForColor,
21
- initials,
22
- name,
23
- ring,
24
- shape,
25
- ...rest
26
- } = props;
27
-
28
- const showRing = active === 'active' && activeAppearance === 'ring';
29
- const transparentRing = !!ring?.transparent;
30
- const showBadge = (!active || active === 'unset') && !!badge && !!badge.status;
31
- const accessibilityText = `${name || ''}${showBadge ? `, ${badge.status}` : ''}`;
32
-
33
- const badgeProps: PresenceBadgeProps = {
34
- size: 'small',
35
- ...badge,
36
- };
37
-
38
- const state: JSAvatarState = {
39
- showRing,
40
- transparentRing,
41
- showBadge,
42
- };
43
-
44
- const _initials = initials || getInitials(name);
45
- const avatarColorsIdx = getHashCodeWeb(idForColor ?? name ?? '') % AvatarColors.length;
46
- const _avatarColor = avatarColor === 'colorful' ? AvatarColors[avatarColorsIdx] : avatarColor;
47
-
48
- return {
49
- props: {
50
- accessible: true,
51
- accessibilityLabel: accessibilityLabel || accessibilityText,
52
- accessibilityRole: accessibilityRole ?? 'image',
53
- avatarColor: _avatarColor,
54
- shape: shape || 'circular',
55
- ...rest,
56
- active,
57
- activeAppearance,
58
- badge: badgeProps,
59
- initials: _initials,
60
- },
61
- state: {
62
- ...state,
63
- },
64
- };
65
- };
66
-
67
- /**
68
- * A function which takes a name and returns initials
69
- *
70
- * @param name
71
- * @returns initials. First letter of the word if only one word was provided.
72
- * First letters of the first and last words if more words were provided.
73
- * Words in braces, titles, special characters, parantheses and dashes should be ignored.
74
- */
75
- export const getInitials = (name: string): string => {
76
- if (!name) {
77
- return '';
78
- }
79
- const ARABIC_ASIAN_REGEXP = new RegExp(
80
- '[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\u1100-\u11FF\u3130-\u318F\uA960-\uA97F\uAC00-\uD7AF\uD7B0-\uD7FF\u3040-\u309F\u30A0-\u30FF\u3400-\u4DBF\u4E00-\u9FFF\uF900-\uFAFF\uD840-\uD869]',
81
- 'g',
82
- );
83
- const words = removeRedundantCharacters(name);
84
- const wordsLength = words.length;
85
- const lastWordIdx = wordsLength - 1;
86
- const firstLetter = words[0].charAt(0).toUpperCase();
87
- const lastLetter = wordsLength > 1 ? words[lastWordIdx].charAt(0).toUpperCase() : '';
88
- const initials = `${firstLetter}${ARABIC_ASIAN_REGEXP.test(name) ? '' : lastLetter}`;
89
- return initials;
90
- };
91
-
92
- /**
93
- * A function which takes a name and returns array of valid words
94
- *
95
- * @param name
96
- * @returns array of words without phone numbers and special characters.
97
- */
98
- export const removeRedundantCharacters = (name: string): string[] => {
99
- if (!name) {
100
- return [];
101
- }
102
- const WORDS_IN_BRACES_REGEXP = new RegExp('[(\\[\\{][^\\)\\]\\}]*[\\)\\]\\}]', 'g');
103
- const PHONE_NUMBER_REGEXP = new RegExp('(\\+|(\\d|\\s))', 'g');
104
- const SPECIAL_CHARACTERS_REGEXP = new RegExp('[!"#\'$%&*+,-./:;>=<?@^_`|~¡¢£¤¥¦§¨©ª«¬®ˉ°±²¼½¾¿×÷]', 'g');
105
- const words = name
106
- .replace(WORDS_IN_BRACES_REGEXP, '')
107
- .replace(PHONE_NUMBER_REGEXP, ' ')
108
- .replace(SPECIAL_CHARACTERS_REGEXP, '')
109
- .trim()
110
- .split(' ');
111
- return removeTitlesFromName(words);
112
- };
113
-
114
- /**
115
- * A function which verifies whether words array contains title
116
- *
117
- * @param words array of words in name
118
- * @returns array of words without titles
119
- */
120
- export const removeTitlesFromName = (words: string[]): string[] => {
121
- return words.filter((word) => !titles.has(word));
122
- };