-
Notifications
You must be signed in to change notification settings - Fork 171
Expand file tree
/
Copy pathBasicAvatar.tsx
More file actions
154 lines (141 loc) · 6.3 KB
/
BasicAvatar.tsx
File metadata and controls
154 lines (141 loc) · 6.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import { useState, useCallback } from 'react';
import type { FunctionComponent } from 'react';
import { View, Text, Platform } from 'react-native';
import { ToggleButton } from '@fluentui/react-native';
import type { AvatarSize, AvatarColor, AvatarActive } from '@fluentui-react-native/avatar';
import { AvatarSizes, AvatarColors, Avatar } from '@fluentui-react-native/avatar';
import type { PresenceBadgeStatus } from '@fluentui-react-native/badge';
import { PresenceBadgeStatuses } from '@fluentui-react-native/badge';
import { svgProps } from '../Common/iconExamples';
import { StyledPicker } from '../Common/StyledPicker';
import { commonTestStyles as commonStyles } from '../Common/styles';
import { satyaPhotoUrl, undefinedText } from '../PersonaCoin/styles';
type WithUndefined<T> = T | typeof undefinedText;
const avatarActive: AvatarActive[] = ['unset', 'active', 'inactive'];
const avatarColors: AvatarColor[] = ['neutral', 'brand', 'colorful', ...AvatarColors];
const allSizes: WithUndefined<AvatarSize>[] = [undefinedText, ...AvatarSizes];
const allPresences: WithUndefined<PresenceBadgeStatus>[] = [undefinedText, ...PresenceBadgeStatuses];
export const StandardUsage: FunctionComponent = () => {
const [isSquare, setSquare] = useState(false);
const [showImage, setShowImage] = useState(true);
const [outOfOffice, setOutOfOffice] = useState(false);
const [active, setActive] = useState<AvatarActive>('unset');
const [imageSize, setImageSize] = useState<WithUndefined<AvatarSize>>(72);
const [presence, setPresence] = useState<WithUndefined<PresenceBadgeStatus>>('available');
const [avatarColor, setAvatarColor] = useState<AvatarColor>('brass');
const onActiveChange = useCallback((value) => setActive(value), []);
const onAvatarColorChange = useCallback((value) => setAvatarColor(value), []);
const onSizeChange = useCallback((value) => setImageSize(value), []);
const onPresenceChange = useCallback((value) => setPresence(value), []);
const avatarSizesForPicker = allSizes.map((size) => size.toString());
const activeAppearance = 'ring';
const fontBuiltInProps = {
fontFamily: 'Arial',
codepoint: 0x2663,
};
const svgIconsEnabled = ['ios', 'macos', 'win32', 'android'].includes(Platform.OS as string);
const badgeStatus = presence === undefinedText ? undefined : presence;
return (
<View style={commonStyles.root}>
<View style={commonStyles.settingsPicker}>
<ToggleButton onClick={() => setShowImage(!showImage)} checked={showImage} style={commonStyles.vmargin}>
{showImage ? 'Hide' : 'Show'} image
</ToggleButton>
<ToggleButton onClick={() => setSquare(!isSquare)} checked={isSquare} style={commonStyles.vmargin}>
Set {isSquare ? ' circle' : ' square'} Avatar
</ToggleButton>
<ToggleButton onClick={() => setOutOfOffice(!outOfOffice)} checked={outOfOffice} style={commonStyles.vmargin}>
Set {outOfOffice ? ' In office' : ' Out of office'}
</ToggleButton>
<StyledPicker
style={commonStyles.vmargin}
prompt="Size"
selected={imageSize.toString()}
onChange={onSizeChange}
collection={avatarSizesForPicker}
/>
<StyledPicker style={commonStyles.vmargin} prompt="Active" selected={active} onChange={onActiveChange} collection={avatarActive} />
{active === 'active' && <Text>Active appearance is ring</Text>}
<StyledPicker
style={commonStyles.vmargin}
prompt="Avatar Color"
selected={avatarColor}
onChange={onAvatarColorChange}
collection={avatarColors}
/>
<StyledPicker
style={commonStyles.vmargin}
prompt="Presence status"
selected={presence}
onChange={onPresenceChange}
collection={allPresences}
/>
</View>
<View style={commonStyles.pickerControlled}>
<Avatar
accessibilityLabel="Fall-back Icon"
accessibilityHint="A picture representing a user"
size={imageSize === undefinedText ? undefined : imageSize}
/>
<Avatar
active={active}
activeAppearance={activeAppearance}
size={imageSize === undefinedText ? undefined : imageSize}
name="Satya Nadella"
shape={isSquare ? 'square' : 'circular'}
accessibilityLabel="Photo of Satya Nadella"
badge={{ status: badgeStatus, outOfOffice, accessibilityLabel: badgeStatus }}
imageUrl={showImage ? satyaPhotoUrl : undefined}
avatarColor={avatarColor}
/>
<Avatar
active={active}
activeAppearance={activeAppearance}
size={imageSize === undefinedText ? undefined : imageSize}
shape={isSquare ? 'square' : 'circular'}
accessibilityLabel="Icon"
image={{ source: showImage ? { uri: satyaPhotoUrl } : undefined }}
name="* Richard Faynman *"
avatarColor="#ff0099"
initialsColor="yellow"
/>
<Avatar
active={active}
activeAppearance={activeAppearance}
size={36}
shape={isSquare ? 'square' : 'circular'}
accessibilityLabel="SVG Icon"
icon={{ fontSource: fontBuiltInProps }}
avatarColor={avatarColor}
badge={{ status: 'outOfOffice', outOfOffice }}
/>
<Avatar
active={active}
activeAppearance={activeAppearance}
size={imageSize === undefinedText ? undefined : imageSize}
shape={isSquare ? 'square' : 'circular'}
accessibilityLabel="SVG Icon"
icon={{ fontSource: fontBuiltInProps, color: 'green' }}
avatarColor={avatarColor}
badge={{ status: 'outOfOffice', outOfOffice }}
/>
{svgIconsEnabled && (
<>
<Avatar
accessibilityHint="A picture representing a user"
active={active}
activeAppearance={activeAppearance}
size={imageSize === undefinedText ? undefined : imageSize}
shape={isSquare ? 'square' : 'circular'}
accessibilityLabel="SVG Icon"
icon={{ svgSource: svgProps }}
avatarColor={avatarColor}
badge={{ status: 'away', outOfOffice }}
idForColor="15"
/>
</>
)}
</View>
</View>
);
};