@papillonarts/components 0.44.0 → 0.45.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.
Files changed (38) hide show
  1. package/build/Modern/Avatar/Avatar.d.ts +28 -0
  2. package/build/Modern/Avatar/Avatar.d.ts.map +1 -0
  3. package/build/Modern/Avatar/Avatar.docs.json +51 -0
  4. package/build/Modern/Avatar/Avatar.js +56 -0
  5. package/build/Modern/Avatar/Avatar.module.scss +36 -0
  6. package/build/Modern/Avatar/__tests__/Avatar.doc.md +110 -0
  7. package/build/Modern/Avatar/index.d.ts +3 -0
  8. package/build/Modern/Avatar/index.d.ts.map +1 -0
  9. package/build/Modern/Avatar/index.js +12 -0
  10. package/build/Modern/AvatarStack/AvatarStack.d.ts +14 -0
  11. package/build/Modern/AvatarStack/AvatarStack.d.ts.map +1 -0
  12. package/build/Modern/AvatarStack/AvatarStack.docs.json +81 -0
  13. package/build/Modern/AvatarStack/AvatarStack.js +155 -0
  14. package/build/Modern/AvatarStack/AvatarStack.module.scss +270 -0
  15. package/build/Modern/AvatarStack/__tests__/AvatarStack.doc.md +194 -0
  16. package/build/Modern/AvatarStack/index.d.ts +3 -0
  17. package/build/Modern/AvatarStack/index.d.ts.map +1 -0
  18. package/build/Modern/AvatarStack/index.js +12 -0
  19. package/build/Modern/index.d.ts +14 -0
  20. package/build/Modern/index.d.ts.map +1 -1
  21. package/build/Modern/index.js +8 -0
  22. package/build/Modern/type.d.ts +1 -0
  23. package/build/Modern/type.d.ts.map +1 -1
  24. package/build/Modern/utils/hasInteractiveNodes.d.ts +11 -0
  25. package/build/Modern/utils/hasInteractiveNodes.d.ts.map +1 -0
  26. package/build/Modern/utils/hasInteractiveNodes.js +64 -0
  27. package/build/Modern/utils/testing.d.ts +2 -0
  28. package/build/Modern/utils/testing.d.ts.map +1 -0
  29. package/build/Modern/utils/testing.js +29 -0
  30. package/build/Modern/utils/types/ViewportRangeKeys.d.ts +3 -0
  31. package/build/Modern/utils/types/ViewportRangeKeys.d.ts.map +1 -0
  32. package/build/Modern/utils/types/ViewportRangeKeys.js +5 -0
  33. package/build/Modern/utils/types/index.d.ts +1 -0
  34. package/build/Modern/utils/types/index.d.ts.map +1 -1
  35. package/build/Modern/utils/types/index.js +11 -0
  36. package/build/index.d.ts +1 -1
  37. package/build/index.d.ts.map +1 -1
  38. package/package.json +4 -4
@@ -0,0 +1,28 @@
1
+ import { ComponentPropsWithoutRef } from 'react';
2
+ import type { ResponsiveValue } from '../hooks/useResponsiveValue';
3
+ export declare const DEFAULT_AVATAR_SIZE = 20;
4
+ export type AvatarProps = {
5
+ /** Sets the width and height of the avatar. */
6
+ size?: number | ResponsiveValue<number>;
7
+ /** Sets the shape of the avatar to a square if true. If false, the avatar will be circular. */
8
+ square?: boolean;
9
+ /** URL of the avatar image. */
10
+ src: string;
11
+ /** Provide alt text when the Avatar is used without the user's name next to it. */
12
+ alt?: string;
13
+ /** Additional class name. */
14
+ className?: string;
15
+ } & ComponentPropsWithoutRef<'img'>;
16
+ export declare const Avatar: import("react").ForwardRefExoticComponent<{
17
+ /** Sets the width and height of the avatar. */
18
+ size?: number | ResponsiveValue<number>;
19
+ /** Sets the shape of the avatar to a square if true. If false, the avatar will be circular. */
20
+ square?: boolean;
21
+ /** URL of the avatar image. */
22
+ src: string;
23
+ /** Provide alt text when the Avatar is used without the user's name next to it. */
24
+ alt?: string;
25
+ /** Additional class name. */
26
+ className?: string;
27
+ } & Omit<import("react").DetailedHTMLProps<import("react").ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "ref"> & import("react").RefAttributes<HTMLImageElement>>;
28
+ //# sourceMappingURL=Avatar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Avatar.d.ts","sourceRoot":"","sources":["../../../src/Modern/Avatar/Avatar.tsx"],"names":[],"mappings":"AACA,OAAO,EAAiB,wBAAwB,EAAc,MAAM,OAAO,CAAA;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAIlE,eAAO,MAAM,mBAAmB,KAAK,CAAA;AAErC,MAAM,MAAM,WAAW,GAAG;IACxB,+CAA+C;IAC/C,IAAI,CAAC,EAAE,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAA;IACvC,+FAA+F;IAC/F,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,+BAA+B;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,mFAAmF;IACnF,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,6BAA6B;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,GAAG,wBAAwB,CAAC,KAAK,CAAC,CAAA;AAEnC,eAAO,MAAM,MAAM;IAZjB,+CAA+C;WACxC,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC;IACvC,+FAA+F;aACtF,OAAO;IAChB,+BAA+B;SAC1B,MAAM;IACX,mFAAmF;UAC7E,MAAM;IACZ,6BAA6B;gBACjB,MAAM;4KAuClB,CAAA"}
@@ -0,0 +1,51 @@
1
+ {
2
+ "id": "avatar",
3
+ "name": "Avatar",
4
+ "status": "alpha",
5
+ "a11yReviewed": "2025-01-08",
6
+ "stories": [
7
+ {
8
+ "id": "components-avatar--default"
9
+ },
10
+ {
11
+ "id": "components-avatar-features--square"
12
+ },
13
+ {
14
+ "id": "components-avatar-features--size"
15
+ },
16
+ {
17
+ "id": "components-avatar-features--size-responsive"
18
+ }
19
+ ],
20
+ "importPath": "@primer/react",
21
+ "props": [
22
+ {
23
+ "name": "size",
24
+ "type": "number | ResponsiveValue<number>",
25
+ "defaultValue": "20",
26
+ "description": "Sets the width and height of the avatar."
27
+ },
28
+ {
29
+ "name": "square",
30
+ "type": "boolean",
31
+ "defaultValue": "false",
32
+ "description": "Sets the shape of the avatar to a square if true. If false, the avatar will be circular."
33
+ },
34
+ {
35
+ "name": "src",
36
+ "type": "string",
37
+ "description": "URL of the avatar image."
38
+ },
39
+ {
40
+ "name": "alt",
41
+ "type": "string",
42
+ "defaultValue": "\"\"",
43
+ "description": "Provide alt text when the Avatar is used without the user's name next to it."
44
+ },
45
+ {
46
+ "name": "ref",
47
+ "type": "React.RefObject<HTMLImageElement>"
48
+ }
49
+ ],
50
+ "subcomponents": []
51
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.DEFAULT_AVATAR_SIZE = exports.Avatar = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
+ var _clsx = require("clsx");
12
+ var _react = require("react");
13
+ var _useResponsiveValue = require("../hooks/useResponsiveValue");
14
+ var _AvatarModule = _interopRequireDefault(require("./Avatar.module.scss"));
15
+ var _jsxRuntime = require("react/jsx-runtime");
16
+ var _excluded = ["alt", "size", "square", "className", "style"];
17
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
+ var DEFAULT_AVATAR_SIZE = exports.DEFAULT_AVATAR_SIZE = 20;
20
+ var Avatar = exports.Avatar = /*#__PURE__*/(0, _react.forwardRef)(function Avatar(_ref, ref) {
21
+ var _ref$alt = _ref.alt,
22
+ alt = _ref$alt === void 0 ? '' : _ref$alt,
23
+ _ref$size = _ref.size,
24
+ size = _ref$size === void 0 ? DEFAULT_AVATAR_SIZE : _ref$size,
25
+ _ref$square = _ref.square,
26
+ square = _ref$square === void 0 ? false : _ref$square,
27
+ className = _ref.className,
28
+ style = _ref.style,
29
+ rest = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
30
+ var isResponsive = (0, _useResponsiveValue.isResponsiveValue)(size);
31
+ var cssSizeVars = {};
32
+ if (isResponsive) {
33
+ for (var _i = 0, _Object$entries = Object.entries(size); _i < _Object$entries.length; _i++) {
34
+ var _Object$entries$_i = (0, _slicedToArray2["default"])(_Object$entries[_i], 2),
35
+ key = _Object$entries$_i[0],
36
+ value = _Object$entries$_i[1];
37
+ cssSizeVars["--avatarSize-".concat(key)] = "".concat(value, "px");
38
+ }
39
+ } else {
40
+ cssSizeVars['--avatarSize-regular'] = "".concat(size, "px");
41
+ }
42
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("img", _objectSpread({
43
+ "data-component": "Avatar",
44
+ className: (0, _clsx.clsx)(className, _AvatarModule["default"].Avatar),
45
+ ref: ref,
46
+ alt: alt,
47
+ "data-responsive": isResponsive ? '' : undefined,
48
+ "data-square": square ? '' : undefined,
49
+ width: isResponsive ? undefined : size,
50
+ height: isResponsive ? undefined : size,
51
+ style: style ? _objectSpread(_objectSpread({}, cssSizeVars), style) : cssSizeVars
52
+ }, rest));
53
+ });
54
+ if (process.env.NODE_ENV !== 'production') {
55
+ Avatar.displayName = 'Avatar';
56
+ }
@@ -0,0 +1,36 @@
1
+ /* stylelint-disable custom-property-pattern */
2
+
3
+ :where(.Avatar) {
4
+ display: inline-block;
5
+ width: var(--avatarSize-regular);
6
+ height: var(--avatarSize-regular);
7
+ overflow: hidden; /* Ensure page layout in Firefox should images fail to load */
8
+ /* stylelint-disable-next-line primer/typography */
9
+ line-height: 1;
10
+ vertical-align: middle;
11
+ border-radius: 50%;
12
+ /* stylelint-disable-next-line primer/box-shadow */
13
+ box-shadow: 0 0 0 1px var(--avatar-borderColor);
14
+
15
+ &:where([data-square]) {
16
+ /* stylelint-disable-next-line primer/borders */
17
+ border-radius: clamp(4px, calc(var(--avatarSize-regular) - 24px), var(--borderRadius-medium));
18
+ }
19
+
20
+ &:where([data-responsive]) {
21
+ @media screen and (--viewportRange-narrow) {
22
+ width: var(--avatarSize-narrow);
23
+ height: var(--avatarSize-narrow);
24
+ }
25
+
26
+ @media screen and (--viewportRange-regular) {
27
+ width: var(--avatarSize-regular);
28
+ height: var(--avatarSize-regular);
29
+ }
30
+
31
+ @media screen and (--viewportRange-wide) {
32
+ width: var(--avatarSize-wide);
33
+ height: var(--avatarSize-wide);
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,110 @@
1
+ # Features
2
+
3
+ ```
4
+ Avatar all props and variants
5
+ ```
6
+
7
+ ## Props
8
+
9
+ ```typescript
10
+ export type AvatarProps = {
11
+ /** Sets the width and height of the avatar. */
12
+ size?: number | ResponsiveValue<number>
13
+ /** Sets the shape of the avatar to a square if true. If false, the avatar will be circular. */
14
+ square?: boolean
15
+ /** URL of the avatar image. */
16
+ src: string
17
+ /** Provide alt text when the Avatar is used without the user's name next to it. */
18
+ alt?: string
19
+ /** Additional class name. */
20
+ className?: string
21
+ } & ComponentPropsWithoutRef<'img'>
22
+ ```
23
+
24
+ ## Variants
25
+
26
+ ```
27
+ Default
28
+
29
+ Square
30
+
31
+ Size
32
+
33
+ Size Responsive
34
+
35
+ Should Accept Call With No Props
36
+
37
+ Should Not Accept System Props
38
+ ```
39
+
40
+ ### Default
41
+
42
+ > Avatar default variant
43
+
44
+ ```tsx
45
+ <Avatar src="https://avatars.githubusercontent.com/u/7143434?v=4" />
46
+ ```
47
+
48
+ ### Square
49
+
50
+ > Avatar square variant
51
+
52
+ ```tsx
53
+ <Avatar square alt="primer" src="https://avatars.githubusercontent.com/primer" />
54
+ ```
55
+
56
+ ### Size
57
+
58
+ > Avatar with various sizes
59
+
60
+ ```tsx
61
+ <div>
62
+ <Avatar size={4} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
63
+ <Avatar size={8} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
64
+ <Avatar size={12} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
65
+ <Avatar size={16} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
66
+ <Avatar size={20} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
67
+ <Avatar size={24} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
68
+ <Avatar size={28} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
69
+ <Avatar size={32} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
70
+ <Avatar size={40} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
71
+ <Avatar size={48} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
72
+ <Avatar size={56} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
73
+ <Avatar size={64} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
74
+ </div>
75
+ ```
76
+
77
+ ### Size Responsive
78
+
79
+ > Avatar with responsive sizes
80
+
81
+ ```tsx
82
+ <div>
83
+ <Avatar size={{ narrow: 4, regular: 8, wide: 12 }} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
84
+ <Avatar size={{ narrow: 8, regular: 12, wide: 16 }} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
85
+ <Avatar size={{ narrow: 12, regular: 16, wide: 20 }} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
86
+ <Avatar size={{ narrow: 16, regular: 20, wide: 24 }} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
87
+ <Avatar size={{ narrow: 20, regular: 24, wide: 28 }} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
88
+ <Avatar size={{ narrow: 24, regular: 28, wide: 32 }} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
89
+ <Avatar size={{ narrow: 28, regular: 32, wide: 40 }} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
90
+ <Avatar size={{ narrow: 32, regular: 40, wide: 48 }} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
91
+ <Avatar size={{ narrow: 40, regular: 48, wide: 56 }} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
92
+ <Avatar size={{ narrow: 48, regular: 56, wide: 64 }} alt="mona" src="https://avatars.githubusercontent.com/u/7143434?v=4" />
93
+ </div>
94
+ ```
95
+
96
+ ### Should Accept Call With No Props
97
+
98
+ > Avatar Should Accept Call With No Props
99
+
100
+ ```tsx
101
+ <Avatar src="https://avatars.githubusercontent.com/primer" />
102
+ ```
103
+
104
+ ### Should Not Accept System Props
105
+
106
+ > Avatar Should Not Accept System Props
107
+
108
+ ```tsx
109
+ <Avatar src="https://avatars.githubusercontent.com/primer" backgroundColor="thistle" />
110
+ ```
@@ -0,0 +1,3 @@
1
+ export { Avatar } from './Avatar';
2
+ export type { AvatarProps } from './Avatar';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/Modern/Avatar/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Avatar", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _Avatar.Avatar;
10
+ }
11
+ });
12
+ var _Avatar = require("./Avatar");
@@ -0,0 +1,14 @@
1
+ import { CSSProperties, ReactNode } from 'react';
2
+ import type { ResponsiveValue } from '../hooks/useResponsiveValue';
3
+ export interface AvatarStackProps {
4
+ alignRight?: boolean;
5
+ disableExpand?: boolean;
6
+ variant?: 'cascade' | 'stack';
7
+ shape?: 'circle' | 'square';
8
+ size?: number | ResponsiveValue<number>;
9
+ className?: string;
10
+ children: ReactNode;
11
+ style?: CSSProperties;
12
+ }
13
+ export declare const AvatarStack: ({ children, variant, shape, alignRight, disableExpand, size, className, style, }: AvatarStackProps) => import("react/jsx-runtime").JSX.Element;
14
+ //# sourceMappingURL=AvatarStack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AvatarStack.d.ts","sourceRoot":"","sources":["../../../src/Modern/AvatarStack/AvatarStack.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EAGb,SAAS,EAOV,MAAM,OAAO,CAAA;AAGd,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAiBlE,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,OAAO,CAAC,EAAE,SAAS,GAAG,OAAO,CAAA;IAC7B,KAAK,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAA;IAC3B,IAAI,CAAC,EAAE,MAAM,GAAG,eAAe,CAAC,MAAM,CAAC,CAAA;IACvC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,SAAS,CAAA;IACnB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB;AA8BD,eAAO,MAAM,WAAW,GAAI,kFASzB,gBAAgB,4CAkHlB,CAAA"}
@@ -0,0 +1,81 @@
1
+ {
2
+ "id": "avatar_stack",
3
+ "name": "AvatarStack",
4
+ "status": "alpha",
5
+ "a11yReviewed": "2025-01-08",
6
+ "stories": [
7
+ {
8
+ "id": "components-modern-avatarstack--default"
9
+ },
10
+ {
11
+ "id": "components-modern-avatarstack--align-right"
12
+ },
13
+ {
14
+ "id": "components-modern-avatarstack--disable-expand"
15
+ },
16
+ {
17
+ "id": "components-modern-avatarstack--custom-size"
18
+ },
19
+ {
20
+ "id": "components-modern-avatarstack--custom-size-responsive"
21
+ },
22
+ {
23
+ "id": "components-modern-avatarstack--square-shape"
24
+ },
25
+ {
26
+ "id": "components-modern-avatarstack--stack-variant"
27
+ }
28
+ ],
29
+ "importPath": "@papillonarts/components",
30
+ "props": [
31
+ {
32
+ "name": "children",
33
+ "type": "ReactNode",
34
+ "description": "A set of Avatar components to stack",
35
+ "defaultValue": ""
36
+ },
37
+ {
38
+ "name": "alignRight",
39
+ "type": "boolean",
40
+ "defaultValue": "false",
41
+ "description": "Align the avatars to the right"
42
+ },
43
+ {
44
+ "name": "disableExpand",
45
+ "type": "boolean",
46
+ "defaultValue": "false",
47
+ "description": "Do not spread the avatars on hover"
48
+ },
49
+ {
50
+ "name": "variant",
51
+ "type": "'cascade' | 'stack'",
52
+ "defaultValue": "'cascade'",
53
+ "description": "The variant of the avatar stack layout"
54
+ },
55
+ {
56
+ "name": "shape",
57
+ "type": "'circle' | 'square'",
58
+ "defaultValue": "'circle'",
59
+ "description": "The shape of the avatars"
60
+ },
61
+ {
62
+ "name": "size",
63
+ "type": "number | { narrow?: number; regular?: number; wide?: number; }",
64
+ "defaultValue": "20",
65
+ "description": "The size of the avatar children in pixels."
66
+ },
67
+ {
68
+ "name": "className",
69
+ "type": "string",
70
+ "description": "Class name for custom styling.",
71
+ "defaultValue": ""
72
+ },
73
+ {
74
+ "name": "style",
75
+ "type": "CSSProperties",
76
+ "description": "Inline styles for the component.",
77
+ "defaultValue": ""
78
+ }
79
+ ],
80
+ "subcomponents": []
81
+ }
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.AvatarStack = void 0;
8
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _clsx = require("clsx");
12
+ var _react = require("react");
13
+ var _Avatar = require("../Avatar/Avatar");
14
+ var _useResponsiveValue = require("../hooks/useResponsiveValue");
15
+ var _hasInteractiveNodes = require("../utils/hasInteractiveNodes");
16
+ var _AvatarStackModule = _interopRequireDefault(require("./AvatarStack.module.scss"));
17
+ var _jsxRuntime = require("react/jsx-runtime");
18
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
19
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
20
+ var transformChildren = function transformChildren(children, shape) {
21
+ return _react.Children.map(children, function (child) {
22
+ if (! /*#__PURE__*/(0, _react.isValidElement)(child)) return child;
23
+ return /*#__PURE__*/(0, _react.cloneElement)(child, _objectSpread(_objectSpread({}, child.props), {}, {
24
+ square: (shape === 'square' ? true : undefined) || child.props.square,
25
+ className: (0, _clsx.clsx)(child.props.className, 'pc-AvatarItem', _AvatarStackModule["default"].AvatarItem)
26
+ }));
27
+ });
28
+ };
29
+ var AvatarStackBody = function AvatarStackBody(_ref) {
30
+ var disableExpand = _ref.disableExpand,
31
+ hasInteractiveChildren = _ref.hasInteractiveChildren,
32
+ stackContainer = _ref.stackContainer,
33
+ children = _ref.children;
34
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
35
+ "data-disable-expand": disableExpand ? '' : undefined,
36
+ className: (0, _clsx.clsx)({
37
+ 'pc-AvatarStack--disableExpand': disableExpand
38
+ }, 'pc-AvatarStackBody', _AvatarStackModule["default"].AvatarStackBody),
39
+ tabIndex: !hasInteractiveChildren && !disableExpand ? 0 : undefined,
40
+ ref: stackContainer,
41
+ children: children
42
+ });
43
+ };
44
+ var AvatarStack = exports.AvatarStack = function AvatarStack(_ref2) {
45
+ var children = _ref2.children,
46
+ _ref2$variant = _ref2.variant,
47
+ variant = _ref2$variant === void 0 ? 'cascade' : _ref2$variant,
48
+ _ref2$shape = _ref2.shape,
49
+ shape = _ref2$shape === void 0 ? 'circle' : _ref2$shape,
50
+ alignRight = _ref2.alignRight,
51
+ disableExpand = _ref2.disableExpand,
52
+ size = _ref2.size,
53
+ className = _ref2.className,
54
+ style = _ref2.style;
55
+ var _useState = (0, _react.useState)(false),
56
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
57
+ hasInteractiveChildren = _useState2[0],
58
+ setHasInteractiveChildren = _useState2[1];
59
+ var stackContainer = (0, _react.useRef)(null);
60
+ var count = _react.Children.count(children);
61
+ var getAvatarChildSizes = function getAvatarChildSizes() {
62
+ var avatarSizeMap = {
63
+ narrow: [],
64
+ regular: [],
65
+ wide: []
66
+ };
67
+ return _react.Children.toArray(children).reduce(function (acc, child) {
68
+ // if child is not an Avatar, return the default avatar sizes from the accumulator
69
+ if (! /*#__PURE__*/(0, _react.isValidElement)(child)) return acc;
70
+ for (var _i = 0, _Object$keys = Object.keys(avatarSizeMap); _i < _Object$keys.length; _i++) {
71
+ var responsiveKey = _Object$keys[_i];
72
+ // if the child has responsive `size` prop values, push the value to the appropriate viewport property in the avatarSizeMap
73
+ if ((0, _useResponsiveValue.isResponsiveValue)(child.props.size)) {
74
+ avatarSizeMap[responsiveKey].push(child.props.size[responsiveKey] || _Avatar.DEFAULT_AVATAR_SIZE);
75
+ }
76
+ // otherwise, the size is a number (or undefined), so push the value to all viewport properties in the avatarSizeMap
77
+ else {
78
+ avatarSizeMap[responsiveKey].push(child.props.size || _Avatar.DEFAULT_AVATAR_SIZE);
79
+ }
80
+
81
+ // set the smallest size in each viewport property as the value for that viewport property in the accumulator
82
+ acc[responsiveKey] = Math.min.apply(Math, (0, _toConsumableArray2["default"])(avatarSizeMap[responsiveKey]));
83
+ }
84
+ return acc;
85
+ }, {
86
+ narrow: _Avatar.DEFAULT_AVATAR_SIZE,
87
+ regular: _Avatar.DEFAULT_AVATAR_SIZE,
88
+ wide: _Avatar.DEFAULT_AVATAR_SIZE
89
+ });
90
+ };
91
+ var childSizes = getAvatarChildSizes();
92
+ (0, _react.useEffect)(function () {
93
+ if (stackContainer.current) {
94
+ var interactiveChildren = function interactiveChildren() {
95
+ setHasInteractiveChildren((0, _hasInteractiveNodes.hasInteractiveNodes)(stackContainer.current));
96
+ };
97
+ var observer = new MutationObserver(interactiveChildren);
98
+ observer.observe(stackContainer.current, {
99
+ childList: true
100
+ });
101
+
102
+ // Call on initial render, then call it again only if there's a mutation
103
+ interactiveChildren();
104
+ return function () {
105
+ observer.disconnect();
106
+ };
107
+ }
108
+ }, []);
109
+ var getResponsiveAvatarSizeStyles = function getResponsiveAvatarSizeStyles() {
110
+ // if there is no size set on the AvatarStack, use the `size` props of the Avatar children to set the `--avatar-stack-size` CSS variable
111
+ if (!size) {
112
+ return {
113
+ '--stackSize-narrow': "".concat(childSizes.narrow, "px"),
114
+ '--stackSize-regular': "".concat(childSizes.regular, "px"),
115
+ '--stackSize-wide': "".concat(childSizes.wide, "px")
116
+ };
117
+ }
118
+
119
+ // if the `size` prop is set and responsive, set the `--avatar-stack-size` CSS variable for each viewport
120
+ if ((0, _useResponsiveValue.isResponsiveValue)(size)) {
121
+ return {
122
+ '--stackSize-narrow': "".concat(size.narrow || _Avatar.DEFAULT_AVATAR_SIZE, "px"),
123
+ '--stackSize-regular': "".concat(size.regular || _Avatar.DEFAULT_AVATAR_SIZE, "px"),
124
+ '--stackSize-wide': "".concat(size.wide || _Avatar.DEFAULT_AVATAR_SIZE, "px")
125
+ };
126
+ }
127
+
128
+ // if the `size` prop is set and not responsive, it is a number, so we can just set the `--avatar-stack-size` CSS variable to that number
129
+ return {
130
+ '--avatar-stack-size': "".concat(size, "px")
131
+ };
132
+ };
133
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
134
+ "data-variant": variant,
135
+ "data-shape": shape,
136
+ "data-avatar-count": count > 3 ? '3+' : count,
137
+ "data-align-right": alignRight ? '' : undefined,
138
+ "data-responsive": !size || (0, _useResponsiveValue.isResponsiveValue)(size) ? '' : undefined,
139
+ className: (0, _clsx.clsx)({
140
+ 'pc-AvatarStack--variant': variant,
141
+ 'pc-AvatarStack--shape': shape,
142
+ 'pc-AvatarStack--two': count === 2,
143
+ 'pc-AvatarStack--three': count === 3,
144
+ 'pc-AvatarStack--three-plus': count > 3,
145
+ 'pc-AvatarStack--right': alignRight
146
+ }, className, _AvatarStackModule["default"].AvatarStack),
147
+ style: _objectSpread(_objectSpread({}, getResponsiveAvatarSizeStyles()), style),
148
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(AvatarStackBody, {
149
+ disableExpand: disableExpand,
150
+ hasInteractiveChildren: hasInteractiveChildren,
151
+ stackContainer: stackContainer,
152
+ children: [' ', transformChildren(children, shape)]
153
+ })
154
+ });
155
+ };