carbon-react 123.8.0 → 123.9.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/esm/components/portrait/portrait.component.d.ts +3 -1
- package/esm/components/portrait/portrait.component.js +37 -26
- package/esm/components/portrait/portrait.config.d.ts +4 -4
- package/esm/components/portrait/portrait.style.d.ts +8 -21
- package/esm/components/portrait/portrait.style.js +42 -85
- package/esm/components/profile/profile.component.d.ts +9 -3
- package/esm/components/profile/profile.component.js +36 -19
- package/esm/components/profile/profile.config.d.ts +7 -7
- package/esm/components/profile/profile.config.js +14 -14
- package/esm/components/profile/profile.style.d.ts +10 -12
- package/esm/components/profile/profile.style.js +30 -13
- package/lib/components/portrait/portrait.component.d.ts +3 -1
- package/lib/components/portrait/portrait.component.js +41 -31
- package/lib/components/portrait/portrait.config.d.ts +4 -4
- package/lib/components/portrait/portrait.style.d.ts +8 -21
- package/lib/components/portrait/portrait.style.js +43 -90
- package/lib/components/profile/profile.component.d.ts +9 -3
- package/lib/components/profile/profile.component.js +35 -18
- package/lib/components/profile/profile.config.d.ts +7 -7
- package/lib/components/profile/profile.config.js +14 -14
- package/lib/components/profile/profile.style.d.ts +10 -12
- package/lib/components/profile/profile.style.js +32 -14
- package/package.json +1 -1
- package/esm/components/portrait/portrait-gravatar.component.d.ts +0 -16
- package/esm/components/portrait/portrait-gravatar.component.js +0 -33
- package/esm/components/portrait/portrait-initials.component.d.ts +0 -16
- package/esm/components/portrait/portrait-initials.component.js +0 -67
- package/lib/components/portrait/portrait-gravatar.component.d.ts +0 -16
- package/lib/components/portrait/portrait-gravatar.component.js +0 -41
- package/lib/components/portrait/portrait-initials.component.d.ts +0 -16
- package/lib/components/portrait/portrait-initials.component.js +0 -77
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { ProfileSize } from "./profile.config";
|
|
3
|
-
interface
|
|
3
|
+
interface ProfileSProps {
|
|
4
4
|
size?: ProfileSize;
|
|
5
|
+
hasSrc?: boolean;
|
|
6
|
+
darkBackground?: boolean;
|
|
5
7
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
declare const
|
|
12
|
-
|
|
13
|
-
declare const ProfileStyle: import("styled-components").StyledComponent<"div", any, ProfileHasSrcProps, never>;
|
|
14
|
-
declare const ProfileDetailsStyle: import("styled-components").StyledComponent<"div", any, ProfileDetailsStyleProps, never>;
|
|
15
|
-
declare const ProfileAvatarStyle: import("styled-components").StyledComponent<({ alt, darkBackground, gravatar, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: import("../portrait").PortraitProps) => import("react").JSX.Element, any, {}, never>;
|
|
16
|
-
export { ProfileStyle, ProfileNameStyle, ProfileDetailsStyle, ProfileAvatarStyle, ProfileEmailStyle, };
|
|
8
|
+
declare const ProfileNameStyle: import("styled-components").StyledComponent<"span", any, ProfileSProps, never>;
|
|
9
|
+
declare const ProfileEmailStyle: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../link").LinkProps & import("react").RefAttributes<HTMLButtonElement | HTMLLinkElement>>, any, Pick<ProfileSProps, "size" | "darkBackground">, never>;
|
|
10
|
+
declare const ProfileTextStyle: import("styled-components").StyledComponent<"span", any, ProfileSProps, never>;
|
|
11
|
+
declare const ProfileStyle: import("styled-components").StyledComponent<"div", any, Pick<ProfileSProps, "darkBackground" | "hasSrc">, never>;
|
|
12
|
+
declare const ProfileDetailsStyle: import("styled-components").StyledComponent<"div", any, Pick<ProfileSProps, "size" | "hasSrc">, never>;
|
|
13
|
+
declare const ProfileAvatarStyle: import("styled-components").StyledComponent<({ alt, name, darkBackground, gravatar, iconType, initials, shape, size, src, onClick, tooltipMessage, tooltipId, tooltipIsVisible, tooltipPosition, tooltipType, tooltipSize, tooltipBgColor, tooltipFontColor, ...rest }: import("../portrait").PortraitProps) => import("react").JSX.Element, any, {}, never>;
|
|
14
|
+
export { ProfileStyle, ProfileNameStyle, ProfileDetailsStyle, ProfileAvatarStyle, ProfileEmailStyle, ProfileTextStyle, };
|
|
@@ -3,44 +3,62 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.ProfileStyle = exports.ProfileNameStyle = exports.ProfileEmailStyle = exports.ProfileDetailsStyle = exports.ProfileAvatarStyle = void 0;
|
|
6
|
+
exports.ProfileTextStyle = exports.ProfileStyle = exports.ProfileNameStyle = exports.ProfileEmailStyle = exports.ProfileDetailsStyle = exports.ProfileAvatarStyle = void 0;
|
|
7
7
|
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
8
8
|
var _styledSystem = require("styled-system");
|
|
9
9
|
var _portrait = _interopRequireDefault(require("../portrait"));
|
|
10
10
|
var _base = _interopRequireDefault(require("../../style/themes/base"));
|
|
11
11
|
var _profile = _interopRequireDefault(require("./profile.config"));
|
|
12
|
+
var _link = _interopRequireDefault(require("../link"));
|
|
13
|
+
var _portrait2 = require("../portrait/portrait.style");
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
15
|
const ProfileNameStyle = _styledComponents.default.span`
|
|
14
16
|
font-weight: bold;
|
|
15
|
-
display: block;
|
|
16
17
|
font-size: ${({
|
|
17
18
|
size = "M"
|
|
18
19
|
}) => _profile.default[size].nameSize};
|
|
19
20
|
`;
|
|
20
21
|
exports.ProfileNameStyle = ProfileNameStyle;
|
|
21
|
-
const ProfileEmailStyle = _styledComponents.default.
|
|
22
|
-
|
|
22
|
+
const ProfileEmailStyle = (0, _styledComponents.default)(_link.default)`
|
|
23
|
+
a {
|
|
24
|
+
font-size: ${({
|
|
23
25
|
size = "M"
|
|
24
26
|
}) => _profile.default[size].emailSize};
|
|
27
|
+
color: ${({
|
|
28
|
+
darkBackground
|
|
29
|
+
}) => darkBackground && "var(--colorsActionMajor350)"};
|
|
30
|
+
}
|
|
25
31
|
`;
|
|
26
32
|
exports.ProfileEmailStyle = ProfileEmailStyle;
|
|
33
|
+
const ProfileTextStyle = _styledComponents.default.span`
|
|
34
|
+
font-size: ${({
|
|
35
|
+
size = "M"
|
|
36
|
+
}) => _profile.default[size].emailSize};
|
|
37
|
+
`;
|
|
38
|
+
exports.ProfileTextStyle = ProfileTextStyle;
|
|
27
39
|
const ProfileStyle = _styledComponents.default.div`
|
|
40
|
+
border-radius: inherit;
|
|
28
41
|
white-space: nowrap;
|
|
29
|
-
color:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
42
|
+
color: ${({
|
|
43
|
+
darkBackground
|
|
44
|
+
}) => darkBackground ? "var(--colorsUtilityReadOnly600)" : "var(--colorsUtilityYin090)"};
|
|
45
|
+
background-color: ${({
|
|
46
|
+
darkBackground
|
|
47
|
+
}) => darkBackground ? "var(--colorsUtilityYin090)" : "transparent"};
|
|
48
|
+
display: flex;
|
|
49
|
+
flex-direction: row;
|
|
34
50
|
${_styledSystem.margin}
|
|
51
|
+
|
|
52
|
+
${_portrait2.StyledPortraitContainer} {
|
|
53
|
+
flex-shrink: 0;
|
|
54
|
+
}
|
|
35
55
|
`;
|
|
36
56
|
exports.ProfileStyle = ProfileStyle;
|
|
37
57
|
const ProfileDetailsStyle = _styledComponents.default.div`
|
|
38
58
|
vertical-align: middle;
|
|
39
|
-
display:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
size = "M"
|
|
43
|
-
}) => hasSrc ? _profile.default[size].marginTop : ""};
|
|
59
|
+
display: flex;
|
|
60
|
+
flex-direction: column;
|
|
61
|
+
justify-content: center;
|
|
44
62
|
line-height: ${({
|
|
45
63
|
size = "M"
|
|
46
64
|
}) => _profile.default[size].lineHeight};
|
package/package.json
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { PortraitSizes, PortraitShapes } from "./portrait.component";
|
|
3
|
-
export interface PortraitGravatarProps {
|
|
4
|
-
/** The user's email address for the Gravatar. */
|
|
5
|
-
gravatarEmail: string;
|
|
6
|
-
/** The size of the Gravatar. */
|
|
7
|
-
size: PortraitSizes;
|
|
8
|
-
/** The shape of the Gravatar. */
|
|
9
|
-
shape?: PortraitShapes;
|
|
10
|
-
/** The `alt` HTML string. */
|
|
11
|
-
alt?: string;
|
|
12
|
-
/** A callback to execute if the Gravatar image fails to load. */
|
|
13
|
-
errorCallback?: () => void;
|
|
14
|
-
}
|
|
15
|
-
declare const PortraitGravatar: ({ gravatarEmail, size, alt, shape, errorCallback, }: PortraitGravatarProps) => React.JSX.Element;
|
|
16
|
-
export default PortraitGravatar;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import PropTypes from "prop-types";
|
|
3
|
-
import MD5 from "crypto-js/md5";
|
|
4
|
-
import { StyledPortraitGravatar } from "./portrait.style";
|
|
5
|
-
import { PORTRAIT_SIZE_PARAMS } from "./portrait.config";
|
|
6
|
-
const PortraitGravatar = ({
|
|
7
|
-
gravatarEmail,
|
|
8
|
-
size,
|
|
9
|
-
alt,
|
|
10
|
-
shape = "circle",
|
|
11
|
-
errorCallback
|
|
12
|
-
}) => {
|
|
13
|
-
const gravatarSrc = () => {
|
|
14
|
-
const {
|
|
15
|
-
dimensions
|
|
16
|
-
} = PORTRAIT_SIZE_PARAMS[size];
|
|
17
|
-
const base = "https://www.gravatar.com/avatar/";
|
|
18
|
-
const hash = MD5(gravatarEmail.toLowerCase());
|
|
19
|
-
const fallbackOption = "404"; // "Return an HTTP 404 File Not Found response"
|
|
20
|
-
|
|
21
|
-
/** @see https://en.gravatar.com/site/implement/images/#default-image */
|
|
22
|
-
return `${base}${hash}?s=${dimensions}&d=${fallbackOption}`;
|
|
23
|
-
};
|
|
24
|
-
return /*#__PURE__*/React.createElement(StyledPortraitGravatar, {
|
|
25
|
-
src: gravatarSrc(),
|
|
26
|
-
alt: alt,
|
|
27
|
-
size: size,
|
|
28
|
-
shape: shape,
|
|
29
|
-
onError: errorCallback,
|
|
30
|
-
"data-element": "user-image"
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
export default PortraitGravatar;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { PortraitSizes, PortraitShapes } from "./portrait.component";
|
|
3
|
-
export interface PortraitInitialsProps {
|
|
4
|
-
/** The user's initials to render. */
|
|
5
|
-
initials: string;
|
|
6
|
-
/** The size of the initials image. */
|
|
7
|
-
size: PortraitSizes;
|
|
8
|
-
/** Use a dark background. */
|
|
9
|
-
darkBackground?: boolean;
|
|
10
|
-
/** The shape of the Portrait. */
|
|
11
|
-
shape?: PortraitShapes;
|
|
12
|
-
/** The `alt` HTML string. */
|
|
13
|
-
alt?: string;
|
|
14
|
-
}
|
|
15
|
-
declare const PortraitInitials: ({ initials, size, shape, darkBackground, alt, }: PortraitInitialsProps) => React.JSX.Element;
|
|
16
|
-
export default PortraitInitials;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
2
|
-
import PropTypes from "prop-types";
|
|
3
|
-
import tokens from "@sage/design-tokens/js/base/common";
|
|
4
|
-
import { StyledPortraitInitials, StyledPortraitInitialsImg, getColorsForInitials } from "./portrait.style";
|
|
5
|
-
import { PORTRAIT_SIZE_PARAMS } from "./portrait.config";
|
|
6
|
-
const PortraitInitials = ({
|
|
7
|
-
initials,
|
|
8
|
-
size,
|
|
9
|
-
shape = "circle",
|
|
10
|
-
darkBackground,
|
|
11
|
-
alt
|
|
12
|
-
}) => {
|
|
13
|
-
const [cachedImageDataUrl, setCachedImageDataUrl] = useState();
|
|
14
|
-
useEffect(() => {
|
|
15
|
-
setCachedImageDataUrl("");
|
|
16
|
-
}, [initials, size, darkBackground]);
|
|
17
|
-
const generateDataUrl = () => {
|
|
18
|
-
if (cachedImageDataUrl) {
|
|
19
|
-
return cachedImageDataUrl;
|
|
20
|
-
}
|
|
21
|
-
const {
|
|
22
|
-
textColor,
|
|
23
|
-
bgColor
|
|
24
|
-
} = getColorsForInitials(darkBackground);
|
|
25
|
-
let canvas = document.createElement("canvas");
|
|
26
|
-
const context = canvas.getContext("2d");
|
|
27
|
-
let {
|
|
28
|
-
dimensions
|
|
29
|
-
} = PORTRAIT_SIZE_PARAMS[size];
|
|
30
|
-
dimensions -= 2;
|
|
31
|
-
|
|
32
|
-
// Set canvas with & height
|
|
33
|
-
canvas.width = dimensions;
|
|
34
|
-
canvas.height = dimensions;
|
|
35
|
-
|
|
36
|
-
// Select a font family to support different language characters like Arial
|
|
37
|
-
/* istanbul ignore else */
|
|
38
|
-
if (context) {
|
|
39
|
-
context.font = `${Math.round(canvas.width / 2.4)}px "Sage UI", Arial`;
|
|
40
|
-
context.textAlign = "center";
|
|
41
|
-
|
|
42
|
-
// Setup background and front color
|
|
43
|
-
context.fillStyle = tokens[bgColor];
|
|
44
|
-
context.fillRect(0, 0, dimensions, dimensions);
|
|
45
|
-
context.fillStyle = tokens[textColor];
|
|
46
|
-
context.fillText(initials.slice(0, 3).toUpperCase(), dimensions / 2, dimensions / 1.5);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Set image representation in default format (png)
|
|
50
|
-
const dataURI = canvas.toDataURL();
|
|
51
|
-
|
|
52
|
-
// Dispose canvas element
|
|
53
|
-
canvas = null;
|
|
54
|
-
setCachedImageDataUrl(dataURI);
|
|
55
|
-
return dataURI;
|
|
56
|
-
};
|
|
57
|
-
return /*#__PURE__*/React.createElement(StyledPortraitInitials, {
|
|
58
|
-
"data-element": "initials",
|
|
59
|
-
size: size,
|
|
60
|
-
shape: shape,
|
|
61
|
-
initials: initials
|
|
62
|
-
}, /*#__PURE__*/React.createElement(StyledPortraitInitialsImg, {
|
|
63
|
-
src: generateDataUrl(),
|
|
64
|
-
alt: alt
|
|
65
|
-
}));
|
|
66
|
-
};
|
|
67
|
-
export default PortraitInitials;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { PortraitSizes, PortraitShapes } from "./portrait.component";
|
|
3
|
-
export interface PortraitGravatarProps {
|
|
4
|
-
/** The user's email address for the Gravatar. */
|
|
5
|
-
gravatarEmail: string;
|
|
6
|
-
/** The size of the Gravatar. */
|
|
7
|
-
size: PortraitSizes;
|
|
8
|
-
/** The shape of the Gravatar. */
|
|
9
|
-
shape?: PortraitShapes;
|
|
10
|
-
/** The `alt` HTML string. */
|
|
11
|
-
alt?: string;
|
|
12
|
-
/** A callback to execute if the Gravatar image fails to load. */
|
|
13
|
-
errorCallback?: () => void;
|
|
14
|
-
}
|
|
15
|
-
declare const PortraitGravatar: ({ gravatarEmail, size, alt, shape, errorCallback, }: PortraitGravatarProps) => React.JSX.Element;
|
|
16
|
-
export default PortraitGravatar;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = _interopRequireDefault(require("react"));
|
|
8
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
var _md = _interopRequireDefault(require("crypto-js/md5"));
|
|
10
|
-
var _portrait = require("./portrait.style");
|
|
11
|
-
var _portrait2 = require("./portrait.config");
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
const PortraitGravatar = ({
|
|
14
|
-
gravatarEmail,
|
|
15
|
-
size,
|
|
16
|
-
alt,
|
|
17
|
-
shape = "circle",
|
|
18
|
-
errorCallback
|
|
19
|
-
}) => {
|
|
20
|
-
const gravatarSrc = () => {
|
|
21
|
-
const {
|
|
22
|
-
dimensions
|
|
23
|
-
} = _portrait2.PORTRAIT_SIZE_PARAMS[size];
|
|
24
|
-
const base = "https://www.gravatar.com/avatar/";
|
|
25
|
-
const hash = (0, _md.default)(gravatarEmail.toLowerCase());
|
|
26
|
-
const fallbackOption = "404"; // "Return an HTTP 404 File Not Found response"
|
|
27
|
-
|
|
28
|
-
/** @see https://en.gravatar.com/site/implement/images/#default-image */
|
|
29
|
-
return `${base}${hash}?s=${dimensions}&d=${fallbackOption}`;
|
|
30
|
-
};
|
|
31
|
-
return /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitGravatar, {
|
|
32
|
-
src: gravatarSrc(),
|
|
33
|
-
alt: alt,
|
|
34
|
-
size: size,
|
|
35
|
-
shape: shape,
|
|
36
|
-
onError: errorCallback,
|
|
37
|
-
"data-element": "user-image"
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
var _default = PortraitGravatar;
|
|
41
|
-
exports.default = _default;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { PortraitSizes, PortraitShapes } from "./portrait.component";
|
|
3
|
-
export interface PortraitInitialsProps {
|
|
4
|
-
/** The user's initials to render. */
|
|
5
|
-
initials: string;
|
|
6
|
-
/** The size of the initials image. */
|
|
7
|
-
size: PortraitSizes;
|
|
8
|
-
/** Use a dark background. */
|
|
9
|
-
darkBackground?: boolean;
|
|
10
|
-
/** The shape of the Portrait. */
|
|
11
|
-
shape?: PortraitShapes;
|
|
12
|
-
/** The `alt` HTML string. */
|
|
13
|
-
alt?: string;
|
|
14
|
-
}
|
|
15
|
-
declare const PortraitInitials: ({ initials, size, shape, darkBackground, alt, }: PortraitInitialsProps) => React.JSX.Element;
|
|
16
|
-
export default PortraitInitials;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
-
var _common = _interopRequireDefault(require("@sage/design-tokens/js/base/common"));
|
|
10
|
-
var _portrait = require("./portrait.style");
|
|
11
|
-
var _portrait2 = require("./portrait.config");
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
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); }
|
|
14
|
-
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; }
|
|
15
|
-
const PortraitInitials = ({
|
|
16
|
-
initials,
|
|
17
|
-
size,
|
|
18
|
-
shape = "circle",
|
|
19
|
-
darkBackground,
|
|
20
|
-
alt
|
|
21
|
-
}) => {
|
|
22
|
-
const [cachedImageDataUrl, setCachedImageDataUrl] = (0, _react.useState)();
|
|
23
|
-
(0, _react.useEffect)(() => {
|
|
24
|
-
setCachedImageDataUrl("");
|
|
25
|
-
}, [initials, size, darkBackground]);
|
|
26
|
-
const generateDataUrl = () => {
|
|
27
|
-
if (cachedImageDataUrl) {
|
|
28
|
-
return cachedImageDataUrl;
|
|
29
|
-
}
|
|
30
|
-
const {
|
|
31
|
-
textColor,
|
|
32
|
-
bgColor
|
|
33
|
-
} = (0, _portrait.getColorsForInitials)(darkBackground);
|
|
34
|
-
let canvas = document.createElement("canvas");
|
|
35
|
-
const context = canvas.getContext("2d");
|
|
36
|
-
let {
|
|
37
|
-
dimensions
|
|
38
|
-
} = _portrait2.PORTRAIT_SIZE_PARAMS[size];
|
|
39
|
-
dimensions -= 2;
|
|
40
|
-
|
|
41
|
-
// Set canvas with & height
|
|
42
|
-
canvas.width = dimensions;
|
|
43
|
-
canvas.height = dimensions;
|
|
44
|
-
|
|
45
|
-
// Select a font family to support different language characters like Arial
|
|
46
|
-
/* istanbul ignore else */
|
|
47
|
-
if (context) {
|
|
48
|
-
context.font = `${Math.round(canvas.width / 2.4)}px "Sage UI", Arial`;
|
|
49
|
-
context.textAlign = "center";
|
|
50
|
-
|
|
51
|
-
// Setup background and front color
|
|
52
|
-
context.fillStyle = _common.default[bgColor];
|
|
53
|
-
context.fillRect(0, 0, dimensions, dimensions);
|
|
54
|
-
context.fillStyle = _common.default[textColor];
|
|
55
|
-
context.fillText(initials.slice(0, 3).toUpperCase(), dimensions / 2, dimensions / 1.5);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Set image representation in default format (png)
|
|
59
|
-
const dataURI = canvas.toDataURL();
|
|
60
|
-
|
|
61
|
-
// Dispose canvas element
|
|
62
|
-
canvas = null;
|
|
63
|
-
setCachedImageDataUrl(dataURI);
|
|
64
|
-
return dataURI;
|
|
65
|
-
};
|
|
66
|
-
return /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitInitials, {
|
|
67
|
-
"data-element": "initials",
|
|
68
|
-
size: size,
|
|
69
|
-
shape: shape,
|
|
70
|
-
initials: initials
|
|
71
|
-
}, /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitInitialsImg, {
|
|
72
|
-
src: generateDataUrl(),
|
|
73
|
-
alt: alt
|
|
74
|
-
}));
|
|
75
|
-
};
|
|
76
|
-
var _default = PortraitInitials;
|
|
77
|
-
exports.default = _default;
|