@learningpool/ui 1.6.0-beta.3 → 1.6.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/navigation/MobileNavigation/MobileNavigation.d.ts +39 -0
- package/components/navigation/MobileNavigation/MobileNavigation.js +188 -0
- package/components/navigation/MobileNavigation/MobileNavigationAvatar.d.ts +28 -0
- package/components/navigation/MobileNavigation/MobileNavigationAvatar.js +124 -0
- package/components/navigation/MobileNavigation/MobileNavigationAvatarStyles.d.ts +827 -0
- package/components/navigation/MobileNavigation/MobileNavigationAvatarStyles.js +33 -0
- package/components/navigation/MobileNavigation/MobileNavigationDrawer.d.ts +24 -0
- package/components/navigation/MobileNavigation/MobileNavigationDrawer.js +148 -0
- package/components/navigation/MobileNavigation/MobileNavigationDrawerStyles.d.ts +392 -0
- package/components/navigation/MobileNavigation/MobileNavigationDrawerStyles.js +44 -0
- package/components/navigation/MobileNavigation/MobileNavigationItem/MobileNavigationItem.d.ts +19 -0
- package/components/navigation/MobileNavigation/MobileNavigationItem/MobileNavigationItem.js +91 -0
- package/components/navigation/MobileNavigation/MobileNavigationItem/MobileNavigationItemFlyoutMenu.d.ts +15 -0
- package/components/navigation/MobileNavigation/MobileNavigationItem/MobileNavigationItemFlyoutMenu.js +26 -0
- package/components/navigation/MobileNavigation/MobileNavigationItem/MobileNavigationItemFlyoutMenuStyles.d.ts +112 -0
- package/components/navigation/MobileNavigation/MobileNavigationItem/MobileNavigationItemFlyoutMenuStyles.js +66 -0
- package/components/navigation/MobileNavigation/MobileNavigationItem/MobileNavigationItemStyles.d.ts +126 -0
- package/components/navigation/MobileNavigation/MobileNavigationItem/MobileNavigationItemStyles.js +71 -0
- package/components/navigation/MobileNavigation/MobileNavigationMotion.d.ts +141 -0
- package/components/navigation/MobileNavigation/MobileNavigationMotion.js +109 -0
- package/components/navigation/MobileNavigation/MobileNavigationSearch.d.ts +10 -0
- package/components/navigation/MobileNavigation/MobileNavigationSearch.js +52 -0
- package/components/navigation/MobileNavigation/MobileNavigationSearchStyles.d.ts +257 -0
- package/components/navigation/MobileNavigation/MobileNavigationSearchStyles.js +20 -0
- package/components/navigation/MobileNavigation/MobileNavigationStyles.d.ts +405 -0
- package/components/navigation/MobileNavigation/MobileNavigationStyles.js +104 -0
- package/components/navigation/MobileNavigation/MobileNavigationToggleSearchX.d.ts +2 -0
- package/components/navigation/MobileNavigation/MobileNavigationToggleSearchX.js +32 -0
- package/components/navigation/MobileNavigation/MobileNavigationToggleX.d.ts +2 -0
- package/components/navigation/MobileNavigation/MobileNavigationToggleX.js +26 -0
- package/components/navigation/MobileNavigation/MobileNavigationToggleXStyles.d.ts +36 -0
- package/components/navigation/MobileNavigation/MobileNavigationToggleXStyles.js +10 -0
- package/components/navigation/VerticalNavigation/VerticalNavigation.d.ts +1 -0
- package/components/navigation/VerticalNavigation/VerticalNavigation.js +27 -24
- package/components/navigation/VerticalNavigation/VerticalNavigationItem/VerticalNavigationItem.js +1 -1
- package/components/navigation/VerticalNavigation/VerticalNavigationItem/VerticalNavigationItemFlyoutMenu.js +1 -1
- package/components/navigation/VerticalNavigation/VerticalNavigationStyles.js +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +4 -2
- package/utils/constants.d.ts +6 -0
- package/utils/constants.js +6 -0
- package/utils/helpers.d.ts +6 -0
- package/utils/helpers.js +17 -0
- package/utils/hooks.d.ts +1 -0
- package/utils/hooks.js +29 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IMobileNavigationItemProps } from './MobileNavigationItem/MobileNavigationItem';
|
|
3
|
+
import { IAvatarMenuItemProps } from './MobileNavigationAvatar';
|
|
4
|
+
interface MobileNavigationProps {
|
|
5
|
+
logo?: string;
|
|
6
|
+
logoText?: string;
|
|
7
|
+
logoOnClick?: any;
|
|
8
|
+
items?: IMobileNavigationItemProps[];
|
|
9
|
+
secondaryItems?: IMobileNavigationItemProps[];
|
|
10
|
+
hasStreamHome?: boolean;
|
|
11
|
+
streamHomeAccessToken?: string;
|
|
12
|
+
streamHomeBaseUrl?: string;
|
|
13
|
+
streamHomeApiKey?: string;
|
|
14
|
+
avatarName?: string;
|
|
15
|
+
isDrawerOpen?: boolean;
|
|
16
|
+
isSearchOpen?: boolean;
|
|
17
|
+
isAvatarOpen?: boolean;
|
|
18
|
+
isPersistent?: boolean;
|
|
19
|
+
setIsPersistent?: any;
|
|
20
|
+
hideAvatarInitials?: boolean;
|
|
21
|
+
showNotchIndicator?: boolean;
|
|
22
|
+
hasSearch?: boolean;
|
|
23
|
+
searchPanelPlaceholder?: string;
|
|
24
|
+
searchPanelDefaultValue?: string;
|
|
25
|
+
searchPanelOnClickSearch?: any;
|
|
26
|
+
hasAvatar?: boolean;
|
|
27
|
+
avatarPanelOnClickSwitchDirection?: any;
|
|
28
|
+
avatarPanelOnClickLogout?: any;
|
|
29
|
+
avatarPanelOnClickViewProfile?: any;
|
|
30
|
+
avatarPanelViewProfileString?: string;
|
|
31
|
+
avatarPanelOnClickEditProfile?: any;
|
|
32
|
+
avatarPanelEditProfileString?: string;
|
|
33
|
+
avatarPanelMenuItems?: Array<IAvatarMenuItemProps>;
|
|
34
|
+
avatarPanelOnClickMainAction?: any;
|
|
35
|
+
avatarPanelMainActionString?: string;
|
|
36
|
+
avatarPanelSettingItems?: Array<IAvatarMenuItemProps>;
|
|
37
|
+
}
|
|
38
|
+
declare const MobileNavigation: (props: MobileNavigationProps) => React.ReactElement;
|
|
39
|
+
export default MobileNavigation;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
24
|
+
import React, { useEffect } from 'react';
|
|
25
|
+
import { Person, PersonOutline } from '@mui/icons-material';
|
|
26
|
+
import { StyledBottomNavigationAction, StyledPaper, StyledBottomNavigation, StyledNotchSVG, StyledNotchShadow, StyledNotchShadowMask } from './MobileNavigationStyles';
|
|
27
|
+
import { StyledAvatar } from './MobileNavigationAvatarStyles';
|
|
28
|
+
import SwipeableTemporaryDrawer from './MobileNavigationDrawer';
|
|
29
|
+
import SwipeableTemporarySearch from './MobileNavigationSearch';
|
|
30
|
+
import SwipeableTemporaryAvatar from './MobileNavigationAvatar';
|
|
31
|
+
import { ToggleX } from './MobileNavigationToggleX';
|
|
32
|
+
import { ToggleSearchX } from './MobileNavigationToggleSearchX';
|
|
33
|
+
import { useCurrentWidth } from '../../../utils/hooks';
|
|
34
|
+
import { slice } from 'lodash';
|
|
35
|
+
import { motion } from 'framer-motion';
|
|
36
|
+
import { MOBILE_NAV_PANEL_TYPES } from '../../../utils/constants';
|
|
37
|
+
var MobileNavigation = function (props) {
|
|
38
|
+
var _a, _b;
|
|
39
|
+
var items = props.items, secondaryItems = props.secondaryItems, hideAvatarInitials = props.hideAvatarInitials, hasSearch = props.hasSearch, hasAvatar = props.hasAvatar, showNotchIndicator = props.showNotchIndicator, rest = __rest(props, ["items", "secondaryItems", "hideAvatarInitials", "hasSearch", "hasAvatar", "showNotchIndicator"]);
|
|
40
|
+
var propIsDrawerOpen = typeof (props === null || props === void 0 ? void 0 : props.isDrawerOpen) === 'boolean' ? props.isDrawerOpen : undefined;
|
|
41
|
+
var propIsSearchOpen = typeof (props === null || props === void 0 ? void 0 : props.isSearchOpen) === 'boolean' ? props.isSearchOpen : undefined;
|
|
42
|
+
var propIsAvatarOpen = typeof (props === null || props === void 0 ? void 0 : props.isAvatarOpen) === 'boolean' ? props.isAvatarOpen : undefined;
|
|
43
|
+
var avatarName = (_a = props === null || props === void 0 ? void 0 : props.avatarName) !== null && _a !== void 0 ? _a : 'Avatar name';
|
|
44
|
+
var _c = React.useState(propIsDrawerOpen !== null && propIsDrawerOpen !== void 0 ? propIsDrawerOpen : false), isDrawerOpen = _c[0], setIsDrawerOpen = _c[1];
|
|
45
|
+
var _d = React.useState(propIsSearchOpen !== null && propIsSearchOpen !== void 0 ? propIsSearchOpen : false), isSearchOpen = _d[0], setIsSearchOpen = _d[1];
|
|
46
|
+
var _e = React.useState(propIsAvatarOpen !== null && propIsAvatarOpen !== void 0 ? propIsAvatarOpen : false), isAvatarOpen = _e[0], setIsAvatarOpen = _e[1];
|
|
47
|
+
var maxMobilePrimaryItems = 3;
|
|
48
|
+
var priorityItems = slice(items, 0, maxMobilePrimaryItems);
|
|
49
|
+
var _f = React.useState(0), value = _f[0], setValue = _f[1];
|
|
50
|
+
var _g = React.useState(0), mobileNotchPosition = _g[0], setMobileNotchPosition = _g[1];
|
|
51
|
+
var windowWidth = useCurrentWidth();
|
|
52
|
+
var currentDirection = window.localStorage.getItem('@learningpool/ui/store/mobile-navigation-direction');
|
|
53
|
+
var _h = React.useState(currentDirection !== null && currentDirection !== void 0 ? currentDirection : 'ltr'), mobileNavDirection = _h[0], setMobileNavDirection = _h[1];
|
|
54
|
+
useEffect(function () {
|
|
55
|
+
window.localStorage.setItem('@learningpool/ui/store/mobile-navigation-direction', mobileNavDirection);
|
|
56
|
+
positionMobileNotch();
|
|
57
|
+
}, [mobileNavDirection]);
|
|
58
|
+
useEffect(function () { return setIsDrawerOpen(propIsDrawerOpen !== null && propIsDrawerOpen !== void 0 ? propIsDrawerOpen : false); }, [propIsDrawerOpen]);
|
|
59
|
+
useEffect(function () { return setIsSearchOpen(propIsSearchOpen !== null && propIsSearchOpen !== void 0 ? propIsSearchOpen : false); }, [propIsSearchOpen]);
|
|
60
|
+
useEffect(function () { return setIsAvatarOpen(propIsAvatarOpen !== null && propIsAvatarOpen !== void 0 ? propIsAvatarOpen : false); }, [propIsAvatarOpen]);
|
|
61
|
+
useEffect(function () { return setAvatarInitials(handleAvatarInitials(avatarName)); }, [avatarName]);
|
|
62
|
+
useEffect(function () {
|
|
63
|
+
function hideNotch() {
|
|
64
|
+
var HIDE_NOTCH = -1;
|
|
65
|
+
if (!isDrawerOpen && !isSearchOpen && !isAvatarOpen) {
|
|
66
|
+
setValue(HIDE_NOTCH);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
hideNotch();
|
|
70
|
+
}, [isDrawerOpen, isSearchOpen, isAvatarOpen]);
|
|
71
|
+
var handleAvatarInitials = function (avatarName) {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
var firstInitial = avatarName.split('')[0] || '';
|
|
74
|
+
var secondInitial = '';
|
|
75
|
+
if (((_a = avatarName.split(' ')) === null || _a === void 0 ? void 0 : _a.length) > 1) {
|
|
76
|
+
firstInitial = avatarName.split(' ')[0][0];
|
|
77
|
+
if (((_b = avatarName.split(' ')[1]) === null || _b === void 0 ? void 0 : _b.length) > 0) {
|
|
78
|
+
secondInitial = avatarName === null || avatarName === void 0 ? void 0 : avatarName.split(' ')[1][0];
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return "".concat(firstInitial).concat(secondInitial);
|
|
82
|
+
};
|
|
83
|
+
var _j = React.useState((_b = handleAvatarInitials(avatarName)) !== null && _b !== void 0 ? _b : 'AN'), avatarInitials = _j[0], setAvatarInitials = _j[1];
|
|
84
|
+
var toggleDrawer = function (open, action) { return function (event) {
|
|
85
|
+
event === null || event === void 0 ? void 0 : event.stopPropagation();
|
|
86
|
+
if (event.type === 'keydown') {
|
|
87
|
+
if (event.key === 'Tab' || event.key === 'Shift') {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Close any open drawers
|
|
92
|
+
setIsDrawerOpen(false);
|
|
93
|
+
setIsSearchOpen(false);
|
|
94
|
+
setIsAvatarOpen(false);
|
|
95
|
+
// Handle drawer toggling based on 'action' or default to 'drawer'
|
|
96
|
+
switch (action) {
|
|
97
|
+
case MOBILE_NAV_PANEL_TYPES.SEARCH: {
|
|
98
|
+
setIsSearchOpen(open !== null && open !== void 0 ? open : !isSearchOpen);
|
|
99
|
+
setValue(1);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case MOBILE_NAV_PANEL_TYPES.AVATAR: {
|
|
103
|
+
setIsAvatarOpen(open !== null && open !== void 0 ? open : !isAvatarOpen);
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
default: {
|
|
107
|
+
setIsDrawerOpen(open !== null && open !== void 0 ? open : !isDrawerOpen);
|
|
108
|
+
setValue(0);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}; };
|
|
113
|
+
var NOTCH = {
|
|
114
|
+
Height: 50,
|
|
115
|
+
Width: 50
|
|
116
|
+
};
|
|
117
|
+
var positionMobileNotch = function () {
|
|
118
|
+
var _a;
|
|
119
|
+
var selectedDOMRect = (_a = document.querySelectorAll('.MuiBottomNavigationAction-root, .bottom-navigation-item')[value]) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
120
|
+
setMobileNotchPosition(selectedDOMRect ? selectedDOMRect.left + (selectedDOMRect.width / 2) - (NOTCH.Width / 2) : mobileNotchPosition);
|
|
121
|
+
};
|
|
122
|
+
React.useEffect(function () { return positionMobileNotch(); }, [value, windowWidth]);
|
|
123
|
+
var variantsPaper = {
|
|
124
|
+
open: {
|
|
125
|
+
opacity: 1
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
var variantsContainer = {
|
|
129
|
+
open: {
|
|
130
|
+
transition: { staggerChildren: 0.07, delayChildren: 0.25 }
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
var variantsButtons = {
|
|
134
|
+
open: {
|
|
135
|
+
y: 0,
|
|
136
|
+
opacity: 1,
|
|
137
|
+
transition: {
|
|
138
|
+
y: { stiffness: 500, velocity: -100 }
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
return (_jsxs(_Fragment, { children: [_jsx(SwipeableTemporaryDrawer, __assign({ isDrawerOpen: isDrawerOpen, setIsDrawerOpen: setIsDrawerOpen, items: items, secondaryItems: secondaryItems, label: 'Primary' }, rest)), hasSearch && (_jsx(SwipeableTemporarySearch, __assign({}, rest, { isSearchOpen: isSearchOpen, setIsSearchOpen: setIsSearchOpen }))), hasAvatar && (_jsx(SwipeableTemporaryAvatar, __assign({}, rest, { isAvatarOpen: isAvatarOpen, setIsAvatarOpen: setIsAvatarOpen, avatarName: avatarName, mobileNavDirection: mobileNavDirection, setMobileNavDirection: setMobileNavDirection }))), _jsxs(StyledPaper, __assign({ elevation: 3,
|
|
143
|
+
// @ts-expect-error
|
|
144
|
+
component: motion.div, animate: 'open', variants: variantsPaper, initial: { opacity: 0 }, transition: {
|
|
145
|
+
// when: 'beforeChildren'
|
|
146
|
+
} }, { children: [showNotchIndicator &&
|
|
147
|
+
_jsxs(motion.div, __assign({ style: { zIndex: '-1' }, initial: {
|
|
148
|
+
opacity: 0,
|
|
149
|
+
x: -75,
|
|
150
|
+
y: 100
|
|
151
|
+
}, animate: {
|
|
152
|
+
opacity: 1,
|
|
153
|
+
x: mobileNotchPosition,
|
|
154
|
+
y: value < 0 ? 100 : -2
|
|
155
|
+
}, transition: {
|
|
156
|
+
x: {
|
|
157
|
+
// duration: 0.5,
|
|
158
|
+
type: 'spring',
|
|
159
|
+
// mass: 0.5,
|
|
160
|
+
bounce: 0.25
|
|
161
|
+
// stiffness: 50
|
|
162
|
+
},
|
|
163
|
+
y: {
|
|
164
|
+
delay: 0.25,
|
|
165
|
+
// duration: 0.5,
|
|
166
|
+
type: 'spring',
|
|
167
|
+
// mass: 0.5,
|
|
168
|
+
bounce: 0
|
|
169
|
+
}
|
|
170
|
+
// duration: 0.5
|
|
171
|
+
} }, { children: [_jsx(StyledNotchShadow, {}), _jsx(StyledNotchSVG, __assign({ viewBox: "0 0 22 85", xmlns: "http://www.w3.org/2000/svg" }, { children: _jsx(motion.path, { d: "M0 0V85V76.0381C0.774 69.7533 4.9101 64.7829 7.5488 63.5975C7.668 63.5518 7.7867 63.5052 7.9049 63.4576C16.1679 60.1279 22 52.035 22 42.5799C22 33.1612 16.2126 25.0941 8 21.7408C7.8723 21.6887 7.7441 21.6377 7.6153 21.5879C4.8325 20.3142 0.4173 14.8748 0 8.13255V0Z" }) })), _jsx(StyledNotchShadowMask, {})] })), _jsxs(StyledBottomNavigation, __assign({ value: value, onChange: function (event, newValue) { return setValue(newValue); },
|
|
172
|
+
// @ts-expect-error
|
|
173
|
+
component: motion.div, animate: 'open', variants: variantsContainer, style: {
|
|
174
|
+
flexDirection: mobileNavDirection && mobileNavDirection === 'rtl' ? 'row-reverse' : 'row'
|
|
175
|
+
} }, { children: [_jsx(StyledBottomNavigationAction, { icon: _jsx(ToggleX, {}), onClick: toggleDrawer(!isDrawerOpen, MOBILE_NAV_PANEL_TYPES.DRAWER),
|
|
176
|
+
// @ts-expect-error
|
|
177
|
+
component: motion.div, animate: isDrawerOpen ? 'open' : 'closed', variants: variantsButtons, "aria-label": isDrawerOpen ? 'Close drawer panel' : 'Open drawer panel', "aria-expanded": isDrawerOpen ? 'true' : 'false', "aria-controls": 'mobile-nav-menu', style: {
|
|
178
|
+
marginInlineStart: (hasSearch || hasAvatar) && (mobileNavDirection && mobileNavDirection === 'rtl') ? 'auto' : 'initial',
|
|
179
|
+
marginInlineEnd: (hasSearch || hasAvatar) && (mobileNavDirection && mobileNavDirection === 'rtl') ? 'initial' : 'auto'
|
|
180
|
+
} }), hasSearch && (_jsx(StyledBottomNavigationAction, { icon: _jsx(ToggleSearchX, {}), onClick: toggleDrawer(!isSearchOpen, MOBILE_NAV_PANEL_TYPES.SEARCH),
|
|
181
|
+
// @ts-expect-error
|
|
182
|
+
component: motion.div, animate: isSearchOpen ? 'open' : 'closed', variants: variantsButtons, "aria-label": isSearchOpen ? 'Close search panel' : 'Open search panel', "aria-expanded": isSearchOpen ? 'true' : 'false', "aria-controls": 'mobile-nav-menu' })), hasAvatar && (_jsx(StyledBottomNavigationAction, { onClick: toggleDrawer(!isAvatarOpen, MOBILE_NAV_PANEL_TYPES.AVATAR), icon: !hideAvatarInitials
|
|
183
|
+
? _jsx(StyledAvatar, { children: avatarInitials })
|
|
184
|
+
: value === (priorityItems ? priorityItems.length + 1 : 1) ? _jsx(Person, {}) : _jsx(PersonOutline, {}),
|
|
185
|
+
// @ts-expect-error
|
|
186
|
+
component: motion.button, variants: variantsButtons, "aria-label": isAvatarOpen ? 'Close Profile Menu' : 'Open Profile Menu', "aria-expanded": isAvatarOpen ? 'true' : 'false', "aria-controls": 'mobile-nav-menu' }))] }))] }))] }));
|
|
187
|
+
};
|
|
188
|
+
export default MobileNavigation;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface IAvatarMenuItemProps {
|
|
3
|
+
label: string;
|
|
4
|
+
icon: any;
|
|
5
|
+
onClick: any;
|
|
6
|
+
}
|
|
7
|
+
export interface ISwipeableTemporaryAvatarProps {
|
|
8
|
+
avatarName: string;
|
|
9
|
+
editProfileText?: string;
|
|
10
|
+
logoutText?: string;
|
|
11
|
+
isAvatarOpen: boolean;
|
|
12
|
+
setIsAvatarOpen?: any;
|
|
13
|
+
mobileNavDirection?: string;
|
|
14
|
+
setMobileNavDirection?: any;
|
|
15
|
+
avatarPanelOnClickSwitchDirection?: any;
|
|
16
|
+
avatarPanelOnClickLogout?: any;
|
|
17
|
+
avatarPanelOnClickViewProfile?: any;
|
|
18
|
+
avatarPanelViewProfileString?: string;
|
|
19
|
+
avatarPanelOnClickEditProfile?: any;
|
|
20
|
+
avatarPanelEditProfileString?: string;
|
|
21
|
+
avatarPanelMenuItems?: Array<IAvatarMenuItemProps>;
|
|
22
|
+
avatarPanelOnClickMainAction?: any;
|
|
23
|
+
avatarPanelMainActionString?: string;
|
|
24
|
+
avatarPanelSettingItems?: Array<IAvatarMenuItemProps>;
|
|
25
|
+
avatarPanelInvertNavString?: string;
|
|
26
|
+
}
|
|
27
|
+
declare const SwipeableTemporaryAvatar: (props: ISwipeableTemporaryAvatarProps) => React.ReactElement;
|
|
28
|
+
export default SwipeableTemporaryAvatar;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import React, { useEffect } from 'react';
|
|
14
|
+
import { Box, ButtonGroup, IconButton, Button, Link, List, ListItem, ListItemIcon, ListItemText } from '../../../index';
|
|
15
|
+
import { StyledSwipeableAvatar, StyledBox, StyledBoxProfile, StyledAvatarName, StyledAvatar, StyledOutlineButton, StyledBoxProfileEdit, StyledListItemButton } from './MobileNavigationAvatarStyles';
|
|
16
|
+
import { useTheme } from '@mui/material/styles';
|
|
17
|
+
import EditIcon from '@mui/icons-material/Edit';
|
|
18
|
+
import LogoutIcon from '@mui/icons-material/Logout';
|
|
19
|
+
import { motion } from 'framer-motion';
|
|
20
|
+
import { motionParent, motionFadeIn, motionFadeInUp, motionWhileHover, motionWhileTap } from './MobileNavigationMotion';
|
|
21
|
+
import ToggleOffIcon from '@mui/icons-material/ToggleOff';
|
|
22
|
+
import ToggleOnIcon from '@mui/icons-material/ToggleOn';
|
|
23
|
+
import { handleAvatarInitials } from '../../../utils/helpers';
|
|
24
|
+
var SwipeableTemporaryAvatar = function (props) {
|
|
25
|
+
var _a;
|
|
26
|
+
var theme = useTheme();
|
|
27
|
+
var avatarName = props.avatarName, mobileNavDirection = props.mobileNavDirection, 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;
|
|
28
|
+
var _b = React.useState(isAvatarOpen !== null && isAvatarOpen !== void 0 ? isAvatarOpen : false), isOpen = _b[0], setIsOpen = _b[1];
|
|
29
|
+
React.useEffect(function () { return handleOpenState(isAvatarOpen); }, [isAvatarOpen]);
|
|
30
|
+
var handleOpenState = function (open) {
|
|
31
|
+
setIsOpen(open);
|
|
32
|
+
setIsAvatarOpen(open);
|
|
33
|
+
};
|
|
34
|
+
var toggleAvatar = function (open) {
|
|
35
|
+
return function (event) {
|
|
36
|
+
if (event && event.type === 'keydown' &&
|
|
37
|
+
(event.key === 'Tab' ||
|
|
38
|
+
event.key === 'Shift')) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
handleOpenState(open);
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
useEffect(function () { return setAvatarInitials(handleAvatarInitials(avatarName)); }, [
|
|
45
|
+
avatarName
|
|
46
|
+
]);
|
|
47
|
+
var _c = React.useState((_a = handleAvatarInitials(avatarName)) !== null && _a !== void 0 ? _a : 'AN'), avatarInitials = _c[0], setAvatarInitials = _c[1];
|
|
48
|
+
var handleOnClickSwitchDirection = function () {
|
|
49
|
+
setMobileNavDirection(mobileNavDirection === 'rtl' ? 'ltr' : 'rtl');
|
|
50
|
+
avatarPanelOnClickSwitchDirection && avatarPanelOnClickSwitchDirection();
|
|
51
|
+
};
|
|
52
|
+
return (_jsx(StyledSwipeableAvatar, __assign({ anchor: 'bottom', open: isOpen, onClose: toggleAvatar(false), hideBackdrop: true, ModalProps: {
|
|
53
|
+
keepMounted: true
|
|
54
|
+
} }, { children: _jsxs(StyledBox, __assign({ animate: isAvatarOpen ? 'open' : 'closed', variants: motionParent }, { children: [avatarPanelOnClickLogout && (_jsx(IconButton
|
|
55
|
+
// @ts-expect-error
|
|
56
|
+
, __assign({
|
|
57
|
+
// @ts-expect-error
|
|
58
|
+
component: motion.button, variants: motionFadeIn, style: {
|
|
59
|
+
left: theme.direction === 'rtl' ? theme.spacing(1) : 'auto',
|
|
60
|
+
position: 'absolute',
|
|
61
|
+
right: theme.direction === 'rtl' ? 'auto' : theme.spacing(1),
|
|
62
|
+
top: theme.spacing(1)
|
|
63
|
+
}, onClick: avatarPanelOnClickLogout }, { children: _jsx(LogoutIcon, {}) }))), _jsxs(Box, __assign({ style: {
|
|
64
|
+
alignItems: 'center',
|
|
65
|
+
display: 'flex',
|
|
66
|
+
flexDirection: 'column'
|
|
67
|
+
} }, { children: [_jsxs(StyledBoxProfile, __assign({ variants: motionFadeInUp }, { 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({ variants: motionFadeInUp, style: {
|
|
68
|
+
flexDirection: 'row',
|
|
69
|
+
marginBottom: theme.spacing(1)
|
|
70
|
+
} }, { children: _jsxs(ButtonGroup, __assign({ variant: "contained", "aria-label": "split button" }, { children: [_jsx(Button, __assign({ variant: 'contained', color: 'primary', size: 'medium', onClick: avatarPanelOnClickViewProfile }, { children: avatarPanelViewProfileString !== null && avatarPanelViewProfileString !== void 0 ? avatarPanelViewProfileString : 'View Profile' })), avatarPanelOnClickEditProfile && (_jsx(Button, __assign({ size: 'medium', "aria-label": avatarPanelEditProfileString !== null && avatarPanelEditProfileString !== void 0 ? avatarPanelEditProfileString : 'Edit Profile', onClick: avatarPanelOnClickEditProfile }, { children: _jsx(EditIcon, {}) })))] })) })))] })), _jsxs(Box, __assign({ style: {
|
|
71
|
+
alignItems: 'center',
|
|
72
|
+
display: 'flex',
|
|
73
|
+
flexDirection: 'column'
|
|
74
|
+
} }, { children: [avatarPanelMenuItems && avatarPanelMenuItems.length > 0 && (_jsx(List, __assign({ style: {
|
|
75
|
+
marginInlineStart: '3rem',
|
|
76
|
+
marginBottom: theme.spacing(2),
|
|
77
|
+
maxWidth: '18rem'
|
|
78
|
+
} }, { children: avatarPanelMenuItems.map(function (avatarMenuItem) { return (_jsx(ListItem, __assign({ component: motion.div, variants: motionFadeInUp, whileHover: motionWhileHover, whileTap: motionWhileTap, disablePadding: true }, { children: _jsxs(StyledListItemButton
|
|
79
|
+
// TODO: figure out if these are links or buttons
|
|
80
|
+
// @ts-expect-error
|
|
81
|
+
, __assign({
|
|
82
|
+
// TODO: figure out if these are links or buttons
|
|
83
|
+
// @ts-expect-error
|
|
84
|
+
component: Link, role: 'link', onClick: avatarMenuItem.onClick }, { children: [_jsx(ListItemIcon, __assign({ "aria-hidden": true, style: {
|
|
85
|
+
minWidth: theme.spacing(5)
|
|
86
|
+
} }, { children: avatarMenuItem.icon })), _jsx(ListItemText, { primary: avatarMenuItem.label })] })) }))); }) }))), avatarPanelOnClickMainAction && _jsx(StyledOutlineButton
|
|
87
|
+
// @ts-expect-error
|
|
88
|
+
, __assign({
|
|
89
|
+
// @ts-expect-error
|
|
90
|
+
component: motion.button, variants: motionFadeInUp, disablePadding: true, variant: 'outlined', color: 'primary', size: 'medium', onClick: avatarPanelOnClickMainAction }, { children: avatarPanelMainActionString })), _jsxs(List, __assign({ style: { marginBottom: theme.spacing(2) } }, { children: [avatarPanelSettingItems &&
|
|
91
|
+
avatarPanelSettingItems.length > 0 &&
|
|
92
|
+
avatarPanelSettingItems.map(function (avatarMenuItem) { return (_jsx(ListItem, __assign({ component: motion.div, variants: motionFadeInUp, whileHover: motionWhileHover, whileTap: motionWhileTap, disablePadding: true }, { children: _jsxs(StyledListItemButton
|
|
93
|
+
// TODO: figure out if these are links or buttons
|
|
94
|
+
// @ts-expect-error
|
|
95
|
+
, __assign({
|
|
96
|
+
// TODO: figure out if these are links or buttons
|
|
97
|
+
// @ts-expect-error
|
|
98
|
+
component: Link, role: 'link', onClick: avatarMenuItem.onClick }, { children: [_jsx(ListItemIcon, __assign({ "aria-hidden": true, style: {
|
|
99
|
+
minWidth: theme.spacing(5)
|
|
100
|
+
} }, { children: avatarMenuItem.icon })), _jsx(ListItemText, { primary: avatarMenuItem.label })] })) }))); }), avatarPanelOnClickSwitchDirection && (_jsx(ListItem, __assign({ component: motion.div, variants: motionFadeInUp, whileHover: motionWhileHover, whileTap: motionWhileTap, disablePadding: true }, { children: _jsxs(StyledListItemButton
|
|
101
|
+
// TODO: figure out if these are links or buttons
|
|
102
|
+
// @ts-expect-error
|
|
103
|
+
, __assign({
|
|
104
|
+
// TODO: figure out if these are links or buttons
|
|
105
|
+
// @ts-expect-error
|
|
106
|
+
component: Link, role: 'link', onClick: handleOnClickSwitchDirection }, { children: [_jsx(ListItemText, { primary: avatarPanelInvertNavString !== null && avatarPanelInvertNavString !== void 0 ? avatarPanelInvertNavString : 'Invert navigation bar' }), _jsx(ListItemIcon, __assign({ "aria-hidden": true, style: {
|
|
107
|
+
minWidth: theme.spacing(5),
|
|
108
|
+
marginInlineStart: '0.5rem'
|
|
109
|
+
} }, { children: mobileNavDirection === 'ltr'
|
|
110
|
+
? (_jsx(ToggleOffIcon, { style: {
|
|
111
|
+
boxSizing: 'border-box',
|
|
112
|
+
height: '2em',
|
|
113
|
+
padding: '0.15em',
|
|
114
|
+
width: '2em'
|
|
115
|
+
} }))
|
|
116
|
+
: (_jsx(ToggleOnIcon, { style: {
|
|
117
|
+
boxSizing: 'border-box',
|
|
118
|
+
color: 'green',
|
|
119
|
+
height: '2em',
|
|
120
|
+
padding: '0.15em',
|
|
121
|
+
width: '2em'
|
|
122
|
+
} })) }))] })) })))] }))] }))] })) })));
|
|
123
|
+
};
|
|
124
|
+
export default SwipeableTemporaryAvatar;
|