@atlaskit/teams-avatar 2.3.9 → 2.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/teams-avatar
2
2
 
3
+ ## 2.3.11
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 2.3.10
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 2.3.9
4
16
 
5
17
  ### Patch Changes
@@ -13,7 +13,14 @@ var _avatar = _interopRequireDefault(require("@atlaskit/avatar"));
13
13
  var _colors = require("@atlaskit/theme/colors");
14
14
  var _teamsAvatarImage = require("./teams-avatar-image");
15
15
  var _utils = require("./utils");
16
- var _excluded = ["testId", "src", "size"];
16
+ var _excluded = ["testId", "src", "size", "teamId"];
17
+ /*
18
+ * The component accepts src and teamId as input params. Order of preference:
19
+ * If src is provided, use that directly.
20
+ * Else if teamId is provided, use that to generate the static image URL.
21
+ * Else fallback.
22
+ */
23
+
17
24
  var ICON_BACKGROUND = exports.ICON_BACKGROUND = "var(--ds-icon-inverse, ".concat(_colors.N0, ")");
18
25
  var ICON_COLOR = exports.ICON_COLOR = "var(--ds-icon-subtle, ".concat(_colors.N90, ")");
19
26
  function TeamAvatar(_ref) {
@@ -21,7 +28,11 @@ function TeamAvatar(_ref) {
21
28
  src = _ref.src,
22
29
  _ref$size = _ref.size,
23
30
  size = _ref$size === void 0 ? 'medium' : _ref$size,
31
+ _ref$teamId = _ref.teamId,
32
+ teamId = _ref$teamId === void 0 ? '' : _ref$teamId,
24
33
  props = (0, _objectWithoutProperties2.default)(_ref, _excluded);
34
+ // Strip ARI in case the teamId was given in that format
35
+ teamId = teamId.replace('ari:cloud:identity::team/', '');
25
36
  return /*#__PURE__*/_react.default.createElement(_avatar.default, (0, _extends2.default)({
26
37
  appearance: (0, _utils.isSquareIcon)(src) ? 'square' : 'circle'
27
38
  }, props, {
@@ -31,6 +42,7 @@ function TeamAvatar(_ref) {
31
42
  }), /*#__PURE__*/_react.default.createElement(_teamsAvatarImage.TeamAvatarImage, {
32
43
  src: src,
33
44
  size: size,
34
- testId: testId
45
+ testId: testId,
46
+ teamId: teamId
35
47
  }));
36
48
  }
@@ -13,6 +13,7 @@ var React = _react;
13
13
  var _runtime = require("@compiled/react/runtime");
14
14
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
15
  var _fallback = require("./fallback");
16
+ var _utils = require("./utils");
16
17
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
17
18
  var boxShadowCssVar = '--avatar-box-shadow';
18
19
  var bgColorCssVar = '--avatar-bg-color';
@@ -69,17 +70,19 @@ var TeamAvatarImage = exports.TeamAvatarImage = function TeamAvatarImage(_ref) {
69
70
  alt = _ref$alt === void 0 ? '' : _ref$alt,
70
71
  src = _ref.src,
71
72
  size = _ref.size,
72
- testId = _ref.testId;
73
+ testId = _ref.testId,
74
+ teamId = _ref.teamId;
73
75
  var _useState = (0, _react.useState)(false),
74
76
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
75
77
  hasImageErrored = _useState2[0],
76
78
  setHasImageErrored = _useState2[1];
79
+ var avatarSrc = (0, _utils.getTeamAvatarSrc)(src, teamId);
77
80
 
78
81
  // If src changes, reset state
79
82
  (0, _react.useEffect)(function () {
80
83
  setHasImageErrored(false);
81
- }, [src]);
82
- if (!src || hasImageErrored) {
84
+ }, [avatarSrc]);
85
+ if (!avatarSrc || hasImageErrored) {
83
86
  return /*#__PURE__*/React.createElement(_fallback.FallbackAvatar, {
84
87
  "aria-label": alt,
85
88
  width: SIZES[size],
@@ -92,7 +95,7 @@ var TeamAvatarImage = exports.TeamAvatarImage = function TeamAvatarImage(_ref) {
92
95
  "aria-label": alt,
93
96
  className: (0, _runtime.ax)([unboundStyles.root, containerStyles.root, borderRadiusMap[size], widthHeightMap[size]])
94
97
  }, /*#__PURE__*/React.createElement("img", {
95
- src: src,
98
+ src: avatarSrc,
96
99
  alt: alt,
97
100
  "data-testId": testId && "".concat(testId, "--image"),
98
101
  onError: function onError() {
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getTeamAvatarSrc = getTeamAvatarSrc;
7
+ /**
8
+ * If a src value is given, we'll use that directly.
9
+ * Otherwise we'll generate a static URL from the teamId.
10
+ * If neither are provided, return undefined so that the fallback will be used.
11
+ */
12
+ function getTeamAvatarSrc(src, teamId) {
13
+ if (src) {
14
+ return src;
15
+ } else if (teamId) {
16
+ return "/gateway/api/v4/teams/".concat(teamId, "/avatar");
17
+ }
18
+ return undefined;
19
+ }
@@ -4,14 +4,25 @@ import Avatar from '@atlaskit/avatar';
4
4
  import { N0, N90 } from '@atlaskit/theme/colors';
5
5
  import { TeamAvatarImage } from './teams-avatar-image';
6
6
  import { isSquareIcon } from './utils';
7
+
8
+ /*
9
+ * The component accepts src and teamId as input params. Order of preference:
10
+ * If src is provided, use that directly.
11
+ * Else if teamId is provided, use that to generate the static image URL.
12
+ * Else fallback.
13
+ */
14
+
7
15
  export const ICON_BACKGROUND = `var(--ds-icon-inverse, ${N0})`;
8
16
  export const ICON_COLOR = `var(--ds-icon-subtle, ${N90})`;
9
17
  export default function TeamAvatar({
10
18
  testId,
11
19
  src,
12
20
  size = 'medium',
21
+ teamId = '',
13
22
  ...props
14
23
  }) {
24
+ // Strip ARI in case the teamId was given in that format
25
+ teamId = teamId.replace('ari:cloud:identity::team/', '');
15
26
  return /*#__PURE__*/React.createElement(Avatar, _extends({
16
27
  appearance: isSquareIcon(src) ? 'square' : 'circle'
17
28
  }, props, {
@@ -21,6 +32,7 @@ export default function TeamAvatar({
21
32
  }), /*#__PURE__*/React.createElement(TeamAvatarImage, {
22
33
  src: src,
23
34
  size: size,
24
- testId: testId
35
+ testId: testId,
36
+ teamId: teamId
25
37
  }));
26
38
  }
@@ -4,6 +4,7 @@ import * as React from 'react';
4
4
  import { ax, ix } from "@compiled/react/runtime";
5
5
  import { useEffect, useState } from 'react';
6
6
  import { FallbackAvatar } from './fallback';
7
+ import { getTeamAvatarSrc } from './utils';
7
8
  const boxShadowCssVar = '--avatar-box-shadow';
8
9
  const bgColorCssVar = '--avatar-bg-color';
9
10
 
@@ -58,15 +59,17 @@ export const TeamAvatarImage = ({
58
59
  alt = '',
59
60
  src,
60
61
  size,
61
- testId
62
+ testId,
63
+ teamId
62
64
  }) => {
63
65
  const [hasImageErrored, setHasImageErrored] = useState(false);
66
+ const avatarSrc = getTeamAvatarSrc(src, teamId);
64
67
 
65
68
  // If src changes, reset state
66
69
  useEffect(() => {
67
70
  setHasImageErrored(false);
68
- }, [src]);
69
- if (!src || hasImageErrored) {
71
+ }, [avatarSrc]);
72
+ if (!avatarSrc || hasImageErrored) {
70
73
  return /*#__PURE__*/React.createElement(FallbackAvatar, {
71
74
  "aria-label": alt,
72
75
  width: SIZES[size],
@@ -79,7 +82,7 @@ export const TeamAvatarImage = ({
79
82
  "aria-label": alt,
80
83
  className: ax([unboundStyles.root, containerStyles.root, borderRadiusMap[size], widthHeightMap[size]])
81
84
  }, /*#__PURE__*/React.createElement("img", {
82
- src: src,
85
+ src: avatarSrc,
83
86
  alt: alt,
84
87
  "data-testId": testId && `${testId}--image`,
85
88
  onError: () => setHasImageErrored(true),
@@ -0,0 +1,13 @@
1
+ /**
2
+ * If a src value is given, we'll use that directly.
3
+ * Otherwise we'll generate a static URL from the teamId.
4
+ * If neither are provided, return undefined so that the fallback will be used.
5
+ */
6
+ export function getTeamAvatarSrc(src, teamId) {
7
+ if (src) {
8
+ return src;
9
+ } else if (teamId) {
10
+ return `/gateway/api/v4/teams/${teamId}/avatar`;
11
+ }
12
+ return undefined;
13
+ }
@@ -1,11 +1,19 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["testId", "src", "size"];
3
+ var _excluded = ["testId", "src", "size", "teamId"];
4
4
  import React from 'react';
5
5
  import Avatar from '@atlaskit/avatar';
6
6
  import { N0, N90 } from '@atlaskit/theme/colors';
7
7
  import { TeamAvatarImage } from './teams-avatar-image';
8
8
  import { isSquareIcon } from './utils';
9
+
10
+ /*
11
+ * The component accepts src and teamId as input params. Order of preference:
12
+ * If src is provided, use that directly.
13
+ * Else if teamId is provided, use that to generate the static image URL.
14
+ * Else fallback.
15
+ */
16
+
9
17
  export var ICON_BACKGROUND = "var(--ds-icon-inverse, ".concat(N0, ")");
10
18
  export var ICON_COLOR = "var(--ds-icon-subtle, ".concat(N90, ")");
11
19
  export default function TeamAvatar(_ref) {
@@ -13,7 +21,11 @@ export default function TeamAvatar(_ref) {
13
21
  src = _ref.src,
14
22
  _ref$size = _ref.size,
15
23
  size = _ref$size === void 0 ? 'medium' : _ref$size,
24
+ _ref$teamId = _ref.teamId,
25
+ teamId = _ref$teamId === void 0 ? '' : _ref$teamId,
16
26
  props = _objectWithoutProperties(_ref, _excluded);
27
+ // Strip ARI in case the teamId was given in that format
28
+ teamId = teamId.replace('ari:cloud:identity::team/', '');
17
29
  return /*#__PURE__*/React.createElement(Avatar, _extends({
18
30
  appearance: isSquareIcon(src) ? 'square' : 'circle'
19
31
  }, props, {
@@ -23,6 +35,7 @@ export default function TeamAvatar(_ref) {
23
35
  }), /*#__PURE__*/React.createElement(TeamAvatarImage, {
24
36
  src: src,
25
37
  size: size,
26
- testId: testId
38
+ testId: testId,
39
+ teamId: teamId
27
40
  }));
28
41
  }
@@ -5,6 +5,7 @@ import * as React from 'react';
5
5
  import { ax, ix } from "@compiled/react/runtime";
6
6
  import { useEffect, useState } from 'react';
7
7
  import { FallbackAvatar } from './fallback';
8
+ import { getTeamAvatarSrc } from './utils';
8
9
  var boxShadowCssVar = '--avatar-box-shadow';
9
10
  var bgColorCssVar = '--avatar-bg-color';
10
11
 
@@ -60,17 +61,19 @@ export var TeamAvatarImage = function TeamAvatarImage(_ref) {
60
61
  alt = _ref$alt === void 0 ? '' : _ref$alt,
61
62
  src = _ref.src,
62
63
  size = _ref.size,
63
- testId = _ref.testId;
64
+ testId = _ref.testId,
65
+ teamId = _ref.teamId;
64
66
  var _useState = useState(false),
65
67
  _useState2 = _slicedToArray(_useState, 2),
66
68
  hasImageErrored = _useState2[0],
67
69
  setHasImageErrored = _useState2[1];
70
+ var avatarSrc = getTeamAvatarSrc(src, teamId);
68
71
 
69
72
  // If src changes, reset state
70
73
  useEffect(function () {
71
74
  setHasImageErrored(false);
72
- }, [src]);
73
- if (!src || hasImageErrored) {
75
+ }, [avatarSrc]);
76
+ if (!avatarSrc || hasImageErrored) {
74
77
  return /*#__PURE__*/React.createElement(FallbackAvatar, {
75
78
  "aria-label": alt,
76
79
  width: SIZES[size],
@@ -83,7 +86,7 @@ export var TeamAvatarImage = function TeamAvatarImage(_ref) {
83
86
  "aria-label": alt,
84
87
  className: ax([unboundStyles.root, containerStyles.root, borderRadiusMap[size], widthHeightMap[size]])
85
88
  }, /*#__PURE__*/React.createElement("img", {
86
- src: src,
89
+ src: avatarSrc,
87
90
  alt: alt,
88
91
  "data-testId": testId && "".concat(testId, "--image"),
89
92
  onError: function onError() {
@@ -0,0 +1,13 @@
1
+ /**
2
+ * If a src value is given, we'll use that directly.
3
+ * Otherwise we'll generate a static URL from the teamId.
4
+ * If neither are provided, return undefined so that the fallback will be used.
5
+ */
6
+ export function getTeamAvatarSrc(src, teamId) {
7
+ if (src) {
8
+ return src;
9
+ } else if (teamId) {
10
+ return "/gateway/api/v4/teams/".concat(teamId, "/avatar");
11
+ }
12
+ return undefined;
13
+ }
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
2
  import { type AvatarPropTypes } from '@atlaskit/avatar';
3
- export type TeamAvatarProps = Omit<AvatarPropTypes, 'appearance'>;
3
+ export type TeamAvatarProps = Omit<AvatarPropTypes, 'appearance'> & {
4
+ teamId?: string;
5
+ };
4
6
  export declare const ICON_BACKGROUND: "var(--ds-icon-inverse)";
5
7
  export declare const ICON_COLOR: "var(--ds-icon-subtle)";
6
- export default function TeamAvatar({ testId, src, size, ...props }: TeamAvatarProps): React.JSX.Element;
8
+ export default function TeamAvatar({ testId, src, size, teamId, ...props }: TeamAvatarProps): React.JSX.Element;
@@ -5,6 +5,7 @@ type AvatarImageProps = {
5
5
  alt?: string;
6
6
  src?: string;
7
7
  testId?: string;
8
+ teamId?: string;
8
9
  };
9
10
  /**
10
11
  * __Avatar image__
@@ -2,18 +2,18 @@
2
2
  * @jsxRuntime classic
3
3
  * @jsx jsx
4
4
  */
5
- /// <reference types="react" />
6
5
  import { type SizeType } from '@atlaskit/avatar';
7
6
  type AvatarImageProps = {
8
7
  size: SizeType;
9
8
  alt?: string;
10
9
  src?: string;
11
10
  testId?: string;
11
+ teamId?: string;
12
12
  };
13
13
  /**
14
14
  * __Avatar image__
15
15
  *
16
16
  * An avatar image is an internal component used to control the rendering phases of an image.
17
17
  */
18
- export declare const TeamAvatarImage: ({ alt, src, size, testId }: AvatarImageProps) => JSX.Element;
18
+ export declare const TeamAvatarImage: ({ alt, src, size, testId, teamId }: AvatarImageProps) => JSX.Element;
19
19
  export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * If a src value is given, we'll use that directly.
3
+ * Otherwise we'll generate a static URL from the teamId.
4
+ * If neither are provided, return undefined so that the fallback will be used.
5
+ */
6
+ export declare function getTeamAvatarSrc(src?: string, teamId?: string): string | undefined;
@@ -1,6 +1,8 @@
1
1
  import React from 'react';
2
2
  import { type AvatarPropTypes } from '@atlaskit/avatar';
3
- export type TeamAvatarProps = Omit<AvatarPropTypes, 'appearance'>;
3
+ export type TeamAvatarProps = Omit<AvatarPropTypes, 'appearance'> & {
4
+ teamId?: string;
5
+ };
4
6
  export declare const ICON_BACKGROUND: "var(--ds-icon-inverse)";
5
7
  export declare const ICON_COLOR: "var(--ds-icon-subtle)";
6
- export default function TeamAvatar({ testId, src, size, ...props }: TeamAvatarProps): React.JSX.Element;
8
+ export default function TeamAvatar({ testId, src, size, teamId, ...props }: TeamAvatarProps): React.JSX.Element;
@@ -5,6 +5,7 @@ type AvatarImageProps = {
5
5
  alt?: string;
6
6
  src?: string;
7
7
  testId?: string;
8
+ teamId?: string;
8
9
  };
9
10
  /**
10
11
  * __Avatar image__
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  /**
3
2
  * @jsxRuntime classic
4
3
  * @jsx jsx
@@ -9,11 +8,12 @@ type AvatarImageProps = {
9
8
  alt?: string;
10
9
  src?: string;
11
10
  testId?: string;
11
+ teamId?: string;
12
12
  };
13
13
  /**
14
14
  * __Avatar image__
15
15
  *
16
16
  * An avatar image is an internal component used to control the rendering phases of an image.
17
17
  */
18
- export declare const TeamAvatarImage: ({ alt, src, size, testId }: AvatarImageProps) => JSX.Element;
18
+ export declare const TeamAvatarImage: ({ alt, src, size, testId, teamId }: AvatarImageProps) => JSX.Element;
19
19
  export {};
@@ -0,0 +1,6 @@
1
+ /**
2
+ * If a src value is given, we'll use that directly.
3
+ * Otherwise we'll generate a static URL from the teamId.
4
+ * If neither are provided, return undefined so that the fallback will be used.
5
+ */
6
+ export declare function getTeamAvatarSrc(src?: string, teamId?: string): string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/teams-avatar",
3
- "version": "2.3.9",
3
+ "version": "2.3.11",
4
4
  "description": "A team avatar is a visual representation of a team.",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -40,11 +40,11 @@
40
40
  "dependencies": {
41
41
  "@atlaskit/avatar": "^25.1.0",
42
42
  "@atlaskit/css": "^0.12.0",
43
- "@atlaskit/icon": "^27.8.0",
43
+ "@atlaskit/icon": "^28.0.0",
44
44
  "@atlaskit/platform-feature-flags": "^1.1.0",
45
45
  "@atlaskit/primitives": "^14.11.0",
46
46
  "@atlaskit/theme": "^19.0.0",
47
- "@atlaskit/tokens": "^5.6.0",
47
+ "@atlaskit/tokens": "^6.0.0",
48
48
  "@babel/runtime": "^7.0.0",
49
49
  "@compiled/react": "^0.18.3",
50
50
  "@emotion/react": "^11.7.1"
@@ -60,7 +60,6 @@
60
60
  "@atlassian/feature-flags-test-utils": "^0.3.0",
61
61
  "@testing-library/react": "^13.4.0",
62
62
  "react-dom": "^18.2.0",
63
- "typescript": "~5.4.2",
64
63
  "wait-for-expect": "^1.2.0"
65
64
  },
66
65
  "techstack": {