@fluentui-react-native/experimental-avatar 0.14.45 → 0.15.2

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 (104) hide show
  1. package/CHANGELOG.json +61 -1
  2. package/CHANGELOG.md +26 -2
  3. package/FRNAvatar.podspec +2 -2
  4. package/{lib-commonjs/Avatar.d.ts → lib/NativeAvatar.d.ts} +6 -6
  5. package/lib/NativeAvatar.d.ts.map +1 -0
  6. package/lib/{Avatar.js → NativeAvatar.js} +3 -3
  7. package/lib/NativeAvatar.js.map +1 -0
  8. package/lib/index.d.ts +1 -3
  9. package/lib/index.d.ts.map +1 -1
  10. package/lib/index.js +1 -3
  11. package/lib/index.js.map +1 -1
  12. package/{lib/Avatar.d.ts → lib-commonjs/NativeAvatar.d.ts} +6 -6
  13. package/lib-commonjs/NativeAvatar.d.ts.map +1 -0
  14. package/lib-commonjs/{Avatar.js → NativeAvatar.js} +4 -4
  15. package/lib-commonjs/NativeAvatar.js.map +1 -0
  16. package/lib-commonjs/index.d.ts +1 -3
  17. package/lib-commonjs/index.d.ts.map +1 -1
  18. package/lib-commonjs/index.js +1 -3
  19. package/lib-commonjs/index.js.map +1 -1
  20. package/package.json +2 -10
  21. package/src/{Avatar.tsx → NativeAvatar.tsx} +11 -11
  22. package/src/__tests__/Avatar.test.jsx +129 -0
  23. package/src/__tests__/__snapshots__/{JSAvatar.test.jsx.snap → Avatar.test.jsx.snap} +0 -0
  24. package/src/index.ts +1 -3
  25. package/MIGRATION.md +0 -157
  26. package/SPEC.md +0 -295
  27. package/jest.config.js +0 -2
  28. package/lib/Avatar.d.ts.map +0 -1
  29. package/lib/Avatar.js.map +0 -1
  30. package/lib/JSAvatar.d.ts +0 -12
  31. package/lib/JSAvatar.d.ts.map +0 -1
  32. package/lib/JSAvatar.js +0 -84
  33. package/lib/JSAvatar.js.map +0 -1
  34. package/lib/JSAvatar.styling.d.ts +0 -5
  35. package/lib/JSAvatar.styling.d.ts.map +0 -1
  36. package/lib/JSAvatar.styling.js +0 -158
  37. package/lib/JSAvatar.styling.js.map +0 -1
  38. package/lib/JSAvatar.types.d.ts +0 -213
  39. package/lib/JSAvatar.types.d.ts.map +0 -1
  40. package/lib/JSAvatar.types.js +0 -56
  41. package/lib/JSAvatar.types.js.map +0 -1
  42. package/lib/JSAvatarTokens.d.ts +0 -5
  43. package/lib/JSAvatarTokens.d.ts.map +0 -1
  44. package/lib/JSAvatarTokens.js +0 -198
  45. package/lib/JSAvatarTokens.js.map +0 -1
  46. package/lib/JSAvatarTokens.win32.d.ts +0 -5
  47. package/lib/JSAvatarTokens.win32.d.ts.map +0 -1
  48. package/lib/JSAvatarTokens.win32.js +0 -201
  49. package/lib/JSAvatarTokens.win32.js.map +0 -1
  50. package/lib/getHashCode.d.ts +0 -8
  51. package/lib/getHashCode.d.ts.map +0 -1
  52. package/lib/getHashCode.js +0 -16
  53. package/lib/getHashCode.js.map +0 -1
  54. package/lib/titles.d.ts +0 -2
  55. package/lib/titles.d.ts.map +0 -1
  56. package/lib/titles.js +0 -109
  57. package/lib/titles.js.map +0 -1
  58. package/lib/useAvatar.d.ts +0 -33
  59. package/lib/useAvatar.d.ts.map +0 -1
  60. package/lib/useAvatar.js +0 -106
  61. package/lib/useAvatar.js.map +0 -1
  62. package/lib-commonjs/Avatar.d.ts.map +0 -1
  63. package/lib-commonjs/Avatar.js.map +0 -1
  64. package/lib-commonjs/JSAvatar.d.ts +0 -12
  65. package/lib-commonjs/JSAvatar.d.ts.map +0 -1
  66. package/lib-commonjs/JSAvatar.js +0 -88
  67. package/lib-commonjs/JSAvatar.js.map +0 -1
  68. package/lib-commonjs/JSAvatar.styling.d.ts +0 -5
  69. package/lib-commonjs/JSAvatar.styling.d.ts.map +0 -1
  70. package/lib-commonjs/JSAvatar.styling.js +0 -161
  71. package/lib-commonjs/JSAvatar.styling.js.map +0 -1
  72. package/lib-commonjs/JSAvatar.types.d.ts +0 -213
  73. package/lib-commonjs/JSAvatar.types.d.ts.map +0 -1
  74. package/lib-commonjs/JSAvatar.types.js +0 -59
  75. package/lib-commonjs/JSAvatar.types.js.map +0 -1
  76. package/lib-commonjs/JSAvatarTokens.d.ts +0 -5
  77. package/lib-commonjs/JSAvatarTokens.d.ts.map +0 -1
  78. package/lib-commonjs/JSAvatarTokens.js +0 -202
  79. package/lib-commonjs/JSAvatarTokens.js.map +0 -1
  80. package/lib-commonjs/JSAvatarTokens.win32.d.ts +0 -5
  81. package/lib-commonjs/JSAvatarTokens.win32.d.ts.map +0 -1
  82. package/lib-commonjs/JSAvatarTokens.win32.js +0 -205
  83. package/lib-commonjs/JSAvatarTokens.win32.js.map +0 -1
  84. package/lib-commonjs/getHashCode.d.ts +0 -8
  85. package/lib-commonjs/getHashCode.d.ts.map +0 -1
  86. package/lib-commonjs/getHashCode.js +0 -20
  87. package/lib-commonjs/getHashCode.js.map +0 -1
  88. package/lib-commonjs/titles.d.ts +0 -2
  89. package/lib-commonjs/titles.d.ts.map +0 -1
  90. package/lib-commonjs/titles.js +0 -112
  91. package/lib-commonjs/titles.js.map +0 -1
  92. package/lib-commonjs/useAvatar.d.ts +0 -33
  93. package/lib-commonjs/useAvatar.d.ts.map +0 -1
  94. package/lib-commonjs/useAvatar.js +0 -113
  95. package/lib-commonjs/useAvatar.js.map +0 -1
  96. package/src/JSAvatar.styling.ts +0 -201
  97. package/src/JSAvatar.tsx +0 -96
  98. package/src/JSAvatar.types.ts +0 -286
  99. package/src/JSAvatarTokens.ts +0 -201
  100. package/src/JSAvatarTokens.win32.ts +0 -204
  101. package/src/__tests__/JSAvatar.test.jsx +0 -96
  102. package/src/getHashCode.ts +0 -16
  103. package/src/titles.ts +0 -108
  104. package/src/useAvatar.ts +0 -126
@@ -1,96 +0,0 @@
1
- import * as React from 'react';
2
- import { JSAvatar } from '..';
3
- import { getInitials } from '../useAvatar';
4
- import * as renderer from 'react-test-renderer';
5
-
6
- const emptyData = [
7
- [undefined, ''],
8
- [null, ''],
9
- ['', ''],
10
- ];
11
- const testData = [
12
- ['Marie', 'M'],
13
- ['Aadi KaPoor', 'AK'],
14
- ['Marie Beaudouin', 'MB'],
15
- ['Aadi Meni KaPoor', 'AK'],
16
- ['Will Little (Teams)', 'WL'],
17
- ['Will Little-Tanaka', 'WL'],
18
- ['-Aadi Kapoor', 'AK'],
19
- ['Richard 23 Feynman', 'RF'],
20
- ['* Richard *', 'R'],
21
- ['Richard Feynman [Teams],', 'RF'],
22
- ['Richard Feynman {Teams}', 'RF'],
23
- ['-Test str with *spaces', 'TS'],
24
- ['Second, First', 'SF'],
25
- ];
26
- const namesWithTitles = [
27
- ['Mr Feynman', 'F'],
28
- ['Dr Richard Feynman', 'RF'],
29
- ['Aadi Meni Ka Jr', 'AK'],
30
- ['Consul General Richard Faynman', 'RF'],
31
- ['Major General Victor', 'V'],
32
- ];
33
-
34
- const languageTestData = [
35
- ['خسرو رحیمی', 'خ'], // Arabic
36
- ['桂英', '桂'], // Chinese
37
- ['佳', '佳'],
38
- ['宋智洋', '宋'],
39
- ['강현', '강'], // Korean
40
- ['최종래', '최'],
41
- ['남궁 성종', '남'],
42
- ['松田', '松'], // Japanese
43
- ['海野', '海'],
44
- ['かり', 'か'],
45
- ['Илон Маск', 'ИМ'], // Cyrillic
46
- ['Írissa Þórðardóttir', 'ÍÞ'], // non-ASCII characters
47
- ['Øyvind Åsen', 'ØÅ'],
48
- ['ثابت بن قره', 'ث'], // Thābit ibn Qurra - result in PCX - ثابت
49
- ['שירה לוי', 'של'], // Hebrew - Shira Levi
50
- ];
51
-
52
- const phoneNumbersAndDigits = [
53
- ['12345678', ''],
54
- ['+47 12 34 56 78 (X 5678)', ''],
55
- ['47 12 34', ''],
56
- ['47 12', ''],
57
- ['James Ext 2', 'JE'],
58
- ['1', ''],
59
- ['A2', 'A'],
60
- ];
61
-
62
- const edgeCaseData = [
63
- ['4lex 5loo', 'LL'],
64
- [' !@#$%^&*()=+ (Alpha) David (The man) `~<>,./?[]{}| Goff (Gamma) ', 'DG'],
65
- ['+1 (555) 123-4567 ext.4567', 'E'],
66
- ['1 Ext 2', 'E'],
67
- ['1x1', 'X'],
68
- ];
69
-
70
- describe('Avatar rendering', () => {
71
- it('renders Avatar', () => {
72
- const tree = renderer.create(<JSAvatar />).toJSON();
73
- expect(tree).toMatchSnapshot();
74
- });
75
- });
76
-
77
- describe('getInitials method', () => {
78
- it.each(emptyData)("returns an empty string for '%s'", (text, expected) => {
79
- expect(getInitials(text)).toBe(expected);
80
- });
81
- it.each(testData)("render correct initials for input '%s'", (text, expected) => {
82
- expect(getInitials(text)).toBe(expected);
83
- });
84
- it.each(namesWithTitles)("render initials for names with titles: '%s'", (text, expected) => {
85
- expect(getInitials(text)).toBe(expected);
86
- });
87
- it.each(languageTestData)("render initials for different languages: '%s'", (text, expected) => {
88
- expect(getInitials(text)).toBe(expected);
89
- });
90
- it.each(phoneNumbersAndDigits)("returns an empty string for phone numbers: '%s'", (text, expected) => {
91
- expect(getInitials(text)).toBe(expected);
92
- });
93
- it.each(edgeCaseData)("render initials for edge cases: '%s'", (text, expected) => {
94
- expect(getInitials(text)).toBe(expected);
95
- });
96
- });
@@ -1,16 +0,0 @@
1
- /**
2
- * A function which returns hash code for the avatar color. Web implementation
3
- *
4
- * @param str is idForColor or name
5
- * @returns hash code of the color
6
- */
7
- export const getHashCodeWeb = (str: string): number => {
8
- let hashCode = 0;
9
- for (let len: number = str.length - 1; len >= 0; len--) {
10
- const ch = str.charCodeAt(len);
11
- const shift = len % 8;
12
- hashCode ^= (ch << shift) + (ch >> (8 - shift)); // eslint-disable-line no-bitwise
13
- }
14
-
15
- return hashCode;
16
- };
package/src/titles.ts DELETED
@@ -1,108 +0,0 @@
1
- export const titles = new Set<string>([
2
- 'Mr',
3
- 'Mrs',
4
- 'Miss',
5
- 'Ms',
6
- 'Dr',
7
- 'Admiral',
8
- 'Air Comm',
9
- 'Ambassador',
10
- 'Baron',
11
- 'Baroness',
12
- 'Brig & Mrs',
13
- 'Brig Gen',
14
- 'Brigadier',
15
- 'Brother',
16
- 'Canon',
17
- 'Capt',
18
- 'Chief',
19
- 'Cllr',
20
- 'Col',
21
- 'Commander',
22
- 'Commander & Mrs',
23
- 'Consul',
24
- 'Consul General',
25
- 'Count',
26
- 'Countess',
27
- 'Countess of',
28
- 'Cpl',
29
- 'Dame',
30
- 'Deputy',
31
- 'Dr & Mrs',
32
- 'Drs',
33
- 'Duchess',
34
- 'Duke',
35
- 'Earl',
36
- 'Father',
37
- 'General',
38
- 'Gräfin',
39
- 'HE',
40
- 'HMA',
41
- 'Her Grace',
42
- 'His Excellency',
43
- 'Jr',
44
- 'Judge',
45
- 'Justice',
46
- 'Lady',
47
- 'Lic',
48
- 'Llc',
49
- 'Lord',
50
- 'Lord & Lady',
51
- 'Lt',
52
- 'Lt Col',
53
- 'Lt Cpl',
54
- 'M',
55
- 'Madam',
56
- 'Madame',
57
- 'Major',
58
- 'Major General',
59
- 'Marchioness',
60
- 'Marquis',
61
- 'Minister',
62
- 'Mme',
63
- 'Mr & Dr',
64
- 'Mr & Mrs',
65
- 'Mr & Ms',
66
- 'Prince',
67
- 'Princess',
68
- 'Professor',
69
- 'Prof',
70
- 'Prof & Dr',
71
- 'Prof & Mrs',
72
- 'Prof & Rev',
73
- 'Prof Dame',
74
- 'Prof Dr',
75
- 'Pvt',
76
- 'Rabbi',
77
- 'Rear Admiral',
78
- 'Rev',
79
- 'Rev & Mrs',
80
- 'Rev Canon',
81
- 'Rev Dr',
82
- 'Senator',
83
- 'Sgt',
84
- 'Sheriff',
85
- 'Sir',
86
- 'Sir & Lady',
87
- 'Sister',
88
- 'Sr',
89
- 'Sqr. Leader',
90
- 'The Earl of',
91
- 'The Hon',
92
- 'The Hon Dr',
93
- 'The Hon Lady',
94
- 'The Hon Lord',
95
- 'The Hon Mrs',
96
- 'The Hon Sir',
97
- 'The Honourable',
98
- 'The Rt Hon',
99
- 'The Rt Hon Dr',
100
- 'The Rt Hon Lord',
101
- 'The Rt Hon Sir',
102
- 'The Rt Hon Visc',
103
- 'Viscount',
104
- 'van',
105
- 'I',
106
- 'II',
107
- 'III',
108
- ]);
package/src/useAvatar.ts DELETED
@@ -1,126 +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
- import { createIconProps } from '@fluentui-react-native/interactive-hooks';
6
- /**
7
- * Re-usable hook for FURN Avatar.
8
- * This hook configures Avatar props and state for FURN Avatar.
9
- *
10
- * @param props user props sent to FURN Avatar
11
- * @returns configured props and state for FURN Avatar
12
- */
13
- export const useAvatar = (props: JSAvatarProps): AvatarInfo => {
14
- const {
15
- avatarColor,
16
- active,
17
- accessibilityLabel,
18
- accessibilityRole,
19
- activeAppearance,
20
- badge,
21
- idForColor,
22
- initials,
23
- name,
24
- shape,
25
- transparentRing,
26
- icon,
27
- ...rest
28
- } = props;
29
-
30
- const showRing = active === 'active' && activeAppearance === 'ring';
31
- const showBadge = (!active || active === 'unset') && !!badge && !!badge.status;
32
- const accessibilityText = `${name || ''}${showBadge ? `, ${badge.status}` : ''}`;
33
-
34
- const badgeProps: PresenceBadgeProps = {
35
- size: 'small',
36
- ...badge,
37
- };
38
-
39
- const state: JSAvatarState = {
40
- showRing,
41
- transparentRing: !!transparentRing,
42
- showBadge,
43
- };
44
-
45
- const _initials = initials || getInitials(name);
46
- const avatarColorsIdx = getHashCodeWeb(idForColor ?? name ?? '') % AvatarColors.length;
47
- const _avatarColor = avatarColor === 'colorful' ? AvatarColors[avatarColorsIdx] : avatarColor;
48
-
49
- const iconProps = createIconProps(icon);
50
-
51
- return {
52
- props: {
53
- accessible: true,
54
- accessibilityLabel: accessibilityLabel || accessibilityText,
55
- accessibilityRole: accessibilityRole ?? 'image',
56
- avatarColor: _avatarColor,
57
- shape: shape || 'circular',
58
- ...rest,
59
- active,
60
- activeAppearance,
61
- badge: badgeProps,
62
- initials: _initials,
63
- icon: iconProps,
64
- },
65
- state: {
66
- ...state,
67
- },
68
- };
69
- };
70
-
71
- /**
72
- * A function which takes a name and returns initials
73
- *
74
- * @param name
75
- * @returns initials. First letter of the word if only one word was provided.
76
- * First letters of the first and last words if more words were provided.
77
- * Words in braces, titles, special characters, parantheses and dashes should be ignored.
78
- */
79
- export const getInitials = (name: string): string => {
80
- if (!name) {
81
- return '';
82
- }
83
- const ARABIC_ASIAN_REGEXP = new RegExp(
84
- '[\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]',
85
- 'g',
86
- );
87
- const words = removeRedundantCharacters(name);
88
- const wordsLength = words.length;
89
- const lastWordIdx = wordsLength - 1;
90
- const firstLetter = words[0].charAt(0).toUpperCase();
91
- const lastLetter = wordsLength > 1 ? words[lastWordIdx].charAt(0).toUpperCase() : '';
92
- const initials = `${firstLetter}${ARABIC_ASIAN_REGEXP.test(name) ? '' : lastLetter}`;
93
- return initials;
94
- };
95
-
96
- /**
97
- * A function which takes a name and returns array of valid words
98
- *
99
- * @param name
100
- * @returns array of words without phone numbers and special characters.
101
- */
102
- export const removeRedundantCharacters = (name: string): string[] => {
103
- if (!name) {
104
- return [];
105
- }
106
- const WORDS_IN_BRACES_REGEXP = new RegExp('[(\\[\\{][^\\)\\]\\}]*[\\)\\]\\}]', 'g');
107
- const PHONE_NUMBER_REGEXP = new RegExp('(\\+|(\\d|\\s))', 'g');
108
- const SPECIAL_CHARACTERS_REGEXP = new RegExp('[!"#\'$%&*+,-./:;>=<?@^_`|~¡¢£¤¥¦§¨©ª«¬®ˉ°±²¼½¾¿×÷]', 'g');
109
- const words = name
110
- .replace(WORDS_IN_BRACES_REGEXP, '')
111
- .replace(PHONE_NUMBER_REGEXP, ' ')
112
- .replace(SPECIAL_CHARACTERS_REGEXP, '')
113
- .trim()
114
- .split(' ');
115
- return removeTitlesFromName(words);
116
- };
117
-
118
- /**
119
- * A function which verifies whether words array contains title
120
- *
121
- * @param words array of words in name
122
- * @returns array of words without titles
123
- */
124
- export const removeTitlesFromName = (words: string[]): string[] => {
125
- return words.filter((word) => !titles.has(word));
126
- };