@learningpool/ui 1.8.7 → 1.8.8

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.
@@ -9,6 +9,15 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
12
21
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
22
  import React, { useEffect } from 'react';
14
23
  import { Box, ButtonGroup, Button, Link, List, ListItem, ListItemIcon, ListItemText } from '../../../index';
@@ -18,15 +27,15 @@ import EditIcon from '@mui/icons-material/Edit';
18
27
  import LogoutIcon from '@mui/icons-material/Logout';
19
28
  import ToggleOffIcon from '@mui/icons-material/ToggleOff';
20
29
  import ToggleOnIcon from '@mui/icons-material/ToggleOn';
21
- import { handleAvatarInitials, useStaggerAnimation } from '../../../utils/helpers';
30
+ import { handleAvatarInitials, useFadeIn } from '../../../utils/helpers';
22
31
  import { animated } from '@react-spring/web';
23
32
  import { defaultAttributes } from '../../../utils/dataAttributes';
24
33
  var SwipeableTemporaryAvatar = function (props) {
25
- var _a;
34
+ var _a, _b, _c, _d;
26
35
  var theme = useTheme();
27
36
  var avatarName = props.avatarName, mobileNavDirection = props.mobileNavDirection, avatarPanelLogoutString = props.avatarPanelLogoutString, isAvatarOpen = props.isAvatarOpen, setIsAvatarOpen = props.setIsAvatarOpen, setMobileNavDirection = props.setMobileNavDirection, avatarPanelOnClickSwitchDirection = props.avatarPanelOnClickSwitchDirection, avatarPanelOnClickLogout = props.avatarPanelOnClickLogout, avatarPanelOnClickViewProfile = props.avatarPanelOnClickViewProfile, avatarPanelViewProfileString = props.avatarPanelViewProfileString, avatarPanelOnClickEditProfile = props.avatarPanelOnClickEditProfile, avatarPanelEditProfileString = props.avatarPanelEditProfileString, avatarPanelMenuItems = props.avatarPanelMenuItems, avatarPanelOnClickMainAction = props.avatarPanelOnClickMainAction, avatarPanelMainActionString = props.avatarPanelMainActionString, avatarPanelSettingItems = props.avatarPanelSettingItems, avatarPanelInvertNavString = props.avatarPanelInvertNavString, dataAttributes = props.dataAttributes;
28
37
  var dataIds = __assign(__assign({}, defaultAttributes), dataAttributes);
29
- var _b = React.useState(isAvatarOpen !== null && isAvatarOpen !== void 0 ? isAvatarOpen : false), isOpen = _b[0], setIsOpen = _b[1];
38
+ var _e = React.useState(isAvatarOpen !== null && isAvatarOpen !== void 0 ? isAvatarOpen : false), isOpen = _e[0], setIsOpen = _e[1];
30
39
  React.useEffect(function () { return handleOpenState(isAvatarOpen); }, [isAvatarOpen]);
31
40
  var handleOpenState = function (open) {
32
41
  setIsOpen(open);
@@ -42,30 +51,42 @@ var SwipeableTemporaryAvatar = function (props) {
42
51
  handleOpenState(open);
43
52
  };
44
53
  };
45
- var _c = React.useState((_a = handleAvatarInitials(avatarName)) !== null && _a !== void 0 ? _a : 'AN'), avatarInitials = _c[0], setAvatarInitials = _c[1];
54
+ var _f = React.useState((_a = handleAvatarInitials(avatarName)) !== null && _a !== void 0 ? _a : 'AN'), avatarInitials = _f[0], setAvatarInitials = _f[1];
46
55
  useEffect(function () { return setAvatarInitials(handleAvatarInitials(avatarName)); }, [avatarName]);
47
56
  var handleOnClickSwitchDirection = function () {
48
57
  setMobileNavDirection(mobileNavDirection === 'rtl' ? 'ltr' : 'rtl');
49
58
  avatarPanelOnClickSwitchDirection && avatarPanelOnClickSwitchDirection();
50
59
  };
51
- // First item starts at 70ms
52
- // see STAGGER_ITEMS_DELAY in helpers.js
53
- var animationCount = 1;
54
- var incrementAnimationCount = function () { return animationCount++; };
60
+ // Workaround to handle the react-spring calls without
61
+ // adding additional hook calls on prop or state changes
62
+ // --
63
+ // Store the total possible number of animations in a ref
64
+ // this way the number of hook calls never changes
65
+ // --
66
+ // First item starts at 70ms, see STAGGER_ITEMS_DELAY in helpers.js
67
+ var additionalItems = [
68
+ 'avatarPanelOnClickLogout',
69
+ 'avatarName',
70
+ 'avatarPanelOnClickViewProfile',
71
+ 'avatarPanelOnClickMainAction',
72
+ 'mobileNavDirection'
73
+ ];
74
+ var totalItems = __spreadArray(__spreadArray(__spreadArray([], avatarPanelMenuItems !== null && avatarPanelMenuItems !== void 0 ? avatarPanelMenuItems : [], true), avatarPanelSettingItems !== null && avatarPanelSettingItems !== void 0 ? avatarPanelSettingItems : [], true), additionalItems, true);
75
+ var animationRefs = React.useRef(totalItems && totalItems.map(function (item, index) { return useFadeIn(index, !isAvatarOpen); }));
55
76
  return (_jsx(StyledSwipeableAvatar, __assign({ "data-id": dataIds.MobileNavAvatarPanel, anchor: 'bottom', open: isOpen, onClose: toggleAvatar(false), hideBackdrop: true, ModalProps: {
56
77
  keepMounted: true
57
78
  } }, { children: _jsxs(StyledBox, { children: [avatarPanelOnClickLogout && (_jsx(Button
58
79
  // @ts-expect-error
59
80
  , __assign({
60
81
  // @ts-expect-error
61
- component: animated.button, style: __assign({ left: theme.direction === 'rtl' ? theme.spacing(1) : 'auto', position: 'absolute', right: theme.direction === 'rtl' ? 'auto' : theme.spacing(1), top: theme.spacing(1) }, useStaggerAnimation(isOpen, animationCount, incrementAnimationCount)), onClick: function () {
82
+ component: animated.button, style: __assign({ left: theme.direction === 'rtl' ? theme.spacing(1) : 'auto', position: 'absolute', right: theme.direction === 'rtl' ? 'auto' : theme.spacing(1), top: theme.spacing(1) }, animationRefs.current[0]), onClick: function () {
62
83
  handleOpenState(false);
63
84
  avatarPanelOnClickLogout();
64
85
  }, startIcon: _jsx(LogoutIcon, {}), variant: 'text', color: 'inherit' }, { children: avatarPanelLogoutString !== null && avatarPanelLogoutString !== void 0 ? avatarPanelLogoutString : 'Logout' }))), _jsxs(Box, __assign({ "data-id": dataIds.MobileNavAvatarProfile, style: {
65
86
  alignItems: 'center',
66
87
  display: 'flex',
67
88
  flexDirection: 'column'
68
- } }, { children: [_jsxs(StyledBoxProfile, __assign({ style: useStaggerAnimation(isOpen, animationCount, incrementAnimationCount) }, { children: [_jsx(StyledAvatar, __assign({ style: { marginRight: '0.5rem' } }, { children: avatarInitials })), _jsxs(StyledAvatarName, { children: [_jsx("span", __assign({ style: { fontWeight: 300 } }, { children: "Hi," })), " ", _jsx("strong", { children: avatarName.split(' ')[0] })] })] })), avatarPanelOnClickViewProfile && (_jsx(StyledBoxProfileEdit, __assign({ style: __assign({ flexDirection: 'row', marginBottom: theme.spacing(1) }, useStaggerAnimation(isOpen, animationCount, incrementAnimationCount)) }, { children: _jsxs(ButtonGroup, __assign({ variant: 'outlined', "aria-label": "split button" }, { children: [_jsx(StyledOutlineButton, __assign({ variant: 'outlined', color: 'inherit', size: 'medium', onClick: function () {
89
+ } }, { children: [_jsxs(StyledBoxProfile, __assign({ style: animationRefs.current[1] }, { children: [_jsx(StyledAvatar, __assign({ style: { marginRight: '0.5rem' } }, { children: avatarInitials })), _jsxs(StyledAvatarName, { children: [_jsx("span", __assign({ style: { fontWeight: 300 } }, { children: "Hi," })), " ", _jsx("strong", { children: avatarName.split(' ')[0] })] })] })), avatarPanelOnClickViewProfile && (_jsx(StyledBoxProfileEdit, __assign({ style: __assign({ flexDirection: 'row', marginBottom: theme.spacing(1) }, animationRefs.current[2]) }, { children: _jsxs(ButtonGroup, __assign({ variant: 'outlined', "aria-label": "split button" }, { children: [_jsx(StyledOutlineButton, __assign({ variant: 'outlined', color: 'inherit', size: 'medium', onClick: function () {
69
90
  handleOpenState(false);
70
91
  avatarPanelOnClickViewProfile();
71
92
  } }, { children: avatarPanelViewProfileString !== null && avatarPanelViewProfileString !== void 0 ? avatarPanelViewProfileString : 'View Profile' })), avatarPanelOnClickEditProfile && (_jsx(StyledOutlineButton, __assign({ size: 'medium', variant: 'outlined', color: 'inherit', "aria-label": avatarPanelEditProfileString !== null && avatarPanelEditProfileString !== void 0 ? avatarPanelEditProfileString : 'Edit Profile', onClick: function () {
@@ -79,10 +100,7 @@ var SwipeableTemporaryAvatar = function (props) {
79
100
  marginInlineStart: '3rem',
80
101
  marginBottom: theme.spacing(2),
81
102
  maxWidth: '18rem'
82
- } }, { children: avatarPanelMenuItems.map(function (avatarMenuItem) { return (_jsx(ListItem, __assign({ component: animated.div, style: useStaggerAnimation(isOpen, animationCount, incrementAnimationCount),
83
- // whileHover={motionWhileHover}
84
- // whileTap={motionWhileTap}
85
- disablePadding: true }, { children: _jsxs(StyledListItemButton
103
+ } }, { children: avatarPanelMenuItems.map(function (avatarMenuItem, index) { return (_jsx(ListItem, __assign({ component: animated.div, style: animationRefs.current[index + 2], disablePadding: true }, { children: _jsxs(StyledListItemButton
86
104
  // TODO: figure out if these are links or buttons
87
105
  // @ts-expect-error
88
106
  , __assign({
@@ -97,29 +115,26 @@ var SwipeableTemporaryAvatar = function (props) {
97
115
  // @ts-expect-error
98
116
  , __assign({
99
117
  // @ts-expect-error
100
- component: animated.button, style: useStaggerAnimation(isOpen, animationCount, incrementAnimationCount), disablePadding: true, variant: 'outlined', color: 'inherit', size: 'medium', onClick: function () {
118
+ component: animated.button, style: animationRefs.current[((_b = avatarPanelMenuItems === null || avatarPanelMenuItems === void 0 ? void 0 : avatarPanelMenuItems.length) !== null && _b !== void 0 ? _b : 0) + 3], disablePadding: true, variant: 'outlined', color: 'inherit', size: 'medium', onClick: function () {
101
119
  handleOpenState(false);
102
120
  avatarPanelOnClickMainAction();
103
121
  } }, { children: avatarPanelMainActionString })), _jsxs(List, __assign({ style: { marginBottom: theme.spacing(2) } }, { children: [avatarPanelSettingItems &&
104
122
  avatarPanelSettingItems.length > 0 &&
105
- avatarPanelSettingItems.map(function (avatarMenuItem) { return (_jsx(ListItem, __assign({ component: animated.div, style: useStaggerAnimation(isOpen, animationCount, incrementAnimationCount),
106
- // whileHover={motionWhileHover}
107
- // whileTap={motionWhileTap}
108
- disablePadding: true }, { children: _jsxs(StyledListItemButton
109
- // TODO: figure out if these are links or buttons
110
- // @ts-expect-error
111
- , __assign({
123
+ avatarPanelSettingItems.map(function (avatarMenuItem, index) {
124
+ var _a;
125
+ return (_jsx(ListItem, __assign({ component: animated.div, style: animationRefs.current[((_a = avatarPanelMenuItems === null || avatarPanelMenuItems === void 0 ? void 0 : avatarPanelMenuItems.length) !== null && _a !== void 0 ? _a : 0) + index + 3], disablePadding: true }, { children: _jsxs(StyledListItemButton
112
126
  // TODO: figure out if these are links or buttons
113
127
  // @ts-expect-error
114
- component: Link, role: 'link', onClick: function () {
115
- handleOpenState(false);
116
- avatarMenuItem.onClick();
117
- } }, { children: [_jsx(ListItemIcon, __assign({ "aria-hidden": true, style: {
118
- minWidth: theme.spacing(5)
119
- } }, { children: avatarMenuItem.icon })), _jsx(ListItemText, { primary: avatarMenuItem.label })] })) }))); }), avatarPanelOnClickSwitchDirection && (_jsx(ListItem, __assign({ component: animated.div, style: useStaggerAnimation(isOpen, animationCount, incrementAnimationCount),
120
- // whileHover={motionWhileHover}
121
- // whileTap={motionWhileTap}
122
- disablePadding: true }, { children: _jsxs(StyledListItemButton
128
+ , __assign({
129
+ // TODO: figure out if these are links or buttons
130
+ // @ts-expect-error
131
+ component: Link, role: 'link', onClick: function () {
132
+ handleOpenState(false);
133
+ avatarMenuItem.onClick();
134
+ } }, { children: [_jsx(ListItemIcon, __assign({ "aria-hidden": true, style: {
135
+ minWidth: theme.spacing(5)
136
+ } }, { children: avatarMenuItem.icon })), _jsx(ListItemText, { primary: avatarMenuItem.label })] })) })));
137
+ }), avatarPanelOnClickSwitchDirection && (_jsx(ListItem, __assign({ component: animated.div, style: animationRefs.current[((_c = avatarPanelMenuItems === null || avatarPanelMenuItems === void 0 ? void 0 : avatarPanelMenuItems.length) !== null && _c !== void 0 ? _c : 0) + ((_d = avatarPanelSettingItems === null || avatarPanelSettingItems === void 0 ? void 0 : avatarPanelSettingItems.length) !== null && _d !== void 0 ? _d : 0) + 4], disablePadding: true }, { children: _jsxs(StyledListItemButton
123
138
  // TODO: figure out if these are links or buttons
124
139
  // @ts-expect-error
125
140
  , __assign({
@@ -9,6 +9,15 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
12
21
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
13
22
  import * as React from 'react';
14
23
  import { useTheme } from '@mui/material/styles';
@@ -16,7 +25,7 @@ import { List, ListItemText } from '../../../index';
16
25
  import { StyledSwipeableDrawer, StyledBox, StyledListItem, StyledDivider, StyledListSecondaryItem, StyledDrawerLogo, StyledDrawerLogoText, StyledListSecondaryList, StyledListItemText, StyledListSecondaryButton, StyledChildList, StyledChildListItem, StyledChildListItemText, StyledListItemButton, StyledChildListItemButton } from './MobileNavigationDrawerStyles';
17
26
  import { StreamSuiteLogo } from '../../../assets/Images';
18
27
  import { animated } from '@react-spring/web';
19
- import { useStaggerAnimation } from '../../../utils/helpers';
28
+ import { useFadeIn } from '../../../utils/helpers';
20
29
  import { getOffsetNavigationContrastText } from '../helpers';
21
30
  import { defaultAttributes } from '../../../utils/dataAttributes';
22
31
  export default function SwipeableTemporaryDrawer(props) {
@@ -39,33 +48,45 @@ export default function SwipeableTemporaryDrawer(props) {
39
48
  handleOpenState(open);
40
49
  };
41
50
  };
42
- // First item starts at 70ms
43
- // see STAGGER_ITEMS_DELAY in helpers.js
44
- var animationCount = 1;
45
- var incrementAnimationCount = function () { return animationCount++; };
46
- var list = function () { return (_jsxs(StyledBox, __assign({ onClick: toggleDrawer(false), onKeyDown: toggleDrawer(false) }, { children: [_jsxs(StyledDrawerLogo, __assign({ "data-id": dataIds.MobileNavDrawerBrand, onClick: logoOnClick !== null && logoOnClick !== void 0 ? logoOnClick : null, style: useStaggerAnimation(isDrawerOpen, animationCount, incrementAnimationCount) }, { children: [logo
47
- ? typeof logo === 'string'
48
- ? (_jsx("img", { height: 38, width: 38, src: logo, alt: logoText !== null && logoText !== void 0 ? logoText : 'Site Logo' }))
49
- : logo
50
- : (_jsx(StreamSuiteLogo, { style: {
51
- fill: getOffsetNavigationContrastText(theme)
52
- } })), _jsx(StyledDrawerLogoText, __assign({ variant: 'body1' }, { children: logoText !== null && logoText !== void 0 ? logoText : 'Site Logo' }))] })), _jsx(List, __assign({ "data-id": dataIds.MobileNavDrawerPrimaryList }, { children: items && items.length > 0 && items.map(function (item, index) {
53
- var label = item.label, children = item.children;
54
- return (_jsxs(StyledListItem, __assign({ "data-id": dataIds.MobileNavDrawerPrimaryItem, disablePadding: true,
55
- // @ts-expect-error
56
- component: animated.li, style: useStaggerAnimation(isDrawerOpen, animationCount, incrementAnimationCount) }, { children: [_jsx(StyledListItemButton
57
- // whileHover={{ scale: 1.02 }}
58
- // whileTap={{ scale: 0.95 }}
59
- , __assign({}, item, { children: _jsx(StyledListItemText, { primary: label }) })), children && children.length > 0 && (_jsx(StyledChildList, __assign({ "data-id": dataIds.MobileNavDrawerPrimaryChildList, "aria-label": label }, { children: children.map(function (childItem) { return (_jsx(StyledChildListItem, __assign({ "data-id": dataIds.MobileNavDrawerPrimaryChildItem }, { children: _jsx(StyledChildListItemButton
60
- // whileHover={{ scale: 1.02 }}
61
- // whileTap={{ scale: 0.95 }}
62
- , __assign({}, childItem, { children: _jsx(StyledChildListItemText, { primary: childItem.label }, childItem.label) })) }), childItem.label)); }) })))] }), label));
63
- }) })), secondaryItems && secondaryItems.length > 0 && (_jsxs(_Fragment, { children: [_jsx(animated.div, __assign({ style: useStaggerAnimation(isDrawerOpen, animationCount, incrementAnimationCount) }, { children: _jsx(StyledDivider, {}) })), _jsx(StyledListSecondaryList, __assign({ "data-id": dataIds.MobileNavDrawerSecondaryList }, { children: secondaryItems && secondaryItems.length > 0 && secondaryItems.map(function (item, index) { return (_jsx(StyledListSecondaryItem, __assign({ "data-id": dataIds.MobileNavDrawerSecondaryItem, disablePadding: true,
51
+ // Workaround to handle the react-spring calls without
52
+ // adding additional hook calls on prop or state changes
53
+ // --
54
+ // Store the total possible number of animations in a ref
55
+ // this way the number of hook calls never changes
56
+ // --
57
+ // First item starts at 70ms, see STAGGER_ITEMS_DELAY in helpers.js
58
+ var additionalItems = ['logo', 'divider'];
59
+ var totalItems = __spreadArray(__spreadArray(__spreadArray([], items !== null && items !== void 0 ? items : [], true), secondaryItems !== null && secondaryItems !== void 0 ? secondaryItems : [], true), additionalItems, true);
60
+ var animationRefs = React.useRef(totalItems && totalItems.map(function (item, index) { return useFadeIn(index, !isOpen); }));
61
+ var list = function () {
62
+ var _a;
63
+ return (_jsxs(StyledBox, __assign({ onClick: toggleDrawer(false), onKeyDown: toggleDrawer(false) }, { children: [_jsxs(StyledDrawerLogo, __assign({ "data-id": dataIds.MobileNavDrawerBrand, onClick: logoOnClick !== null && logoOnClick !== void 0 ? logoOnClick : null, style: animationRefs.current[0] }, { children: [logo
64
+ ? typeof logo === 'string'
65
+ ? (_jsx("img", { height: 38, width: 38, src: logo, alt: logoText !== null && logoText !== void 0 ? logoText : 'Site Logo' }))
66
+ : logo
67
+ : (_jsx(StreamSuiteLogo, { style: {
68
+ fill: getOffsetNavigationContrastText(theme)
69
+ } })), _jsx(StyledDrawerLogoText, __assign({ variant: 'body1' }, { children: logoText !== null && logoText !== void 0 ? logoText : 'Site Logo' }))] })), _jsx(List, __assign({ "data-id": dataIds.MobileNavDrawerPrimaryList }, { children: items && items.length > 0 && items.map(function (item, index) {
70
+ var label = item.label, children = item.children;
71
+ return (_jsxs(StyledListItem, __assign({ "data-id": dataIds.MobileNavDrawerPrimaryItem, disablePadding: true,
64
72
  // @ts-expect-error
65
- component: animated.li, style: useStaggerAnimation(isDrawerOpen, animationCount, incrementAnimationCount) }, { children: _jsx(StyledListSecondaryButton
66
- // whileHover={{ scale: 1.02 }}
67
- // whileTap={{ scale: 0.95, boxShadow: '0 6px 15px rgb(36 37 38 / 0%);' }}
68
- , __assign({}, item, { children: _jsx(ListItemText, { primary: item.label }) })) }), item.label)); }) }))] }))] }))); };
73
+ component: animated.li, style: animationRefs.current[index] }, { children: [_jsx(StyledListItemButton
74
+ // whileHover={{ scale: 1.02 }}
75
+ // whileTap={{ scale: 0.95 }}
76
+ , __assign({}, item, { children: _jsx(StyledListItemText, { primary: label }) })), children && children.length > 0 && (_jsx(StyledChildList, __assign({ "data-id": dataIds.MobileNavDrawerPrimaryChildList, "aria-label": label }, { children: children.map(function (childItem) { return (_jsx(StyledChildListItem, __assign({ "data-id": dataIds.MobileNavDrawerPrimaryChildItem }, { children: _jsx(StyledChildListItemButton
77
+ // whileHover={{ scale: 1.02 }}
78
+ // whileTap={{ scale: 0.95 }}
79
+ , __assign({}, childItem, { children: _jsx(StyledChildListItemText, { primary: childItem.label }, childItem.label) })) }), childItem.label)); }) })))] }), label));
80
+ }) })), secondaryItems && secondaryItems.length > 0 && (_jsxs(_Fragment, { children: [_jsx(animated.div, __assign({ style: animationRefs.current[((_a = items === null || items === void 0 ? void 0 : items.length) !== null && _a !== void 0 ? _a : 0) + 1] }, { children: _jsx(StyledDivider, {}) })), _jsx(StyledListSecondaryList, __assign({ "data-id": dataIds.MobileNavDrawerSecondaryList }, { children: secondaryItems && secondaryItems.length > 0 && secondaryItems.map(function (item, index) {
81
+ var _a;
82
+ return (_jsx(StyledListSecondaryItem, __assign({ "data-id": dataIds.MobileNavDrawerSecondaryItem, disablePadding: true,
83
+ // @ts-expect-error
84
+ component: animated.li, style: animationRefs.current[((_a = items === null || items === void 0 ? void 0 : items.length) !== null && _a !== void 0 ? _a : 0) + index + 2] }, { children: _jsx(StyledListSecondaryButton
85
+ // whileHover={{ scale: 1.02 }}
86
+ // whileTap={{ scale: 0.95, boxShadow: '0 6px 15px rgb(36 37 38 / 0%);' }}
87
+ , __assign({}, item, { children: _jsx(ListItemText, { primary: item.label }) })) }), item.label));
88
+ }) }))] }))] })));
89
+ };
69
90
  return (_jsx("aside", { children: _jsx(StyledSwipeableDrawer, __assign({ "data-id": dataIds.MobileNavDrawerPanel, anchor: 'bottom', open: isOpen, onClose: toggleDrawer(false), hideBackdrop: true, ModalProps: {
70
91
  keepMounted: true
71
92
  } }, { children: list() })) }));
@@ -20,6 +20,15 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  }
21
21
  return t;
22
22
  };
23
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
24
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
25
+ if (ar || !(i in from)) {
26
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
27
+ ar[i] = from[i];
28
+ }
29
+ }
30
+ return to.concat(ar || Array.prototype.slice.call(from));
31
+ };
23
32
  import { createElement as _createElement } from "react";
24
33
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
25
34
  import React, { useEffect } from 'react';
@@ -64,6 +73,11 @@ var VerticalNavigation = function (props) {
64
73
  var logoWidth = 38;
65
74
  useEffect(function () { return setIsDrawerOpen(propIsDrawerOpen !== null && propIsDrawerOpen !== void 0 ? propIsDrawerOpen : false); }, [propIsDrawerOpen]);
66
75
  useEffect(function () { return setIsDrawerOpen(propIsPersistent !== null && propIsPersistent !== void 0 ? propIsPersistent : false); }, [propIsPersistent]);
76
+ useEffect(function () {
77
+ if (!avatarName || !hasAvatar) {
78
+ setIsAvatarOpen(false);
79
+ }
80
+ }, [avatarName, hasAvatar]);
67
81
  // This fixes an issue with how MUI handles the modal and aria-hidden.
68
82
  // When open, the Modal adds aria-hidden="true" to a top-level element,
69
83
  // which causes some screen readers to annouce the elements as "blank".
@@ -95,113 +109,125 @@ var VerticalNavigation = function (props) {
95
109
  setIsAppSwitcherOpen(false);
96
110
  setIsDrawerOpen(open !== null && open !== void 0 ? open : !isDrawerOpen);
97
111
  }; };
98
- // First item starts at 70ms
99
- // see STAGGER_ITEMS_DELAY in helpers.js
100
- var animationCount = 1;
101
- var incrementAnimationCount = function () { return animationCount++; };
102
- var listContent = function () { return (_jsxs(Box, __assign({ sx: {
103
- display: 'flex',
104
- flex: '1 auto',
105
- flexDirection: 'column',
106
- justifyContent: 'flex-start',
107
- '.wrapper': {
112
+ // Workaround to handle the react-spring calls without
113
+ // adding additional hook calls on prop or state changes
114
+ // --
115
+ // Store the total possible number of animations in a ref
116
+ // this way the number of hook calls never changes
117
+ // --
118
+ // First item starts at 70ms, see STAGGER_ITEMS_DELAY in helpers.js
119
+ var additionalItems = ['hasStreamHome', 'hasAvatar', 'avatarName'];
120
+ var totalItems = __spreadArray(__spreadArray(__spreadArray([], items !== null && items !== void 0 ? items : [], true), secondaryItems !== null && secondaryItems !== void 0 ? secondaryItems : [], true), additionalItems, true);
121
+ var animationRefs = React.useRef(totalItems && totalItems.map(function (item, index) { return useFadeIn(index); }));
122
+ var listContent = function () {
123
+ var _a, _b, _c;
124
+ return (_jsxs(Box, __assign({ sx: {
108
125
  display: 'flex',
109
- position: 'relative'
110
- },
111
- '.wrapper > :not(:first-of-type)': {
112
- position: 'absolute',
113
- right: 0,
114
- background: 'transparent',
115
- fontSize: 0
116
- }
117
- }, className: 'grid-container' }, { children: [_jsx("div", __assign({ className: 'wrapper', style: { backgroundColor: getNavigationBackground(theme) }, "data-id": dataIds.VerticalNavigationBrand }, { children: _jsxs(DrawerHeader, __assign({ onClick: logoOnClick !== null && logoOnClick !== void 0 ? logoOnClick : null, isDrawerOpen: isDrawerOpen || isPersistent, style: useFadeIn(animationCount, incrementAnimationCount) }, { children: [_jsx(Tooltip, __assign({ disableHoverListener: isDrawerOpen || isPersistent, disableFocusListener: isDrawerOpen || isPersistent, disableTouchListener: isDrawerOpen || isPersistent, title: logoText !== null && logoText !== void 0 ? logoText : '', placement: theme.direction === 'rtl' ? 'left' : 'right' }, { children: logo
118
- ? typeof logo === 'string'
119
- ? (_jsx("img", { src: logo, height: "".concat(logoHeight, "px"), width: "".concat(logoWidth, "px"), style: {
120
- marginInlineEnd: '16px'
121
- }, alt: logoText !== null && logoText !== void 0 ? logoText : messages['site-logo'] }))
122
- : logo
123
- : (_jsx(StreamSuiteLogo, { style: {
124
- height: "".concat(logoHeight, "px"),
125
- width: "".concat(logoWidth, "px"),
126
- marginInlineEnd: '16px',
127
- fill: getNavigationContrastText(theme)
128
- } })) })), _jsx(ListItemText, { primary: logoText !== null && logoText !== void 0 ? logoText : '', isDrawerOpen: isDrawerOpen || isPersistent })] })) })), _jsxs("div", __assign({ className: 'wrapper', "data-id": dataIds.VerticalNavigationToggle }, { children: [_jsxs(NotchContainer, __assign({ sx: { height: '85px', position: 'relative !important' } }, { children: [_jsx(NotchBackground, {}), !isPersistent && _jsx(NotchBackgroundClip, {}), _jsx(NotchSeemMask, {})] })), !isPersistent && _jsx(DrawerToggle, __assign({ onClick: toggleDrawer(!isDrawerOpen), "aria-label": isDrawerOpen ? messages['close-navigation'] : messages['open-navigation'], "aria-expanded": isDrawerOpen ? 'true' : 'false', "aria-controls": "vertical-navigation", isDrawerOpen: isDrawerOpen,
129
- // @ts-expect-error
130
- component: animated.button, style: useFadeIn(animationCount, incrementAnimationCount) }, { children: _jsx(DrawerToggleHitboxContent, { children: isDrawerOpen
131
- ? (_jsx(ChevronLeft, { style: {
132
- fill: getNavigationContrastText(theme),
133
- fontSize: '1.75rem',
134
- height: '1.75rem',
135
- width: '1.75rem'
136
- } }))
137
- : (_jsx(ChevronRight, { style: {
138
- fill: getNavigationContrastText(theme),
139
- fontSize: '1.75rem',
140
- height: '1.75rem',
141
- width: '1.75rem'
142
- } })) }) })), _jsx(Box, { style: {
143
- borderRadius: '50%',
144
- boxShadow: '5px 0 15px 0 rgb(0 0 0 / 10%)',
145
- display: 'none',
146
- height: '50px',
147
- left: '12px',
148
- position: 'fixed',
149
- right: 'auto !important',
150
- top: '50%',
151
- transform: 'translate(50%, -50%)',
152
- width: '50px'
153
- } }), _jsxs(DrawerToggle, __assign({ onClick: handleIsPersistent, "aria-label": isDrawerOpen ? messages['close-navigation'] : messages['open-navigation'], "aria-expanded": isDrawerOpen ? 'true' : 'false', "aria-controls": "vertical-navigation", style: {
154
- display: 'none',
155
- position: 'fixed',
156
- top: '50%',
157
- transform: 'translate(50%, -50%)',
158
- zIndex: 10
159
- } }, { children: [_jsx(NotchExtendSVG, { style: {
160
- display: 'block',
161
- fill: getNavigationBackground(theme),
162
- height: '165px',
163
- left: '-12px',
164
- padding: '0',
165
- position: 'absolute',
166
- top: '-61px',
167
- transition: 'none',
168
- width: '90px',
169
- zIndex: '-1'
170
- } }), _jsx(DrawerToggleHitboxContent, __assign({ style: {
171
- background: 'transparent',
172
- boxShadow: 'none',
173
- fontSize: '1.3rem',
174
- height: '1.3rem',
175
- padding: theme.spacing(1),
176
- width: '1.3rem'
177
- } }, { children: isPersistent
178
- ? (_jsx(PushPin, { style: {
179
- fontSize: '1.3rem',
180
- height: '1.3rem',
181
- width: '1.3rem'
126
+ flex: '1 auto',
127
+ flexDirection: 'column',
128
+ justifyContent: 'flex-start',
129
+ '.wrapper': {
130
+ display: 'flex',
131
+ position: 'relative'
132
+ },
133
+ '.wrapper > :not(:first-of-type)': {
134
+ position: 'absolute',
135
+ right: 0,
136
+ background: 'transparent',
137
+ fontSize: 0
138
+ }
139
+ }, className: 'grid-container' }, { children: [_jsx("div", __assign({ className: 'wrapper', style: { backgroundColor: getNavigationBackground(theme) }, "data-id": dataIds.VerticalNavigationBrand }, { children: _jsxs(DrawerHeader, __assign({ onClick: logoOnClick !== null && logoOnClick !== void 0 ? logoOnClick : null, isDrawerOpen: isDrawerOpen || isPersistent, style: animationRefs.current[0] }, { children: [_jsx(Tooltip, __assign({ disableHoverListener: isDrawerOpen || isPersistent, disableFocusListener: isDrawerOpen || isPersistent, disableTouchListener: isDrawerOpen || isPersistent, title: logoText !== null && logoText !== void 0 ? logoText : '', placement: theme.direction === 'rtl' ? 'left' : 'right' }, { children: logo
140
+ ? typeof logo === 'string'
141
+ ? (_jsx("img", { src: logo, height: "".concat(logoHeight, "px"), width: "".concat(logoWidth, "px"), style: {
142
+ marginInlineEnd: '16px'
143
+ }, alt: logoText !== null && logoText !== void 0 ? logoText : messages['site-logo'] }))
144
+ : logo
145
+ : (_jsx(StreamSuiteLogo, { style: {
146
+ height: "".concat(logoHeight, "px"),
147
+ width: "".concat(logoWidth, "px"),
148
+ marginInlineEnd: '16px',
149
+ fill: getNavigationContrastText(theme)
150
+ } })) })), _jsx(ListItemText, { primary: logoText !== null && logoText !== void 0 ? logoText : '', isDrawerOpen: isDrawerOpen || isPersistent })] })) })), _jsxs("div", __assign({ className: 'wrapper', "data-id": dataIds.VerticalNavigationToggle }, { children: [_jsxs(NotchContainer, __assign({ sx: { height: '85px', position: 'relative !important' } }, { children: [_jsx(NotchBackground, {}), !isPersistent && _jsx(NotchBackgroundClip, {}), _jsx(NotchSeemMask, {})] })), !isPersistent && _jsx(DrawerToggle, __assign({ onClick: toggleDrawer(!isDrawerOpen), "aria-label": isDrawerOpen ? messages['close-navigation'] : messages['open-navigation'], "aria-expanded": isDrawerOpen ? 'true' : 'false', "aria-controls": "vertical-navigation", isDrawerOpen: isDrawerOpen,
151
+ // @ts-expect-error
152
+ component: animated.button, style: animationRefs.current[0] }, { children: _jsx(DrawerToggleHitboxContent, { children: isDrawerOpen
153
+ ? (_jsx(ChevronLeft, { style: {
154
+ fill: getNavigationContrastText(theme),
155
+ fontSize: '1.75rem',
156
+ height: '1.75rem',
157
+ width: '1.75rem'
182
158
  } }))
183
- : (_jsx(PushPin, { style: {
184
- fontSize: '1.3rem',
185
- height: '1.3rem',
186
- width: '1.3rem'
187
- } })) }))] }))] })), _jsx(NotchSVG, { style: { height: '0', position: 'absolute', width: '0' } }), _jsx("div", __assign({ className: 'wrapper', "data-id": dataIds.VerticalNavigationPrimary, style: {
188
- backgroundColor: getNavigationBackground(theme),
189
- flex: '1 1px',
190
- marginTop: '-1px',
191
- overflow: 'auto',
192
- position: 'relative',
193
- zIndex: 10
194
- } }, { children: _jsx(StyledNav, __assign({ tabIndex: -1, "aria-label": 'Primary' }, { children: _jsx(List, __assign({ "data-id": dataIds.VerticalNavigationPrimaryList, style: {
195
- height: '100%',
196
- width: DRAWER_WIDTH.Expanded,
197
- marginTop: "-".concat(theme.spacing(0.5), " !important")
198
- } }, { children: items && items.length > 0 && items.map(function (item, index) { return (_createElement(VerticalNavigationItem, __assign({}, item, { "data-id": dataIds.VerticalNavigationPrimaryListItem, key: "".concat(item.label, " - ").concat(index), index: index, isDrawerOpen: isDrawerOpen || isPersistent, style: useFadeIn(animationCount, incrementAnimationCount) }))); }) })) })) })), _jsx("div", __assign({ className: 'wrapper', "data-id": dataIds.VerticalNavigationSecondary, style: { backgroundColor: getNavigationBackground(theme) } }, { children: _jsxs(StyledNavSecondary, __assign({ "aria-label": 'Secondary' }, { children: [_jsx(StyledDivider, { isDrawerOpen: isDrawerOpen || isPersistent }), _jsxs(List, __assign({ "data-id": dataIds.VerticalNavigationSecondaryList, style: { width: DRAWER_WIDTH.Expanded } }, { children: [hasStreamHome
199
- ? (_jsx(VerticalNavigationItem, { "data-id": dataIds.VerticalNavigationAppSwitcherToggle, label: messages['app-switcher'], icon: _jsx(Apps, {}), onClick: handleToggleAppsClick, content: (_jsx(AppSwitcher, { isAppSwitcherOpen: isAppSwitcherOpen, setIsAppSwitcherOpen: setIsAppSwitcherOpen, applications: streamHomeApplications, apiKey: streamHomeApiKey !== null && streamHomeApiKey !== void 0 ? streamHomeApiKey : '', baseUrl: streamHomeBaseUrl !== null && streamHomeBaseUrl !== void 0 ? streamHomeBaseUrl : '', token: streamHomeAccessToken !== null && streamHomeAccessToken !== void 0 ? streamHomeAccessToken : '', isDrawerOpen: isDrawerOpen })), isDrawerOpen: isDrawerOpen || isPersistent, isSecondary: true, hasCustomContent: true, style: useFadeIn(animationCount, incrementAnimationCount) }))
200
- : null, secondaryItems && secondaryItems.length > 0 && secondaryItems.map(function (item, index) { return (_createElement(VerticalNavigationItem, __assign({}, item, { "data-id": dataIds.VerticalNavigationSecondaryListItem, key: "".concat(item.label, " - ").concat(index), index: index, isDrawerOpen: isDrawerOpen || isPersistent, isSecondary: true, style: useFadeIn(animationCount, incrementAnimationCount) }))); }), hasAvatar && avatarName && (_jsx(VerticalNavigationItem, { label: avatarName, "data-id": dataIds.VerticalNavigationAvatarToggle, "aria-controls": 'avatar-panel', icon: _jsx(Avatar, __assign({ style: {
201
- fontSize: '0.75rem',
202
- height: 32,
203
- width: 32
204
- } }, { children: handleAvatarInitials(avatarName) })), style: __assign({ maxHeight: isDrawerOpen ? '200px' : '48px', overflow: 'hidden', padding: 0, minHeight: 52, transition: "max-height 225ms ".concat(motion.easeInOut, " 0ms !important") }, useFadeIn(animationCount, incrementAnimationCount)), onClick: function () { return setIsAvatarOpen(!isAvatarOpen); }, hasFlyout: true, fullHeightFlyout: true, content: _jsx(AvatarPanel, __assign({ avatarName: avatarName, isAvatarOpen: isAvatarOpen, localization: localization }, rest)), isDrawerOpen: isDrawerOpen }))] }))] })) }))] }))); };
159
+ : (_jsx(ChevronRight, { style: {
160
+ fill: getNavigationContrastText(theme),
161
+ fontSize: '1.75rem',
162
+ height: '1.75rem',
163
+ width: '1.75rem'
164
+ } })) }) })), _jsx(Box, { style: {
165
+ borderRadius: '50%',
166
+ boxShadow: '5px 0 15px 0 rgb(0 0 0 / 10%)',
167
+ display: 'none',
168
+ height: '50px',
169
+ left: '12px',
170
+ position: 'fixed',
171
+ right: 'auto !important',
172
+ top: '50%',
173
+ transform: 'translate(50%, -50%)',
174
+ width: '50px'
175
+ } }), _jsxs(DrawerToggle, __assign({ onClick: handleIsPersistent, "aria-label": isDrawerOpen ? messages['close-navigation'] : messages['open-navigation'], "aria-expanded": isDrawerOpen ? 'true' : 'false', "aria-controls": "vertical-navigation", style: {
176
+ display: 'none',
177
+ position: 'fixed',
178
+ top: '50%',
179
+ transform: 'translate(50%, -50%)',
180
+ zIndex: 10
181
+ } }, { children: [_jsx(NotchExtendSVG, { style: {
182
+ display: 'block',
183
+ fill: getNavigationBackground(theme),
184
+ height: '165px',
185
+ left: '-12px',
186
+ padding: '0',
187
+ position: 'absolute',
188
+ top: '-61px',
189
+ transition: 'none',
190
+ width: '90px',
191
+ zIndex: '-1'
192
+ } }), _jsx(DrawerToggleHitboxContent, __assign({ style: {
193
+ background: 'transparent',
194
+ boxShadow: 'none',
195
+ fontSize: '1.3rem',
196
+ height: '1.3rem',
197
+ padding: theme.spacing(1),
198
+ width: '1.3rem'
199
+ } }, { children: isPersistent
200
+ ? (_jsx(PushPin, { style: {
201
+ fontSize: '1.3rem',
202
+ height: '1.3rem',
203
+ width: '1.3rem'
204
+ } }))
205
+ : (_jsx(PushPin, { style: {
206
+ fontSize: '1.3rem',
207
+ height: '1.3rem',
208
+ width: '1.3rem'
209
+ } })) }))] }))] })), _jsx(NotchSVG, { style: { height: '0', position: 'absolute', width: '0' } }), _jsx("div", __assign({ className: 'wrapper', "data-id": dataIds.VerticalNavigationPrimary, style: {
210
+ backgroundColor: getNavigationBackground(theme),
211
+ flex: '1 1px',
212
+ marginTop: '-1px',
213
+ overflow: 'auto',
214
+ position: 'relative',
215
+ zIndex: 10
216
+ } }, { children: _jsx(StyledNav, __assign({ tabIndex: -1, "aria-label": 'Primary' }, { children: _jsx(List, __assign({ "data-id": dataIds.VerticalNavigationPrimaryList, style: {
217
+ height: '100%',
218
+ width: DRAWER_WIDTH.Expanded,
219
+ marginTop: "-".concat(theme.spacing(0.5), " !important")
220
+ } }, { children: items && items.length > 0 && items.map(function (item, index) { return (_createElement(VerticalNavigationItem, __assign({}, item, { "data-id": dataIds.VerticalNavigationPrimaryListItem, key: "".concat(item.label, " - ").concat(index), index: index, isDrawerOpen: isDrawerOpen || isPersistent, style: animationRefs.current[index] }))); }) })) })) })), _jsx("div", __assign({ className: 'wrapper', "data-id": dataIds.VerticalNavigationSecondary, style: { backgroundColor: getNavigationBackground(theme) } }, { children: _jsxs(StyledNavSecondary, __assign({ "aria-label": 'Secondary' }, { children: [_jsx(StyledDivider, { isDrawerOpen: isDrawerOpen || isPersistent }), _jsxs(List, __assign({ "data-id": dataIds.VerticalNavigationSecondaryList, style: { width: DRAWER_WIDTH.Expanded } }, { children: [hasStreamHome
221
+ ? (_jsx(VerticalNavigationItem, { "data-id": dataIds.VerticalNavigationAppSwitcherToggle, label: messages['app-switcher'], icon: _jsx(Apps, {}), onClick: handleToggleAppsClick, content: (_jsx(AppSwitcher, { isAppSwitcherOpen: isAppSwitcherOpen, setIsAppSwitcherOpen: setIsAppSwitcherOpen, applications: streamHomeApplications, apiKey: streamHomeApiKey !== null && streamHomeApiKey !== void 0 ? streamHomeApiKey : '', baseUrl: streamHomeBaseUrl !== null && streamHomeBaseUrl !== void 0 ? streamHomeBaseUrl : '', token: streamHomeAccessToken !== null && streamHomeAccessToken !== void 0 ? streamHomeAccessToken : '', isDrawerOpen: isDrawerOpen })), isDrawerOpen: isDrawerOpen || isPersistent, isSecondary: true, hasCustomContent: true, style: animationRefs.current[((_a = items === null || items === void 0 ? void 0 : items.length) !== null && _a !== void 0 ? _a : 0) + 1] }))
222
+ : null, secondaryItems && secondaryItems.length > 0 && secondaryItems.map(function (item, index) {
223
+ var _a;
224
+ return (_createElement(VerticalNavigationItem, __assign({}, item, { "data-id": dataIds.VerticalNavigationSecondaryListItem, key: "".concat(item.label, " - ").concat(index), index: index, isDrawerOpen: isDrawerOpen || isPersistent, isSecondary: true, style: animationRefs.current[((_a = items === null || items === void 0 ? void 0 : items.length) !== null && _a !== void 0 ? _a : 0) + index + 1] })));
225
+ }), hasAvatar && avatarName && (_jsx(VerticalNavigationItem, { label: avatarName, "data-id": dataIds.VerticalNavigationAvatarToggle, "aria-controls": 'avatar-panel', icon: _jsx(Avatar, __assign({ style: {
226
+ fontSize: '0.75rem',
227
+ height: 32,
228
+ width: 32
229
+ } }, { children: handleAvatarInitials(avatarName) })), style: __assign({ maxHeight: isDrawerOpen ? '200px' : '48px', overflow: 'hidden', padding: 0, minHeight: 52, transition: "max-height 225ms ".concat(motion.easeInOut, " 0ms !important") }, animationRefs.current[((_b = items === null || items === void 0 ? void 0 : items.length) !== null && _b !== void 0 ? _b : 0) + ((_c = secondaryItems === null || secondaryItems === void 0 ? void 0 : secondaryItems.length) !== null && _c !== void 0 ? _c : 0) + 2]), onClick: function () { return setIsAvatarOpen(!isAvatarOpen); }, hasFlyout: true, fullHeightFlyout: true, content: _jsx(AvatarPanel, __assign({ avatarName: avatarName, isAvatarOpen: isAvatarOpen, localization: localization }, rest)), isDrawerOpen: isDrawerOpen }))] }))] })) }))] })));
230
+ };
205
231
  return (_jsxs(StyledAside, __assign({ "aria-label": messages['site-navigation'], "data-id": dataIds.VerticalNavigationContainer }, { children: [_jsx(DrawerShadow, { className: 'drawerShadow', "aria-hidden": 'true', isDrawerOpen: isDrawerOpen || isPersistent, style: {
206
232
  display: isPersistent ? 'none' : 'block'
207
233
  } }), _jsx(Modal, __assign({ "aria-hidden": false, keepMounted: true, disablePortal: true, open: isDrawerOpen, onClose: toggleDrawer(false) }, { children: _jsx(StyledDrawer, __assign({ id: 'vertical-navigation', anchor: 'left', open: isDrawerOpen || isPersistent, onClose: toggleDrawer(false), variant: 'permanent' }, { children: listContent() })) }))] })));
@@ -9,6 +9,15 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
12
21
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
22
  import React, { useEffect } from 'react';
14
23
  import { Box, Link, List, ListItem, ListItemIcon, ListItemText } from '../../../index';
@@ -16,14 +25,14 @@ import { StyledBox, StyledBoxProfile, StyledButton, StyledAvatarName, StyledAvat
16
25
  import { useTheme } from '@mui/material/styles';
17
26
  import EditIcon from '@mui/icons-material/Edit';
18
27
  import LogoutIcon from '@mui/icons-material/Logout';
19
- import { handleAvatarInitials, useStaggerAnimation } from '../../../utils/helpers';
28
+ import { handleAvatarInitials, useFadeIn } from '../../../utils/helpers';
20
29
  import { Person, Settings } from '@mui/icons-material';
21
30
  import { animated } from '@react-spring/web';
22
31
  import { FlyoutMenuItemText } from './VerticalNavigationItem/VerticalNavigationItemFlyoutMenuStyles';
23
32
  import { defaultMessages } from '../../../lang/en-us';
24
33
  import { defaultAttributes } from '../../../utils/dataAttributes';
25
34
  var AvatarPanel = function (props) {
26
- var _a;
35
+ var _a, _b, _c, _d;
27
36
  var theme = useTheme();
28
37
  var avatarName = props.avatarName, avatarPanelOnClickLogout = props.avatarPanelOnClickLogout, avatarPanelLogoutString = props.avatarPanelLogoutString, avatarPanelOnClickViewProfile = props.avatarPanelOnClickViewProfile, avatarPanelViewProfileString = props.avatarPanelViewProfileString, avatarPanelOnClickEditProfile = props.avatarPanelOnClickEditProfile, avatarPanelEditProfileString = props.avatarPanelEditProfileString, avatarPanelMenuItems = props.avatarPanelMenuItems, avatarPanelOnClickMainAction = props.avatarPanelOnClickMainAction, avatarPanelMainActionString = props.avatarPanelMainActionString, avatarPanelSettingItems = props.avatarPanelSettingItems, avatarPanelFootnote = props.avatarPanelFootnote, isAvatarOpen = props.isAvatarOpen, localization = props.localization, dataAttributes = props.dataAttributes;
29
38
  var messages = __assign(__assign({}, defaultMessages), localization);
@@ -31,27 +40,39 @@ var AvatarPanel = function (props) {
31
40
  useEffect(function () {
32
41
  setAvatarInitials(handleAvatarInitials(avatarName));
33
42
  }, [avatarName]);
34
- var _b = React.useState((_a = handleAvatarInitials(avatarName)) !== null && _a !== void 0 ? _a : 'AN'), avatarInitials = _b[0], setAvatarInitials = _b[1];
35
- // First item starts at 70ms
36
- // see STAGGER_ITEMS_DELAY in helpers.js
37
- var animationCount = 1;
38
- var incrementAnimationCount = function () { return animationCount++; };
43
+ var _e = React.useState((_a = handleAvatarInitials(avatarName)) !== null && _a !== void 0 ? _a : 'AN'), avatarInitials = _e[0], setAvatarInitials = _e[1];
44
+ // Workaround to handle the react-spring calls without
45
+ // adding additional hook calls on prop or state changes
46
+ // --
47
+ // Store the total possible number of animations in a ref
48
+ // this way the number of hook calls never changes
49
+ // --
50
+ // First item starts at 70ms, see STAGGER_ITEMS_DELAY in helpers.js
51
+ var additionalItems = [
52
+ 'avatarPanelOnClickLogout',
53
+ 'avatarName',
54
+ 'avatarPanelOnClickViewProfile',
55
+ 'avatarPanelOnClickMainAction',
56
+ 'avatarPanelFootnote'
57
+ ];
58
+ var totalItems = __spreadArray(__spreadArray(__spreadArray([], avatarPanelMenuItems !== null && avatarPanelMenuItems !== void 0 ? avatarPanelMenuItems : [], true), avatarPanelSettingItems !== null && avatarPanelSettingItems !== void 0 ? avatarPanelSettingItems : [], true), additionalItems, true);
59
+ var animationRefs = React.useRef(totalItems && totalItems.map(function (item, index) { return useFadeIn(index, !isAvatarOpen); }));
39
60
  return (_jsxs(StyledBox, { children: [avatarPanelOnClickLogout && (_jsx(StyledButton
40
61
  // @ts-expect-error
41
62
  , __assign({
42
63
  // @ts-expect-error
43
- component: animated.button, style: __assign({ left: theme.direction === 'rtl' ? theme.spacing(1) : 'auto', position: 'absolute', right: theme.direction === 'rtl' ? 'auto' : theme.spacing(1), top: theme.spacing(1) }, useStaggerAnimation(isAvatarOpen, animationCount, incrementAnimationCount)), onClick: avatarPanelOnClickLogout, startIcon: _jsx(LogoutIcon, {}), variant: 'text', color: 'inherit' }, { children: avatarPanelLogoutString !== null && avatarPanelLogoutString !== void 0 ? avatarPanelLogoutString : messages.logout }))), _jsxs(Box, __assign({ "data-id": dataIds.VerticalNavigationAvatarProfile, style: {
64
+ component: animated.button, style: __assign({ left: theme.direction === 'rtl' ? theme.spacing(1) : 'auto', position: 'absolute', right: theme.direction === 'rtl' ? 'auto' : theme.spacing(1), top: theme.spacing(1) }, animationRefs.current[0]), onClick: avatarPanelOnClickLogout, startIcon: _jsx(LogoutIcon, {}), variant: 'text', color: 'inherit' }, { children: avatarPanelLogoutString !== null && avatarPanelLogoutString !== void 0 ? avatarPanelLogoutString : messages.logout }))), _jsxs(Box, __assign({ "data-id": dataIds.VerticalNavigationAvatarProfile, style: {
44
65
  alignItems: 'center',
45
66
  display: 'flex',
46
67
  flexDirection: 'column'
47
- } }, { children: [_jsxs(StyledBoxProfile, __assign({ style: useStaggerAnimation(isAvatarOpen, animationCount, incrementAnimationCount) }, { children: [_jsx(StyledAvatar, __assign({ style: { marginInlineEnd: '0.5rem' } }, { children: avatarInitials })), _jsxs(StyledAvatarName, { children: [_jsx("span", __assign({ style: { fontWeight: 300 } }, { children: messages.greeting })), " ", _jsx("strong", { children: avatarName.split(' ')[0] })] })] })), avatarPanelOnClickViewProfile && (_jsx(StyledBoxProfileEdit, __assign({ style: __assign({ marginBottom: theme.spacing(2) }, useStaggerAnimation(isAvatarOpen, animationCount, incrementAnimationCount)) }, { children: _jsxs(StyledButtonGroup, __assign({ variant: 'outlined', "aria-label": "split button" }, { children: [_jsx(StyledButton, __assign({ variant: 'outlined', color: 'inherit', size: 'medium', onClick: avatarPanelOnClickViewProfile, startIcon: _jsx(Person, {}) }, { children: avatarPanelViewProfileString !== null && avatarPanelViewProfileString !== void 0 ? avatarPanelViewProfileString : messages['view-profile'] })), avatarPanelOnClickEditProfile && (_jsx(StyledButton, __assign({ variant: 'outlined', color: 'inherit', size: 'medium', "aria-label": avatarPanelEditProfileString !== null && avatarPanelEditProfileString !== void 0 ? avatarPanelEditProfileString : messages['edit-profile'], onClick: avatarPanelOnClickEditProfile }, { children: _jsx(EditIcon, {}) })))] })) })))] })), _jsxs(Box, __assign({ style: {
68
+ } }, { children: [_jsxs(StyledBoxProfile, __assign({ style: animationRefs.current[1] }, { children: [_jsx(StyledAvatar, __assign({ style: { marginInlineEnd: '0.5rem' } }, { children: avatarInitials })), _jsxs(StyledAvatarName, { children: [_jsx("span", __assign({ style: { fontWeight: 300 } }, { children: messages.greeting })), " ", _jsx("strong", { children: avatarName.split(' ')[0] })] })] })), avatarPanelOnClickViewProfile && (_jsx(StyledBoxProfileEdit, __assign({ style: __assign({ marginBottom: theme.spacing(2) }, animationRefs.current[2]) }, { children: _jsxs(StyledButtonGroup, __assign({ variant: 'outlined', "aria-label": "split button" }, { children: [_jsx(StyledButton, __assign({ variant: 'outlined', color: 'inherit', size: 'medium', onClick: avatarPanelOnClickViewProfile, startIcon: _jsx(Person, {}) }, { children: avatarPanelViewProfileString !== null && avatarPanelViewProfileString !== void 0 ? avatarPanelViewProfileString : messages['view-profile'] })), avatarPanelOnClickEditProfile && (_jsx(StyledButton, __assign({ variant: 'outlined', color: 'inherit', size: 'medium', "aria-label": avatarPanelEditProfileString !== null && avatarPanelEditProfileString !== void 0 ? avatarPanelEditProfileString : messages['edit-profile'], onClick: avatarPanelOnClickEditProfile }, { children: _jsx(EditIcon, {}) })))] })) })))] })), _jsxs(Box, __assign({ style: {
48
69
  alignItems: 'center',
49
70
  display: 'flex',
50
71
  flexDirection: 'column'
51
72
  } }, { children: [avatarPanelMenuItems && avatarPanelMenuItems.length > 0 && (_jsx(List, __assign({ "data-id": dataIds.VerticalNavigationFlyoutList, style: {
52
73
  marginBottom: theme.spacing(2),
53
74
  maxWidth: '14rem'
54
- } }, { children: avatarPanelMenuItems.map(function (avatarMenuItem, index) { return (_jsx(ListItem, __assign({ "data-id": dataIds.VerticalNavigationFlyoutListItem, component: animated.div, style: useStaggerAnimation(isAvatarOpen, animationCount, incrementAnimationCount), disablePadding: true }, { children: _jsxs(StyledListItemButton
75
+ } }, { children: avatarPanelMenuItems.map(function (avatarMenuItem, index) { return (_jsx(ListItem, __assign({ "data-id": dataIds.VerticalNavigationFlyoutListItem, component: animated.div, style: animationRefs.current[index + 2], disablePadding: true }, { children: _jsxs(StyledListItemButton
55
76
  // TODO: figure out if these are links or buttons
56
77
  // @ts-expect-error
57
78
  , __assign({
@@ -61,16 +82,19 @@ var AvatarPanel = function (props) {
61
82
  // @ts-expect-error
62
83
  , __assign({
63
84
  // @ts-expect-error
64
- component: animated.button, style: useStaggerAnimation(isAvatarOpen, animationCount, incrementAnimationCount), variant: 'outlined', color: 'inherit', size: 'medium', onClick: avatarPanelOnClickMainAction, startIcon: _jsx(Settings, {}) }, { children: avatarPanelMainActionString })), _jsx(List, __assign({ "data-id": dataIds.VerticalNavigationFlyoutList, style: { marginBottom: theme.spacing(2) } }, { children: avatarPanelSettingItems &&
85
+ component: animated.button, style: animationRefs.current[((_b = avatarPanelMenuItems === null || avatarPanelMenuItems === void 0 ? void 0 : avatarPanelMenuItems.length) !== null && _b !== void 0 ? _b : 0) + 3], variant: 'outlined', color: 'inherit', size: 'medium', onClick: avatarPanelOnClickMainAction, startIcon: _jsx(Settings, {}) }, { children: avatarPanelMainActionString })), _jsx(List, __assign({ "data-id": dataIds.VerticalNavigationFlyoutList, style: { marginBottom: theme.spacing(2) } }, { children: avatarPanelSettingItems &&
65
86
  avatarPanelSettingItems.length > 0 &&
66
- avatarPanelSettingItems.map(function (avatarMenuItem, index) { return (_jsx(ListItem, __assign({ "data-id": dataIds.VerticalNavigationFlyoutListItem, component: animated.div, style: useStaggerAnimation(isAvatarOpen, animationCount, incrementAnimationCount), disablePadding: true }, { children: _jsxs(StyledListItemButton
67
- // TODO: figure out if these are links or buttons
68
- // @ts-expect-error
69
- , __assign({
87
+ avatarPanelSettingItems.map(function (avatarMenuItem, index) {
88
+ var _a;
89
+ return (_jsx(ListItem, __assign({ "data-id": dataIds.VerticalNavigationFlyoutListItem, component: animated.div, style: animationRefs.current[((_a = avatarPanelMenuItems === null || avatarPanelMenuItems === void 0 ? void 0 : avatarPanelMenuItems.length) !== null && _a !== void 0 ? _a : 0) + index + 3], disablePadding: true }, { children: _jsxs(StyledListItemButton
70
90
  // TODO: figure out if these are links or buttons
71
91
  // @ts-expect-error
72
- component: Link, role: 'link', onClick: avatarMenuItem.onClick }, { children: [_jsx(ListItemIcon, __assign({ "aria-hidden": true, style: {
73
- minWidth: theme.spacing(5)
74
- } }, { children: avatarMenuItem.icon })), _jsx(ListItemText, { primary: avatarMenuItem.label })] })) }), "".concat(avatarMenuItem.label, " - ").concat(index))); }) }))] })), _jsx(Box, __assign({ "data-id": dataIds.VerticalNavigationFlyoutFootnote, className: 'avatar-panel-footnote' }, { children: avatarPanelFootnote && avatarPanelFootnote }))] }));
92
+ , __assign({
93
+ // TODO: figure out if these are links or buttons
94
+ // @ts-expect-error
95
+ component: Link, role: 'link', onClick: avatarMenuItem.onClick }, { children: [_jsx(ListItemIcon, __assign({ "aria-hidden": true, style: {
96
+ minWidth: theme.spacing(5)
97
+ } }, { children: avatarMenuItem.icon })), _jsx(ListItemText, { primary: avatarMenuItem.label })] })) }), "".concat(avatarMenuItem.label, " - ").concat(index)));
98
+ }) }))] })), _jsx(Box, __assign({ "data-id": dataIds.VerticalNavigationFlyoutFootnote, className: 'avatar-panel-footnote', style: animationRefs.current[((_c = avatarPanelMenuItems === null || avatarPanelMenuItems === void 0 ? void 0 : avatarPanelMenuItems.length) !== null && _c !== void 0 ? _c : 0) + ((_d = avatarPanelSettingItems === null || avatarPanelSettingItems === void 0 ? void 0 : avatarPanelSettingItems.length) !== null && _d !== void 0 ? _d : 0) + 4] }, { children: avatarPanelFootnote && avatarPanelFootnote }))] }));
75
99
  };
76
100
  export default AvatarPanel;
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "components",
10
10
  "ui"
11
11
  ],
12
- "version": "1.8.7",
12
+ "version": "1.8.8",
13
13
  "private": false,
14
14
  "main": "index.js",
15
15
  "module": "index.js",
@@ -17,17 +17,20 @@ export declare const stringToColor: (string: string) => string;
17
17
  */
18
18
  export declare const stringAvatar: (name: string) => any;
19
19
  /**
20
- * Accepts a number and returns a react-spring style object from useSpring
21
- * @param trigger boolean - Trigger to reverse the animation from main component
22
- * @param animationCount number - Count tracking items from main component
23
- * @param incrementAnimationCount Function - Function to increment animationCount from main component
20
+ * Accepts an order, optional in/out toggle and returns
21
+ * a react-spring style object from useSpring that fades an item
22
+ * in based on it's order
23
+ * @param delayOrder number - Order for delaying items
24
+ * @param reverse boolean - Toggles the direction of the animation
24
25
  * @returns Object
25
26
  */
26
- export declare const useStaggerAnimation: (trigger: boolean, animationCount: number, incrementAnimationCount: Function) => Object;
27
+ export declare const useFadeIn: (delayOrder: number, reverse?: boolean) => Object;
27
28
  /**
28
- * Accepts a number and returns a react-spring style object from useSpring
29
- * @param animationCount number - Count tracking items from main component
30
- * @param incrementAnimationCount Function - Function to increment animationCount from main component
29
+ * Accepts an order, optional in/out toggle and returns
30
+ * a react-spring style object from useSpring that fades and moves
31
+ * an item in based on it's order
32
+ * @param delayOrder number - Order for delaying items
33
+ * @param reverse boolean - Toggles the direction of the animation
31
34
  * @returns Object
32
35
  */
33
- export declare const useFadeIn: (animationCount: number, incrementAnimationCount: Function) => Object;
36
+ export declare const useFadeAndMoveIn: (delayOrder: number, reverse?: boolean) => Object;
package/utils/helpers.js CHANGED
@@ -9,6 +9,7 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
+ import { useEffect, useRef } from 'react';
12
13
  import { useSpring, config } from '@react-spring/web';
13
14
  /**
14
15
  * Accepts a string and returns 2 characters (max) as initials e.g. AN from Avatar Name
@@ -62,36 +63,55 @@ export var stringAvatar = function (name) {
62
63
  };
63
64
  var STAGGER_ITEMS_DELAY = 70;
64
65
  /**
65
- * Accepts a number and returns a react-spring style object from useSpring
66
- * @param trigger boolean - Trigger to reverse the animation from main component
67
- * @param animationCount number - Count tracking items from main component
68
- * @param incrementAnimationCount Function - Function to increment animationCount from main component
66
+ * Accepts an order, optional in/out toggle and returns
67
+ * a react-spring style object from useSpring based on the
68
+ * animation configuration provided
69
+ * @param animationConfig object - Config for useSpring animation (react-spring object)
70
+ * @param delayOrder number - Order for delaying items
71
+ * @param reverse boolean - Toggles the direction of the animation
69
72
  * @returns Object
70
73
  */
71
- export var useStaggerAnimation = function (trigger, animationCount, incrementAnimationCount) {
74
+ var useStaggerIn = function (animationConfig, delayOrder, reverse) {
72
75
  var defaultAnimationConfig = {
73
- from: { opacity: 0, y: 10 },
74
- to: { opacity: 1, y: 0 },
75
- reverse: !trigger,
76
+ reverse: reverse,
76
77
  config: __assign(__assign({}, config.default), { mass: 1 })
77
78
  };
78
- var staggerAnimation = useSpring(__assign(__assign({}, defaultAnimationConfig), { delay: trigger ? STAGGER_ITEMS_DELAY * (animationCount + 1) : 0 }));
79
- incrementAnimationCount();
80
- return staggerAnimation;
79
+ var animationCountRef = useRef(0);
80
+ var staggerInAnimation = useSpring(__assign(__assign(__assign({}, defaultAnimationConfig), animationConfig), { delay: STAGGER_ITEMS_DELAY * delayOrder }));
81
+ useEffect(function () {
82
+ animationCountRef.current += 1;
83
+ });
84
+ return staggerInAnimation;
81
85
  };
82
86
  /**
83
- * Accepts a number and returns a react-spring style object from useSpring
84
- * @param animationCount number - Count tracking items from main component
85
- * @param incrementAnimationCount Function - Function to increment animationCount from main component
87
+ * Accepts an order, optional in/out toggle and returns
88
+ * a react-spring style object from useSpring that fades an item
89
+ * in based on it's order
90
+ * @param delayOrder number - Order for delaying items
91
+ * @param reverse boolean - Toggles the direction of the animation
86
92
  * @returns Object
87
93
  */
88
- export var useFadeIn = function (animationCount, incrementAnimationCount) {
89
- var defaultAnimationConfig = {
94
+ export var useFadeIn = function (delayOrder, reverse) {
95
+ if (reverse === void 0) { reverse = false; }
96
+ var animationConfig = {
90
97
  from: { opacity: 0 },
91
- to: { opacity: 1 },
92
- config: __assign(__assign({}, config.default), { mass: 1 })
98
+ to: { opacity: 1 }
99
+ };
100
+ return useStaggerIn(animationConfig, delayOrder, reverse);
101
+ };
102
+ /**
103
+ * Accepts an order, optional in/out toggle and returns
104
+ * a react-spring style object from useSpring that fades and moves
105
+ * an item in based on it's order
106
+ * @param delayOrder number - Order for delaying items
107
+ * @param reverse boolean - Toggles the direction of the animation
108
+ * @returns Object
109
+ */
110
+ export var useFadeAndMoveIn = function (delayOrder, reverse) {
111
+ if (reverse === void 0) { reverse = false; }
112
+ var animationConfig = {
113
+ from: { opacity: 0, y: 10 },
114
+ to: { opacity: 1, y: 0 }
93
115
  };
94
- var staggerFadeInUpAnimation = useSpring(__assign(__assign({}, defaultAnimationConfig), { delay: STAGGER_ITEMS_DELAY * (animationCount + 1) }));
95
- incrementAnimationCount();
96
- return staggerFadeInUpAnimation;
116
+ return useStaggerIn(animationConfig, delayOrder, reverse);
97
117
  };