@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,113 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __rest = (this && this.__rest) || function (s, e) {
14
- var t = {};
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
16
- t[p] = s[p];
17
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
18
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
19
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
20
- t[p[i]] = s[p[i]];
21
- }
22
- return t;
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.removeTitlesFromName = exports.removeRedundantCharacters = exports.getInitials = exports.useAvatar = void 0;
26
- var JSAvatar_types_1 = require("./JSAvatar.types");
27
- var titles_1 = require("./titles");
28
- var getHashCode_1 = require("./getHashCode");
29
- var interactive_hooks_1 = require("@fluentui-react-native/interactive-hooks");
30
- /**
31
- * Re-usable hook for FURN Avatar.
32
- * This hook configures Avatar props and state for FURN Avatar.
33
- *
34
- * @param props user props sent to FURN Avatar
35
- * @returns configured props and state for FURN Avatar
36
- */
37
- var useAvatar = function (props) {
38
- var _a;
39
- var avatarColor = props.avatarColor, active = props.active, accessibilityLabel = props.accessibilityLabel, accessibilityRole = props.accessibilityRole, activeAppearance = props.activeAppearance, badge = props.badge, idForColor = props.idForColor, initials = props.initials, name = props.name, shape = props.shape, transparentRing = props.transparentRing, icon = props.icon, rest = __rest(props, ["avatarColor", "active", "accessibilityLabel", "accessibilityRole", "activeAppearance", "badge", "idForColor", "initials", "name", "shape", "transparentRing", "icon"]);
40
- var showRing = active === 'active' && activeAppearance === 'ring';
41
- var showBadge = (!active || active === 'unset') && !!badge && !!badge.status;
42
- var accessibilityText = "".concat(name || '').concat(showBadge ? ", ".concat(badge.status) : '');
43
- var badgeProps = __assign({ size: 'small' }, badge);
44
- var state = {
45
- showRing: showRing,
46
- transparentRing: !!transparentRing,
47
- showBadge: showBadge,
48
- };
49
- var _initials = initials || (0, exports.getInitials)(name);
50
- var avatarColorsIdx = (0, getHashCode_1.getHashCodeWeb)((_a = idForColor !== null && idForColor !== void 0 ? idForColor : name) !== null && _a !== void 0 ? _a : '') % JSAvatar_types_1.AvatarColors.length;
51
- var _avatarColor = avatarColor === 'colorful' ? JSAvatar_types_1.AvatarColors[avatarColorsIdx] : avatarColor;
52
- var iconProps = (0, interactive_hooks_1.createIconProps)(icon);
53
- return {
54
- props: __assign(__assign({ accessible: true, accessibilityLabel: accessibilityLabel || accessibilityText, accessibilityRole: accessibilityRole !== null && accessibilityRole !== void 0 ? accessibilityRole : 'image', avatarColor: _avatarColor, shape: shape || 'circular' }, rest), { active: active, activeAppearance: activeAppearance, badge: badgeProps, initials: _initials, icon: iconProps }),
55
- state: __assign({}, state),
56
- };
57
- };
58
- exports.useAvatar = useAvatar;
59
- /**
60
- * A function which takes a name and returns initials
61
- *
62
- * @param name
63
- * @returns initials. First letter of the word if only one word was provided.
64
- * First letters of the first and last words if more words were provided.
65
- * Words in braces, titles, special characters, parantheses and dashes should be ignored.
66
- */
67
- var getInitials = function (name) {
68
- if (!name) {
69
- return '';
70
- }
71
- var ARABIC_ASIAN_REGEXP = new RegExp('[\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]', 'g');
72
- var words = (0, exports.removeRedundantCharacters)(name);
73
- var wordsLength = words.length;
74
- var lastWordIdx = wordsLength - 1;
75
- var firstLetter = words[0].charAt(0).toUpperCase();
76
- var lastLetter = wordsLength > 1 ? words[lastWordIdx].charAt(0).toUpperCase() : '';
77
- var initials = "".concat(firstLetter).concat(ARABIC_ASIAN_REGEXP.test(name) ? '' : lastLetter);
78
- return initials;
79
- };
80
- exports.getInitials = getInitials;
81
- /**
82
- * A function which takes a name and returns array of valid words
83
- *
84
- * @param name
85
- * @returns array of words without phone numbers and special characters.
86
- */
87
- var removeRedundantCharacters = function (name) {
88
- if (!name) {
89
- return [];
90
- }
91
- var WORDS_IN_BRACES_REGEXP = new RegExp('[(\\[\\{][^\\)\\]\\}]*[\\)\\]\\}]', 'g');
92
- var PHONE_NUMBER_REGEXP = new RegExp('(\\+|(\\d|\\s))', 'g');
93
- var SPECIAL_CHARACTERS_REGEXP = new RegExp('[!"#\'$%&*+,-./:;>=<?@^_`|~¡¢£¤¥¦§¨©ª«¬®ˉ°±²¼½¾¿×÷]', 'g');
94
- var words = name
95
- .replace(WORDS_IN_BRACES_REGEXP, '')
96
- .replace(PHONE_NUMBER_REGEXP, ' ')
97
- .replace(SPECIAL_CHARACTERS_REGEXP, '')
98
- .trim()
99
- .split(' ');
100
- return (0, exports.removeTitlesFromName)(words);
101
- };
102
- exports.removeRedundantCharacters = removeRedundantCharacters;
103
- /**
104
- * A function which verifies whether words array contains title
105
- *
106
- * @param words array of words in name
107
- * @returns array of words without titles
108
- */
109
- var removeTitlesFromName = function (words) {
110
- return words.filter(function (word) { return !titles_1.titles.has(word); });
111
- };
112
- exports.removeTitlesFromName = removeTitlesFromName;
113
- //# sourceMappingURL=useAvatar.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAvatar.js","sourceRoot":"","sources":["../src/useAvatar.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mDAA0F;AAE1F,mCAAkC;AAClC,6CAA+C;AAC/C,8EAA2E;AAC3E;;;;;;GAMG;AACI,IAAM,SAAS,GAAG,UAAC,KAAoB;;IAE1C,IAAA,WAAW,GAaT,KAAK,YAbI,EACX,MAAM,GAYJ,KAAK,OAZD,EACN,kBAAkB,GAWhB,KAAK,mBAXW,EAClB,iBAAiB,GAUf,KAAK,kBAVU,EACjB,gBAAgB,GASd,KAAK,iBATS,EAChB,KAAK,GAQH,KAAK,MARF,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;IACpD,IAAI,CAAC,IAAI,EAAE;QACT,OAAO,EAAE,CAAC;KACX;IACD,IAAM,sBAAsB,GAAG,IAAI,MAAM,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAC;IACpF,IAAM,mBAAmB,GAAG,IAAI,MAAM,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;IAC/D,IAAM,yBAAyB,GAAG,IAAI,MAAM,CAAC,qDAAqD,EAAE,GAAG,CAAC,CAAC;IACzG,IAAM,KAAK,GAAG,IAAI;SACf,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC;SACnC,OAAO,CAAC,mBAAmB,EAAE,GAAG,CAAC;SACjC,OAAO,CAAC,yBAAyB,EAAE,EAAE,CAAC;SACtC,IAAI,EAAE;SACN,KAAK,CAAC,GAAG,CAAC,CAAC;IACd,OAAO,IAAA,4BAAoB,EAAC,KAAK,CAAC,CAAC;AACrC,CAAC,CAAC;AAdW,QAAA,yBAAyB,6BAcpC;AAEF;;;;;GAKG;AACI,IAAM,oBAAoB,GAAG,UAAC,KAAe;IAClD,OAAO,KAAK,CAAC,MAAM,CAAC,UAAC,IAAI,IAAK,OAAA,CAAC,eAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAjB,CAAiB,CAAC,CAAC;AACnD,CAAC,CAAC;AAFW,QAAA,oBAAoB,wBAE/B"}
@@ -1,201 +0,0 @@
1
- import {
2
- JSAvatarName,
3
- JSAvatarTokens,
4
- AvatarConfigurableProps,
5
- AvatarSlotProps,
6
- JSAvatarProps,
7
- AvatarColors,
8
- AvatarSizesForTokens,
9
- AvatarNamedColor,
10
- ColorSchemes,
11
- AvatarColorSchemes,
12
- } from './JSAvatar.types';
13
- import { Theme, UseStylingOptions, buildProps } from '@fluentui-react-native/framework';
14
- import { defaultJSAvatarTokens } from './JSAvatarTokens';
15
- import { borderStyles, fontStyles } from '@fluentui-react-native/tokens';
16
- import { globalTokens } from '@fluentui-react-native/theme-tokens';
17
-
18
- export const avatarStates: (keyof JSAvatarTokens)[] = [
19
- ...AvatarColors,
20
- ...AvatarSizesForTokens,
21
- 'neutral',
22
- 'brand',
23
- 'circular',
24
- 'square',
25
- 'inactive',
26
- 'iconColor',
27
- 'iconSize',
28
- 'size',
29
- ];
30
-
31
- const tokensThatAreAlsoProps: (keyof AvatarConfigurableProps)[] = [
32
- 'active',
33
- 'avatarColor',
34
- 'initialsColor',
35
- 'ringBackgroundColor',
36
- 'ringColor',
37
- 'ringInnerGap',
38
- 'ringThickness',
39
- ];
40
-
41
- export const stylingSettings: UseStylingOptions<JSAvatarProps, AvatarSlotProps, JSAvatarTokens> = {
42
- tokens: [defaultJSAvatarTokens, JSAvatarName],
43
- tokensThatAreAlsoProps,
44
- states: avatarStates,
45
- slotProps: {
46
- root: buildProps(
47
- (tokens: JSAvatarTokens) => {
48
- const { size, active, avatarOpacity } = tokens;
49
- const ringConfig = getRingConfig(tokens);
50
- const avatarSize = active === 'active' ? ringConfig.size : size;
51
-
52
- return {
53
- style: {
54
- alignItems: 'center',
55
- justifyContent: 'center',
56
- width: avatarSize,
57
- height: avatarSize,
58
- opacity: avatarOpacity,
59
- },
60
- };
61
- },
62
- ['avatarOpacity', 'size'],
63
- ),
64
- initials: buildProps(
65
- (tokens: JSAvatarTokens, theme: Theme) => {
66
- return {
67
- style: {
68
- ...fontStyles.from(tokens, theme),
69
- color: tokens.initialsColor || tokens.color,
70
- textAlign: 'center',
71
- },
72
- };
73
- },
74
- ['color', 'initialsColor', ...fontStyles.keys],
75
- ),
76
- initialsBackground: buildProps(
77
- (tokens: JSAvatarTokens, theme: Theme) => {
78
- const { backgroundColor, size, avatarColor } = tokens;
79
- const _avatarColor =
80
- !avatarColor || AvatarColors.includes(avatarColor as AvatarNamedColor) || ColorSchemes.includes(avatarColor as AvatarColorSchemes)
81
- ? backgroundColor
82
- : avatarColor;
83
- const ringConfig = getRingConfig(tokens);
84
-
85
- return {
86
- style: {
87
- ...borderStyles.from(tokens, theme),
88
- width: size,
89
- height: size,
90
- justifyContent: 'center',
91
- alignItems: 'center',
92
- backgroundColor: _avatarColor,
93
- borderWidth: tokens.borderWidth,
94
- borderColor: tokens.borderColor,
95
- marginTop: ringConfig.ringThickness,
96
- marginLeft: ringConfig.ringThickness,
97
- },
98
- };
99
- },
100
- ['avatarColor', 'backgroundColor', 'size', 'borderColor', 'borderWidth', 'ringThickness', ...borderStyles.keys],
101
- ),
102
- image: buildProps(
103
- (tokens: JSAvatarTokens) => {
104
- const { borderRadius, size, borderWidth, borderColor } = tokens;
105
- const ringConfig = getRingConfig(tokens);
106
- return {
107
- style: {
108
- borderRadius: borderRadius,
109
- width: size,
110
- height: size,
111
- borderWidth: borderWidth,
112
- borderColor: borderColor,
113
- marginTop: ringConfig.ringThickness,
114
- marginLeft: ringConfig.ringThickness,
115
- },
116
- };
117
- },
118
- ['borderRadius', 'size', 'borderColor', 'borderWidth', 'ringThickness'],
119
- ),
120
- icon: buildProps(
121
- (tokens: JSAvatarTokens) => {
122
- return {
123
- style: {
124
- position: 'absolute',
125
- fontSize: tokens.iconSize || tokens.fontSize,
126
- },
127
- color: tokens.iconColor || tokens.color,
128
- width: tokens.iconSize,
129
- height: tokens.iconSize,
130
- };
131
- },
132
- ['iconSize', 'iconColor'],
133
- ),
134
- ring: buildProps(
135
- (tokens: JSAvatarTokens, theme: Theme) => {
136
- const { ringColor, ringBackgroundColor } = tokens;
137
- const ringConfig = getRingConfig(tokens);
138
- return {
139
- style: {
140
- borderStyle: 'solid',
141
- width: ringConfig.size,
142
- height: ringConfig.size,
143
- ...borderStyles.from(tokens, theme),
144
- borderWidth: ringConfig.ringThickness,
145
- backgroundColor: ringBackgroundColor || 'transparent',
146
- borderColor: ringColor,
147
- },
148
- };
149
- },
150
- ['size', 'ringColor', 'ringBackgroundColor', 'ringThickness', ...borderStyles.keys],
151
- ),
152
- badge: buildProps(
153
- (tokens: JSAvatarTokens) => {
154
- return {
155
- size: tokens.badgeSize,
156
- shape: 'circular',
157
- };
158
- },
159
- ['badgeSize'],
160
- ),
161
- },
162
- };
163
-
164
- function getRingConfig(tokens: JSAvatarTokens): any {
165
- const { size, ringThickness } = tokens;
166
- const SMALL_SIZE = 48;
167
- const MEDIUM_SIZE = 71;
168
-
169
- const strokeSize = {
170
- small: globalTokens.stroke.width.thick,
171
- medium: globalTokens.stroke.width.thicker,
172
- large: globalTokens.stroke.width.thickest,
173
- };
174
- if (ringThickness) {
175
- return {
176
- size: size + ringThickness * 4,
177
- ringThickness,
178
- innerStroke: ringThickness,
179
- };
180
- } else {
181
- if (size <= SMALL_SIZE) {
182
- return {
183
- size: size + strokeSize.small * 4,
184
- ringThickness: strokeSize.small,
185
- innerStroke: strokeSize.small,
186
- };
187
- }
188
- if (size <= MEDIUM_SIZE) {
189
- return {
190
- size: size + strokeSize.medium * 4,
191
- ringThickness: strokeSize.medium,
192
- innerStroke: strokeSize.medium,
193
- };
194
- }
195
- return {
196
- size: size + strokeSize.large * 4,
197
- ringThickness: strokeSize.large,
198
- innerStroke: strokeSize.large,
199
- };
200
- }
201
- }
package/src/JSAvatar.tsx DELETED
@@ -1,96 +0,0 @@
1
- /** @jsx withSlots */
2
- import { Image, View, Text, Platform } from 'react-native';
3
- import { Fragment } from 'react';
4
- import { JSAvatarProps, JSAvatarType, JSAvatarName, JSAvatarState, AvatarSlotProps } from './JSAvatar.types';
5
- import { stylingSettings } from './JSAvatar.styling';
6
- import { compose, UseSlots, mergeProps, withSlots, Slots } from '@fluentui-react-native/framework';
7
- import { useAvatar } from './useAvatar';
8
- import { PresenceBadge } from '@fluentui-react-native/badge';
9
- import { Icon } from '@fluentui-react-native/icon';
10
- import { Svg, Path, SvgProps } from 'react-native-svg';
11
- import { SvgIconProps } from '@fluentui-react-native/icon';
12
-
13
- /**
14
- * A function which determines if a set of styles should be applied to the compoent given the current state and props of the avatar.
15
- *
16
- * @param layer The name of the state that is being checked for
17
- * @param state The current state of the avatar
18
- * @param userProps The props that were passed into the avatar
19
- * @returns Whether the styles that are assigned to the layer should be applied to the avatar
20
- */
21
- export const avatarLookup = (layer: string, state: JSAvatarState, userProps: JSAvatarProps): boolean => {
22
- const size = userProps.size;
23
- const avatarSize = size ? `size${size}` : '';
24
- return (
25
- state[layer] ||
26
- userProps[layer] ||
27
- layer === userProps['shape'] ||
28
- (!userProps['shape'] && layer === 'circular') ||
29
- layer === userProps['avatarColor'] ||
30
- layer === avatarSize ||
31
- (userProps.active === 'inactive' && layer === 'inactive')
32
- );
33
- };
34
-
35
- export const JSAvatar = compose<JSAvatarType>({
36
- displayName: JSAvatarName,
37
- ...stylingSettings,
38
- slots: {
39
- root: View,
40
- image: Image,
41
- initials: Text,
42
- initialsBackground: View,
43
- icon: Icon,
44
- ring: View,
45
- badge: PresenceBadge,
46
- },
47
- useRender: (userProps: JSAvatarProps, useSlots: UseSlots<JSAvatarType>) => {
48
- const avatar = useAvatar(userProps);
49
- const Slots = useSlots(avatar.props, (layer) => avatarLookup(layer, avatar.state, avatar.props));
50
-
51
- return (final: JSAvatarProps) => {
52
- const { showRing, transparentRing, showBadge } = avatar.state;
53
- const { badge, ...mergedProps } = avatar.props;
54
- const svgIconsEnabled = ['ios', 'macos', 'win32', 'android'].includes(Platform.OS as string);
55
- const RingComponent = showRing && !transparentRing ? Slots.ring : Fragment;
56
-
57
- return (
58
- <Slots.root {...mergedProps}>
59
- <RingComponent>{renderAvatar(final, avatar.props, Slots, svgIconsEnabled)}</RingComponent>
60
- {svgIconsEnabled && showBadge && <Slots.badge {...badge} />}
61
- </Slots.root>
62
- );
63
- };
64
- },
65
- });
66
-
67
- function renderAvatar(final: JSAvatarProps, avatarProps: JSAvatarProps, Slots: Slots<AvatarSlotProps>, svgIconsEnabled?: boolean) {
68
- const { icon, initials, imageUrl } = mergeProps(avatarProps, final);
69
- return imageUrl ? (
70
- <Slots.image source={{ uri: imageUrl }} />
71
- ) : (
72
- <Slots.initialsBackground accessible={false}>
73
- {initials ? (
74
- <Slots.initials accessible={false}>{initials}</Slots.initials>
75
- ) : avatarProps.icon ? (
76
- <Slots.icon {...icon} accessible={false} />
77
- ) : (
78
- svgIconsEnabled && <Slots.icon svgSource={svgProps} accessible={false} />
79
- )}
80
- </Slots.initialsBackground>
81
- );
82
- }
83
-
84
- const fallbackIconSvg: React.FunctionComponent<SvgProps> = () => {
85
- return (
86
- <Svg viewBox="0 0 14 16">
87
- <Path
88
- fill="currentColor"
89
- d="M7 0C4.79086 0 3 1.79086 3 4C3 6.20914 4.79086 8 7 8C9.20914 8 11 6.20914 11 4C11 1.79086 9.20914 0 7 0ZM4 4C4 2.34315 5.34315 1 7 1C8.65685 1 10 2.34315 10 4C10 5.65685 8.65685 7 7 7C5.34315 7 4 5.65685 4 4ZM2.00873 9C0.903151 9 0 9.88687 0 11C0 12.6912 0.83281 13.9663 2.13499 14.7966C3.41697 15.614 5.14526 16 7 16C8.85474 16 10.583 15.614 11.865 14.7966C13.1672 13.9663 14 12.6912 14 11C14 9.89557 13.1045 9.00001 12 9.00001L2.00873 9ZM1 11C1 10.4467 1.44786 10 2.00873 10L12 10C12.5522 10 13 10.4478 13 11C13 12.3088 12.3777 13.2837 11.3274 13.9534C10.2568 14.636 8.73511 15 7 15C5.26489 15 3.74318 14.636 2.67262 13.9534C1.62226 13.2837 1 12.3088 1 11Z"
90
- ></Path>
91
- </Svg>
92
- );
93
- };
94
- const svgProps: SvgIconProps = {
95
- src: fallbackIconSvg,
96
- };