carbon-react 123.8.0 → 123.9.1

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 (33) hide show
  1. package/esm/components/breadcrumbs/crumb/crumb.component.d.ts +1 -1
  2. package/esm/components/portrait/portrait.component.d.ts +3 -1
  3. package/esm/components/portrait/portrait.component.js +37 -26
  4. package/esm/components/portrait/portrait.config.d.ts +4 -4
  5. package/esm/components/portrait/portrait.style.d.ts +8 -21
  6. package/esm/components/portrait/portrait.style.js +42 -85
  7. package/esm/components/profile/profile.component.d.ts +9 -3
  8. package/esm/components/profile/profile.component.js +36 -19
  9. package/esm/components/profile/profile.config.d.ts +7 -7
  10. package/esm/components/profile/profile.config.js +14 -14
  11. package/esm/components/profile/profile.style.d.ts +10 -12
  12. package/esm/components/profile/profile.style.js +30 -13
  13. package/lib/components/breadcrumbs/crumb/crumb.component.d.ts +1 -1
  14. package/lib/components/portrait/portrait.component.d.ts +3 -1
  15. package/lib/components/portrait/portrait.component.js +41 -31
  16. package/lib/components/portrait/portrait.config.d.ts +4 -4
  17. package/lib/components/portrait/portrait.style.d.ts +8 -21
  18. package/lib/components/portrait/portrait.style.js +43 -90
  19. package/lib/components/profile/profile.component.d.ts +9 -3
  20. package/lib/components/profile/profile.component.js +35 -18
  21. package/lib/components/profile/profile.config.d.ts +7 -7
  22. package/lib/components/profile/profile.config.js +14 -14
  23. package/lib/components/profile/profile.style.d.ts +10 -12
  24. package/lib/components/profile/profile.style.js +32 -14
  25. package/package.json +1 -1
  26. package/esm/components/portrait/portrait-gravatar.component.d.ts +0 -16
  27. package/esm/components/portrait/portrait-gravatar.component.js +0 -33
  28. package/esm/components/portrait/portrait-initials.component.d.ts +0 -16
  29. package/esm/components/portrait/portrait-initials.component.js +0 -67
  30. package/lib/components/portrait/portrait-gravatar.component.d.ts +0 -16
  31. package/lib/components/portrait/portrait-gravatar.component.js +0 -41
  32. package/lib/components/portrait/portrait-initials.component.d.ts +0 -16
  33. package/lib/components/portrait/portrait-initials.component.js +0 -77
@@ -3,34 +3,51 @@ import { margin } from "styled-system";
3
3
  import Portrait from "../portrait";
4
4
  import baseTheme from "../../style/themes/base";
5
5
  import profileConfigSizes from "./profile.config";
6
+ import Link from "../link";
7
+ import { StyledPortraitContainer } from "../portrait/portrait.style";
6
8
  const ProfileNameStyle = styled.span`
7
9
  font-weight: bold;
8
- display: block;
9
10
  font-size: ${({
10
11
  size = "M"
11
12
  }) => profileConfigSizes[size].nameSize};
12
13
  `;
13
- const ProfileEmailStyle = styled.span`
14
+ const ProfileEmailStyle = styled(Link)`
15
+ a {
16
+ font-size: ${({
17
+ size = "M"
18
+ }) => profileConfigSizes[size].emailSize};
19
+ color: ${({
20
+ darkBackground
21
+ }) => darkBackground && "var(--colorsActionMajor350)"};
22
+ }
23
+ `;
24
+ const ProfileTextStyle = styled.span`
14
25
  font-size: ${({
15
26
  size = "M"
16
27
  }) => profileConfigSizes[size].emailSize};
17
28
  `;
18
29
  const ProfileStyle = styled.div`
30
+ border-radius: inherit;
19
31
  white-space: nowrap;
20
- color: var(--colorsUtilityYin090);
21
- display: ${({
22
- hasSrc
23
- }) => hasSrc ? "flex" : ""};
24
-
32
+ color: ${({
33
+ darkBackground
34
+ }) => darkBackground ? "var(--colorsUtilityReadOnly600)" : "var(--colorsUtilityYin090)"};
35
+ background-color: ${({
36
+ darkBackground
37
+ }) => darkBackground ? "var(--colorsUtilityYin090)" : "transparent"};
38
+ display: flex;
39
+ flex-direction: row;
25
40
  ${margin}
41
+
42
+ ${StyledPortraitContainer} {
43
+ flex-shrink: 0;
44
+ }
26
45
  `;
27
46
  const ProfileDetailsStyle = styled.div`
28
47
  vertical-align: middle;
29
- display: inline-block;
30
- margin-top: ${({
31
- hasSrc,
32
- size = "M"
33
- }) => hasSrc ? profileConfigSizes[size].marginTop : ""};
48
+ display: flex;
49
+ flex-direction: column;
50
+ justify-content: center;
34
51
  line-height: ${({
35
52
  size = "M"
36
53
  }) => profileConfigSizes[size].lineHeight};
@@ -44,4 +61,4 @@ const ProfileAvatarStyle = styled(Portrait)`
44
61
  ProfileStyle.defaultProps = {
45
62
  theme: baseTheme
46
63
  };
47
- export { ProfileStyle, ProfileNameStyle, ProfileDetailsStyle, ProfileAvatarStyle, ProfileEmailStyle };
64
+ export { ProfileStyle, ProfileNameStyle, ProfileDetailsStyle, ProfileAvatarStyle, ProfileEmailStyle, ProfileTextStyle };
@@ -1,5 +1,5 @@
1
- import { LinkProps } from "components/link/link.component";
2
1
  import React from "react";
2
+ import { LinkProps } from "../../link";
3
3
  import { TagProps } from "../../../__internal__/utils/helpers/tags";
4
4
  export interface CrumbProps extends Omit<LinkProps, "tooltipMessage" | "tooltipPosition" | "iconType" | "iconAlign" | "isSkipLink" | "isDarkBackground" | "ariaLabel" | "className" | "variant" | "target" | "rel" | "icon" | "disabled">, TagProps {
5
5
  /** This sets the Crumb to current, does not render Link */
@@ -10,6 +10,8 @@ export interface PortraitProps extends MarginProps {
10
10
  src?: string;
11
11
  /** The size of the Portrait. */
12
12
  size?: PortraitSizes;
13
+ /** @private @ignore */
14
+ name?: string;
13
15
  /** The `alt` HTML string. */
14
16
  alt?: string;
15
17
  /** The shape of the Portrait. */
@@ -39,5 +41,5 @@ export interface PortraitProps extends MarginProps {
39
41
  /** Override font color of the Tooltip, provide any color from palette or any valid css color value. */
40
42
  tooltipFontColor?: string;
41
43
  }
42
- export declare const Portrait: ({ alt, darkBackground, gravatar, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: PortraitProps) => React.JSX.Element;
44
+ declare const Portrait: ({ alt, name, darkBackground, gravatar, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: PortraitProps) => React.JSX.Element;
43
45
  export default Portrait;
@@ -3,15 +3,15 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.Portrait = void 0;
6
+ exports.default = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _md = _interopRequireDefault(require("crypto-js/md5"));
9
10
  var _invariant = _interopRequireDefault(require("invariant"));
10
11
  var _tooltip = _interopRequireDefault(require("../tooltip"));
11
12
  var _tags = _interopRequireDefault(require("../../__internal__/utils/helpers/tags/tags"));
12
- var _portraitGravatar = _interopRequireDefault(require("./portrait-gravatar.component"));
13
- var _portraitInitials = _interopRequireDefault(require("./portrait-initials.component"));
14
- var _portrait = require("./portrait.style");
13
+ var _portrait = require("./portrait.config");
14
+ var _portrait2 = require("./portrait.style");
15
15
  var _utils = require("../../style/utils");
16
16
  var _carbonProvider = require("../carbon-provider/carbon-provider.component");
17
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -19,9 +19,10 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
19
19
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
20
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
21
21
  const Portrait = ({
22
- alt = "",
22
+ alt,
23
+ name,
23
24
  darkBackground = false,
24
- gravatar,
25
+ gravatar = "",
25
26
  iconType = "individual",
26
27
  initials,
27
28
  shape,
@@ -48,39 +49,41 @@ const Portrait = ({
48
49
  setExternalError(false);
49
50
  }, [gravatar, src]);
50
51
  const tagProps = (0, _tags.default)("portrait", rest);
52
+ const gravatarSrc = () => {
53
+ const {
54
+ dimensions
55
+ } = _portrait.PORTRAIT_SIZE_PARAMS[size];
56
+ const base = "https://www.gravatar.com/avatar/";
57
+ const hash = (0, _md.default)(gravatar.toLowerCase());
58
+ const fallbackOption = "404"; // "Return an HTTP 404 File Not Found response"
59
+
60
+ /** @see https://en.gravatar.com/site/implement/images/#default-image */
61
+ return `${base}${hash}?s=${dimensions}&d=${fallbackOption}`;
62
+ };
51
63
  const renderComponent = () => {
52
- let portrait = /*#__PURE__*/_react.default.createElement(_portrait.StyledIcon, {
64
+ let portrait = /*#__PURE__*/_react.default.createElement(_portrait2.StyledIcon, {
53
65
  type: iconType,
54
- size: size,
55
- shape: shape || defaultShape,
56
- darkBackground: darkBackground
66
+ size: size
57
67
  });
58
68
  if (initials) {
59
- portrait = /*#__PURE__*/_react.default.createElement(_portraitInitials.default, {
69
+ portrait = /*#__PURE__*/_react.default.createElement(_portrait2.StyledPortraitInitials, {
60
70
  size: size,
61
- shape: shape || defaultShape,
62
- initials: initials,
63
- darkBackground: darkBackground,
64
- alt: alt
65
- });
71
+ "data-element": "initials"
72
+ }, initials.slice(0, 3).toUpperCase());
66
73
  }
67
74
  if (src && !externalError) {
68
- portrait = /*#__PURE__*/_react.default.createElement(_portrait.StyledCustomImg, {
75
+ portrait = /*#__PURE__*/_react.default.createElement(_portrait2.StyledCustomImg, {
69
76
  src: src,
70
- alt: alt,
71
- size: size,
72
- shape: shape || defaultShape,
77
+ alt: alt || name || "",
73
78
  "data-element": "user-image",
74
79
  onError: () => setExternalError(true)
75
80
  });
76
81
  }
77
82
  if (gravatar && !externalError) {
78
- portrait = /*#__PURE__*/_react.default.createElement(_portraitGravatar.default, {
79
- gravatarEmail: gravatar,
80
- shape: shape || defaultShape,
81
- size: size,
82
- alt: alt,
83
- errorCallback: () => setExternalError(true)
83
+ portrait = /*#__PURE__*/_react.default.createElement(_portrait2.StyledPortraitGravatar, {
84
+ src: gravatarSrc(),
85
+ alt: alt || name || "",
86
+ onError: () => setExternalError(true)
84
87
  });
85
88
  }
86
89
  if (tooltipMessage) {
@@ -93,16 +96,23 @@ const Portrait = ({
93
96
  isVisible: tooltipIsVisible,
94
97
  bgColor: tooltipBgColor,
95
98
  fontColor: tooltipFontColor
96
- }, /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitContainer, _extends({}, (0, _utils.filterStyledSystemMarginProps)(rest), {
99
+ }, /*#__PURE__*/_react.default.createElement(_portrait2.StyledPortraitContainer, _extends({}, (0, _utils.filterStyledSystemMarginProps)(rest), {
97
100
  onClick: onClick
98
- }, tagProps), portrait));
101
+ }, tagProps, {
102
+ darkBackground: darkBackground,
103
+ size: size,
104
+ shape: shape || defaultShape
105
+ }), portrait));
99
106
  }
100
- return /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitContainer, _extends({}, (0, _utils.filterStyledSystemMarginProps)(rest), {
107
+ return /*#__PURE__*/_react.default.createElement(_portrait2.StyledPortraitContainer, _extends({}, (0, _utils.filterStyledSystemMarginProps)(rest), {
101
108
  onClick: onClick
102
- }, tagProps), portrait);
109
+ }, tagProps, {
110
+ darkBackground: darkBackground,
111
+ size: size,
112
+ shape: shape || defaultShape
113
+ }), portrait);
103
114
  };
104
115
  return renderComponent();
105
116
  };
106
- exports.Portrait = Portrait;
107
117
  var _default = Portrait;
108
118
  exports.default = _default;
@@ -1,7 +1,7 @@
1
- export declare const PORTRAIT_SHAPES: string[];
2
- declare type PortraitSize = "XS" | "S" | "M" | "ML" | "L" | "XL" | "XXL";
3
- export declare const PORTRAIT_SIZES: PortraitSize[];
4
- declare type PortraitSizeParams = Record<PortraitSize, {
1
+ import { PortraitShapes, PortraitSizes } from "./portrait.component";
2
+ export declare const PORTRAIT_SHAPES: PortraitShapes[];
3
+ export declare const PORTRAIT_SIZES: PortraitSizes[];
4
+ declare type PortraitSizeParams = Record<PortraitSizes, {
5
5
  dimensions: number;
6
6
  iconDimensions: number;
7
7
  }>;
@@ -1,28 +1,15 @@
1
1
  import React from "react";
2
2
  import { MarginProps } from "styled-system";
3
- import { IconType } from "../icon";
4
3
  import { PortraitSizes, PortraitShapes } from "./portrait.component";
5
- export declare function getColorsForInitials(darkBackground?: boolean): {
6
- textColor: "colorsUtilityYang100" | "colorsUtilityYin055";
7
- bgColor: "colorsUtilityMajor400" | "colorsUtilityMajor025";
8
- };
9
- declare type PortraitSizeAndShape = {
4
+ declare type StyledPortraitProps = {
5
+ darkBackground?: boolean;
10
6
  size: PortraitSizes;
11
7
  shape?: PortraitShapes;
8
+ onClick?: (ev: React.MouseEvent<HTMLElement>) => void;
12
9
  };
13
- export declare const StyledPortraitInitials: import("styled-components").StyledComponent<"div", any, PortraitSizeAndShape & {
14
- initials?: string | undefined;
15
- }, never>;
16
- export declare const StyledPortraitInitialsImg: import("styled-components").StyledComponent<"img", any, {}, never>;
17
- export declare const StyledPortraitGravatar: import("styled-components").StyledComponent<"img", any, PortraitSizeAndShape, never>;
18
- export declare const StyledCustomImg: import("styled-components").StyledComponent<"img", any, PortraitSizeAndShape, never>;
19
- export declare const StyledIcon: import("styled-components").StyledComponent<React.ForwardRefExoticComponent<import("../icon").IconProps & React.RefAttributes<HTMLSpanElement>>, any, {
20
- size: PortraitSizes;
21
- shape?: PortraitShapes | undefined;
22
- darkBackground: boolean;
23
- type: IconType;
24
- }, never>;
25
- export declare const StyledPortraitContainer: import("styled-components").StyledComponent<"div", any, MarginProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & {
26
- onClick?: ((ev: React.MouseEvent<HTMLElement>) => void) | undefined;
27
- }, never>;
10
+ export declare const StyledPortraitInitials: import("styled-components").StyledComponent<"div", any, Pick<StyledPortraitProps, "size">, never>;
11
+ export declare const StyledPortraitGravatar: import("styled-components").StyledComponent<"img", any, {}, never>;
12
+ export declare const StyledCustomImg: import("styled-components").StyledComponent<"img", any, {}, never>;
13
+ export declare const StyledIcon: import("styled-components").StyledComponent<React.ForwardRefExoticComponent<import("../icon").IconProps & React.RefAttributes<HTMLSpanElement>>, any, Pick<StyledPortraitProps, "size">, never>;
14
+ export declare const StyledPortraitContainer: import("styled-components").StyledComponent<"div", any, StyledPortraitProps & MarginProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>>, never>;
28
15
  export {};
@@ -3,100 +3,35 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.StyledPortraitInitialsImg = exports.StyledPortraitInitials = exports.StyledPortraitGravatar = exports.StyledPortraitContainer = exports.StyledIcon = exports.StyledCustomImg = void 0;
7
- exports.getColorsForInitials = getColorsForInitials;
8
- var _styledComponents = _interopRequireWildcard(require("styled-components"));
6
+ exports.StyledPortraitInitials = exports.StyledPortraitGravatar = exports.StyledPortraitContainer = exports.StyledIcon = exports.StyledCustomImg = void 0;
7
+ var _styledComponents = _interopRequireDefault(require("styled-components"));
9
8
  var _styledSystem = require("styled-system");
10
9
  var _base = _interopRequireDefault(require("../../style/themes/base"));
11
10
  var _icon = _interopRequireDefault(require("../icon"));
12
11
  var _portrait = require("./portrait.config");
12
+ var _profile = _interopRequireDefault(require("../profile/profile.config"));
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
- function stylingForSize({
17
- size,
18
- initials
19
- }) {
20
- const params = _portrait.PORTRAIT_SIZE_PARAMS[size];
21
- if (initials) {
22
- return (0, _styledComponents.css)`
23
- width: inherit;
24
- height: inherit;
25
- margin: 1px;
26
- `;
27
- }
28
- return (0, _styledComponents.css)`
29
- width: ${params?.dimensions}px;
30
- height: ${params?.dimensions}px;
31
- `;
32
- }
33
- function stylingForShape({
34
- shape
35
- }) {
36
- let cssString = "overflow: hidden;";
37
- if (shape === "square") cssString += "border-radius: 0px;";
38
- if (shape === "circle") cssString += "border-radius: var(--borderRadiusCircle);";
39
- return (0, _styledComponents.css)`
40
- ${cssString}
41
- `;
42
- }
43
- function stylingForIcon({
44
- size,
45
- darkBackground
46
- }) {
47
- const params = _portrait.PORTRAIT_SIZE_PARAMS[size];
48
- let color = "var(--colorsUtilityMajor200)";
49
- let backgroundColor = "var(--colorsUtilityMajor025)";
50
- if (darkBackground) {
51
- color = "var(--colorsUtilityMajor025)";
52
- backgroundColor = "var(--colorsUtilityMajor200)";
53
- }
54
- return (0, _styledComponents.css)`
55
- background-color: ${backgroundColor};
56
- color: ${color};
57
- ::before {
58
- font-size: ${params?.iconDimensions}px;
59
- }
60
- `;
61
- }
62
- function getColorsForInitials(darkBackground) {
63
- return {
64
- textColor: darkBackground ? "colorsUtilityYang100" : "colorsUtilityYin055",
65
- bgColor: darkBackground ? "colorsUtilityMajor400" : "colorsUtilityMajor025"
66
- };
67
- }
68
14
  const StyledPortraitInitials = _styledComponents.default.div`
69
- display: inline-block;
70
- vertical-align: middle;
71
- box-sizing: border-box;
72
- ${stylingForSize}
73
- ${stylingForShape}
74
- outline: 1px solid var(--colorsUtilityMajor200);
75
- /* Styling for safari. This ensures that there is no outline on the component but that a border is still present
76
- to achieve the same styling as Chrome and Firefox */
77
- @media not all and (min-resolution: 0.001dpcm) {
78
- @supports (-webkit-appearance: none) and (stroke-color: transparent) {
79
- border: 1px solid var(--colorsUtilityMajor200);
80
- outline: none;
81
- }
82
- }
15
+ font-weight: bold;
16
+ font-size: ${({
17
+ size
18
+ }) => _profile.default[size].initialSize};
19
+ display: flex;
20
+ white-space: nowrap;
21
+ align-items: center;
22
+ justify-content: center;
23
+ height: inherit;
24
+ width: inherit;
83
25
  `;
84
26
  exports.StyledPortraitInitials = StyledPortraitInitials;
85
- const StyledPortraitInitialsImg = _styledComponents.default.img`
86
- display: block;
87
- `;
88
- exports.StyledPortraitInitialsImg = StyledPortraitInitialsImg;
89
27
  const StyledPortraitGravatar = _styledComponents.default.img`
90
- display: inline-block;
91
- vertical-align: middle;
92
- ${stylingForSize}
93
- ${stylingForShape}
28
+ height: inherit;
29
+ width: inherit;
94
30
  `;
95
31
  exports.StyledPortraitGravatar = StyledPortraitGravatar;
96
32
  const StyledCustomImg = _styledComponents.default.img`
97
- display: block;
98
- ${stylingForSize}
99
- ${stylingForShape}
33
+ height: inherit;
34
+ width: inherit;
100
35
  `;
101
36
 
102
37
  // && is used here to increase the specificity
@@ -104,18 +39,36 @@ const StyledCustomImg = _styledComponents.default.img`
104
39
  exports.StyledCustomImg = StyledCustomImg;
105
40
  const StyledIcon = (0, _styledComponents.default)(_icon.default)`
106
41
  && {
107
- box-sizing: border-box;
108
- line-height: 14px;
109
- ${stylingForSize}
110
- ${stylingForIcon}
111
- ${stylingForShape}
112
- border: 1px dashed ${({
113
- darkBackground
114
- }) => darkBackground ? "var(--colorsUtilityMajorTransparent)" : "var(--colorsUtilityMajor200)"};
42
+ color: inherit;
43
+ height: inherit;
44
+ width: inherit;
45
+
46
+ ::before {
47
+ font-size: ${({
48
+ size
49
+ }) => _portrait.PORTRAIT_SIZE_PARAMS[size].iconDimensions}px;
50
+ }
115
51
  }
116
52
  `;
117
53
  exports.StyledIcon = StyledIcon;
118
54
  const StyledPortraitContainer = _styledComponents.default.div`
55
+ color: ${({
56
+ darkBackground
57
+ }) => darkBackground ? "var(--colorsUtilityReadOnly600)" : "var(--colorsUtilityYin090)"};
58
+ background-color: ${({
59
+ darkBackground
60
+ }) => darkBackground ? "var(--colorsUtilityYin090)" : "var(--colorsUtilityReadOnly400)"};
61
+ width: ${({
62
+ size
63
+ }) => _portrait.PORTRAIT_SIZE_PARAMS[size].dimensions}px;
64
+ height: ${({
65
+ size
66
+ }) => _portrait.PORTRAIT_SIZE_PARAMS[size].dimensions}px;
67
+ overflow: hidden;
68
+ border-radius: ${({
69
+ shape
70
+ }) => shape === "square" ? "0px" : "var(--borderRadiusCircle)"};
71
+ border: 1px solid var(--colorsUtilityReadOnly600);
119
72
  display: inline-block;
120
73
  ${({
121
74
  onClick
@@ -5,14 +5,20 @@ export interface ProfileProps {
5
5
  className?: string;
6
6
  /** Custom source URL */
7
7
  src?: string;
8
+ /** The `alt` HTML string. */
9
+ alt?: string;
8
10
  /** Define the name to display. */
9
- name: string;
11
+ name?: string;
10
12
  /** Define the email to use (will check Gravatar for image). */
11
- email: string;
13
+ email?: string;
14
+ /** Define read-only text to display. */
15
+ text?: string;
12
16
  /** Define initials to display if there is no Gravatar image. */
13
17
  initials?: string;
14
18
  /** Allow to setup size for the component */
15
19
  size?: ProfileSize;
20
+ /** Use a dark background. */
21
+ darkBackground?: boolean;
16
22
  }
17
- export declare const Profile: ({ src, className, initials, name, size, email, ...props }: ProfileProps) => React.JSX.Element;
23
+ export declare const Profile: ({ src, alt, className, initials, name, size, email, text, darkBackground, ...props }: ProfileProps) => React.JSX.Element;
18
24
  export default Profile;
@@ -17,52 +17,69 @@ function acronymize(str) {
17
17
  if (!matches) return "";
18
18
  return matches.join("");
19
19
  }
20
+ let useOfNoNameWarnTriggered = false;
20
21
  const Profile = ({
21
22
  src,
23
+ alt,
22
24
  className,
23
25
  initials,
24
26
  name,
25
27
  size,
26
28
  email,
29
+ text,
30
+ darkBackground,
27
31
  ...props
28
32
  }) => {
29
33
  const getInitials = () => {
30
34
  if (initials) return initials;
31
- return acronymize(name);
35
+ return acronymize(name).slice(0, 3).toUpperCase();
36
+ };
37
+ const commonAvatarProps = {
38
+ darkBackground,
39
+ alt,
40
+ name,
41
+ initials: getInitials(),
42
+ size
32
43
  };
33
44
  const avatar = () => {
34
45
  if (src) {
35
- return /*#__PURE__*/_react.default.createElement(_profile.ProfileAvatarStyle, {
46
+ return /*#__PURE__*/_react.default.createElement(_profile.ProfileAvatarStyle, _extends({
36
47
  src: src,
37
- alt: getInitials(),
38
- initials: getInitials(),
39
- size: size,
40
- shape: "circle",
41
48
  "data-element": "user-image"
42
- });
49
+ }, commonAvatarProps));
43
50
  }
44
- return /*#__PURE__*/_react.default.createElement(_profile.ProfileAvatarStyle, {
45
- initials: getInitials(),
46
- gravatar: email,
47
- size: size
48
- });
51
+ return /*#__PURE__*/_react.default.createElement(_profile.ProfileAvatarStyle, _extends({
52
+ gravatar: email
53
+ }, commonAvatarProps));
49
54
  };
50
- const text = () => {
51
- return /*#__PURE__*/_react.default.createElement(_profile.ProfileDetailsStyle, {
55
+ if (!useOfNoNameWarnTriggered && !name && (email || text)) {
56
+ useOfNoNameWarnTriggered = true;
57
+ console.warn("[WARNING] The `email` or `text` prop should not be used without the `name` prop in `Profile`." + " Please use the `name` prop as well as `email` or `text`.");
58
+ }
59
+ const children = () => {
60
+ if (name) return /*#__PURE__*/_react.default.createElement(_profile.ProfileDetailsStyle, {
52
61
  size: size,
53
- hasSrc: !!src
62
+ hasSrc: !!src,
63
+ "data-element": "details"
54
64
  }, /*#__PURE__*/_react.default.createElement(_profile.ProfileNameStyle, {
55
65
  size: size,
56
66
  "data-element": "name"
57
67
  }, name), /*#__PURE__*/_react.default.createElement(_profile.ProfileEmailStyle, {
68
+ href: `mailto: ${email}`,
58
69
  size: size,
70
+ darkBackground: darkBackground,
59
71
  "data-element": "email"
60
- }, email));
72
+ }, email), /*#__PURE__*/_react.default.createElement(_profile.ProfileTextStyle, {
73
+ size: size,
74
+ "data-element": "text"
75
+ }, text));
76
+ return null;
61
77
  };
62
78
  return /*#__PURE__*/_react.default.createElement(_profile.ProfileStyle, _extends({
63
79
  className: className,
64
- hasSrc: !!src
65
- }, (0, _tags.default)("profile", props), (0, _utils.filterStyledSystemMarginProps)(props)), avatar(), text());
80
+ hasSrc: !!src,
81
+ darkBackground: darkBackground
82
+ }, (0, _tags.default)("profile", props), (0, _utils.filterStyledSystemMarginProps)(props)), avatar(), children());
66
83
  };
67
84
  exports.Profile = Profile;
68
85
  var _default = Profile;
@@ -3,53 +3,53 @@ declare type AllProfileSizes = typeof PROFILE_SIZES;
3
3
  export declare type ProfileSize = AllProfileSizes[number];
4
4
  declare const _default: {
5
5
  XS: {
6
+ initialSize: string;
6
7
  nameSize: string;
7
8
  emailSize: string;
8
9
  lineHeight: string;
9
10
  marginLeft: string;
10
- marginTop: string;
11
11
  };
12
12
  S: {
13
+ initialSize: string;
13
14
  nameSize: string;
14
15
  emailSize: string;
15
16
  lineHeight: string;
16
17
  marginLeft: string;
17
- marginTop: string;
18
18
  };
19
19
  M: {
20
+ initialSize: string;
20
21
  nameSize: string;
21
22
  emailSize: string;
22
23
  lineHeight: string;
23
24
  marginLeft: string;
24
- marginTop: string;
25
25
  };
26
26
  ML: {
27
+ initialSize: string;
27
28
  nameSize: string;
28
29
  emailSize: string;
29
30
  lineHeight: string;
30
31
  marginLeft: string;
31
- marginTop: string;
32
32
  };
33
33
  L: {
34
+ initialSize: string;
34
35
  nameSize: string;
35
36
  emailSize: string;
36
37
  lineHeight: string;
37
38
  marginLeft: string;
38
- marginTop: string;
39
39
  };
40
40
  XL: {
41
+ initialSize: string;
41
42
  nameSize: string;
42
43
  emailSize: string;
43
44
  lineHeight: string;
44
45
  marginLeft: string;
45
- marginTop: string;
46
46
  };
47
47
  XXL: {
48
+ initialSize: string;
48
49
  nameSize: string;
49
50
  emailSize: string;
50
51
  lineHeight: string;
51
52
  marginLeft: string;
52
- marginTop: string;
53
53
  };
54
54
  };
55
55
  export default _default;