@atlaskit/avatar 25.9.1 → 25.9.2

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 (77) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/avatar-content.js +22 -21
  3. package/dist/cjs/avatar-item.js +2 -2
  4. package/dist/cjs/avatar.js +10 -8
  5. package/dist/cjs/constants.js +2 -15
  6. package/dist/cjs/context.js +1 -31
  7. package/dist/cjs/get-appearance.js +17 -0
  8. package/dist/cjs/index.js +2 -2
  9. package/dist/cjs/internal/content-context.js +22 -0
  10. package/dist/cjs/internal/ensure-is-inside-avatar-context.js +18 -0
  11. package/dist/cjs/internal/get-custom-element.js +16 -0
  12. package/dist/cjs/internal/presence-wrapper.js +61 -0
  13. package/dist/cjs/internal/status-wrapper.js +60 -0
  14. package/dist/cjs/presence.js +2 -49
  15. package/dist/cjs/status.js +2 -48
  16. package/dist/es2019/avatar-content.js +4 -3
  17. package/dist/es2019/avatar-item.js +1 -1
  18. package/dist/es2019/avatar.js +6 -4
  19. package/dist/es2019/constants.js +1 -14
  20. package/dist/es2019/context.js +1 -29
  21. package/dist/es2019/get-appearance.js +11 -0
  22. package/dist/es2019/index.js +1 -1
  23. package/dist/es2019/internal/content-context.js +16 -0
  24. package/dist/es2019/internal/ensure-is-inside-avatar-context.js +13 -0
  25. package/dist/es2019/internal/get-custom-element.js +10 -0
  26. package/dist/es2019/internal/presence-wrapper.js +53 -0
  27. package/dist/es2019/internal/status-wrapper.js +52 -0
  28. package/dist/es2019/presence.js +1 -49
  29. package/dist/es2019/status.js +1 -48
  30. package/dist/esm/avatar-content.js +22 -21
  31. package/dist/esm/avatar-item.js +1 -1
  32. package/dist/esm/avatar.js +6 -4
  33. package/dist/esm/constants.js +1 -14
  34. package/dist/esm/context.js +0 -30
  35. package/dist/esm/get-appearance.js +11 -0
  36. package/dist/esm/index.js +1 -1
  37. package/dist/esm/internal/content-context.js +16 -0
  38. package/dist/esm/internal/ensure-is-inside-avatar-context.js +13 -0
  39. package/dist/esm/internal/get-custom-element.js +10 -0
  40. package/dist/esm/internal/presence-wrapper.js +52 -0
  41. package/dist/esm/internal/status-wrapper.js +51 -0
  42. package/dist/esm/presence.js +1 -48
  43. package/dist/esm/status.js +1 -47
  44. package/dist/types/constants.d.ts +1 -4
  45. package/dist/types/context.d.ts +1 -36
  46. package/dist/types/get-appearance.d.ts +3 -0
  47. package/dist/types/index.d.ts +1 -1
  48. package/dist/types/internal/content-context.d.ts +29 -0
  49. package/dist/types/internal/ensure-is-inside-avatar-context.d.ts +6 -0
  50. package/dist/types/internal/get-custom-element.d.ts +3 -0
  51. package/dist/types/internal/presence-wrapper.d.ts +19 -0
  52. package/dist/types/internal/status-wrapper.d.ts +19 -0
  53. package/dist/types/presence.d.ts +1 -12
  54. package/dist/types/status.d.ts +1 -12
  55. package/dist/types-ts4.5/constants.d.ts +1 -4
  56. package/dist/types-ts4.5/context.d.ts +1 -36
  57. package/dist/types-ts4.5/get-appearance.d.ts +3 -0
  58. package/dist/types-ts4.5/index.d.ts +1 -1
  59. package/dist/types-ts4.5/internal/content-context.d.ts +29 -0
  60. package/dist/types-ts4.5/internal/ensure-is-inside-avatar-context.d.ts +6 -0
  61. package/dist/types-ts4.5/internal/get-custom-element.d.ts +3 -0
  62. package/dist/types-ts4.5/internal/presence-wrapper.d.ts +19 -0
  63. package/dist/types-ts4.5/internal/status-wrapper.d.ts +19 -0
  64. package/dist/types-ts4.5/presence.d.ts +1 -12
  65. package/dist/types-ts4.5/status.d.ts +1 -12
  66. package/package.json +1 -1
  67. package/dist/cjs/utilities.js +0 -26
  68. package/dist/es2019/utilities.js +0 -19
  69. package/dist/esm/utilities.js +0 -19
  70. package/dist/types/utilities.d.ts +0 -4
  71. package/dist/types-ts4.5/utilities.d.ts +0 -4
  72. /package/dist/cjs/{presence.compiled.css → internal/presence-wrapper.compiled.css} +0 -0
  73. /package/dist/cjs/{status.compiled.css → internal/status-wrapper.compiled.css} +0 -0
  74. /package/dist/es2019/{presence.compiled.css → internal/presence-wrapper.compiled.css} +0 -0
  75. /package/dist/es2019/{status.compiled.css → internal/status-wrapper.compiled.css} +0 -0
  76. /package/dist/esm/{presence.compiled.css → internal/presence-wrapper.compiled.css} +0 -0
  77. /package/dist/esm/{status.compiled.css → internal/status-wrapper.compiled.css} +0 -0
@@ -13,32 +13,4 @@ import { createContext, useContext } from 'react';
13
13
  * ```
14
14
  */
15
15
  export const AvatarContext = /*#__PURE__*/createContext(undefined);
16
- export const useAvatarContext = () => useContext(AvatarContext);
17
- const defaultAvatarContentProps = {
18
- as: 'span',
19
- appearance: 'circle',
20
- avatarImage: null,
21
- ref: null,
22
- size: 'medium'
23
- };
24
-
25
- /**
26
- * __Avatar content context__
27
- *
28
- * This context provides the props for the AvatarContent component, enabling
29
- * consumers to compose the AvatarContent with the Avatar component.
30
- */
31
- export const AvatarContentContext = /*#__PURE__*/createContext(defaultAvatarContentProps);
32
- export const useAvatarContent = () => useContext(AvatarContentContext);
33
-
34
- /**
35
- * Used to ensure Avatar sub-components are used within a Avatar component,
36
- * and provide a useful error message if not.
37
- */
38
- export const EnsureIsInsideAvatarContext = /*#__PURE__*/createContext(false);
39
- export const useEnsureIsInsideAvatar = () => {
40
- const context = useContext(EnsureIsInsideAvatarContext);
41
- if (!context) {
42
- throw new Error('Avatar sub-components must be used within a Avatar component.');
43
- }
44
- };
16
+ export const useAvatarContext = () => useContext(AvatarContext);
@@ -0,0 +1,11 @@
1
+ const getAppearanceForAppType = appType => {
2
+ switch (appType) {
3
+ case 'agent':
4
+ return 'hexagon';
5
+ case 'user':
6
+ case 'system':
7
+ default:
8
+ return 'circle';
9
+ }
10
+ };
11
+ export default getAppearanceForAppType;
@@ -4,6 +4,6 @@ export { default as AvatarItem } from './avatar-item';
4
4
  export { default as Presence } from './presence';
5
5
  export { default as Status } from './status';
6
6
  export { default as Skeleton } from './skeleton';
7
- export { getAppearanceForAppType } from './utilities';
7
+ export { default as getAppearanceForAppType } from './get-appearance';
8
8
  export { AvatarContext, useAvatarContext } from './context';
9
9
  export { AVATAR_SIZES, BORDER_WIDTH, AVATAR_RADIUS, ACTIVE_SCALE_FACTOR } from './constants';
@@ -0,0 +1,16 @@
1
+ import { createContext } from 'react';
2
+ const defaultAvatarContentProps = {
3
+ as: 'span',
4
+ appearance: 'circle',
5
+ avatarImage: null,
6
+ ref: null,
7
+ size: 'medium'
8
+ };
9
+
10
+ /**
11
+ * __Avatar content context__
12
+ *
13
+ * This context provides the props for the AvatarContent component, enabling
14
+ * consumers to compose the AvatarContent with the Avatar component.
15
+ */
16
+ export const AvatarContentContext = /*#__PURE__*/createContext(defaultAvatarContentProps);
@@ -0,0 +1,13 @@
1
+ import { createContext, useContext } from 'react';
2
+
3
+ /**
4
+ * Used to ensure Avatar sub-components are used within a Avatar component,
5
+ * and provide a useful error message if not.
6
+ */
7
+ export const EnsureIsInsideAvatarContext = /*#__PURE__*/createContext(false);
8
+ export const useEnsureIsInsideAvatar = () => {
9
+ const context = useContext(EnsureIsInsideAvatarContext);
10
+ if (!context) {
11
+ throw new Error('Avatar sub-components must be used within a Avatar component.');
12
+ }
13
+ };
@@ -0,0 +1,10 @@
1
+ const getCustomElement = (isDisabled, href, onClick, ariaHasPopup) => {
2
+ if (href && !isDisabled) {
3
+ return 'a';
4
+ }
5
+ if (onClick || isDisabled || ariaHasPopup) {
6
+ return 'button';
7
+ }
8
+ return 'span';
9
+ };
10
+ export default getCustomElement;
@@ -0,0 +1,53 @@
1
+ /* presence-wrapper.tsx generated by @compiled/babel-plugin v0.39.1 */
2
+ import "./presence-wrapper.compiled.css";
3
+ import * as React from 'react';
4
+ import { ax, ix } from "@compiled/react/runtime";
5
+ import AvatarPresence from '../presence';
6
+ const styles = {
7
+ root: "_kqswstnw _lcxvglyw"
8
+ };
9
+ const iconSizeMap = {
10
+ small: "_4t3i1crf _1bsb1crf",
11
+ medium: "_4t3idlk8 _1bsbdlk8",
12
+ large: "_4t3io7ao _1bsbo7ao",
13
+ xlarge: "_4t3if6fq _1bsbf6fq"
14
+ };
15
+ const circleIconOffsetMap = {
16
+ small: "_94n5idpf _1xi2idpf",
17
+ medium: "_94n5idpf _1xi2idpf",
18
+ large: "_94n5t94y _1xi2t94y",
19
+ xlarge: "_94n51v6z _1xi21v6z"
20
+ };
21
+ const squareIconOffsetMap = {
22
+ root: "_94n5myb0 _1xi2myb0"
23
+ };
24
+ const hexagonIconOffsetMap = {
25
+ small: "_94n51n1a _1xi21n1a",
26
+ medium: "_94n51n1a _1xi21n1a",
27
+ large: "_94n51y44 _1xi2myb0",
28
+ xlarge: "_94n5l52n _1xi21lpd"
29
+ };
30
+
31
+ /**
32
+ * __Presence wrapper__
33
+ *
34
+ * A presence wrapper is used internally to position presence ontop of the avatar.
35
+ */
36
+ const PresenceWrapper = ({
37
+ size,
38
+ appearance,
39
+ children,
40
+ borderColor,
41
+ presence,
42
+ testId
43
+ }) => {
44
+ return /*#__PURE__*/React.createElement("span", {
45
+ "aria-hidden": "true",
46
+ "data-testid": testId && `${testId}--presence`,
47
+ className: ax([styles.root, iconSizeMap[size], circleIconOffsetMap[size], appearance === 'square' && squareIconOffsetMap.root, appearance === 'hexagon' && hexagonIconOffsetMap[size]])
48
+ }, /*#__PURE__*/React.createElement(AvatarPresence, {
49
+ borderColor: borderColor,
50
+ presence: !children ? presence : undefined
51
+ }, children));
52
+ };
53
+ export default PresenceWrapper;
@@ -0,0 +1,52 @@
1
+ /* status-wrapper.tsx generated by @compiled/babel-plugin v0.39.1 */
2
+ import "./status-wrapper.compiled.css";
3
+ import * as React from 'react';
4
+ import { ax, ix } from "@compiled/react/runtime";
5
+ import AvatarStatus from '../status';
6
+ const styles = {
7
+ root: "_kqswstnw"
8
+ };
9
+ const iconSizeMap = {
10
+ small: "_4t3i1crf _1bsb1crf",
11
+ medium: "_4t3idlk8 _1bsbdlk8",
12
+ large: "_4t3io7ao _1bsbo7ao",
13
+ xlarge: "_4t3if6fq _1bsbf6fq"
14
+ };
15
+ const circleIconOffsetMap = {
16
+ small: "_rjxpidpf _152tidpf",
17
+ medium: "_rjxpidpf _152tidpf",
18
+ large: "_rjxpt94y _152tt94y",
19
+ xlarge: "_rjxp1v6z _152t1v6z"
20
+ };
21
+ const squareIconOffsetMap = {
22
+ root: "_rjxpidpf _152tidpf"
23
+ };
24
+ const hexagonIconOffsetMap = {
25
+ small: "_rjxp1n1a _152t1n1a",
26
+ medium: "_rjxp1n1a _152t1n1a",
27
+ large: "_rjxpmyb0 _152t1y44",
28
+ xlarge: "_rjxp1lpd _152tl52n"
29
+ };
30
+ /**
31
+ * __Status wrapper__
32
+ *
33
+ * A status wrapper is used internally to position status on top of the avatar.
34
+ */
35
+ const StatusWrapper = ({
36
+ size,
37
+ status,
38
+ appearance,
39
+ borderColor,
40
+ children,
41
+ testId
42
+ }) => {
43
+ return /*#__PURE__*/React.createElement("span", {
44
+ "aria-hidden": "true",
45
+ "data-testid": testId && `${testId}--status`,
46
+ className: ax([styles.root, iconSizeMap[size], circleIconOffsetMap[size], appearance === 'square' && squareIconOffsetMap.root, appearance === 'hexagon' && hexagonIconOffsetMap[size]])
47
+ }, /*#__PURE__*/React.createElement(AvatarStatus, {
48
+ borderColor: borderColor,
49
+ status: !children ? status : undefined
50
+ }, children));
51
+ };
52
+ export default StatusWrapper;
@@ -1,5 +1,4 @@
1
1
  /* presence.tsx generated by @compiled/babel-plugin v0.39.1 */
2
- import "./presence.compiled.css";
3
2
  import * as React from 'react';
4
3
  import { ax, ix } from "@compiled/react/runtime";
5
4
  import { Fragment } from 'react';
@@ -66,51 +65,4 @@ const AvatarPresence = ({
66
65
  width: "100%",
67
66
  xmlns: "http://www.w3.org/2000/svg"
68
67
  }, getPresence(presence)) : children);
69
- export default AvatarPresence;
70
- const styles = {
71
- root: "_kqswstnw _lcxvglyw"
72
- };
73
- const iconSizeMap = {
74
- small: "_4t3i1crf _1bsb1crf",
75
- medium: "_4t3idlk8 _1bsbdlk8",
76
- large: "_4t3io7ao _1bsbo7ao",
77
- xlarge: "_4t3if6fq _1bsbf6fq"
78
- };
79
- const circleIconOffsetMap = {
80
- small: "_94n5idpf _1xi2idpf",
81
- medium: "_94n5idpf _1xi2idpf",
82
- large: "_94n5t94y _1xi2t94y",
83
- xlarge: "_94n51v6z _1xi21v6z"
84
- };
85
- const squareIconOffsetMap = {
86
- root: "_94n5myb0 _1xi2myb0"
87
- };
88
- const hexagonIconOffsetMap = {
89
- small: "_94n51n1a _1xi21n1a",
90
- medium: "_94n51n1a _1xi21n1a",
91
- large: "_94n51y44 _1xi2myb0",
92
- xlarge: "_94n5l52n _1xi21lpd"
93
- };
94
-
95
- /**
96
- * __Presence wrapper__
97
- *
98
- * A presence wrapper is used internally to position presence ontop of the avatar.
99
- */
100
- export const PresenceWrapper = ({
101
- size,
102
- appearance,
103
- children,
104
- borderColor,
105
- presence,
106
- testId
107
- }) => {
108
- return /*#__PURE__*/React.createElement("span", {
109
- "aria-hidden": "true",
110
- "data-testid": testId && `${testId}--presence`,
111
- className: ax([styles.root, iconSizeMap[size], circleIconOffsetMap[size], appearance === 'square' && squareIconOffsetMap.root, appearance === 'hexagon' && hexagonIconOffsetMap[size]])
112
- }, /*#__PURE__*/React.createElement(AvatarPresence, {
113
- borderColor: borderColor,
114
- presence: !children ? presence : undefined
115
- }, children));
116
- };
68
+ export default AvatarPresence;
@@ -1,34 +1,9 @@
1
1
  /* status.tsx generated by @compiled/babel-plugin v0.39.1 */
2
- import "./status.compiled.css";
3
2
  import * as React from 'react';
4
3
  import { ax, ix } from "@compiled/react/runtime";
5
4
  import { Fragment } from 'react';
6
5
  import { G400, N0, N40, N500, R400 } from '@atlaskit/theme/colors';
7
6
  import IconWrapper from './internal/icon-wrapper';
8
- const styles = {
9
- root: "_kqswstnw"
10
- };
11
- const iconSizeMap = {
12
- small: "_4t3i1crf _1bsb1crf",
13
- medium: "_4t3idlk8 _1bsbdlk8",
14
- large: "_4t3io7ao _1bsbo7ao",
15
- xlarge: "_4t3if6fq _1bsbf6fq"
16
- };
17
- const circleIconOffsetMap = {
18
- small: "_rjxpidpf _152tidpf",
19
- medium: "_rjxpidpf _152tidpf",
20
- large: "_rjxpt94y _152tt94y",
21
- xlarge: "_rjxp1v6z _152t1v6z"
22
- };
23
- const squareIconOffsetMap = {
24
- root: "_rjxpidpf _152tidpf"
25
- };
26
- const hexagonIconOffsetMap = {
27
- small: "_rjxp1n1a _152t1n1a",
28
- medium: "_rjxp1n1a _152t1n1a",
29
- large: "_rjxpmyb0 _152t1y44",
30
- xlarge: "_rjxp1lpd _152tl52n"
31
- };
32
7
  const ApprovedIndicator = /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("circle", {
33
8
  fill: `var(--ds-icon-success, ${G400})`,
34
9
  cx: "4",
@@ -88,26 +63,4 @@ const AvatarStatus = ({
88
63
  width: "100%",
89
64
  xmlns: "http://www.w3.org/2000/svg"
90
65
  }, getStatus(status)) : children);
91
- export default AvatarStatus;
92
- /**
93
- * __Status wrapper__
94
- *
95
- * A status wrapper is used internally to position status on top of the avatar.
96
- */
97
- export const StatusWrapper = ({
98
- size,
99
- status,
100
- appearance,
101
- borderColor,
102
- children,
103
- testId
104
- }) => {
105
- return /*#__PURE__*/React.createElement("span", {
106
- "aria-hidden": "true",
107
- "data-testid": testId && `${testId}--status`,
108
- className: ax([styles.root, iconSizeMap[size], circleIconOffsetMap[size], appearance === 'square' && squareIconOffsetMap.root, appearance === 'hexagon' && hexagonIconOffsetMap[size]])
109
- }, /*#__PURE__*/React.createElement(AvatarStatus, {
110
- borderColor: borderColor,
111
- status: !children ? status : undefined
112
- }, children));
113
- };
66
+ export default AvatarStatus;
@@ -4,9 +4,10 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
4
  import "./avatar-content.compiled.css";
5
5
  import * as React from 'react';
6
6
  import { ax, ix } from "@compiled/react/runtime";
7
- import { forwardRef } from 'react';
7
+ import { forwardRef, useContext } from 'react';
8
8
  import { fg } from '@atlaskit/platform-feature-flags';
9
- import { useAvatarContent, useEnsureIsInsideAvatar } from './context';
9
+ import { AvatarContentContext } from './internal/content-context';
10
+ import { useEnsureIsInsideAvatar } from './internal/ensure-is-inside-avatar-context';
10
11
  var boxShadowCssVar = '--avatar-box-shadow';
11
12
  var bgColorCssVar = '--avatar-bg-color';
12
13
  var styles = {
@@ -54,25 +55,25 @@ var marginAdjustmentMap = {
54
55
  export var AvatarContent = /*#__PURE__*/forwardRef(function (_ref, ref) {
55
56
  var children = _ref.children;
56
57
  useEnsureIsInsideAvatar();
57
- var _useAvatarContent = useAvatarContent(),
58
- Container = _useAvatarContent.as,
59
- appearance = _useAvatarContent.appearance,
60
- avatarImage = _useAvatarContent.avatarImage,
61
- _useAvatarContent$bor = _useAvatarContent.borderColor,
62
- borderColor = _useAvatarContent$bor === void 0 ? "var(--ds-surface, #FFFFFF)" : _useAvatarContent$bor,
63
- href = _useAvatarContent.href,
64
- isDisabled = _useAvatarContent.isDisabled,
65
- label = _useAvatarContent.label,
66
- onClick = _useAvatarContent.onClick,
67
- contextRef = _useAvatarContent.ref,
68
- tabIndex = _useAvatarContent.tabIndex,
69
- target = _useAvatarContent.target,
70
- testId = _useAvatarContent.testId,
71
- size = _useAvatarContent.size,
72
- stackIndex = _useAvatarContent.stackIndex,
73
- ariaControls = _useAvatarContent['aria-controls'],
74
- ariaExpanded = _useAvatarContent['aria-expanded'],
75
- ariaHasPopup = _useAvatarContent['aria-haspopup'];
58
+ var _useContext = useContext(AvatarContentContext),
59
+ Container = _useContext.as,
60
+ appearance = _useContext.appearance,
61
+ avatarImage = _useContext.avatarImage,
62
+ _useContext$borderCol = _useContext.borderColor,
63
+ borderColor = _useContext$borderCol === void 0 ? "var(--ds-surface, #FFFFFF)" : _useContext$borderCol,
64
+ href = _useContext.href,
65
+ isDisabled = _useContext.isDisabled,
66
+ label = _useContext.label,
67
+ onClick = _useContext.onClick,
68
+ contextRef = _useContext.ref,
69
+ tabIndex = _useContext.tabIndex,
70
+ target = _useContext.target,
71
+ testId = _useContext.testId,
72
+ size = _useContext.size,
73
+ stackIndex = _useContext.stackIndex,
74
+ ariaControls = _useContext['aria-controls'],
75
+ ariaExpanded = _useContext['aria-expanded'],
76
+ ariaHasPopup = _useContext['aria-haspopup'];
76
77
  var isInteractive = Boolean(onClick || href || isDisabled || ariaHasPopup);
77
78
  var renderedContent = /*#__PURE__*/React.createElement(Container, _extends({
78
79
  style: _defineProperty(_defineProperty({}, bgColorCssVar, borderColor), boxShadowCssVar, "0 0 0 2px ".concat(borderColor)),
@@ -7,7 +7,7 @@ import { ax, ix } from "@compiled/react/runtime";
7
7
  import { forwardRef, Fragment } from 'react';
8
8
  import { fg } from '@atlaskit/platform-feature-flags';
9
9
  import { Text } from '@atlaskit/primitives/compiled';
10
- import { getCustomElement } from './utilities';
10
+ import getCustomElement from './internal/get-custom-element';
11
11
  var bgColorCssVar = '--avatar-item-bg-color';
12
12
  var styles = {
13
13
  root: "_2rkofajl _12ji1r31 _1qu2glyw _12y31o36 _4bfu1r31 _1hmsglyw _ajmmnqa1 _1h6d1j28 _1dqonqa1 _189e1dm9 _1e0c1txw _vchhusvi _1bsb1osq _4cvr1h6o _bfhk1g13 _syaz1kw7 _1wyb1kw7 _zg8l4jg8 _k48pi7a9 _vwz4kb7n _6rthze3t _1pfhze3t _12l2ze3t _ahbqze3t _85i51b66 _1q511b66 _y4ti1b66 _bozg1b66 _y3gn1e5h",
@@ -9,11 +9,13 @@ import { forwardRef, isValidElement, useCallback, useEffect, useRef } from 'reac
9
9
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
10
10
  import { useId } from '@atlaskit/ds-lib/use-id';
11
11
  import { AvatarContent } from './avatar-content';
12
- import { AvatarContentContext, EnsureIsInsideAvatarContext, useAvatarContext } from './context';
12
+ import { useAvatarContext } from './context';
13
13
  import AvatarImage from './internal/avatar-image';
14
- import { PresenceWrapper } from './presence';
15
- import { StatusWrapper } from './status';
16
- import { getCustomElement } from './utilities';
14
+ import { AvatarContentContext } from './internal/content-context';
15
+ import { EnsureIsInsideAvatarContext } from './internal/ensure-is-inside-avatar-context';
16
+ import getCustomElement from './internal/get-custom-element';
17
+ import PresenceWrapper from './internal/presence-wrapper';
18
+ import StatusWrapper from './internal/status-wrapper';
17
19
  var packageName = "@atlaskit/avatar";
18
20
  var packageVersion = "0.0.0-development";
19
21
  var containerStyles = null;
@@ -17,17 +17,4 @@ export var AVATAR_RADIUS = {
17
17
  xxlarge: 12
18
18
  };
19
19
  export var BORDER_WIDTH = 2;
20
- export var ACTIVE_SCALE_FACTOR = 0.9;
21
- export var CSS_VAR_AVATAR_BGCOLOR = '--avatar-background-color';
22
- export var ICON_SIZES = {
23
- small: 12,
24
- medium: 14,
25
- large: 15,
26
- xlarge: 18
27
- };
28
- export var ICON_OFFSET = {
29
- small: 0,
30
- medium: 0,
31
- large: 1,
32
- xlarge: 7
33
- };
20
+ export var ACTIVE_SCALE_FACTOR = 0.9;
@@ -15,34 +15,4 @@ import { createContext, useContext } from 'react';
15
15
  export var AvatarContext = /*#__PURE__*/createContext(undefined);
16
16
  export var useAvatarContext = function useAvatarContext() {
17
17
  return useContext(AvatarContext);
18
- };
19
- var defaultAvatarContentProps = {
20
- as: 'span',
21
- appearance: 'circle',
22
- avatarImage: null,
23
- ref: null,
24
- size: 'medium'
25
- };
26
-
27
- /**
28
- * __Avatar content context__
29
- *
30
- * This context provides the props for the AvatarContent component, enabling
31
- * consumers to compose the AvatarContent with the Avatar component.
32
- */
33
- export var AvatarContentContext = /*#__PURE__*/createContext(defaultAvatarContentProps);
34
- export var useAvatarContent = function useAvatarContent() {
35
- return useContext(AvatarContentContext);
36
- };
37
-
38
- /**
39
- * Used to ensure Avatar sub-components are used within a Avatar component,
40
- * and provide a useful error message if not.
41
- */
42
- export var EnsureIsInsideAvatarContext = /*#__PURE__*/createContext(false);
43
- export var useEnsureIsInsideAvatar = function useEnsureIsInsideAvatar() {
44
- var context = useContext(EnsureIsInsideAvatarContext);
45
- if (!context) {
46
- throw new Error('Avatar sub-components must be used within a Avatar component.');
47
- }
48
18
  };
@@ -0,0 +1,11 @@
1
+ var getAppearanceForAppType = function getAppearanceForAppType(appType) {
2
+ switch (appType) {
3
+ case 'agent':
4
+ return 'hexagon';
5
+ case 'user':
6
+ case 'system':
7
+ default:
8
+ return 'circle';
9
+ }
10
+ };
11
+ export default getAppearanceForAppType;
package/dist/esm/index.js CHANGED
@@ -4,6 +4,6 @@ export { default as AvatarItem } from './avatar-item';
4
4
  export { default as Presence } from './presence';
5
5
  export { default as Status } from './status';
6
6
  export { default as Skeleton } from './skeleton';
7
- export { getAppearanceForAppType } from './utilities';
7
+ export { default as getAppearanceForAppType } from './get-appearance';
8
8
  export { AvatarContext, useAvatarContext } from './context';
9
9
  export { AVATAR_SIZES, BORDER_WIDTH, AVATAR_RADIUS, ACTIVE_SCALE_FACTOR } from './constants';
@@ -0,0 +1,16 @@
1
+ import { createContext } from 'react';
2
+ var defaultAvatarContentProps = {
3
+ as: 'span',
4
+ appearance: 'circle',
5
+ avatarImage: null,
6
+ ref: null,
7
+ size: 'medium'
8
+ };
9
+
10
+ /**
11
+ * __Avatar content context__
12
+ *
13
+ * This context provides the props for the AvatarContent component, enabling
14
+ * consumers to compose the AvatarContent with the Avatar component.
15
+ */
16
+ export var AvatarContentContext = /*#__PURE__*/createContext(defaultAvatarContentProps);
@@ -0,0 +1,13 @@
1
+ import { createContext, useContext } from 'react';
2
+
3
+ /**
4
+ * Used to ensure Avatar sub-components are used within a Avatar component,
5
+ * and provide a useful error message if not.
6
+ */
7
+ export var EnsureIsInsideAvatarContext = /*#__PURE__*/createContext(false);
8
+ export var useEnsureIsInsideAvatar = function useEnsureIsInsideAvatar() {
9
+ var context = useContext(EnsureIsInsideAvatarContext);
10
+ if (!context) {
11
+ throw new Error('Avatar sub-components must be used within a Avatar component.');
12
+ }
13
+ };
@@ -0,0 +1,10 @@
1
+ var getCustomElement = function getCustomElement(isDisabled, href, onClick, ariaHasPopup) {
2
+ if (href && !isDisabled) {
3
+ return 'a';
4
+ }
5
+ if (onClick || isDisabled || ariaHasPopup) {
6
+ return 'button';
7
+ }
8
+ return 'span';
9
+ };
10
+ export default getCustomElement;
@@ -0,0 +1,52 @@
1
+ /* presence-wrapper.tsx generated by @compiled/babel-plugin v0.39.1 */
2
+ import "./presence-wrapper.compiled.css";
3
+ import * as React from 'react';
4
+ import { ax, ix } from "@compiled/react/runtime";
5
+ import AvatarPresence from '../presence';
6
+ var styles = {
7
+ root: "_kqswstnw _lcxvglyw"
8
+ };
9
+ var iconSizeMap = {
10
+ small: "_4t3i1crf _1bsb1crf",
11
+ medium: "_4t3idlk8 _1bsbdlk8",
12
+ large: "_4t3io7ao _1bsbo7ao",
13
+ xlarge: "_4t3if6fq _1bsbf6fq"
14
+ };
15
+ var circleIconOffsetMap = {
16
+ small: "_94n5idpf _1xi2idpf",
17
+ medium: "_94n5idpf _1xi2idpf",
18
+ large: "_94n5t94y _1xi2t94y",
19
+ xlarge: "_94n51v6z _1xi21v6z"
20
+ };
21
+ var squareIconOffsetMap = {
22
+ root: "_94n5myb0 _1xi2myb0"
23
+ };
24
+ var hexagonIconOffsetMap = {
25
+ small: "_94n51n1a _1xi21n1a",
26
+ medium: "_94n51n1a _1xi21n1a",
27
+ large: "_94n51y44 _1xi2myb0",
28
+ xlarge: "_94n5l52n _1xi21lpd"
29
+ };
30
+
31
+ /**
32
+ * __Presence wrapper__
33
+ *
34
+ * A presence wrapper is used internally to position presence ontop of the avatar.
35
+ */
36
+ var PresenceWrapper = function PresenceWrapper(_ref) {
37
+ var size = _ref.size,
38
+ appearance = _ref.appearance,
39
+ children = _ref.children,
40
+ borderColor = _ref.borderColor,
41
+ presence = _ref.presence,
42
+ testId = _ref.testId;
43
+ return /*#__PURE__*/React.createElement("span", {
44
+ "aria-hidden": "true",
45
+ "data-testid": testId && "".concat(testId, "--presence"),
46
+ className: ax([styles.root, iconSizeMap[size], circleIconOffsetMap[size], appearance === 'square' && squareIconOffsetMap.root, appearance === 'hexagon' && hexagonIconOffsetMap[size]])
47
+ }, /*#__PURE__*/React.createElement(AvatarPresence, {
48
+ borderColor: borderColor,
49
+ presence: !children ? presence : undefined
50
+ }, children));
51
+ };
52
+ export default PresenceWrapper;
@@ -0,0 +1,51 @@
1
+ /* status-wrapper.tsx generated by @compiled/babel-plugin v0.39.1 */
2
+ import "./status-wrapper.compiled.css";
3
+ import * as React from 'react';
4
+ import { ax, ix } from "@compiled/react/runtime";
5
+ import AvatarStatus from '../status';
6
+ var styles = {
7
+ root: "_kqswstnw"
8
+ };
9
+ var iconSizeMap = {
10
+ small: "_4t3i1crf _1bsb1crf",
11
+ medium: "_4t3idlk8 _1bsbdlk8",
12
+ large: "_4t3io7ao _1bsbo7ao",
13
+ xlarge: "_4t3if6fq _1bsbf6fq"
14
+ };
15
+ var circleIconOffsetMap = {
16
+ small: "_rjxpidpf _152tidpf",
17
+ medium: "_rjxpidpf _152tidpf",
18
+ large: "_rjxpt94y _152tt94y",
19
+ xlarge: "_rjxp1v6z _152t1v6z"
20
+ };
21
+ var squareIconOffsetMap = {
22
+ root: "_rjxpidpf _152tidpf"
23
+ };
24
+ var hexagonIconOffsetMap = {
25
+ small: "_rjxp1n1a _152t1n1a",
26
+ medium: "_rjxp1n1a _152t1n1a",
27
+ large: "_rjxpmyb0 _152t1y44",
28
+ xlarge: "_rjxp1lpd _152tl52n"
29
+ };
30
+ /**
31
+ * __Status wrapper__
32
+ *
33
+ * A status wrapper is used internally to position status on top of the avatar.
34
+ */
35
+ var StatusWrapper = function StatusWrapper(_ref) {
36
+ var size = _ref.size,
37
+ status = _ref.status,
38
+ appearance = _ref.appearance,
39
+ borderColor = _ref.borderColor,
40
+ children = _ref.children,
41
+ testId = _ref.testId;
42
+ return /*#__PURE__*/React.createElement("span", {
43
+ "aria-hidden": "true",
44
+ "data-testid": testId && "".concat(testId, "--status"),
45
+ className: ax([styles.root, iconSizeMap[size], circleIconOffsetMap[size], appearance === 'square' && squareIconOffsetMap.root, appearance === 'hexagon' && hexagonIconOffsetMap[size]])
46
+ }, /*#__PURE__*/React.createElement(AvatarStatus, {
47
+ borderColor: borderColor,
48
+ status: !children ? status : undefined
49
+ }, children));
50
+ };
51
+ export default StatusWrapper;