@sproutsocial/racine 8.0.0 → 8.1.0-avatar-update-beta.0
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/__flow__/Avatar/index.js +34 -5
- package/__flow__/Avatar/index.stories.js +29 -0
- package/commonjs/Avatar/index.js +37 -13
- package/lib/Avatar/index.js +36 -13
- package/package.json +1 -1
package/__flow__/Avatar/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { useState, useCallback, useMemo, memo } from "react";
|
|
4
|
-
import styled from "styled-components";
|
|
4
|
+
import styled, { css, type StyledComponent } from "styled-components";
|
|
5
|
+
import classnames from "classnames";
|
|
6
|
+
|
|
7
|
+
import type { TypeTheme } from "../types/theme.flow";
|
|
8
|
+
|
|
5
9
|
import Box from "../Box";
|
|
6
10
|
import Image from "../Image";
|
|
7
11
|
import Text from "../Text";
|
|
@@ -13,11 +17,24 @@ export type TypeProps = {
|
|
|
13
17
|
name: string,
|
|
14
18
|
/** URL of the avatar image. If a URL is not provided, the component will fall back to showing the user's initials */
|
|
15
19
|
src?: string,
|
|
20
|
+
type?: "neutral" | "purple" | "green" | "blue" | "yellow" | "red" | "orange",
|
|
21
|
+
variant?: "dark" | "light",
|
|
22
|
+
bg?: string,
|
|
23
|
+
color?: string,
|
|
16
24
|
size?: string,
|
|
17
25
|
};
|
|
18
26
|
|
|
19
27
|
const AvatarText = styled(({ fontSize, ...rest }) => <Text {...rest} />)`
|
|
20
28
|
font-size: ${(props) => props.fontSize}px;
|
|
29
|
+
color: ${(props) => props.color}px;
|
|
30
|
+
`;
|
|
31
|
+
const Container: StyledComponent<any, TypeTheme, *> = styled(Box)`
|
|
32
|
+
${({ theme, type, variant, bg }) => css`
|
|
33
|
+
color: ${theme.colors[type][variant === "dark" ? "200" : "900"]};
|
|
34
|
+
background: ${bg
|
|
35
|
+
? bg
|
|
36
|
+
: theme.colors[type][variant === "dark" ? "900" : "200"]};
|
|
37
|
+
`}
|
|
21
38
|
`;
|
|
22
39
|
|
|
23
40
|
const getInitials = (name: string, fallback: string = "?"): string => {
|
|
@@ -34,7 +51,11 @@ export const Avatar = ({
|
|
|
34
51
|
appearance = "circle",
|
|
35
52
|
name,
|
|
36
53
|
src,
|
|
54
|
+
variant = "light",
|
|
55
|
+
type = "neutral",
|
|
37
56
|
size = "40px",
|
|
57
|
+
bg,
|
|
58
|
+
color,
|
|
38
59
|
...rest
|
|
39
60
|
}: TypeProps) => {
|
|
40
61
|
const [imageFailedLoading, setImageFailedLoading] = useState(false);
|
|
@@ -48,7 +69,8 @@ export const Avatar = ({
|
|
|
48
69
|
const fontSize = Math.floor(Number(size.replace("px", "")) * 0.4);
|
|
49
70
|
|
|
50
71
|
return (
|
|
51
|
-
<
|
|
72
|
+
<Container
|
|
73
|
+
className={classnames(variant)}
|
|
52
74
|
size={size}
|
|
53
75
|
overflow="hidden"
|
|
54
76
|
borderRadius={appearance === "leaf" ? "40% 0 40% 0" : "50%"}
|
|
@@ -58,13 +80,20 @@ export const Avatar = ({
|
|
|
58
80
|
justifyContent="center"
|
|
59
81
|
alignItems="center"
|
|
60
82
|
title={name}
|
|
61
|
-
bg=
|
|
83
|
+
bg={bg}
|
|
84
|
+
variant={variant}
|
|
85
|
+
type={type}
|
|
62
86
|
data-qa-user-avatar={name}
|
|
63
87
|
// $FlowIssue - upgrade v0.112.0
|
|
64
88
|
{...rest}
|
|
65
89
|
>
|
|
66
90
|
{!src || imageFailedLoading ? (
|
|
67
|
-
<AvatarText
|
|
91
|
+
<AvatarText
|
|
92
|
+
lineHeight={size}
|
|
93
|
+
fontWeight="semibold"
|
|
94
|
+
fontSize={fontSize}
|
|
95
|
+
color={color}
|
|
96
|
+
>
|
|
68
97
|
{initials}
|
|
69
98
|
</AvatarText>
|
|
70
99
|
) : (
|
|
@@ -77,7 +106,7 @@ export const Avatar = ({
|
|
|
77
106
|
m={0}
|
|
78
107
|
/>
|
|
79
108
|
)}
|
|
80
|
-
</
|
|
109
|
+
</Container>
|
|
81
110
|
);
|
|
82
111
|
};
|
|
83
112
|
|
|
@@ -11,6 +11,35 @@ defaultStory.story = {
|
|
|
11
11
|
name: "Default",
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
export const customColors = () => (
|
|
15
|
+
<Avatar name="Joe Smith" bg="purple.500" color="red.200" />
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
customColors.story = {
|
|
19
|
+
name: "Override colors",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const withVariants = () => (
|
|
23
|
+
<div display="inline-block">
|
|
24
|
+
<Avatar mt={5} name="Kent C. Dodds" type="neutral" variant="dark" />
|
|
25
|
+
<Avatar mt={5} name="Kent C. Dodds" type="neutral" variant="light" />
|
|
26
|
+
<Avatar mt={5} name="Kent C. Dodds" type="green" variant="dark" />
|
|
27
|
+
<Avatar mt={5} name="Kent C. Dodds" type="green" variant="light" />
|
|
28
|
+
<Avatar mt={5} name="Kent C. Dodds" type="purple" variant="dark" />
|
|
29
|
+
<Avatar mt={5} name="Kent C. Dodds" type="purple" variant="light" />
|
|
30
|
+
<Avatar mt={5} name="Kent C. Dodds" type="red" variant="light" />
|
|
31
|
+
<Avatar mt={5} name="Kent C. Dodds" type="red" variant="dark" />
|
|
32
|
+
<Avatar mt={5} name="Kent C. Dodds" type="yellow" variant="light" />
|
|
33
|
+
<Avatar mt={5} name="Kent C. Dodds" type="yellow" variant="dark" />
|
|
34
|
+
<Avatar mt={5} name="Kent C. Dodds" type="blue" variant="light" />
|
|
35
|
+
<Avatar mt={5} name="Kent C. Dodds" type="blue" variant="dark" />
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
withVariants.story = {
|
|
40
|
+
name: "With color types",
|
|
41
|
+
};
|
|
42
|
+
|
|
14
43
|
export const withImage = () => (
|
|
15
44
|
<Avatar name="Kent C. Dodds" src="https://github.com/kentcdodds.png" />
|
|
16
45
|
);
|
package/commonjs/Avatar/index.js
CHANGED
|
@@ -5,7 +5,9 @@ exports.default = exports.Avatar = void 0;
|
|
|
5
5
|
|
|
6
6
|
var React = _interopRequireWildcard(require("react"));
|
|
7
7
|
|
|
8
|
-
var _styledComponents =
|
|
8
|
+
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
9
|
+
|
|
10
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
11
|
|
|
10
12
|
var _Box = _interopRequireDefault(require("../Box"));
|
|
11
13
|
|
|
@@ -31,8 +33,20 @@ var AvatarText = (0, _styledComponents.default)(function (_ref) {
|
|
|
31
33
|
}).withConfig({
|
|
32
34
|
displayName: "Avatar__AvatarText",
|
|
33
35
|
componentId: "yx873f-0"
|
|
34
|
-
})(["font-size:", "px;"], function (props) {
|
|
36
|
+
})(["font-size:", "px;color:", "px;"], function (props) {
|
|
35
37
|
return props.fontSize;
|
|
38
|
+
}, function (props) {
|
|
39
|
+
return props.color;
|
|
40
|
+
});
|
|
41
|
+
var Container = (0, _styledComponents.default)(_Box.default).withConfig({
|
|
42
|
+
displayName: "Avatar__Container",
|
|
43
|
+
componentId: "yx873f-1"
|
|
44
|
+
})(["", ""], function (_ref2) {
|
|
45
|
+
var theme = _ref2.theme,
|
|
46
|
+
type = _ref2.type,
|
|
47
|
+
variant = _ref2.variant,
|
|
48
|
+
bg = _ref2.bg;
|
|
49
|
+
return (0, _styledComponents.css)(["color:", ";background:", ";"], theme.colors[type][variant === "dark" ? "200" : "900"], bg ? bg : theme.colors[type][variant === "dark" ? "900" : "200"]);
|
|
36
50
|
});
|
|
37
51
|
|
|
38
52
|
var getInitials = function getInitials(name, fallback) {
|
|
@@ -48,14 +62,20 @@ var getInitials = function getInitials(name, fallback) {
|
|
|
48
62
|
.join("");
|
|
49
63
|
};
|
|
50
64
|
|
|
51
|
-
var Avatar = function Avatar(
|
|
52
|
-
var
|
|
53
|
-
appearance =
|
|
54
|
-
name =
|
|
55
|
-
src =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
var Avatar = function Avatar(_ref3) {
|
|
66
|
+
var _ref3$appearance = _ref3.appearance,
|
|
67
|
+
appearance = _ref3$appearance === void 0 ? "circle" : _ref3$appearance,
|
|
68
|
+
name = _ref3.name,
|
|
69
|
+
src = _ref3.src,
|
|
70
|
+
_ref3$variant = _ref3.variant,
|
|
71
|
+
variant = _ref3$variant === void 0 ? "light" : _ref3$variant,
|
|
72
|
+
_ref3$type = _ref3.type,
|
|
73
|
+
type = _ref3$type === void 0 ? "neutral" : _ref3$type,
|
|
74
|
+
_ref3$size = _ref3.size,
|
|
75
|
+
size = _ref3$size === void 0 ? "40px" : _ref3$size,
|
|
76
|
+
bg = _ref3.bg,
|
|
77
|
+
color = _ref3.color,
|
|
78
|
+
rest = _objectWithoutPropertiesLoose(_ref3, ["appearance", "name", "src", "variant", "type", "size", "bg", "color"]);
|
|
59
79
|
|
|
60
80
|
var _useState = (0, React.useState)(false),
|
|
61
81
|
imageFailedLoading = _useState[0],
|
|
@@ -69,7 +89,8 @@ var Avatar = function Avatar(_ref2) {
|
|
|
69
89
|
}, [setImageFailedLoading]); // Font size for initials is half the size of the avatar, rounded down.
|
|
70
90
|
|
|
71
91
|
var fontSize = Math.floor(Number(size.replace("px", "")) * 0.4);
|
|
72
|
-
return /*#__PURE__*/React.createElement(
|
|
92
|
+
return /*#__PURE__*/React.createElement(Container, _extends({
|
|
93
|
+
className: (0, _classnames.default)(variant),
|
|
73
94
|
size: size,
|
|
74
95
|
overflow: "hidden",
|
|
75
96
|
borderRadius: appearance === "leaf" ? "40% 0 40% 0" : "50%",
|
|
@@ -79,13 +100,16 @@ var Avatar = function Avatar(_ref2) {
|
|
|
79
100
|
justifyContent: "center",
|
|
80
101
|
alignItems: "center",
|
|
81
102
|
title: name,
|
|
82
|
-
bg:
|
|
103
|
+
bg: bg,
|
|
104
|
+
variant: variant,
|
|
105
|
+
type: type,
|
|
83
106
|
"data-qa-user-avatar": name // $FlowIssue - upgrade v0.112.0
|
|
84
107
|
|
|
85
108
|
}, rest), !src || imageFailedLoading ? /*#__PURE__*/React.createElement(AvatarText, {
|
|
86
109
|
lineHeight: size,
|
|
87
110
|
fontWeight: "semibold",
|
|
88
|
-
fontSize: fontSize
|
|
111
|
+
fontSize: fontSize,
|
|
112
|
+
color: color
|
|
89
113
|
}, initials) : /*#__PURE__*/React.createElement(_Image.default, {
|
|
90
114
|
alt: name,
|
|
91
115
|
width: "auto",
|
package/lib/Avatar/index.js
CHANGED
|
@@ -4,7 +4,8 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
4
4
|
|
|
5
5
|
import * as React from "react";
|
|
6
6
|
import { useState, useCallback, useMemo, memo } from "react";
|
|
7
|
-
import styled from "styled-components";
|
|
7
|
+
import styled, { css } from "styled-components";
|
|
8
|
+
import classnames from "classnames";
|
|
8
9
|
import Box from "../Box";
|
|
9
10
|
import Image from "../Image";
|
|
10
11
|
import Text from "../Text";
|
|
@@ -16,8 +17,20 @@ var AvatarText = styled(function (_ref) {
|
|
|
16
17
|
}).withConfig({
|
|
17
18
|
displayName: "Avatar__AvatarText",
|
|
18
19
|
componentId: "yx873f-0"
|
|
19
|
-
})(["font-size:", "px;"], function (props) {
|
|
20
|
+
})(["font-size:", "px;color:", "px;"], function (props) {
|
|
20
21
|
return props.fontSize;
|
|
22
|
+
}, function (props) {
|
|
23
|
+
return props.color;
|
|
24
|
+
});
|
|
25
|
+
var Container = styled(Box).withConfig({
|
|
26
|
+
displayName: "Avatar__Container",
|
|
27
|
+
componentId: "yx873f-1"
|
|
28
|
+
})(["", ""], function (_ref2) {
|
|
29
|
+
var theme = _ref2.theme,
|
|
30
|
+
type = _ref2.type,
|
|
31
|
+
variant = _ref2.variant,
|
|
32
|
+
bg = _ref2.bg;
|
|
33
|
+
return css(["color:", ";background:", ";"], theme.colors[type][variant === "dark" ? "200" : "900"], bg ? bg : theme.colors[type][variant === "dark" ? "900" : "200"]);
|
|
21
34
|
});
|
|
22
35
|
|
|
23
36
|
var getInitials = function getInitials(name, fallback) {
|
|
@@ -33,14 +46,20 @@ var getInitials = function getInitials(name, fallback) {
|
|
|
33
46
|
.join("");
|
|
34
47
|
};
|
|
35
48
|
|
|
36
|
-
export var Avatar = function Avatar(
|
|
37
|
-
var
|
|
38
|
-
appearance =
|
|
39
|
-
name =
|
|
40
|
-
src =
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
export var Avatar = function Avatar(_ref3) {
|
|
50
|
+
var _ref3$appearance = _ref3.appearance,
|
|
51
|
+
appearance = _ref3$appearance === void 0 ? "circle" : _ref3$appearance,
|
|
52
|
+
name = _ref3.name,
|
|
53
|
+
src = _ref3.src,
|
|
54
|
+
_ref3$variant = _ref3.variant,
|
|
55
|
+
variant = _ref3$variant === void 0 ? "light" : _ref3$variant,
|
|
56
|
+
_ref3$type = _ref3.type,
|
|
57
|
+
type = _ref3$type === void 0 ? "neutral" : _ref3$type,
|
|
58
|
+
_ref3$size = _ref3.size,
|
|
59
|
+
size = _ref3$size === void 0 ? "40px" : _ref3$size,
|
|
60
|
+
bg = _ref3.bg,
|
|
61
|
+
color = _ref3.color,
|
|
62
|
+
rest = _objectWithoutPropertiesLoose(_ref3, ["appearance", "name", "src", "variant", "type", "size", "bg", "color"]);
|
|
44
63
|
|
|
45
64
|
var _useState = useState(false),
|
|
46
65
|
imageFailedLoading = _useState[0],
|
|
@@ -54,7 +73,8 @@ export var Avatar = function Avatar(_ref2) {
|
|
|
54
73
|
}, [setImageFailedLoading]); // Font size for initials is half the size of the avatar, rounded down.
|
|
55
74
|
|
|
56
75
|
var fontSize = Math.floor(Number(size.replace("px", "")) * 0.4);
|
|
57
|
-
return /*#__PURE__*/React.createElement(
|
|
76
|
+
return /*#__PURE__*/React.createElement(Container, _extends({
|
|
77
|
+
className: classnames(variant),
|
|
58
78
|
size: size,
|
|
59
79
|
overflow: "hidden",
|
|
60
80
|
borderRadius: appearance === "leaf" ? "40% 0 40% 0" : "50%",
|
|
@@ -64,13 +84,16 @@ export var Avatar = function Avatar(_ref2) {
|
|
|
64
84
|
justifyContent: "center",
|
|
65
85
|
alignItems: "center",
|
|
66
86
|
title: name,
|
|
67
|
-
bg:
|
|
87
|
+
bg: bg,
|
|
88
|
+
variant: variant,
|
|
89
|
+
type: type,
|
|
68
90
|
"data-qa-user-avatar": name // $FlowIssue - upgrade v0.112.0
|
|
69
91
|
|
|
70
92
|
}, rest), !src || imageFailedLoading ? /*#__PURE__*/React.createElement(AvatarText, {
|
|
71
93
|
lineHeight: size,
|
|
72
94
|
fontWeight: "semibold",
|
|
73
|
-
fontSize: fontSize
|
|
95
|
+
fontSize: fontSize,
|
|
96
|
+
color: color
|
|
74
97
|
}, initials) : /*#__PURE__*/React.createElement(Image, {
|
|
75
98
|
alt: name,
|
|
76
99
|
width: "auto",
|