@learningpool/ui 1.6.0-beta.5 → 1.6.0-beta.7

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.
@@ -34,23 +34,24 @@ import { useCurrentWidth } from '../../../utils/hooks';
34
34
  import { slice } from 'lodash';
35
35
  import { motion } from 'framer-motion';
36
36
  import { MOBILE_NAV_PANEL_TYPES } from '../../../utils/constants';
37
+ import { handleAvatarInitials } from '../../../utils/helpers';
37
38
  var MobileNavigation = function (props) {
38
- var _a, _b;
39
+ var _a, _b, _c;
39
40
  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
41
  var propIsDrawerOpen = typeof (props === null || props === void 0 ? void 0 : props.isDrawerOpen) === 'boolean' ? props.isDrawerOpen : undefined;
41
42
  var propIsSearchOpen = typeof (props === null || props === void 0 ? void 0 : props.isSearchOpen) === 'boolean' ? props.isSearchOpen : undefined;
42
43
  var propIsAvatarOpen = typeof (props === null || props === void 0 ? void 0 : props.isAvatarOpen) === 'boolean' ? props.isAvatarOpen : undefined;
43
44
  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];
45
+ var _d = React.useState(propIsDrawerOpen !== null && propIsDrawerOpen !== void 0 ? propIsDrawerOpen : false), isDrawerOpen = _d[0], setIsDrawerOpen = _d[1];
46
+ var _e = React.useState(propIsSearchOpen !== null && propIsSearchOpen !== void 0 ? propIsSearchOpen : false), isSearchOpen = _e[0], setIsSearchOpen = _e[1];
47
+ var _f = React.useState(propIsAvatarOpen !== null && propIsAvatarOpen !== void 0 ? propIsAvatarOpen : false), isAvatarOpen = _f[0], setIsAvatarOpen = _f[1];
47
48
  var maxMobilePrimaryItems = 3;
48
49
  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];
50
+ var _g = React.useState(0), value = _g[0], setValue = _g[1];
51
+ var _h = React.useState(0), mobileNotchPosition = _h[0], setMobileNotchPosition = _h[1];
51
52
  var windowWidth = useCurrentWidth();
52
53
  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
+ var _j = React.useState(currentDirection !== null && currentDirection !== void 0 ? currentDirection : 'ltr'), mobileNavDirection = _j[0], setMobileNavDirection = _j[1];
54
55
  useEffect(function () {
55
56
  window.localStorage.setItem('@learningpool/ui/store/mobile-navigation-direction', mobileNavDirection);
56
57
  positionMobileNotch();
@@ -68,19 +69,7 @@ var MobileNavigation = function (props) {
68
69
  }
69
70
  hideNotch();
70
71
  }, [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];
72
+ var _k = React.useState((_b = handleAvatarInitials(avatarName)) !== null && _b !== void 0 ? _b : 'AN'), avatarInitials = _k[0], setAvatarInitials = _k[1];
84
73
  var toggleDrawer = function (open, action) { return function (event) {
85
74
  event === null || event === void 0 ? void 0 : event.stopPropagation();
86
75
  if (event.type === 'keydown') {
@@ -114,12 +103,18 @@ var MobileNavigation = function (props) {
114
103
  Height: 50,
115
104
  Width: 50
116
105
  };
106
+ var BOTTOM_NAVIGATION_ITEM_DOM_ELEMENTS = document.querySelectorAll('.MuiBottomNavigationAction-root, .bottom-navigation-item');
117
107
  var positionMobileNotch = function () {
118
108
  var _a;
119
- var selectedDOMRect = (_a = document.querySelectorAll('.MuiBottomNavigationAction-root, .bottom-navigation-item')[value]) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
109
+ var selectedDOMRect = (_a = BOTTOM_NAVIGATION_ITEM_DOM_ELEMENTS[value]) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
120
110
  setMobileNotchPosition(selectedDOMRect ? selectedDOMRect.left + (selectedDOMRect.width / 2) - (NOTCH.Width / 2) : mobileNotchPosition);
121
111
  };
122
- React.useEffect(function () { return positionMobileNotch(); }, [value, windowWidth]);
112
+ useEffect(function () { return positionMobileNotch(); }, [
113
+ value,
114
+ windowWidth,
115
+ // Fix notch position if scrollbar is hidden/shown
116
+ (_c = BOTTOM_NAVIGATION_ITEM_DOM_ELEMENTS[value]) === null || _c === void 0 ? void 0 : _c.getBoundingClientRect()
117
+ ]);
123
118
  var variantsPaper = {
124
119
  open: {
125
120
  opacity: 1
@@ -41,10 +41,8 @@ var SwipeableTemporaryAvatar = function (props) {
41
41
  handleOpenState(open);
42
42
  };
43
43
  };
44
- useEffect(function () { return setAvatarInitials(handleAvatarInitials(avatarName)); }, [
45
- avatarName
46
- ]);
47
44
  var _c = React.useState((_a = handleAvatarInitials(avatarName)) !== null && _a !== void 0 ? _a : 'AN'), avatarInitials = _c[0], setAvatarInitials = _c[1];
45
+ useEffect(function () { return setAvatarInitials(handleAvatarInitials(avatarName)); }, [avatarName]);
48
46
  var handleOnClickSwitchDirection = function () {
49
47
  setMobileNavDirection(mobileNavDirection === 'rtl' ? 'ltr' : 'rtl');
50
48
  avatarPanelOnClickSwitchDirection && avatarPanelOnClickSwitchDirection();
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { IVerticalNavigationItemProps } from './VerticalNavigationItem/VerticalNavigationItem';
3
+ import { IAvatarMenuItemProps } from './VerticalNavigationAvatar';
3
4
  interface VerticalNavigationProps {
4
5
  logo?: string;
5
6
  logoText?: string;
@@ -15,6 +16,17 @@ interface VerticalNavigationProps {
15
16
  isPersistent?: boolean;
16
17
  setIsPersistent?: any;
17
18
  appRootID?: string;
19
+ hasAvatar?: boolean;
20
+ avatarPanelOnClickSwitchDirection?: any;
21
+ avatarPanelOnClickLogout?: any;
22
+ avatarPanelOnClickViewProfile?: any;
23
+ avatarPanelViewProfileString?: string;
24
+ avatarPanelOnClickEditProfile?: any;
25
+ avatarPanelEditProfileString?: string;
26
+ avatarPanelMenuItems?: Array<IAvatarMenuItemProps>;
27
+ avatarPanelOnClickMainAction?: any;
28
+ avatarPanelMainActionString?: string;
29
+ avatarPanelSettingItems?: Array<IAvatarMenuItemProps>;
18
30
  }
19
31
  declare const VerticalNavigation: (props: VerticalNavigationProps) => React.ReactElement;
20
32
  export default VerticalNavigation;
@@ -9,6 +9,17 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
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
+ };
12
23
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
24
  import React, { useEffect } from 'react';
14
25
  import { useTheme } from '@mui/material/styles';
@@ -20,14 +31,14 @@ import { ChevronLeft, ChevronRight, PushPin } from '@mui/icons-material';
20
31
  import VerticalNavigationItem from './VerticalNavigationItem/VerticalNavigationItem';
21
32
  import { DRAWER_WIDTH, DrawerHeader, DrawerToggle, DrawerToggleHitboxContent, StyledDivider, StyledNav, StyledNavSecondary, DrawerShadow, StyledAside, NotchContainer, NotchBackground, NotchBackgroundClip, NotchSeemMask, StyledDrawer } from './VerticalNavigationStyles';
22
33
  import { ListItem, ListItemButton, ListItemIcon, ListItemText } from './VerticalNavigationItem/VerticalNavigationItemStyles';
23
- import AvatarPanel from './AvatarPanel';
34
+ import AvatarPanel from './VerticalNavigationAvatar';
24
35
  import { motion } from '../../../utils/theme';
25
36
  import { handleAvatarInitials } from '../../../utils/helpers';
26
37
  import { DEFAULT_REACT_APP_ID } from '../../../utils/constants';
27
38
  var VerticalNavigation = function (props) {
28
39
  var _a, _b;
29
40
  var theme = useTheme();
30
- var items = props.items, secondaryItems = props.secondaryItems, logo = props.logo, logoText = props.logoText, logoOnClick = props.logoOnClick, appRootID = props.appRootID, hasStreamHome = props.hasStreamHome, streamHomeApiKey = props.streamHomeApiKey, streamHomeBaseUrl = props.streamHomeBaseUrl, streamHomeAccessToken = props.streamHomeAccessToken;
41
+ var items = props.items, secondaryItems = props.secondaryItems, logo = props.logo, logoText = props.logoText, logoOnClick = props.logoOnClick, appRootID = props.appRootID, hasStreamHome = props.hasStreamHome, streamHomeApiKey = props.streamHomeApiKey, streamHomeBaseUrl = props.streamHomeBaseUrl, streamHomeAccessToken = props.streamHomeAccessToken, rest = __rest(props, ["items", "secondaryItems", "logo", "logoText", "logoOnClick", "appRootID", "hasStreamHome", "streamHomeApiKey", "streamHomeBaseUrl", "streamHomeAccessToken"]);
31
42
  var propIsDrawerOpen = typeof (props === null || props === void 0 ? void 0 : props.isDrawerOpen) === 'boolean' ? props.isDrawerOpen : undefined;
32
43
  var propIsPersistent = typeof (props === null || props === void 0 ? void 0 : props.isPersistent) === 'boolean' ? props.isPersistent : undefined;
33
44
  var avatarName = (_a = props === null || props === void 0 ? void 0 : props.avatarName) !== null && _a !== void 0 ? _a : 'Avatar name';
@@ -200,7 +211,7 @@ var VerticalNavigation = function (props) {
200
211
  padding: 0,
201
212
  minHeight: 52,
202
213
  transition: "max-height 225ms ".concat(motion.easeInOut, " 0ms !important")
203
- }, hasFlyout: true, fullHeightFlyout: true, content: _jsx(AvatarPanel, { avatarName: avatarName }), isDrawerOpen: isDrawerOpen }))
214
+ }, hasFlyout: true, fullHeightFlyout: true, content: _jsx(AvatarPanel, __assign({ avatarName: avatarName }, rest)), isDrawerOpen: isDrawerOpen }))
204
215
  : null] }))] })) }))] }))); };
205
216
  return (_jsxs(StyledAside, __assign({ "aria-label": "Site navigation" }, { children: [_jsx(DrawerShadow, { className: 'drawerShadow', "aria-hidden": 'true', isDrawerOpen: isDrawerOpen || isPersistent, style: {
206
217
  display: isPersistent ? 'none' : 'block'
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ export interface IAvatarMenuItemProps {
3
+ label: string;
4
+ icon: any;
5
+ onClick: any;
6
+ }
7
+ export interface IAvatarPanelProps {
8
+ avatarName: string;
9
+ editProfileText?: string;
10
+ logoutText?: string;
11
+ avatarPanelOnClickSwitchDirection?: any;
12
+ avatarPanelOnClickLogout?: any;
13
+ avatarPanelOnClickViewProfile?: any;
14
+ avatarPanelViewProfileString?: string;
15
+ avatarPanelOnClickEditProfile?: any;
16
+ avatarPanelEditProfileString?: string;
17
+ avatarPanelMenuItems?: Array<IAvatarMenuItemProps>;
18
+ avatarPanelOnClickMainAction?: any;
19
+ avatarPanelMainActionString?: string;
20
+ avatarPanelSettingItems?: Array<IAvatarMenuItemProps>;
21
+ avatarPanelInvertNavString?: string;
22
+ }
23
+ declare const AvatarPanel: (props: IAvatarPanelProps) => React.ReactElement;
24
+ export default AvatarPanel;
@@ -0,0 +1,84 @@
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, Button, Link, List, ListItem, ListItemIcon, ListItemText } from '../../../index';
15
+ import { StyledBox, StyledBoxProfile, StyledAvatarName, StyledAvatar, StyledOutlineButton, StyledBoxProfileEdit, StyledListItemButton } from './VerticalNavigationAvatarStyles';
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 './VerticalNavigationMotion';
21
+ import { handleAvatarInitials } from '../../../utils/helpers';
22
+ import { Person, Settings } from '@mui/icons-material';
23
+ var AvatarPanel = function (props) {
24
+ var _a;
25
+ var theme = useTheme();
26
+ var avatarName = props.avatarName, avatarPanelOnClickLogout = props.avatarPanelOnClickLogout, logoutText = props.logoutText, avatarPanelOnClickViewProfile = props.avatarPanelOnClickViewProfile, avatarPanelViewProfileString = props.avatarPanelViewProfileString, avatarPanelOnClickEditProfile = props.avatarPanelOnClickEditProfile, avatarPanelEditProfileString = props.avatarPanelEditProfileString, avatarPanelMenuItems = props.avatarPanelMenuItems, avatarPanelOnClickMainAction = props.avatarPanelOnClickMainAction, avatarPanelMainActionString = props.avatarPanelMainActionString, avatarPanelSettingItems = props.avatarPanelSettingItems;
27
+ useEffect(function () { return setAvatarInitials(handleAvatarInitials(avatarName)); }, [
28
+ avatarName
29
+ ]);
30
+ var _b = React.useState((_a = handleAvatarInitials(avatarName)) !== null && _a !== void 0 ? _a : 'AN'), avatarInitials = _b[0], setAvatarInitials = _b[1];
31
+ return (_jsxs(StyledBox
32
+ // TODO: add check for isAvatarOpen to trigger animation effects
33
+ // animate={ isAvatarOpen ? 'open' : 'closed' }
34
+ , __assign({
35
+ // TODO: add check for isAvatarOpen to trigger animation effects
36
+ // animate={ isAvatarOpen ? 'open' : 'closed' }
37
+ variants: motionParent }, { children: [avatarPanelOnClickLogout && (_jsx(Button
38
+ // @ts-expect-error
39
+ , __assign({
40
+ // @ts-expect-error
41
+ component: motion.button, variants: motionFadeIn, style: {
42
+ left: theme.direction === 'rtl' ? theme.spacing(1) : 'auto',
43
+ position: 'absolute',
44
+ right: theme.direction === 'rtl' ? 'auto' : theme.spacing(1),
45
+ top: theme.spacing(1)
46
+ }, onClick: avatarPanelOnClickLogout, startIcon: _jsx(LogoutIcon, {}), variant: 'text', color: 'inherit' }, { children: logoutText !== null && logoutText !== void 0 ? logoutText : 'Logout' }))), _jsxs(Box, __assign({ style: {
47
+ alignItems: 'center',
48
+ display: 'flex',
49
+ flexDirection: 'column'
50
+ } }, { 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: {
51
+ flexDirection: 'row',
52
+ marginBottom: theme.spacing(1)
53
+ } }, { children: _jsxs(ButtonGroup, __assign({ variant: "contained", "aria-label": "split button" }, { children: [_jsx(Button, __assign({ variant: 'contained', color: 'primary', size: 'medium', onClick: avatarPanelOnClickViewProfile, startIcon: _jsx(Person, {}) }, { 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: {
54
+ alignItems: 'center',
55
+ display: 'flex',
56
+ flexDirection: 'column'
57
+ } }, { children: [avatarPanelMenuItems && avatarPanelMenuItems.length > 0 && (_jsx(List, __assign({ style: {
58
+ marginBottom: theme.spacing(2),
59
+ maxWidth: '14rem'
60
+ } }, { children: avatarPanelMenuItems.map(function (avatarMenuItem) { return (_jsx(ListItem, __assign({ component: motion.div, variants: motionFadeInUp, whileHover: motionWhileHover, whileTap: motionWhileTap, disablePadding: true }, { children: _jsxs(StyledListItemButton
61
+ // TODO: figure out if these are links or buttons
62
+ // @ts-expect-error
63
+ , __assign({
64
+ // TODO: figure out if these are links or buttons
65
+ // @ts-expect-error
66
+ component: Link, role: 'link', onClick: avatarMenuItem.onClick }, { children: [_jsx(ListItemIcon, __assign({ "aria-hidden": true, style: {
67
+ minWidth: theme.spacing(5)
68
+ } }, { children: avatarMenuItem.icon })), _jsx(ListItemText, { primary: avatarMenuItem.label })] })) }))); }) }))), avatarPanelOnClickMainAction && _jsx(StyledOutlineButton
69
+ // @ts-expect-error
70
+ , __assign({
71
+ // @ts-expect-error
72
+ component: motion.button, variants: motionFadeInUp, disablePadding: true, variant: 'outlined', color: 'primary', size: 'medium', onClick: avatarPanelOnClickMainAction, startIcon: _jsx(Settings, {}) }, { children: avatarPanelMainActionString })), _jsx(List, __assign({ style: { marginBottom: theme.spacing(2) } }, { children: avatarPanelSettingItems &&
73
+ avatarPanelSettingItems.length > 0 &&
74
+ avatarPanelSettingItems.map(function (avatarMenuItem) { return (_jsx(ListItem, __assign({ component: motion.div, variants: motionFadeInUp, whileHover: motionWhileHover, whileTap: motionWhileTap, disablePadding: true }, { children: _jsxs(StyledListItemButton
75
+ // TODO: figure out if these are links or buttons
76
+ // @ts-expect-error
77
+ , __assign({
78
+ // TODO: figure out if these are links or buttons
79
+ // @ts-expect-error
80
+ component: Link, role: 'link', onClick: avatarMenuItem.onClick }, { children: [_jsx(ListItemIcon, __assign({ "aria-hidden": true, style: {
81
+ minWidth: theme.spacing(5)
82
+ } }, { children: avatarMenuItem.icon })), _jsx(ListItemText, { primary: avatarMenuItem.label })] })) }))); }) }))] }))] })));
83
+ };
84
+ export default AvatarPanel;