carbon-react 98.0.0 → 99.0.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.
- package/lib/components/detail/detail.component.js +23 -81
- package/lib/components/loader-bar/loader-bar.style.js +3 -4
- package/lib/components/portrait/portrait-gravatar.component.js +30 -76
- package/lib/components/portrait/portrait-initials.component.js +63 -135
- package/lib/components/portrait/portrait.component.js +80 -138
- package/lib/components/search/search.component.js +1 -0
- package/package.json +3 -1
|
@@ -23,88 +23,30 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
23
23
|
|
|
24
24
|
function _extends() { _extends = Object.assign || 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); }
|
|
25
25
|
|
|
26
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
27
|
-
|
|
28
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
29
|
-
|
|
30
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
31
|
-
|
|
32
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
33
|
-
|
|
34
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
35
|
-
|
|
36
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
37
|
-
|
|
38
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
39
|
-
|
|
40
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
41
|
-
|
|
42
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
43
|
-
|
|
44
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
45
|
-
|
|
46
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
47
|
-
|
|
48
26
|
const marginPropTypes = (0, _utils.filterStyledSystemMarginProps)(_propTypes2.default);
|
|
49
27
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
_defineProperty(_assertThisInitialized(_this), "footnote", () => {
|
|
74
|
-
if (!_this.props.footnote) {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return /*#__PURE__*/_react.default.createElement(_detail.StyledDetailFootnote, {
|
|
79
|
-
"data-element": "footnote",
|
|
80
|
-
hasIcon: _this.props.icon
|
|
81
|
-
}, _this.props.footnote);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
return _this;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
_createClass(Detail, [{
|
|
88
|
-
key: "render",
|
|
89
|
-
value:
|
|
90
|
-
/**
|
|
91
|
-
* @method render
|
|
92
|
-
* @return {Object} JSX
|
|
93
|
-
*/
|
|
94
|
-
function render() {
|
|
95
|
-
const marginProps = (0, _utils.filterStyledSystemMarginProps)(this.props);
|
|
96
|
-
return /*#__PURE__*/_react.default.createElement(_detail.StyledDetail, _extends({
|
|
97
|
-
className: (0, _classnames.default)("carbon-detail", this.props.className),
|
|
98
|
-
hasIcon: this.props.icon
|
|
99
|
-
}, (0, _tags.default)("detail", this.props), marginProps), this.icon(), /*#__PURE__*/_react.default.createElement(_detail.StyledDetailContent, {
|
|
100
|
-
"data-element": "detail-content",
|
|
101
|
-
hasIcon: this.props.icon
|
|
102
|
-
}, this.props.children), this.footnote());
|
|
103
|
-
}
|
|
104
|
-
}]);
|
|
105
|
-
|
|
106
|
-
return Detail;
|
|
107
|
-
}(_react.default.Component);
|
|
28
|
+
const Detail = ({
|
|
29
|
+
className,
|
|
30
|
+
icon,
|
|
31
|
+
footnote,
|
|
32
|
+
children,
|
|
33
|
+
...rest
|
|
34
|
+
}) => {
|
|
35
|
+
const marginProps = (0, _utils.filterStyledSystemMarginProps)(rest);
|
|
36
|
+
return /*#__PURE__*/_react.default.createElement(_detail.StyledDetail, _extends({
|
|
37
|
+
className: (0, _classnames.default)("carbon-detail", className),
|
|
38
|
+
hasIcon: icon
|
|
39
|
+
}, (0, _tags.default)("detail", rest), marginProps), icon && /*#__PURE__*/_react.default.createElement(_detail.StyledDetailIcon, {
|
|
40
|
+
type: icon,
|
|
41
|
+
"data-element": "icon"
|
|
42
|
+
}), /*#__PURE__*/_react.default.createElement(_detail.StyledDetailContent, {
|
|
43
|
+
"data-element": "detail-content",
|
|
44
|
+
hasIcon: icon
|
|
45
|
+
}, children), footnote && /*#__PURE__*/_react.default.createElement(_detail.StyledDetailFootnote, {
|
|
46
|
+
"data-element": "footnote",
|
|
47
|
+
hasIcon: icon
|
|
48
|
+
}, footnote));
|
|
49
|
+
};
|
|
108
50
|
|
|
109
51
|
Detail.propTypes = { ...marginPropTypes,
|
|
110
52
|
|
|
@@ -114,7 +56,7 @@ Detail.propTypes = { ...marginPropTypes,
|
|
|
114
56
|
className: _propTypes.default.string,
|
|
115
57
|
|
|
116
58
|
/**
|
|
117
|
-
* <a href="https://
|
|
59
|
+
* <a href="https://carbon.sage.com/?path=/docs/icon--list-of-icons#list-of-icons" target="_blank">List of supported icons</a>
|
|
118
60
|
*
|
|
119
61
|
* The type of icon to use.
|
|
120
62
|
*/
|
|
@@ -22,7 +22,6 @@ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return
|
|
|
22
22
|
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
|
|
23
23
|
|
|
24
24
|
const INNER_BAR_LENGTH = "128px";
|
|
25
|
-
const OUTER_BAR_LENGTH = "256px";
|
|
26
25
|
const StyledLoader = _styledComponents.default.div`
|
|
27
26
|
${_styledSystem.margin}
|
|
28
27
|
text-align: center;
|
|
@@ -33,10 +32,10 @@ const StyledLoader = _styledComponents.default.div`
|
|
|
33
32
|
exports.StyledLoader = StyledLoader;
|
|
34
33
|
const innerBarAnimation = (0, _styledComponents.keyframes)`
|
|
35
34
|
0% {
|
|
36
|
-
left: -${INNER_BAR_LENGTH}
|
|
35
|
+
left: -${INNER_BAR_LENGTH};
|
|
37
36
|
}
|
|
38
37
|
100% {
|
|
39
|
-
left:
|
|
38
|
+
left: 100%;
|
|
40
39
|
}
|
|
41
40
|
`;
|
|
42
41
|
const StyledLoaderBar = _styledComponents.default.div`
|
|
@@ -46,7 +45,7 @@ const StyledLoaderBar = _styledComponents.default.div`
|
|
|
46
45
|
}) => (0, _styledComponents.css)`
|
|
47
46
|
display: inline-block;
|
|
48
47
|
height: ${getHeight(size)};
|
|
49
|
-
width:
|
|
48
|
+
width: 100%;
|
|
50
49
|
background-color: ${theme.colors.loadingBarBackground};
|
|
51
50
|
overflow: hidden;
|
|
52
51
|
position: relative;
|
|
@@ -19,82 +19,36 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
19
19
|
|
|
20
20
|
function _extends() { _extends = Object.assign || 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
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
_createClass(PortraitGravatar, [{
|
|
54
|
-
key: "gravatarSrc",
|
|
55
|
-
value:
|
|
56
|
-
/** Generates the Gravatar URL for the specified email address and dimensions. */
|
|
57
|
-
function gravatarSrc() {
|
|
58
|
-
const {
|
|
59
|
-
gravatarEmail,
|
|
60
|
-
size
|
|
61
|
-
} = this.props;
|
|
62
|
-
const {
|
|
63
|
-
dimensions
|
|
64
|
-
} = _portrait2.PORTRAIT_SIZE_PARAMS[size];
|
|
65
|
-
const base = "https://www.gravatar.com/avatar/";
|
|
66
|
-
const hash = (0, _md.default)(gravatarEmail.toLowerCase());
|
|
67
|
-
const fallbackOption = "404"; // "Return an HTTP 404 File Not Found response"
|
|
68
|
-
|
|
69
|
-
/** @see https://en.gravatar.com/site/implement/images/#default-image */
|
|
70
|
-
|
|
71
|
-
return `${base}${hash}?s=${dimensions}&d=${fallbackOption}`;
|
|
72
|
-
}
|
|
73
|
-
/** Renders the component. */
|
|
74
|
-
|
|
75
|
-
}, {
|
|
76
|
-
key: "render",
|
|
77
|
-
value: function render() {
|
|
78
|
-
const {
|
|
79
|
-
alt,
|
|
80
|
-
size,
|
|
81
|
-
shape,
|
|
82
|
-
errorCallback,
|
|
83
|
-
...otherProps
|
|
84
|
-
} = this.props;
|
|
85
|
-
return /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitGravatar, _extends({
|
|
86
|
-
src: this.gravatarSrc(),
|
|
87
|
-
alt: alt,
|
|
88
|
-
size: size,
|
|
89
|
-
shape: shape,
|
|
90
|
-
onError: errorCallback,
|
|
91
|
-
"data-element": "user-image"
|
|
92
|
-
}, otherProps));
|
|
93
|
-
}
|
|
94
|
-
}]);
|
|
95
|
-
|
|
96
|
-
return PortraitGravatar;
|
|
97
|
-
}(_react.default.Component);
|
|
22
|
+
const PortraitGravatar = ({
|
|
23
|
+
gravatarEmail,
|
|
24
|
+
size,
|
|
25
|
+
alt,
|
|
26
|
+
shape,
|
|
27
|
+
errorCallback,
|
|
28
|
+
...rest
|
|
29
|
+
}) => {
|
|
30
|
+
const gravatarSrc = () => {
|
|
31
|
+
const {
|
|
32
|
+
dimensions
|
|
33
|
+
} = _portrait2.PORTRAIT_SIZE_PARAMS[size];
|
|
34
|
+
const base = "https://www.gravatar.com/avatar/";
|
|
35
|
+
const hash = (0, _md.default)(gravatarEmail.toLowerCase());
|
|
36
|
+
const fallbackOption = "404"; // "Return an HTTP 404 File Not Found response"
|
|
37
|
+
|
|
38
|
+
/** @see https://en.gravatar.com/site/implement/images/#default-image */
|
|
39
|
+
|
|
40
|
+
return `${base}${hash}?s=${dimensions}&d=${fallbackOption}`;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
return /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitGravatar, _extends({
|
|
44
|
+
src: gravatarSrc(),
|
|
45
|
+
alt: alt,
|
|
46
|
+
size: size,
|
|
47
|
+
shape: shape,
|
|
48
|
+
onError: errorCallback,
|
|
49
|
+
"data-element": "user-image"
|
|
50
|
+
}, rest));
|
|
51
|
+
};
|
|
98
52
|
|
|
99
53
|
PortraitGravatar.propTypes = {
|
|
100
54
|
/** The theme to use. */
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
@@ -21,145 +21,73 @@ var _portrait2 = require("./portrait.config");
|
|
|
21
21
|
|
|
22
22
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
23
|
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
27
|
-
|
|
28
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
29
|
-
|
|
30
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
31
|
-
|
|
32
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
33
|
-
|
|
34
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
35
|
-
|
|
36
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
37
|
-
|
|
38
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
39
|
-
|
|
40
|
-
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
41
|
-
|
|
42
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
43
|
-
|
|
44
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
45
|
-
|
|
46
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
24
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
47
25
|
|
|
48
|
-
|
|
49
|
-
_inherits(PortraitInitials, _React$Component);
|
|
26
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
|
|
50
27
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
function PortraitInitials(...args) {
|
|
54
|
-
var _this;
|
|
55
|
-
|
|
56
|
-
_classCallCheck(this, PortraitInitials);
|
|
57
|
-
|
|
58
|
-
_this = _super.call(this, ...args);
|
|
59
|
-
|
|
60
|
-
_defineProperty(_assertThisInitialized(_this), "cachedImageDataUrl", null);
|
|
61
|
-
|
|
62
|
-
return _this;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
_createClass(PortraitInitials, [{
|
|
66
|
-
key: "UNSAFE_componentWillReceiveProps",
|
|
67
|
-
value:
|
|
68
|
-
/** Invoked before a mounted component receives new props. */
|
|
69
|
-
function UNSAFE_componentWillReceiveProps(nextProps) {
|
|
70
|
-
const shouldClearCache = this.props.theme !== nextProps.theme || this.props.initials !== nextProps.initials || this.props.size !== nextProps.size || this.props.darkBackground !== nextProps.darkBackground;
|
|
28
|
+
function _extends() { _extends = Object.assign || 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); }
|
|
71
29
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
} = this.props;
|
|
90
|
-
const {
|
|
91
|
-
textColor,
|
|
92
|
-
bgColor
|
|
93
|
-
} = (0, _portrait.getColorsForInitials)(theme, darkBackground);
|
|
94
|
-
|
|
95
|
-
let canvas = _browser.default.getDocument().createElement("canvas");
|
|
96
|
-
|
|
97
|
-
let context = canvas.getContext("2d");
|
|
98
|
-
let {
|
|
99
|
-
dimensions
|
|
100
|
-
} = _portrait2.PORTRAIT_SIZE_PARAMS[size];
|
|
101
|
-
dimensions -= 2; // Set canvas with & height
|
|
102
|
-
|
|
103
|
-
canvas.width = dimensions;
|
|
104
|
-
canvas.height = dimensions; // Select a font family to support different language characters
|
|
105
|
-
// like Arial
|
|
106
|
-
|
|
107
|
-
context.font = `${Math.round(canvas.width / 2.4)}px Lato, Arial`;
|
|
108
|
-
context.textAlign = "center"; // Setup background and front color
|
|
109
|
-
|
|
110
|
-
context = this.applyBackground(context, dimensions, bgColor);
|
|
111
|
-
context = this.applyText(context, dimensions, textColor); // Set image representation in default format (png)
|
|
112
|
-
|
|
113
|
-
const dataURI = canvas.toDataURL(); // Dispose canvas element
|
|
114
|
-
|
|
115
|
-
canvas = null;
|
|
116
|
-
this.cachedImageDataUrl = dataURI;
|
|
117
|
-
return this.cachedImageDataUrl;
|
|
118
|
-
}
|
|
119
|
-
/** Applies the background colour to the canvas. */
|
|
120
|
-
|
|
121
|
-
}, {
|
|
122
|
-
key: "applyBackground",
|
|
123
|
-
value: function applyBackground(canvasContext, dimensions, bgColor) {
|
|
124
|
-
canvasContext.fillStyle = bgColor;
|
|
125
|
-
canvasContext.fillRect(0, 0, dimensions, dimensions);
|
|
126
|
-
return canvasContext;
|
|
30
|
+
const PortraitInitials = ({
|
|
31
|
+
theme,
|
|
32
|
+
initials,
|
|
33
|
+
size,
|
|
34
|
+
shape,
|
|
35
|
+
darkBackground,
|
|
36
|
+
alt,
|
|
37
|
+
...rest
|
|
38
|
+
}) => {
|
|
39
|
+
const [cachedImageDataUrl, setCachedImageDataUrl] = (0, _react.useState)();
|
|
40
|
+
(0, _react.useEffect)(() => {
|
|
41
|
+
setCachedImageDataUrl(null);
|
|
42
|
+
}, [theme, initials, size, darkBackground]);
|
|
43
|
+
|
|
44
|
+
const generateDataUrl = () => {
|
|
45
|
+
if (cachedImageDataUrl) {
|
|
46
|
+
return cachedImageDataUrl;
|
|
127
47
|
}
|
|
128
|
-
/** Applies the initials text to the canvas. */
|
|
129
|
-
|
|
130
|
-
}, {
|
|
131
|
-
key: "applyText",
|
|
132
|
-
value: function applyText(canvasContext, dimensions, textColor) {
|
|
133
|
-
const letters = this.props.initials.slice(0, 3);
|
|
134
|
-
canvasContext.fillStyle = textColor;
|
|
135
|
-
canvasContext.fillText(letters.toUpperCase(), dimensions / 2, dimensions / 1.5);
|
|
136
|
-
return canvasContext;
|
|
137
|
-
}
|
|
138
|
-
/** Renders the component. */
|
|
139
|
-
|
|
140
|
-
}, {
|
|
141
|
-
key: "render",
|
|
142
|
-
value: function render() {
|
|
143
|
-
const {
|
|
144
|
-
size,
|
|
145
|
-
shape,
|
|
146
|
-
theme,
|
|
147
|
-
...otherProps
|
|
148
|
-
} = this.props;
|
|
149
|
-
return /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitInitials, _extends({
|
|
150
|
-
"data-element": "initials",
|
|
151
|
-
size: size,
|
|
152
|
-
shape: shape,
|
|
153
|
-
theme: theme
|
|
154
|
-
}, otherProps), /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitInitialsImg, {
|
|
155
|
-
src: this.generateDataUrl(),
|
|
156
|
-
alt: this.props.alt
|
|
157
|
-
}));
|
|
158
|
-
}
|
|
159
|
-
}]);
|
|
160
48
|
|
|
161
|
-
|
|
162
|
-
|
|
49
|
+
const {
|
|
50
|
+
textColor,
|
|
51
|
+
bgColor
|
|
52
|
+
} = (0, _portrait.getColorsForInitials)(theme, darkBackground);
|
|
53
|
+
|
|
54
|
+
let canvas = _browser.default.getDocument().createElement("canvas");
|
|
55
|
+
|
|
56
|
+
const context = canvas.getContext("2d");
|
|
57
|
+
let {
|
|
58
|
+
dimensions
|
|
59
|
+
} = _portrait2.PORTRAIT_SIZE_PARAMS[size];
|
|
60
|
+
dimensions -= 2; // Set canvas with & height
|
|
61
|
+
|
|
62
|
+
canvas.width = dimensions;
|
|
63
|
+
canvas.height = dimensions; // Select a font family to support different language characters
|
|
64
|
+
// like Arial
|
|
65
|
+
|
|
66
|
+
context.font = `${Math.round(canvas.width / 2.4)}px Lato, Arial`;
|
|
67
|
+
context.textAlign = "center"; // Setup background and front color
|
|
68
|
+
|
|
69
|
+
context.fillStyle = bgColor;
|
|
70
|
+
context.fillRect(0, 0, dimensions, dimensions);
|
|
71
|
+
context.fillStyle = textColor;
|
|
72
|
+
context.fillText(initials.slice(0, 3).toUpperCase(), dimensions / 2, dimensions / 1.5); // Set image representation in default format (png)
|
|
73
|
+
|
|
74
|
+
const dataURI = canvas.toDataURL(); // Dispose canvas element
|
|
75
|
+
|
|
76
|
+
canvas = null;
|
|
77
|
+
setCachedImageDataUrl(dataURI);
|
|
78
|
+
return dataURI;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitInitials, _extends({
|
|
82
|
+
"data-element": "initials",
|
|
83
|
+
size: size,
|
|
84
|
+
shape: shape,
|
|
85
|
+
theme: theme
|
|
86
|
+
}, rest), /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitInitialsImg, {
|
|
87
|
+
src: generateDataUrl(),
|
|
88
|
+
alt: alt
|
|
89
|
+
}));
|
|
90
|
+
};
|
|
163
91
|
|
|
164
92
|
PortraitInitials.propTypes = {
|
|
165
93
|
/** The theme to use. */
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
9
|
|
|
10
10
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
11
|
|
|
@@ -25,159 +25,101 @@ var _utils = require("../../style/utils");
|
|
|
25
25
|
|
|
26
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
27
|
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
31
|
-
|
|
32
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
33
|
-
|
|
34
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
35
|
-
|
|
36
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
37
|
-
|
|
38
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
39
|
-
|
|
40
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
41
|
-
|
|
42
|
-
function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
28
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
43
29
|
|
|
44
|
-
function
|
|
30
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
|
|
45
31
|
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
49
|
-
|
|
50
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
32
|
+
function _extends() { _extends = Object.assign || 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); }
|
|
51
33
|
|
|
52
34
|
const marginPropTypes = (0, _utils.filterStyledSystemMarginProps)(_propTypes2.default.space);
|
|
53
35
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
36
|
+
const Portrait = ({
|
|
37
|
+
alt,
|
|
38
|
+
darkBackground,
|
|
39
|
+
gravatar,
|
|
40
|
+
iconType,
|
|
41
|
+
initials,
|
|
42
|
+
shape,
|
|
43
|
+
size,
|
|
44
|
+
src,
|
|
45
|
+
onClick,
|
|
46
|
+
tooltipMessage,
|
|
47
|
+
tooltipId,
|
|
48
|
+
tooltipIsVisible,
|
|
49
|
+
tooltipPosition,
|
|
50
|
+
tooltipType,
|
|
51
|
+
tooltipSize,
|
|
52
|
+
tooltipBgColor,
|
|
53
|
+
tooltipFontColor,
|
|
54
|
+
...rest
|
|
55
|
+
}) => {
|
|
56
|
+
const [externalError, setExternalError] = (0, _react.useState)(false);
|
|
57
|
+
(0, _react.useEffect)(() => {
|
|
58
|
+
setExternalError(false);
|
|
59
|
+
}, [gravatar, src]);
|
|
60
|
+
const tagProps = (0, _tags.default)("portrait", rest);
|
|
61
|
+
|
|
62
|
+
const renderComponent = () => {
|
|
63
|
+
let portrait = /*#__PURE__*/_react.default.createElement(_portrait.StyledIcon, {
|
|
64
|
+
type: iconType,
|
|
65
|
+
size: size,
|
|
66
|
+
shape: shape,
|
|
67
|
+
darkBackground: darkBackground
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (relevantPropsChanged) {
|
|
79
|
-
this.setState({
|
|
80
|
-
externalError: false
|
|
81
|
-
}); // eslint-disable-line react/no-did-update-set-state
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}, {
|
|
85
|
-
key: "getMarginProps",
|
|
86
|
-
value: function getMarginProps() {
|
|
87
|
-
return (0, _utils.filterStyledSystemMarginProps)(this.props);
|
|
88
|
-
}
|
|
89
|
-
}, {
|
|
90
|
-
key: "externalImageLoadFailed",
|
|
91
|
-
value: function externalImageLoadFailed() {
|
|
92
|
-
this.setState({
|
|
93
|
-
externalError: true
|
|
70
|
+
if (initials) {
|
|
71
|
+
portrait = /*#__PURE__*/_react.default.createElement(_portraitInitials.default, {
|
|
72
|
+
size: size,
|
|
73
|
+
shape: shape,
|
|
74
|
+
initials: initials,
|
|
75
|
+
darkBackground: darkBackground,
|
|
76
|
+
alt: alt
|
|
94
77
|
});
|
|
95
78
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
alt,
|
|
101
|
-
darkBackground,
|
|
102
|
-
gravatar,
|
|
103
|
-
iconType,
|
|
104
|
-
initials,
|
|
105
|
-
shape,
|
|
106
|
-
size,
|
|
107
|
-
src,
|
|
108
|
-
onClick,
|
|
109
|
-
tooltipMessage,
|
|
110
|
-
tooltipId,
|
|
111
|
-
tooltipIsVisible,
|
|
112
|
-
tooltipPosition,
|
|
113
|
-
tooltipType,
|
|
114
|
-
tooltipSize,
|
|
115
|
-
tooltipBgColor,
|
|
116
|
-
tooltipFontColor
|
|
117
|
-
} = this.props;
|
|
118
|
-
const tagProps = (0, _tags.default)("portrait", this.props);
|
|
119
|
-
|
|
120
|
-
let portrait = /*#__PURE__*/_react.default.createElement(_portrait.StyledIcon, {
|
|
121
|
-
type: iconType,
|
|
79
|
+
|
|
80
|
+
if (src && !externalError) {
|
|
81
|
+
portrait = /*#__PURE__*/_react.default.createElement(_portrait.StyledCustomImg, {
|
|
82
|
+
src: src,
|
|
83
|
+
alt: alt,
|
|
122
84
|
size: size,
|
|
123
85
|
shape: shape,
|
|
124
|
-
|
|
86
|
+
"data-element": "user-image",
|
|
87
|
+
onError: () => setExternalError(true)
|
|
125
88
|
});
|
|
89
|
+
}
|
|
126
90
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (gravatar && !this.state.externalError) {
|
|
149
|
-
portrait = /*#__PURE__*/_react.default.createElement(_portraitGravatar.default, {
|
|
150
|
-
gravatarEmail: gravatar,
|
|
151
|
-
shape: shape,
|
|
152
|
-
size: size,
|
|
153
|
-
alt: alt,
|
|
154
|
-
errorCallback: () => this.externalImageLoadFailed()
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (tooltipMessage) {
|
|
159
|
-
return /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
160
|
-
message: tooltipMessage,
|
|
161
|
-
id: tooltipId,
|
|
162
|
-
position: tooltipPosition,
|
|
163
|
-
type: tooltipType,
|
|
164
|
-
size: tooltipSize,
|
|
165
|
-
isVisible: tooltipIsVisible,
|
|
166
|
-
bgColor: tooltipBgColor,
|
|
167
|
-
fontColor: tooltipFontColor
|
|
168
|
-
}, /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitContainer, _extends({}, this.getMarginProps(), {
|
|
169
|
-
onClick: onClick
|
|
170
|
-
}, tagProps), portrait));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitContainer, _extends({}, this.getMarginProps(), {
|
|
91
|
+
if (gravatar && !externalError) {
|
|
92
|
+
portrait = /*#__PURE__*/_react.default.createElement(_portraitGravatar.default, {
|
|
93
|
+
gravatarEmail: gravatar,
|
|
94
|
+
shape: shape,
|
|
95
|
+
size: size,
|
|
96
|
+
alt: alt,
|
|
97
|
+
errorCallback: () => setExternalError(true)
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (tooltipMessage) {
|
|
102
|
+
return /*#__PURE__*/_react.default.createElement(_tooltip.default, {
|
|
103
|
+
message: tooltipMessage,
|
|
104
|
+
id: tooltipId,
|
|
105
|
+
position: tooltipPosition,
|
|
106
|
+
type: tooltipType,
|
|
107
|
+
size: tooltipSize,
|
|
108
|
+
isVisible: tooltipIsVisible,
|
|
109
|
+
bgColor: tooltipBgColor,
|
|
110
|
+
fontColor: tooltipFontColor
|
|
111
|
+
}, /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitContainer, _extends({}, (0, _utils.filterStyledSystemMarginProps)(rest), {
|
|
174
112
|
onClick: onClick
|
|
175
|
-
}, tagProps), portrait);
|
|
113
|
+
}, tagProps), portrait));
|
|
176
114
|
}
|
|
177
|
-
}]);
|
|
178
115
|
|
|
179
|
-
|
|
180
|
-
|
|
116
|
+
return /*#__PURE__*/_react.default.createElement(_portrait.StyledPortraitContainer, _extends({}, (0, _utils.filterStyledSystemMarginProps)(rest), {
|
|
117
|
+
onClick: onClick
|
|
118
|
+
}, tagProps), portrait);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
return renderComponent();
|
|
122
|
+
};
|
|
181
123
|
|
|
182
124
|
Portrait.propTypes = { ...marginPropTypes,
|
|
183
125
|
|
|
@@ -175,6 +175,7 @@ const Search = ({
|
|
|
175
175
|
onKeyDown: onKeyDown,
|
|
176
176
|
inputRef: assignInput
|
|
177
177
|
}), searchButton && /*#__PURE__*/_react.default.createElement(_search.StyledSearchButton, null, Boolean(isFocused || (!isControlled ? searchValue.length : value.length)) && /*#__PURE__*/_react.default.createElement(_button.default, _extends({
|
|
178
|
+
tabIndex: iconTabIndex,
|
|
178
179
|
size: "medium",
|
|
179
180
|
px: "16px"
|
|
180
181
|
}, buttonProps), /*#__PURE__*/_react.default.createElement(_search.StyledButtonIcon, null, /*#__PURE__*/_react.default.createElement(_icon.default, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carbon-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "99.0.1",
|
|
4
4
|
"description": "A library of reusable React components for easily building user interfaces.",
|
|
5
5
|
"engineStrict": true,
|
|
6
6
|
"engines": {
|
|
@@ -97,6 +97,7 @@
|
|
|
97
97
|
"cypress": "^8.3.1",
|
|
98
98
|
"cypress-axe": "^0.13.0",
|
|
99
99
|
"cypress-cucumber-preprocessor": "^4.2.0",
|
|
100
|
+
"cypress-each": "^1.5.0",
|
|
100
101
|
"cypress-plugin-tab": "^1.0.5",
|
|
101
102
|
"cypress-real-events": "^1.5.1",
|
|
102
103
|
"cypress-storybook": "^0.5.1",
|
|
@@ -119,6 +120,7 @@
|
|
|
119
120
|
"events": "~1.1.1",
|
|
120
121
|
"husky": "^4.3.6",
|
|
121
122
|
"jest": "^26.6.3",
|
|
123
|
+
"jest-canvas-mock": "^2.3.1",
|
|
122
124
|
"jest-styled-components": "^6.3.1",
|
|
123
125
|
"lint-staged": "^10.5.3",
|
|
124
126
|
"mockdate": "^2.0.2",
|