@fluentui-react-native/experimental-avatar 0.12.19 → 0.13.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.
Files changed (66) hide show
  1. package/CHANGELOG.json +180 -1
  2. package/CHANGELOG.md +49 -2
  3. package/lib/JSAvatar.d.ts +12 -0
  4. package/lib/JSAvatar.d.ts.map +1 -0
  5. package/lib/JSAvatar.helpers.d.ts +17 -0
  6. package/lib/JSAvatar.helpers.d.ts.map +1 -0
  7. package/lib/JSAvatar.helpers.js +103 -0
  8. package/lib/JSAvatar.helpers.js.map +1 -0
  9. package/lib/JSAvatar.js +62 -0
  10. package/lib/JSAvatar.js.map +1 -0
  11. package/lib/JSAvatar.styling.d.ts +5 -0
  12. package/lib/JSAvatar.styling.d.ts.map +1 -0
  13. package/lib/JSAvatar.styling.js +123 -0
  14. package/lib/JSAvatar.styling.js.map +1 -0
  15. package/lib/JSAvatar.types.d.ts +76 -0
  16. package/lib/JSAvatar.types.d.ts.map +1 -0
  17. package/lib/JSAvatar.types.js +2 -0
  18. package/lib/JSAvatar.types.js.map +1 -0
  19. package/lib/JSAvatarTokens.d.ts +5 -0
  20. package/lib/JSAvatarTokens.d.ts.map +1 -0
  21. package/lib/JSAvatarTokens.js +18 -0
  22. package/lib/JSAvatarTokens.js.map +1 -0
  23. package/lib/index.d.ts +2 -0
  24. package/lib/index.d.ts.map +1 -1
  25. package/lib/index.js +2 -0
  26. package/lib/index.js.map +1 -1
  27. package/lib/useAvatar.d.ts +10 -0
  28. package/lib/useAvatar.d.ts.map +1 -0
  29. package/lib/useAvatar.js +52 -0
  30. package/lib/useAvatar.js.map +1 -0
  31. package/lib-commonjs/JSAvatar.d.ts +12 -0
  32. package/lib-commonjs/JSAvatar.d.ts.map +1 -0
  33. package/lib-commonjs/JSAvatar.helpers.d.ts +17 -0
  34. package/lib-commonjs/JSAvatar.helpers.d.ts.map +1 -0
  35. package/lib-commonjs/JSAvatar.helpers.js +110 -0
  36. package/lib-commonjs/JSAvatar.helpers.js.map +1 -0
  37. package/lib-commonjs/JSAvatar.js +64 -0
  38. package/lib-commonjs/JSAvatar.js.map +1 -0
  39. package/lib-commonjs/JSAvatar.styling.d.ts +5 -0
  40. package/lib-commonjs/JSAvatar.styling.d.ts.map +1 -0
  41. package/lib-commonjs/JSAvatar.styling.js +125 -0
  42. package/lib-commonjs/JSAvatar.styling.js.map +1 -0
  43. package/lib-commonjs/JSAvatar.types.d.ts +76 -0
  44. package/lib-commonjs/JSAvatar.types.d.ts.map +1 -0
  45. package/lib-commonjs/JSAvatar.types.js +4 -0
  46. package/lib-commonjs/JSAvatar.types.js.map +1 -0
  47. package/lib-commonjs/JSAvatarTokens.d.ts +5 -0
  48. package/lib-commonjs/JSAvatarTokens.d.ts.map +1 -0
  49. package/lib-commonjs/JSAvatarTokens.js +20 -0
  50. package/lib-commonjs/JSAvatarTokens.js.map +1 -0
  51. package/lib-commonjs/index.d.ts +2 -0
  52. package/lib-commonjs/index.d.ts.map +1 -1
  53. package/lib-commonjs/index.js +2 -0
  54. package/lib-commonjs/index.js.map +1 -1
  55. package/lib-commonjs/useAvatar.d.ts +10 -0
  56. package/lib-commonjs/useAvatar.d.ts.map +1 -0
  57. package/lib-commonjs/useAvatar.js +54 -0
  58. package/lib-commonjs/useAvatar.js.map +1 -0
  59. package/package.json +13 -9
  60. package/src/JSAvatar.helpers.ts +126 -0
  61. package/src/JSAvatar.styling.ts +163 -0
  62. package/src/JSAvatar.tsx +56 -0
  63. package/src/JSAvatar.types.ts +110 -0
  64. package/src/JSAvatarTokens.ts +20 -0
  65. package/src/index.ts +2 -0
  66. package/src/useAvatar.ts +43 -0
@@ -0,0 +1,110 @@
1
+ import type { IViewProps } from '@fluentui-react-native/adapters';
2
+ import { ImageProps, ViewProps, ImageURISource, TextProps, ColorValue } from 'react-native';
3
+ import { IBackgroundColorTokens, IForegroundColorTokens, IBorderTokens } from '@fluentui-react-native/tokens';
4
+
5
+ export const JSAvatarName = 'Avatar';
6
+
7
+ export type AvatarSize = 'size8' | 'size24' | 'size32' | 'size40' | 'size48' | 'size56' | 'size72' | 'size100' | 'size120';
8
+
9
+ export type AvatarShape = 'circular' | 'square';
10
+ export type AvatarActive = 'active' | 'inactive' | 'unset';
11
+ export type AvatarActiveAppearance = 'ring' | 'shadow' | 'glow' | 'ring-shadow' | 'ring-glow';
12
+
13
+ /**
14
+ * Sets color of the avatar when there is no picture. Uses fluent color names
15
+ */
16
+ export type AvatarColor =
17
+ | 'cornflower'
18
+ | 'blue'
19
+ | 'royalBlue'
20
+ | 'teal'
21
+ | 'forest'
22
+ | 'darkGreen'
23
+ | 'berry'
24
+ | 'hotPink'
25
+ | 'grape'
26
+ | 'purple'
27
+ | 'pumpkin'
28
+ | 'red'
29
+ | 'burgundy'
30
+ | 'orchid'
31
+ | 'brass'
32
+ | 'darkRed'
33
+ | 'beige'
34
+ | 'platinum'
35
+ | 'steel'
36
+ | 'brown';
37
+
38
+ export type AvatarPresence = 'none' | 'offline' | 'online' | 'away' | 'dnd' | 'blocked' | 'busy';
39
+
40
+ export type RingThickness = number | 'xSmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge';
41
+
42
+ export interface RingConfig {
43
+ accent?: boolean;
44
+ transparent?: boolean;
45
+ ringColor?: ColorValue; // glow
46
+ ringBackgroundColor?: ColorValue; // inner/outer rings
47
+ ringThickness?: RingThickness;
48
+ innerGap?: RingThickness;
49
+ }
50
+
51
+ export interface AvatarConfigurableProps {
52
+ size?: AvatarSize;
53
+ ring?: RingConfig;
54
+ coinColorFluent?: AvatarColor;
55
+ }
56
+
57
+ export interface JSAvatarProps extends IViewProps, AvatarConfigurableProps {
58
+ active?: AvatarActive;
59
+ activeAppearance?: AvatarActiveAppearance;
60
+ imageUrl?: string;
61
+ imageDescription?: string;
62
+ initials?: string;
63
+ presence?: AvatarPresence;
64
+ isOutOfOffice?: boolean;
65
+ shape?: AvatarShape;
66
+ }
67
+
68
+ export interface AvatarSlotProps {
69
+ root: ViewProps;
70
+ photo: ImageProps;
71
+ initials: TextProps;
72
+ initialsBackground: ViewProps;
73
+ icon: ImageProps;
74
+ ring: ViewProps;
75
+ glow: ViewProps;
76
+ }
77
+
78
+ export type IconAlignment = 'start' | 'center' | 'end';
79
+
80
+ export interface JSAvatarTokens extends IBackgroundColorTokens, IForegroundColorTokens, AvatarConfigurableProps, IBorderTokens {
81
+ avatarSize?: number;
82
+ iconSize?: number;
83
+ iconStrokeWidth?: number;
84
+ iconStrokeColor?: string;
85
+ initialsSize?: number;
86
+ horizontalIconAlignment?: IconAlignment;
87
+ verticalIconAlignment?: IconAlignment;
88
+ physicalSize?: number;
89
+ circular?: JSAvatarTokens;
90
+ square?: JSAvatarTokens;
91
+ }
92
+
93
+ export interface JSAvatarState {
94
+ personaPhotoSource: ImageURISource | undefined;
95
+ iconSource: ImageURISource | undefined;
96
+ showRing: boolean;
97
+ transparentRing: boolean;
98
+ }
99
+
100
+ export interface AvatarInfo {
101
+ props: JSAvatarProps;
102
+ state: JSAvatarState;
103
+ }
104
+
105
+ export interface JSAvatarType {
106
+ props: JSAvatarProps;
107
+ slotProps: AvatarSlotProps;
108
+ tokens: JSAvatarTokens;
109
+ state: JSAvatarState;
110
+ }
@@ -0,0 +1,20 @@
1
+ import { Theme } from '@fluentui-react-native/framework';
2
+ import { TokenSettings } from '@fluentui-react-native/use-styling';
3
+ import { JSAvatarTokens } from '.';
4
+ import { convertCoinColorFluent } from './JSAvatar.helpers';
5
+ import { globalTokens } from '@fluentui-react-native/theme-tokens';
6
+
7
+ export const defaultJSAvatarTokens: TokenSettings<JSAvatarTokens, Theme> = () =>
8
+ ({
9
+ horizontalIconAlignment: 'end',
10
+ verticalIconAlignment: 'end',
11
+ color: 'white', // initials is always 'white', unless overriden by token
12
+ iconStrokeColor: 'white', // icon stroke color is always 'white', unless overriden by token
13
+ backgroundColor: convertCoinColorFluent('cornflower'),
14
+ circular: {
15
+ borderRadius: globalTokens.corner.radius.circle,
16
+ },
17
+ square: {
18
+ borderRadius: globalTokens.corner.radius.medium,
19
+ },
20
+ } as JSAvatarTokens);
package/src/index.ts CHANGED
@@ -1 +1,3 @@
1
1
  export * from './Avatar';
2
+ export * from './JSAvatar';
3
+ export * from './JSAvatar.types';
@@ -0,0 +1,43 @@
1
+ import { JSAvatarProps, AvatarInfo, JSAvatarState } from './JSAvatar.types';
2
+ import { getPresenceIconSource } from './JSAvatar.helpers';
3
+
4
+ /**
5
+ * Re-usable hook for FURN Avatar.
6
+ * This hook configures Avatar props and state for FURN Avatar.
7
+ *
8
+ * @param props user props sent to FURN Avatar
9
+ * @returns configured props and state for FURN Avatar
10
+ */
11
+ export const useAvatar = (props: JSAvatarProps): AvatarInfo => {
12
+ const { imageUrl, imageDescription, initials, presence, isOutOfOffice, ring, shape, ...rest } = props;
13
+
14
+ const personaPhotoSource =
15
+ imageUrl === undefined
16
+ ? undefined
17
+ : {
18
+ uri: imageUrl,
19
+ };
20
+
21
+ const iconSource = presence === undefined ? undefined : getPresenceIconSource(presence, isOutOfOffice || false);
22
+ const showRing = !!ring;
23
+ const transparentRing = !!ring?.transparent;
24
+
25
+ const state: JSAvatarState = {
26
+ iconSource,
27
+ personaPhotoSource,
28
+ showRing,
29
+ transparentRing,
30
+ };
31
+
32
+ return {
33
+ props: {
34
+ children: initials,
35
+ accessibilityLabel: imageDescription,
36
+ shape: shape || 'circular',
37
+ ...rest,
38
+ },
39
+ state: {
40
+ ...state,
41
+ },
42
+ };
43
+ };