@instructure/ui-avatar 11.6.0 → 11.6.1-snapshot-129
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.
- package/CHANGELOG.md +39 -294
- package/es/Avatar/{index.js → v1/index.js} +2 -2
- package/es/Avatar/v2/index.js +168 -0
- package/es/Avatar/v2/props.js +35 -0
- package/es/Avatar/v2/styles.js +166 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -2
- package/lib/Avatar/{index.js → v1/index.js} +3 -3
- package/lib/Avatar/v2/index.js +174 -0
- package/lib/Avatar/v2/props.js +40 -0
- package/lib/Avatar/v2/styles.js +172 -0
- package/lib/{index.js → exports/a.js} +2 -2
- package/lib/exports/b.js +12 -0
- package/package.json +39 -17
- package/src/Avatar/{index.tsx → v1/index.tsx} +2 -2
- package/src/Avatar/v2/README.md +277 -0
- package/src/Avatar/v2/index.tsx +175 -0
- package/src/Avatar/v2/props.ts +137 -0
- package/src/Avatar/v2/styles.ts +194 -0
- package/src/exports/a.ts +25 -0
- package/src/exports/b.ts +25 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Avatar/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/Avatar/v1/index.d.ts.map +1 -0
- package/types/Avatar/v1/props.d.ts.map +1 -0
- package/types/Avatar/v1/styles.d.ts.map +1 -0
- package/types/Avatar/v1/theme.d.ts.map +1 -0
- package/types/Avatar/v2/index.d.ts +60 -0
- package/types/Avatar/v2/index.d.ts.map +1 -0
- package/types/Avatar/v2/props.d.ts +76 -0
- package/types/Avatar/v2/props.d.ts.map +1 -0
- package/types/Avatar/v2/styles.d.ts +26 -0
- package/types/Avatar/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +3 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +3 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/Avatar/index.d.ts.map +0 -1
- package/types/Avatar/props.d.ts.map +0 -1
- package/types/Avatar/styles.d.ts.map +0 -1
- package/types/Avatar/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/es/Avatar/{props.js → v1/props.js} +0 -0
- /package/es/Avatar/{styles.js → v1/styles.js} +0 -0
- /package/es/Avatar/{theme.js → v1/theme.js} +0 -0
- /package/lib/Avatar/{props.js → v1/props.js} +0 -0
- /package/lib/Avatar/{styles.js → v1/styles.js} +0 -0
- /package/lib/Avatar/{theme.js → v1/theme.js} +0 -0
- /package/src/Avatar/{README.md → v1/README.md} +0 -0
- /package/src/Avatar/{props.ts → v1/props.ts} +0 -0
- /package/src/Avatar/{styles.ts → v1/styles.ts} +0 -0
- /package/src/Avatar/{theme.ts → v1/theme.ts} +0 -0
- /package/types/Avatar/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/Avatar/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Avatar/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { useStyle } from '@instructure/emotion';
|
|
27
|
+
import { useState, useEffect, forwardRef } from 'react';
|
|
28
|
+
import { passthroughProps } from '@instructure/ui-react-utils';
|
|
29
|
+
import { renderIconWithProps } from '@instructure/ui-icons';
|
|
30
|
+
import { avatarSizeToIconSize } from "./props.js";
|
|
31
|
+
import generateStyle from "./styles.js";
|
|
32
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
33
|
+
const ICON_COLOR_MAP = {
|
|
34
|
+
accent1: 'accentBlueColor',
|
|
35
|
+
accent2: 'accentGreenColor',
|
|
36
|
+
accent3: 'accentRedColor',
|
|
37
|
+
accent4: 'accentOrangeColor',
|
|
38
|
+
accent5: 'accentGreyColor',
|
|
39
|
+
accent6: 'accentAshColor',
|
|
40
|
+
ai: 'onColor'
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
---
|
|
45
|
+
category: components
|
|
46
|
+
---
|
|
47
|
+
**/
|
|
48
|
+
const Avatar = /*#__PURE__*/forwardRef((props, ref) => {
|
|
49
|
+
const _props$size = props.size,
|
|
50
|
+
size = _props$size === void 0 ? 'medium' : _props$size,
|
|
51
|
+
_props$color = props.color,
|
|
52
|
+
color = _props$color === void 0 ? 'accent1' : _props$color,
|
|
53
|
+
_props$hasInverseColo = props.hasInverseColor,
|
|
54
|
+
hasInverseColor = _props$hasInverseColo === void 0 ? false : _props$hasInverseColo,
|
|
55
|
+
_props$showBorder = props.showBorder,
|
|
56
|
+
showBorder = _props$showBorder === void 0 ? 'auto' : _props$showBorder,
|
|
57
|
+
_props$shape = props.shape,
|
|
58
|
+
shape = _props$shape === void 0 ? 'circle' : _props$shape,
|
|
59
|
+
_props$display = props.display,
|
|
60
|
+
display = _props$display === void 0 ? 'inline' : _props$display,
|
|
61
|
+
_props$onImageLoaded = props.onImageLoaded,
|
|
62
|
+
onImageLoaded = _props$onImageLoaded === void 0 ? _event => {} : _props$onImageLoaded,
|
|
63
|
+
src = props.src,
|
|
64
|
+
name = props.name,
|
|
65
|
+
renderIcon = props.renderIcon,
|
|
66
|
+
alt = props.alt,
|
|
67
|
+
themeOverride = props.themeOverride,
|
|
68
|
+
margin = props.margin;
|
|
69
|
+
const _useState = useState(false),
|
|
70
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
71
|
+
loaded = _useState2[0],
|
|
72
|
+
setLoaded = _useState2[1];
|
|
73
|
+
const styles = useStyle({
|
|
74
|
+
generateStyle,
|
|
75
|
+
themeOverride,
|
|
76
|
+
params: {
|
|
77
|
+
loaded,
|
|
78
|
+
size,
|
|
79
|
+
color,
|
|
80
|
+
hasInverseColor,
|
|
81
|
+
shape,
|
|
82
|
+
src,
|
|
83
|
+
showBorder,
|
|
84
|
+
display,
|
|
85
|
+
margin
|
|
86
|
+
},
|
|
87
|
+
componentId: 'Avatar',
|
|
88
|
+
displayName: 'Avatar'
|
|
89
|
+
});
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
// in case the image is unset in an update, show icons/initials again
|
|
92
|
+
if (loaded && !src) {
|
|
93
|
+
setLoaded(false);
|
|
94
|
+
}
|
|
95
|
+
// Image already loaded (common in SSR)
|
|
96
|
+
//TODO-rework make this work
|
|
97
|
+
// if (src && !loaded && imgRef.current && imgRef.current.complete) {
|
|
98
|
+
// setLoaded(true)
|
|
99
|
+
// onImageLoaded?.()
|
|
100
|
+
// }
|
|
101
|
+
}, [loaded, src]);
|
|
102
|
+
const makeInitialsFromName = () => {
|
|
103
|
+
if (!name || typeof name !== 'string' || name.trim().length === 0) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const currentName = name.trim();
|
|
107
|
+
if (currentName.match(/\s+/)) {
|
|
108
|
+
const names = currentName.split(/\s+/);
|
|
109
|
+
return (names[0][0] + names[names.length - 1][0]).toUpperCase();
|
|
110
|
+
} else {
|
|
111
|
+
return currentName[0].toUpperCase();
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const renderInitials = () => {
|
|
115
|
+
return _jsx("span", {
|
|
116
|
+
"aria-hidden": "true",
|
|
117
|
+
children: makeInitialsFromName()
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
const renderImage = () => _jsx("img", {
|
|
121
|
+
style: {
|
|
122
|
+
width: '100%',
|
|
123
|
+
height: '100%',
|
|
124
|
+
objectFit: 'cover',
|
|
125
|
+
objectPosition: 'center',
|
|
126
|
+
...(loaded ? {} : {
|
|
127
|
+
display: 'none'
|
|
128
|
+
})
|
|
129
|
+
},
|
|
130
|
+
src: src,
|
|
131
|
+
alt: alt ? alt : '',
|
|
132
|
+
onLoad: event => {
|
|
133
|
+
setLoaded(true);
|
|
134
|
+
onImageLoaded(event);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
const renderContent = () => {
|
|
138
|
+
//image in avatar - prioritize image over icon
|
|
139
|
+
if (src) {
|
|
140
|
+
return _jsxs(_Fragment, {
|
|
141
|
+
children: [renderImage(), loaded ? null : renderInitials()]
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
//icon in avatar
|
|
146
|
+
if (renderIcon) {
|
|
147
|
+
const iconSize = avatarSizeToIconSize[size];
|
|
148
|
+
const iconColor = hasInverseColor ? 'onColor' : ICON_COLOR_MAP[color];
|
|
149
|
+
return renderIconWithProps(renderIcon, iconSize, iconColor);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
//initials in avatar
|
|
153
|
+
return renderInitials();
|
|
154
|
+
};
|
|
155
|
+
return _jsx("div", {
|
|
156
|
+
...passthroughProps({
|
|
157
|
+
...props
|
|
158
|
+
}),
|
|
159
|
+
ref: ref,
|
|
160
|
+
"aria-label": alt ? alt : void 0,
|
|
161
|
+
role: alt ? 'img' : void 0,
|
|
162
|
+
css: styles === null || styles === void 0 ? void 0 : styles.avatar,
|
|
163
|
+
children: renderContent()
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
Avatar.displayName = 'Avatar';
|
|
167
|
+
export default Avatar;
|
|
168
|
+
export { Avatar };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const avatarSizeToIconSize = {
|
|
26
|
+
'xx-small': 'xs',
|
|
27
|
+
'x-small': 'xs',
|
|
28
|
+
small: 'sm',
|
|
29
|
+
medium: 'md',
|
|
30
|
+
large: 'lg',
|
|
31
|
+
'x-large': 'xl',
|
|
32
|
+
'xx-large': '2xl'
|
|
33
|
+
};
|
|
34
|
+
const allowedProps = ['name', 'src', 'alt', 'size', 'color', 'hasInverseColor', 'shape', 'margin', 'display', 'onImageLoaded', 'renderIcon', 'showBorder'];
|
|
35
|
+
export { allowedProps, avatarSizeToIconSize };
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { calcSpacingFromShorthand } from '@instructure/emotion';
|
|
26
|
+
/**
|
|
27
|
+
* ---
|
|
28
|
+
* private: true
|
|
29
|
+
* ---
|
|
30
|
+
* Generates the style object from the theme and provided additional information
|
|
31
|
+
* @param componentTheme The theme variable object.
|
|
32
|
+
* @param params Additional parameters to customize the style.
|
|
33
|
+
* @param sharedTokens Shared token object that stores common values for the theme.
|
|
34
|
+
* @return The final style object, which will be used in the component
|
|
35
|
+
*/
|
|
36
|
+
const generateStyle = (componentTheme, params, sharedTokens) => {
|
|
37
|
+
const loaded = params.loaded,
|
|
38
|
+
size = params.size,
|
|
39
|
+
color = params.color,
|
|
40
|
+
hasInverseColor = params.hasInverseColor,
|
|
41
|
+
shape = params.shape,
|
|
42
|
+
showBorder = params.showBorder,
|
|
43
|
+
display = params.display,
|
|
44
|
+
margin = params.margin;
|
|
45
|
+
const sizeStyles = {
|
|
46
|
+
'xx-small': {
|
|
47
|
+
fontSize: componentTheme.fontSize2xs,
|
|
48
|
+
borderWidth: componentTheme.borderWidthSm,
|
|
49
|
+
width: componentTheme.size2xs,
|
|
50
|
+
height: componentTheme.size2xs
|
|
51
|
+
},
|
|
52
|
+
'x-small': {
|
|
53
|
+
fontSize: componentTheme.fontSizeXs,
|
|
54
|
+
borderWidth: componentTheme.borderWidthSm,
|
|
55
|
+
width: componentTheme.sizeXs,
|
|
56
|
+
height: componentTheme.sizeXs
|
|
57
|
+
},
|
|
58
|
+
small: {
|
|
59
|
+
fontSize: componentTheme.fontSizeSm,
|
|
60
|
+
borderWidth: componentTheme.borderWidthSm,
|
|
61
|
+
width: componentTheme.sizeSm,
|
|
62
|
+
height: componentTheme.sizeSm
|
|
63
|
+
},
|
|
64
|
+
medium: {
|
|
65
|
+
fontSize: componentTheme.fontSizeMd,
|
|
66
|
+
borderWidth: componentTheme.borderWidthMd,
|
|
67
|
+
width: componentTheme.sizeMd,
|
|
68
|
+
height: componentTheme.sizeMd
|
|
69
|
+
},
|
|
70
|
+
large: {
|
|
71
|
+
fontSize: componentTheme.fontSizeLg,
|
|
72
|
+
borderWidth: componentTheme.borderWidthMd,
|
|
73
|
+
width: componentTheme.sizeLg,
|
|
74
|
+
height: componentTheme.sizeLg
|
|
75
|
+
},
|
|
76
|
+
'x-large': {
|
|
77
|
+
fontSize: componentTheme.fontSizeXl,
|
|
78
|
+
borderWidth: componentTheme.borderWidthMd,
|
|
79
|
+
width: componentTheme.sizeXl,
|
|
80
|
+
height: componentTheme.sizeXl
|
|
81
|
+
},
|
|
82
|
+
'xx-large': {
|
|
83
|
+
fontSize: componentTheme.fontSize2xl,
|
|
84
|
+
borderWidth: componentTheme.borderWidthMd,
|
|
85
|
+
width: componentTheme.size2xl,
|
|
86
|
+
height: componentTheme.size2xl
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const colorVariants = {
|
|
90
|
+
accent1: {
|
|
91
|
+
text: componentTheme.blueTextColor,
|
|
92
|
+
background: componentTheme.blueBackgroundColor
|
|
93
|
+
},
|
|
94
|
+
accent2: {
|
|
95
|
+
text: componentTheme.greenTextColor,
|
|
96
|
+
background: componentTheme.greenBackgroundColor
|
|
97
|
+
},
|
|
98
|
+
accent3: {
|
|
99
|
+
text: componentTheme.redTextColor,
|
|
100
|
+
background: componentTheme.redBackgroundColor
|
|
101
|
+
},
|
|
102
|
+
accent4: {
|
|
103
|
+
text: componentTheme.orangeTextColor,
|
|
104
|
+
background: componentTheme.orangeBackgroundColor
|
|
105
|
+
},
|
|
106
|
+
accent5: {
|
|
107
|
+
text: componentTheme.greyTextColor,
|
|
108
|
+
background: componentTheme.greyBackgroundColor
|
|
109
|
+
},
|
|
110
|
+
accent6: {
|
|
111
|
+
text: componentTheme.ashTextColor,
|
|
112
|
+
background: componentTheme.ashBackgroundColor
|
|
113
|
+
},
|
|
114
|
+
ai: {
|
|
115
|
+
text: componentTheme.textOnColor,
|
|
116
|
+
background: `linear-gradient(135deg, ${componentTheme.aiTopGradientColor} 0%, ${componentTheme.aiBottomGradientColor} 100%)`
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const getBorder = () => {
|
|
120
|
+
if (showBorder === 'never') {
|
|
121
|
+
return 'none';
|
|
122
|
+
}
|
|
123
|
+
if (showBorder === 'always') {
|
|
124
|
+
return 'solid';
|
|
125
|
+
}
|
|
126
|
+
//if none of the above, so auto
|
|
127
|
+
if (hasInverseColor || color === 'ai') {
|
|
128
|
+
return 'none';
|
|
129
|
+
}
|
|
130
|
+
return 'solid';
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
avatar: {
|
|
134
|
+
label: 'avatar',
|
|
135
|
+
boxSizing: 'border-box',
|
|
136
|
+
border: getBorder(),
|
|
137
|
+
borderRadius: shape === 'circle' ? '50%' : 0,
|
|
138
|
+
...sizeStyles[size],
|
|
139
|
+
background: hasInverseColor || color === 'ai' ? colorVariants[color].background : componentTheme.backgroundColor,
|
|
140
|
+
display: display === 'inline' ? 'inline-flex' : 'flex',
|
|
141
|
+
alignItems: 'center',
|
|
142
|
+
justifyContent: 'center',
|
|
143
|
+
verticalAlign: 'middle',
|
|
144
|
+
color: hasInverseColor ? componentTheme.textOnColor : colorVariants[color].text,
|
|
145
|
+
borderColor: componentTheme.borderColor,
|
|
146
|
+
fontWeight: componentTheme.fontWeight,
|
|
147
|
+
overflow: 'hidden',
|
|
148
|
+
// TODO handle the merging on tokens inside the util
|
|
149
|
+
margin: calcSpacingFromShorthand(margin, {
|
|
150
|
+
...sharedTokens.spacing,
|
|
151
|
+
...sharedTokens.legacy.spacing
|
|
152
|
+
})
|
|
153
|
+
},
|
|
154
|
+
image: {
|
|
155
|
+
label: 'avatar__image',
|
|
156
|
+
width: '100%',
|
|
157
|
+
height: '100%',
|
|
158
|
+
objectFit: 'cover',
|
|
159
|
+
objectPosition: 'center',
|
|
160
|
+
...(loaded ? {} : {
|
|
161
|
+
display: 'none'
|
|
162
|
+
})
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
export default generateStyle;
|
|
@@ -8,7 +8,7 @@ exports.default = exports.Avatar = void 0;
|
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
9
|
var _emotion = require("@instructure/emotion");
|
|
10
10
|
var _react = require("react");
|
|
11
|
-
var
|
|
11
|
+
var _v11_ = require("@instructure/ui-view/v11_6");
|
|
12
12
|
var _callRenderProp = require("@instructure/ui-react-utils/lib/callRenderProp.js");
|
|
13
13
|
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
14
14
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
@@ -65,7 +65,7 @@ category: components
|
|
|
65
65
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
66
66
|
loaded = _useState2[0],
|
|
67
67
|
setLoaded = _useState2[1];
|
|
68
|
-
const styles = (0, _emotion.
|
|
68
|
+
const styles = (0, _emotion.useStyleLegacy)({
|
|
69
69
|
generateStyle: _styles.default,
|
|
70
70
|
generateComponentTheme: _theme.default,
|
|
71
71
|
params: {
|
|
@@ -127,7 +127,7 @@ category: components
|
|
|
127
127
|
children: (0, _callRenderProp.callRenderProp)(renderIcon)
|
|
128
128
|
});
|
|
129
129
|
};
|
|
130
|
-
return (0, _jsxRuntime.jsxs)(
|
|
130
|
+
return (0, _jsxRuntime.jsxs)(_v11_.View, {
|
|
131
131
|
...(0, _passthroughProps.passthroughProps)({
|
|
132
132
|
size,
|
|
133
133
|
color,
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = exports.Avatar = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _emotion = require("@instructure/emotion");
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
12
|
+
var _renderIconWithProps = require("@instructure/ui-icons/lib/IconPropsProvider/renderIconWithProps.js");
|
|
13
|
+
var _props = require("./props");
|
|
14
|
+
var _styles = _interopRequireDefault(require("./styles"));
|
|
15
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
16
|
+
/*
|
|
17
|
+
* The MIT License (MIT)
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
20
|
+
*
|
|
21
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
23
|
+
* in the Software without restriction, including without limitation the rights
|
|
24
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
26
|
+
* furnished to do so, subject to the following conditions:
|
|
27
|
+
*
|
|
28
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
29
|
+
* copies or substantial portions of the Software.
|
|
30
|
+
*
|
|
31
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
+
* SOFTWARE.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
const ICON_COLOR_MAP = {
|
|
41
|
+
accent1: 'accentBlueColor',
|
|
42
|
+
accent2: 'accentGreenColor',
|
|
43
|
+
accent3: 'accentRedColor',
|
|
44
|
+
accent4: 'accentOrangeColor',
|
|
45
|
+
accent5: 'accentGreyColor',
|
|
46
|
+
accent6: 'accentAshColor',
|
|
47
|
+
ai: 'onColor'
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
---
|
|
52
|
+
category: components
|
|
53
|
+
---
|
|
54
|
+
**/
|
|
55
|
+
const Avatar = exports.Avatar = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
56
|
+
const _props$size = props.size,
|
|
57
|
+
size = _props$size === void 0 ? 'medium' : _props$size,
|
|
58
|
+
_props$color = props.color,
|
|
59
|
+
color = _props$color === void 0 ? 'accent1' : _props$color,
|
|
60
|
+
_props$hasInverseColo = props.hasInverseColor,
|
|
61
|
+
hasInverseColor = _props$hasInverseColo === void 0 ? false : _props$hasInverseColo,
|
|
62
|
+
_props$showBorder = props.showBorder,
|
|
63
|
+
showBorder = _props$showBorder === void 0 ? 'auto' : _props$showBorder,
|
|
64
|
+
_props$shape = props.shape,
|
|
65
|
+
shape = _props$shape === void 0 ? 'circle' : _props$shape,
|
|
66
|
+
_props$display = props.display,
|
|
67
|
+
display = _props$display === void 0 ? 'inline' : _props$display,
|
|
68
|
+
_props$onImageLoaded = props.onImageLoaded,
|
|
69
|
+
onImageLoaded = _props$onImageLoaded === void 0 ? _event => {} : _props$onImageLoaded,
|
|
70
|
+
src = props.src,
|
|
71
|
+
name = props.name,
|
|
72
|
+
renderIcon = props.renderIcon,
|
|
73
|
+
alt = props.alt,
|
|
74
|
+
themeOverride = props.themeOverride,
|
|
75
|
+
margin = props.margin;
|
|
76
|
+
const _useState = (0, _react.useState)(false),
|
|
77
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
78
|
+
loaded = _useState2[0],
|
|
79
|
+
setLoaded = _useState2[1];
|
|
80
|
+
const styles = (0, _emotion.useStyle)({
|
|
81
|
+
generateStyle: _styles.default,
|
|
82
|
+
themeOverride,
|
|
83
|
+
params: {
|
|
84
|
+
loaded,
|
|
85
|
+
size,
|
|
86
|
+
color,
|
|
87
|
+
hasInverseColor,
|
|
88
|
+
shape,
|
|
89
|
+
src,
|
|
90
|
+
showBorder,
|
|
91
|
+
display,
|
|
92
|
+
margin
|
|
93
|
+
},
|
|
94
|
+
componentId: 'Avatar',
|
|
95
|
+
displayName: 'Avatar'
|
|
96
|
+
});
|
|
97
|
+
(0, _react.useEffect)(() => {
|
|
98
|
+
// in case the image is unset in an update, show icons/initials again
|
|
99
|
+
if (loaded && !src) {
|
|
100
|
+
setLoaded(false);
|
|
101
|
+
}
|
|
102
|
+
// Image already loaded (common in SSR)
|
|
103
|
+
//TODO-rework make this work
|
|
104
|
+
// if (src && !loaded && imgRef.current && imgRef.current.complete) {
|
|
105
|
+
// setLoaded(true)
|
|
106
|
+
// onImageLoaded?.()
|
|
107
|
+
// }
|
|
108
|
+
}, [loaded, src]);
|
|
109
|
+
const makeInitialsFromName = () => {
|
|
110
|
+
if (!name || typeof name !== 'string' || name.trim().length === 0) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const currentName = name.trim();
|
|
114
|
+
if (currentName.match(/\s+/)) {
|
|
115
|
+
const names = currentName.split(/\s+/);
|
|
116
|
+
return (names[0][0] + names[names.length - 1][0]).toUpperCase();
|
|
117
|
+
} else {
|
|
118
|
+
return currentName[0].toUpperCase();
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const renderInitials = () => {
|
|
122
|
+
return (0, _jsxRuntime.jsx)("span", {
|
|
123
|
+
"aria-hidden": "true",
|
|
124
|
+
children: makeInitialsFromName()
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
const renderImage = () => (0, _jsxRuntime.jsx)("img", {
|
|
128
|
+
style: {
|
|
129
|
+
width: '100%',
|
|
130
|
+
height: '100%',
|
|
131
|
+
objectFit: 'cover',
|
|
132
|
+
objectPosition: 'center',
|
|
133
|
+
...(loaded ? {} : {
|
|
134
|
+
display: 'none'
|
|
135
|
+
})
|
|
136
|
+
},
|
|
137
|
+
src: src,
|
|
138
|
+
alt: alt ? alt : '',
|
|
139
|
+
onLoad: event => {
|
|
140
|
+
setLoaded(true);
|
|
141
|
+
onImageLoaded(event);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
const renderContent = () => {
|
|
145
|
+
//image in avatar - prioritize image over icon
|
|
146
|
+
if (src) {
|
|
147
|
+
return (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
148
|
+
children: [renderImage(), loaded ? null : renderInitials()]
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
//icon in avatar
|
|
153
|
+
if (renderIcon) {
|
|
154
|
+
const iconSize = _props.avatarSizeToIconSize[size];
|
|
155
|
+
const iconColor = hasInverseColor ? 'onColor' : ICON_COLOR_MAP[color];
|
|
156
|
+
return (0, _renderIconWithProps.renderIconWithProps)(renderIcon, iconSize, iconColor);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
//initials in avatar
|
|
160
|
+
return renderInitials();
|
|
161
|
+
};
|
|
162
|
+
return (0, _jsxRuntime.jsx)("div", {
|
|
163
|
+
...(0, _passthroughProps.passthroughProps)({
|
|
164
|
+
...props
|
|
165
|
+
}),
|
|
166
|
+
ref: ref,
|
|
167
|
+
"aria-label": alt ? alt : void 0,
|
|
168
|
+
role: alt ? 'img' : void 0,
|
|
169
|
+
css: styles === null || styles === void 0 ? void 0 : styles.avatar,
|
|
170
|
+
children: renderContent()
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
Avatar.displayName = 'Avatar';
|
|
174
|
+
var _default = exports.default = Avatar;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.avatarSizeToIconSize = exports.allowedProps = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
* copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
* SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const avatarSizeToIconSize = exports.avatarSizeToIconSize = {
|
|
32
|
+
'xx-small': 'xs',
|
|
33
|
+
'x-small': 'xs',
|
|
34
|
+
small: 'sm',
|
|
35
|
+
medium: 'md',
|
|
36
|
+
large: 'lg',
|
|
37
|
+
'x-large': 'xl',
|
|
38
|
+
'xx-large': '2xl'
|
|
39
|
+
};
|
|
40
|
+
const allowedProps = exports.allowedProps = ['name', 'src', 'alt', 'size', 'color', 'hasInverseColor', 'shape', 'margin', 'display', 'onImageLoaded', 'renderIcon', 'showBorder'];
|