@fluentui-react-native/experimental-avatar 0.14.18 → 0.14.19

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 (40) hide show
  1. package/CHANGELOG.json +34 -1
  2. package/CHANGELOG.md +13 -2
  3. package/lib/JSAvatar.d.ts.map +1 -1
  4. package/lib/JSAvatar.helpers.d.ts +1 -3
  5. package/lib/JSAvatar.helpers.d.ts.map +1 -1
  6. package/lib/JSAvatar.helpers.js +0 -29
  7. package/lib/JSAvatar.helpers.js.map +1 -1
  8. package/lib/JSAvatar.js +9 -5
  9. package/lib/JSAvatar.js.map +1 -1
  10. package/lib/JSAvatar.styling.d.ts.map +1 -1
  11. package/lib/JSAvatar.styling.js +36 -33
  12. package/lib/JSAvatar.styling.js.map +1 -1
  13. package/lib/JSAvatar.types.d.ts +21 -6
  14. package/lib/JSAvatar.types.d.ts.map +1 -1
  15. package/lib/JSAvatar.types.js.map +1 -1
  16. package/lib/JSAvatarTokens.d.ts.map +1 -1
  17. package/lib/JSAvatarTokens.js +84 -0
  18. package/lib/JSAvatarTokens.js.map +1 -1
  19. package/lib-commonjs/JSAvatar.d.ts.map +1 -1
  20. package/lib-commonjs/JSAvatar.helpers.d.ts +1 -3
  21. package/lib-commonjs/JSAvatar.helpers.d.ts.map +1 -1
  22. package/lib-commonjs/JSAvatar.helpers.js +1 -31
  23. package/lib-commonjs/JSAvatar.helpers.js.map +1 -1
  24. package/lib-commonjs/JSAvatar.js +9 -5
  25. package/lib-commonjs/JSAvatar.js.map +1 -1
  26. package/lib-commonjs/JSAvatar.styling.d.ts.map +1 -1
  27. package/lib-commonjs/JSAvatar.styling.js +35 -32
  28. package/lib-commonjs/JSAvatar.styling.js.map +1 -1
  29. package/lib-commonjs/JSAvatar.types.d.ts +21 -6
  30. package/lib-commonjs/JSAvatar.types.d.ts.map +1 -1
  31. package/lib-commonjs/JSAvatar.types.js.map +1 -1
  32. package/lib-commonjs/JSAvatarTokens.d.ts.map +1 -1
  33. package/lib-commonjs/JSAvatarTokens.js +84 -0
  34. package/lib-commonjs/JSAvatarTokens.js.map +1 -1
  35. package/package.json +4 -2
  36. package/src/JSAvatar.helpers.ts +1 -39
  37. package/src/JSAvatar.styling.ts +43 -38
  38. package/src/JSAvatar.tsx +9 -4
  39. package/src/JSAvatar.types.ts +21 -6
  40. package/src/JSAvatarTokens.ts +84 -0
@@ -2,7 +2,7 @@ import { JSAvatarName, JSAvatarTokens, AvatarSlotProps, JSAvatarProps } from './
2
2
  import { Theme, UseStylingOptions, buildProps } from '@fluentui-react-native/framework';
3
3
  import { defaultJSAvatarTokens } from './JSAvatarTokens';
4
4
  import { ViewStyle } from 'react-native';
5
- import { calculateEffectiveSizes, convertCoinColorFluent, getRingConfig } from './JSAvatar.helpers';
5
+ import { convertCoinColorFluent, getRingConfig } from './JSAvatar.helpers';
6
6
  import { borderStyles } from '@fluentui-react-native/tokens';
7
7
 
8
8
  const nameMap: { [key: string]: string } = {
@@ -11,7 +11,23 @@ const nameMap: { [key: string]: string } = {
11
11
  end: 'flex-end',
12
12
  };
13
13
 
14
- export const avatarStates: (keyof JSAvatarTokens)[] = ['circular', 'square', 'inactive'];
14
+ export const avatarStates: (keyof JSAvatarTokens)[] = [
15
+ 'circular',
16
+ 'square',
17
+ 'inactive',
18
+ 'size20',
19
+ 'size24',
20
+ 'size28',
21
+ 'size32',
22
+ 'size36',
23
+ 'size40',
24
+ 'size48',
25
+ 'size56',
26
+ 'size64',
27
+ 'size72',
28
+ 'size96',
29
+ 'size120',
30
+ ];
15
31
 
16
32
  export const stylingSettings: UseStylingOptions<JSAvatarProps, AvatarSlotProps, JSAvatarTokens> = {
17
33
  tokens: [defaultJSAvatarTokens, JSAvatarName],
@@ -19,13 +35,12 @@ export const stylingSettings: UseStylingOptions<JSAvatarProps, AvatarSlotProps,
19
35
  slotProps: {
20
36
  root: buildProps(
21
37
  (tokens: JSAvatarTokens) => {
22
- const { physicalSize } = calculateEffectiveSizes(tokens);
23
38
  const { horizontalIconAlignment, verticalIconAlignment } = tokens;
24
39
  return {
25
40
  style: {
26
41
  flexDirection: 'row',
27
- width: physicalSize,
28
- height: physicalSize,
42
+ width: tokens.width,
43
+ height: tokens.height,
29
44
  justifyContent: nameMap[horizontalIconAlignment || 'end'] as ViewStyle['justifyContent'],
30
45
  alignItems: nameMap[verticalIconAlignment || 'end'] as ViewStyle['alignItems'],
31
46
  horizontalIconAlignment,
@@ -34,14 +49,13 @@ export const stylingSettings: UseStylingOptions<JSAvatarProps, AvatarSlotProps,
34
49
  },
35
50
  };
36
51
  },
37
- ['horizontalIconAlignment', 'verticalIconAlignment', 'avatarOpacity'],
52
+ ['horizontalIconAlignment', 'verticalIconAlignment', 'avatarOpacity', 'height', 'width'],
38
53
  ),
39
54
  initials: buildProps(
40
55
  (tokens: JSAvatarTokens) => {
41
- const { initialsSize } = calculateEffectiveSizes(tokens);
42
56
  return {
43
57
  style: {
44
- fontSize: initialsSize,
58
+ fontSize: tokens.initialsSize,
45
59
  },
46
60
  };
47
61
  },
@@ -49,7 +63,6 @@ export const stylingSettings: UseStylingOptions<JSAvatarProps, AvatarSlotProps,
49
63
  ),
50
64
  initialsBackground: buildProps(
51
65
  (tokens: JSAvatarTokens, theme: Theme) => {
52
- const { physicalSize } = calculateEffectiveSizes(tokens);
53
66
  const { backgroundColor, coinColorFluent } = tokens;
54
67
  let effectiveBackgroundColor = backgroundColor;
55
68
  if (coinColorFluent) {
@@ -58,8 +71,8 @@ export const stylingSettings: UseStylingOptions<JSAvatarProps, AvatarSlotProps,
58
71
  return {
59
72
  style: {
60
73
  ...borderStyles.from(tokens, theme),
61
- width: physicalSize,
62
- height: physicalSize,
74
+ width: tokens.width,
75
+ height: tokens.height,
63
76
  flexGrow: 1,
64
77
  alignSelf: 'stretch',
65
78
  justifyContent: 'center',
@@ -68,46 +81,35 @@ export const stylingSettings: UseStylingOptions<JSAvatarProps, AvatarSlotProps,
68
81
  },
69
82
  };
70
83
  },
71
- ['coinColorFluent', 'backgroundColor', 'physicalSize', ...borderStyles.keys],
84
+ ['coinColorFluent', 'backgroundColor', 'width', 'height', ...borderStyles.keys],
72
85
  ),
73
86
  image: buildProps(
74
87
  (tokens: JSAvatarTokens) => {
75
- const { physicalSize } = calculateEffectiveSizes(tokens);
76
-
77
88
  return {
78
89
  style: {
79
90
  borderRadius: tokens.borderRadius,
80
- width: physicalSize,
81
- height: physicalSize,
91
+ width: tokens.width,
92
+ height: tokens.height,
82
93
  },
83
94
  };
84
95
  },
85
- ['physicalSize', 'borderRadius'],
96
+ ['borderRadius', 'width', 'height'],
86
97
  ),
87
98
  icon: buildProps(
88
- (tokens: JSAvatarTokens, theme: Theme) => {
89
- const { iconSize, iconStrokeWidth } = calculateEffectiveSizes(tokens);
90
- const iconSizeAdjusted = iconSize + iconStrokeWidth * 2;
91
- const iconStrokeColor = tokens.iconStrokeColor || theme.colors.background;
99
+ (tokens: JSAvatarTokens) => {
92
100
  return {
93
101
  style: {
94
102
  position: 'absolute',
95
- width: iconSizeAdjusted,
96
- height: iconSizeAdjusted,
97
- bottom: -iconStrokeWidth,
98
- end: -iconStrokeWidth,
99
- borderRadius: iconSizeAdjusted / 2,
100
- borderWidth: iconStrokeWidth,
101
- borderColor: iconStrokeColor,
103
+ width: tokens.iconSize,
104
+ height: tokens.iconSize,
102
105
  },
103
106
  };
104
107
  },
105
- ['iconSize', 'iconStrokeWidth', 'iconStrokeColor'],
108
+ ['iconSize'],
106
109
  ),
107
110
  ring: buildProps(
108
111
  (tokens: JSAvatarTokens, theme: Theme) => {
109
- const { physicalSize } = calculateEffectiveSizes(tokens);
110
- const ringConfig = getRingConfig(physicalSize);
112
+ const ringConfig = getRingConfig(tokens.width);
111
113
 
112
114
  const ringColor = tokens.ringColor;
113
115
  return {
@@ -124,13 +126,16 @@ export const stylingSettings: UseStylingOptions<JSAvatarProps, AvatarSlotProps,
124
126
  },
125
127
  };
126
128
  },
127
- ['physicalSize', 'ring', 'physicalSize', ...borderStyles.keys],
129
+ ['width', 'height', ...borderStyles.keys],
130
+ ),
131
+ badge: buildProps(
132
+ (tokens: JSAvatarTokens) => {
133
+ return {
134
+ size: tokens.badgeSize,
135
+ shape: 'circular',
136
+ };
137
+ },
138
+ ['size'],
128
139
  ),
129
- badge: buildProps((_tokens: JSAvatarTokens) => {
130
- return {
131
- size: 'medium',
132
- shape: 'circular',
133
- };
134
- }, []),
135
140
  },
136
141
  };
package/src/JSAvatar.tsx CHANGED
@@ -5,6 +5,8 @@ import { stylingSettings } from './JSAvatar.styling';
5
5
  import { compose, UseSlots, mergeProps, withSlots } from '@fluentui-react-native/framework';
6
6
  import { useAvatar } from './useAvatar';
7
7
  import { PresenceBadge } from '@fluentui-react-native/badge';
8
+ import { Icon } from '@fluentui-react-native/icon';
9
+ import { createIconProps } from '@fluentui-react-native/interactive-hooks';
8
10
 
9
11
  /**
10
12
  * A function which determines if a set of styles should be applied to the compoent given the current state and props of the avatar.
@@ -20,6 +22,8 @@ export const avatarLookup = (layer: string, state: JSAvatarState, userProps: JSA
20
22
  userProps[layer] ||
21
23
  layer === userProps['shape'] ||
22
24
  (!userProps['shape'] && layer === 'circular') ||
25
+ layer === userProps['size'] ||
26
+ (!userProps['size'] && layer === 'size56') ||
23
27
  (userProps.active === 'inactive' && layer === 'inactive')
24
28
  );
25
29
  };
@@ -32,16 +36,17 @@ export const JSAvatar = compose<JSAvatarType>({
32
36
  image: Image,
33
37
  initials: Text,
34
38
  initialsBackground: View,
35
- icon: Image,
39
+ icon: Icon,
36
40
  ring: View,
37
41
  badge: PresenceBadge,
38
42
  },
39
43
  useRender: (userProps: JSAvatarProps, useSlots: UseSlots<JSAvatarType>) => {
40
44
  const avatar = useAvatar(userProps);
45
+ const iconProps = createIconProps(userProps.icon);
41
46
  const Slots = useSlots(userProps, (layer) => avatarLookup(layer, avatar.state, userProps));
42
47
 
43
48
  return (final: JSAvatarProps) => {
44
- const { activeAppearance, initials, image, badge, ...mergedProps } = mergeProps(avatar.props, final);
49
+ const { activeAppearance, icon, initials, image, badge, ...mergedProps } = mergeProps(avatar.props, final);
45
50
  const { showRing, transparentRing } = avatar.state;
46
51
 
47
52
  return (
@@ -50,11 +55,11 @@ export const JSAvatar = compose<JSAvatarType>({
50
55
  <Slots.image {...image} />
51
56
  ) : (
52
57
  <Slots.initialsBackground>
53
- <Slots.initials>{initials}</Slots.initials>
58
+ {initials ? <Slots.initials>{initials}</Slots.initials> : userProps.icon && <Slots.icon {...iconProps} />}
54
59
  </Slots.initialsBackground>
55
60
  )}
56
61
  {showRing && !transparentRing && <Slots.ring />}
57
- <Slots.badge {...badge} />
62
+ {badge.status && <Slots.badge {...badge} />}
58
63
  </Slots.root>
59
64
  );
60
65
  };
@@ -1,7 +1,8 @@
1
1
  import type { IViewProps } from '@fluentui-react-native/adapters';
2
2
  import { ImageProps, ViewProps, TextProps, ColorValue } from 'react-native';
3
3
  import { IBackgroundColorTokens, IForegroundColorTokens, IBorderTokens } from '@fluentui-react-native/tokens';
4
- import { BadgeProps, PresenceBadgeProps } from '@fluentui-react-native/badge';
4
+ import { BadgeProps, PresenceBadgeProps, BadgeSize } from '@fluentui-react-native/badge';
5
+ import { IconProps, IconSourcesType } from '@fluentui-react-native/icon';
5
6
 
6
7
  export const JSAvatarName = 'Avatar';
7
8
  export const AvatarSizes = [
@@ -66,12 +67,13 @@ export interface AvatarConfigurableProps {
66
67
  export interface JSAvatarProps extends IViewProps, AvatarConfigurableProps {
67
68
  active?: AvatarActive;
68
69
  activeAppearance?: AvatarActiveAppearance;
70
+ badge?: PresenceBadgeProps;
71
+ icon?: IconSourcesType;
69
72
  image?: ImageProps;
70
- src?: string;
71
73
  initials?: string;
72
74
  name?: string;
73
75
  shape?: AvatarShape;
74
- badge?: PresenceBadgeProps;
76
+ src?: string;
75
77
  }
76
78
 
77
79
  export interface AvatarSlotProps {
@@ -79,7 +81,7 @@ export interface AvatarSlotProps {
79
81
  image: ImageProps;
80
82
  initials: TextProps;
81
83
  initialsBackground: ViewProps;
82
- icon: ImageProps;
84
+ icon: IconProps;
83
85
  ring: ViewProps;
84
86
  badge: BadgeProps;
85
87
  }
@@ -87,19 +89,32 @@ export interface AvatarSlotProps {
87
89
  export type IconAlignment = 'start' | 'center' | 'end';
88
90
 
89
91
  export interface JSAvatarTokens extends IBackgroundColorTokens, IForegroundColorTokens, AvatarConfigurableProps, IBorderTokens {
90
- avatarSize?: number;
91
92
  iconSize?: number;
92
93
  iconStrokeWidth?: number;
93
94
  iconStrokeColor?: string;
94
95
  initialsSize?: number;
96
+ height?: number;
95
97
  horizontalIconAlignment?: IconAlignment;
96
98
  verticalIconAlignment?: IconAlignment;
97
- physicalSize?: number;
98
99
  circular?: JSAvatarTokens;
99
100
  square?: JSAvatarTokens;
100
101
  inactive?: JSAvatarTokens;
101
102
  avatarOpacity?: number;
102
103
  ringColor?: ColorValue;
104
+ size20?: JSAvatarTokens;
105
+ size24?: JSAvatarTokens;
106
+ size28?: JSAvatarTokens;
107
+ size32?: JSAvatarTokens;
108
+ size36?: JSAvatarTokens;
109
+ size40?: JSAvatarTokens;
110
+ size48?: JSAvatarTokens;
111
+ size56?: JSAvatarTokens;
112
+ size64?: JSAvatarTokens;
113
+ size72?: JSAvatarTokens;
114
+ size96?: JSAvatarTokens;
115
+ size120?: JSAvatarTokens;
116
+ width?: number;
117
+ badgeSize?: BadgeSize;
103
118
  }
104
119
 
105
120
  export interface JSAvatarState {
@@ -21,4 +21,88 @@ export const defaultJSAvatarTokens: TokenSettings<JSAvatarTokens, Theme> = () =>
21
21
  inactive: {
22
22
  avatarOpacity: 0.8,
23
23
  },
24
+ size20: {
25
+ width: 20,
26
+ height: 20,
27
+ badgeSize: 'smallest',
28
+ iconSize: 10,
29
+ initialsSize: 16,
30
+ },
31
+ size24: {
32
+ width: 24,
33
+ height: 24,
34
+ badgeSize: 'smallest',
35
+ iconSize: 10,
36
+ initialsSize: 16,
37
+ },
38
+ size28: {
39
+ width: 28,
40
+ height: 28,
41
+ badgeSize: 'smaller',
42
+ iconSize: 16,
43
+ initialsSize: 20,
44
+ },
45
+ size32: {
46
+ width: 32,
47
+ height: 32,
48
+ badgeSize: 'smaller',
49
+ iconSize: 16,
50
+ initialsSize: 20,
51
+ },
52
+ size36: {
53
+ width: 36,
54
+ height: 36,
55
+ badgeSize: 'smaller',
56
+ iconSize: 16,
57
+ initialsSize: 20,
58
+ },
59
+ size40: {
60
+ width: 40,
61
+ height: 40,
62
+ badgeSize: 'small',
63
+ iconSize: 16,
64
+ initialsSize: 20,
65
+ },
66
+ size48: {
67
+ width: 48,
68
+ height: 48,
69
+ badgeSize: 'small',
70
+ iconSize: 20,
71
+ initialsSize: 24,
72
+ },
73
+ size56: {
74
+ width: 56,
75
+ height: 56,
76
+ badgeSize: 'medium',
77
+ iconSize: 24,
78
+ initialsSize: 28,
79
+ },
80
+ size64: {
81
+ width: 64,
82
+ height: 64,
83
+ badgeSize: 'large',
84
+ iconSize: 28,
85
+ initialsSize: 32,
86
+ },
87
+ size72: {
88
+ width: 72,
89
+ height: 72,
90
+ badgeSize: 'large',
91
+ iconSize: 28,
92
+ initialsSize: 32,
93
+ },
94
+ size96: {
95
+ width: 96,
96
+ height: 96,
97
+ badgeSize: 'largest',
98
+ iconSize: 40,
99
+ initialsSize: 48,
100
+ },
101
+ size120: {
102
+ width: 120,
103
+ height: 120,
104
+ badgeSize: 'largest',
105
+ iconSize: 40,
106
+ initialsSize: 48,
107
+ },
24
108
  } as JSAvatarTokens);