@tap-payments/os-micro-frontend-shared 0.0.92 → 0.0.95
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/build/components/AppServices/AppServices.d.ts +11 -0
- package/build/components/AppServices/AppServices.js +91 -0
- package/build/components/AppServices/ServiceItem.d.ts +14 -0
- package/build/components/AppServices/ServiceItem.js +40 -0
- package/build/components/AppServices/index.d.ts +2 -0
- package/build/components/AppServices/index.js +2 -0
- package/build/components/AppServices/style.d.ts +14 -0
- package/build/components/AppServices/style.js +33 -0
- package/build/components/index.d.ts +1 -0
- package/build/components/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { AppDetails, UserApp } from '../../types/index.js';
|
|
3
|
+
import { ServiceItemProps } from './ServiceItem';
|
|
4
|
+
interface AppServicesProps extends Pick<ServiceItemProps, 'onClickServiceItem'> {
|
|
5
|
+
appInfo: AppDetails;
|
|
6
|
+
userApp?: UserApp;
|
|
7
|
+
onChangeAppServiceCode?: (serviceCode: string) => void;
|
|
8
|
+
}
|
|
9
|
+
declare function AppServices({ appInfo, userApp, onChangeAppServiceCode, onClickServiceItem }: AppServicesProps): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
declare const _default: React.MemoExoticComponent<typeof AppServices>;
|
|
11
|
+
export default _default;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { memo, useEffect, useRef, useState, useMemo } from 'react';
|
|
3
|
+
import { Box } from '@mui/material';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { useNavigate, useLocation } from 'react-router-dom';
|
|
6
|
+
import { StyledIconForDropDown, StyledMenuTitle, StyledOption, StyledSelect, StyledSelectComponent } from '../index.js';
|
|
7
|
+
import { APP_CODES, blackHeadingDownArrow, blueHeadingDropdownArrow } from '../../constants/index.js';
|
|
8
|
+
import { getNameText } from '../../utils/index.js';
|
|
9
|
+
import ServiceItem from './ServiceItem';
|
|
10
|
+
import { Wrapper } from './style';
|
|
11
|
+
const selectedIcon = (props) => {
|
|
12
|
+
return (_jsx(StyledIconForDropDown, { src: props.className.includes('MuiSelect-iconOpen') ? blueHeadingDropdownArrow : blackHeadingDownArrow, alt: "dropdown" }));
|
|
13
|
+
};
|
|
14
|
+
function AppServices({ appInfo, userApp, onChangeAppServiceCode, onClickServiceItem }) {
|
|
15
|
+
const [initServicesWidth, setInitServicesWidth] = useState(0);
|
|
16
|
+
const [isDropdown, setIsDropdown] = useState(false);
|
|
17
|
+
const [selectedOption, setSelectedOption] = useState('');
|
|
18
|
+
const servicesRef = useRef(null);
|
|
19
|
+
const [openDropdown, setOpenDropdown] = React.useState(false);
|
|
20
|
+
const navigate = useNavigate();
|
|
21
|
+
const pathname = useLocation();
|
|
22
|
+
const { i18n } = useTranslation();
|
|
23
|
+
const services = useMemo(() => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
if (appInfo.appCode === APP_CODES.account.code) {
|
|
26
|
+
return (_a = userApp === null || userApp === void 0 ? void 0 : userApp.app_services.filter((service) => service.code === APP_CODES.account.services.account.code)) !== null && _a !== void 0 ? _a : [];
|
|
27
|
+
}
|
|
28
|
+
return (_b = userApp === null || userApp === void 0 ? void 0 : userApp.app_services) !== null && _b !== void 0 ? _b : [];
|
|
29
|
+
}, [appInfo.appCode, userApp === null || userApp === void 0 ? void 0 : userApp.app_services]);
|
|
30
|
+
const handleChange = (event) => {
|
|
31
|
+
setSelectedOption(event.target.value);
|
|
32
|
+
};
|
|
33
|
+
const handleOpenDropdown = () => {
|
|
34
|
+
setOpenDropdown((prev) => !prev);
|
|
35
|
+
};
|
|
36
|
+
const activeTabTitle = useMemo(() => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
return getNameText((_b = (_a = services.filter((service) => service.code.toLowerCase() === decodeURIComponent(appInfo.serviceCode).toLowerCase())) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.name, i18n.language);
|
|
39
|
+
}, [pathname, appInfo.serviceCode]);
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
setSelectedOption(activeTabTitle);
|
|
42
|
+
}, [activeTabTitle]);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
var _a;
|
|
45
|
+
const iconSize = 51;
|
|
46
|
+
const iconGap = 8;
|
|
47
|
+
const iconMargin = 3;
|
|
48
|
+
setInitServicesWidth(((_a = servicesRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) + iconSize + iconGap + iconMargin);
|
|
49
|
+
}, []);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
setIsDropdown(Number(appInfo === null || appInfo === void 0 ? void 0 : appInfo.dimensions.width) < initServicesWidth + 10);
|
|
52
|
+
}, [appInfo === null || appInfo === void 0 ? void 0 : appInfo.dimensions.width]);
|
|
53
|
+
const renderValue = (selected) => _jsx(StyledSelectComponent, { children: selected });
|
|
54
|
+
const navigateToService = (serviceCode) => {
|
|
55
|
+
navigate(`${appInfo.appCode.toLowerCase()}/${serviceCode.toLowerCase()}`);
|
|
56
|
+
onChangeAppServiceCode === null || onChangeAppServiceCode === void 0 ? void 0 : onChangeAppServiceCode(serviceCode);
|
|
57
|
+
setOpenDropdown(false);
|
|
58
|
+
};
|
|
59
|
+
return (_jsxs(Wrapper, Object.assign({ maximized: appInfo.isMaximized }, { children: [services.length && !isDropdown && (_jsx(Box, Object.assign({ ref: servicesRef, display: "flex", gap: "8px", flexDirection: "row", sx: { userSelect: 'none' } }, { children: services.map((service, idx) => (_jsx(ServiceItem, { appInfo: appInfo, onClickServiceItem: onClickServiceItem, navigateToMenuItem: navigateToService, name: getNameText(service.name, i18n.language) || '', code: service.code }, `service-item-${service.code}-${idx}`))) }))), services.length && isDropdown && (_jsx(StyledSelect, Object.assign({ open: openDropdown, onClick: handleOpenDropdown, displayEmpty: true, inputProps: { 'aria-label': 'Without label' }, MenuProps: {
|
|
60
|
+
anchorOrigin: {
|
|
61
|
+
vertical: 40,
|
|
62
|
+
horizontal: 83,
|
|
63
|
+
},
|
|
64
|
+
PaperProps: {
|
|
65
|
+
style: {
|
|
66
|
+
borderRadius: '0.25rem',
|
|
67
|
+
width: '10.43rem',
|
|
68
|
+
padding: 0,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
MenuListProps: {
|
|
72
|
+
disablePadding: true,
|
|
73
|
+
},
|
|
74
|
+
}, value: selectedOption, IconComponent: selectedIcon, onChange: handleChange, renderValue: renderValue, sx: {
|
|
75
|
+
'& .MuiOutlinedInput-root.MuiList-root-MuiMenu-list': {
|
|
76
|
+
paddingTop: '0px !important',
|
|
77
|
+
paddingBottom: '0px !important',
|
|
78
|
+
},
|
|
79
|
+
} }, { children: services.map((service) => {
|
|
80
|
+
var _a;
|
|
81
|
+
if (((_a = getNameText(service.name, i18n.language)) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.toLowerCase())) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
return (_jsx(StyledOption, Object.assign({ value: getNameText(service.name, i18n.language), onClick: (e) => {
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
e.stopPropagation();
|
|
87
|
+
navigateToService(service.code);
|
|
88
|
+
} }, { children: _jsx(StyledMenuTitle, { children: getNameText(service.name, i18n.language) }) })));
|
|
89
|
+
}) })))] })));
|
|
90
|
+
}
|
|
91
|
+
export default memo(AppServices);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { AppDetails } from '../../types/index.js';
|
|
3
|
+
export interface ServiceItemProps {
|
|
4
|
+
appInfo: AppDetails;
|
|
5
|
+
isDropdown?: boolean;
|
|
6
|
+
name: string;
|
|
7
|
+
code: string;
|
|
8
|
+
onDropdownClick?: () => void;
|
|
9
|
+
navigateToMenuItem: (serviceCode: string) => void;
|
|
10
|
+
onClickServiceItem?: (code: string) => void;
|
|
11
|
+
}
|
|
12
|
+
declare function ServiceItem({ isDropdown, name, code, appInfo, onDropdownClick, navigateToMenuItem, onClickServiceItem }: ServiceItemProps): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
declare const _default: import("react").MemoExoticComponent<typeof ServiceItem>;
|
|
14
|
+
export default _default;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useState } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { DropdownMenu, Icon } from '../index.js';
|
|
5
|
+
import { isInsightService } from '../../utils/index.js';
|
|
6
|
+
import { homeIcon, newWindowIcon } from '../../constants/index.js';
|
|
7
|
+
import { ServiceItemStyled } from './style';
|
|
8
|
+
function ServiceItem({ isDropdown = false, name, code, appInfo, onDropdownClick, navigateToMenuItem, onClickServiceItem }) {
|
|
9
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
10
|
+
const { t } = useTranslation();
|
|
11
|
+
const open = Boolean(anchorEl);
|
|
12
|
+
const handleClose = () => {
|
|
13
|
+
setAnchorEl(null);
|
|
14
|
+
};
|
|
15
|
+
const isHomeService = isInsightService(code);
|
|
16
|
+
return (_jsxs(_Fragment, { children: [_jsx(ServiceItemStyled, Object.assign({ isDropdown: isDropdown, className: appInfo.serviceCode.toLowerCase() === code.toLowerCase() ? 'active' : '', onClick: (e) => {
|
|
17
|
+
e.preventDefault();
|
|
18
|
+
e.stopPropagation();
|
|
19
|
+
navigateToMenuItem(code);
|
|
20
|
+
}, title: isHomeService ? undefined : name, onContextMenu: (event) => {
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
event.stopPropagation();
|
|
23
|
+
handleClose();
|
|
24
|
+
setAnchorEl(event.currentTarget);
|
|
25
|
+
} }, { children: isHomeService ? _jsx(Icon, { src: homeIcon }) : name })), _jsx(DropdownMenu, { open: open, anchorEl: anchorEl, onClose: handleClose, menuItems: [
|
|
26
|
+
{
|
|
27
|
+
label: t('openNewWindow'),
|
|
28
|
+
name: 'new',
|
|
29
|
+
icon: _jsx("img", { src: newWindowIcon, alt: "new-window-icon" }),
|
|
30
|
+
onClick: (e) => {
|
|
31
|
+
e.stopPropagation();
|
|
32
|
+
onClickServiceItem === null || onClickServiceItem === void 0 ? void 0 : onClickServiceItem(code);
|
|
33
|
+
handleClose();
|
|
34
|
+
if (onDropdownClick)
|
|
35
|
+
onDropdownClick();
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
] })] }));
|
|
39
|
+
}
|
|
40
|
+
export default memo(ServiceItem);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare const Wrapper: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
3
|
+
ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
|
|
4
|
+
}, keyof import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & {
|
|
5
|
+
maximized?: boolean | undefined;
|
|
6
|
+
}, {}, {}>;
|
|
7
|
+
export declare const ServiceItemStyled: import("@emotion/styled").StyledComponent<import("@mui/material").TypographyOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
|
|
8
|
+
ref?: ((instance: HTMLSpanElement | null) => void) | import("react").RefObject<HTMLSpanElement> | null | undefined;
|
|
9
|
+
}, "width" | "minHeight" | "height" | "bottom" | "left" | "right" | "top" | "textAlign" | "className" | "style" | "classes" | "border" | "borderTop" | "borderRight" | "borderBottom" | "borderLeft" | "borderColor" | "borderRadius" | "display" | "displayPrint" | "overflow" | "textOverflow" | "visibility" | "whiteSpace" | "flexBasis" | "flexDirection" | "flexWrap" | "justifyContent" | "alignItems" | "alignContent" | "order" | "flex" | "flexGrow" | "flexShrink" | "alignSelf" | "justifyItems" | "justifySelf" | "gap" | "columnGap" | "rowGap" | "gridColumn" | "gridRow" | "gridAutoFlow" | "gridAutoColumns" | "gridAutoRows" | "gridTemplateColumns" | "gridTemplateRows" | "gridTemplateAreas" | "gridArea" | "bgcolor" | "color" | "zIndex" | "position" | "boxShadow" | "maxWidth" | "minWidth" | "maxHeight" | "boxSizing" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "my" | "p" | "pt" | "pr" | "pb" | "pl" | "px" | "py" | "margin" | "marginTop" | "marginRight" | "marginBottom" | "marginLeft" | "marginX" | "marginY" | "marginInline" | "marginInlineStart" | "marginInlineEnd" | "marginBlock" | "marginBlockStart" | "marginBlockEnd" | "padding" | "paddingTop" | "paddingRight" | "paddingBottom" | "paddingLeft" | "paddingX" | "paddingY" | "paddingInline" | "paddingInlineStart" | "paddingInlineEnd" | "paddingBlock" | "paddingBlockStart" | "paddingBlockEnd" | "typography" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "letterSpacing" | "lineHeight" | "textTransform" | "children" | "sx" | "variant" | "align" | "gutterBottom" | "noWrap" | "paragraph" | "variantMapping"> & {
|
|
10
|
+
component?: import("react").ElementType<any, keyof import("react").JSX.IntrinsicElements> | undefined;
|
|
11
|
+
} & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & {
|
|
12
|
+
title?: string | undefined;
|
|
13
|
+
isDropdown: boolean;
|
|
14
|
+
}, {}, {}>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Box from '@mui/material/Box';
|
|
2
|
+
import Text from '../Text';
|
|
3
|
+
import { styled } from '@mui/material/styles';
|
|
4
|
+
import { getBrowserName } from '../../utils/index.js';
|
|
5
|
+
export const Wrapper = styled(Box, { shouldForwardProp: (props) => props !== 'maximized' })(({ theme, maximized }) => ({
|
|
6
|
+
display: 'flex',
|
|
7
|
+
alignItems: 'center',
|
|
8
|
+
gap: theme.spacing(1),
|
|
9
|
+
overflow: 'hidden',
|
|
10
|
+
height: maximized ? '4.75rem' : '4.1875rem',
|
|
11
|
+
paddingBottom: maximized ? '0rem' : '1.2rem',
|
|
12
|
+
paddingInline: theme.spacing(4),
|
|
13
|
+
paddingTop: maximized ? '1.35rem' : theme.spacing(0.5),
|
|
14
|
+
}));
|
|
15
|
+
const browserName = getBrowserName();
|
|
16
|
+
export const ServiceItemStyled = styled(Text, {
|
|
17
|
+
shouldForwardProp: (props) => props !== 'title' && props !== 'isDropdown',
|
|
18
|
+
})(({ title, isDropdown, theme }) => ({
|
|
19
|
+
position: 'relative',
|
|
20
|
+
fontWeight: theme.typography.fontWeightMedium,
|
|
21
|
+
padding: theme.spacing(1),
|
|
22
|
+
color: theme.palette.text.primary,
|
|
23
|
+
fontSize: '11px',
|
|
24
|
+
lineHeight: '15px',
|
|
25
|
+
borderRadius: theme.shape.borderRadius,
|
|
26
|
+
transition: theme.transitions.create(['backgroundColor', 'boxShadow'], {
|
|
27
|
+
easing: theme.transitions.easing.sharp,
|
|
28
|
+
duration: theme.transitions.duration.complex,
|
|
29
|
+
}),
|
|
30
|
+
whiteSpace: 'nowrap',
|
|
31
|
+
textTransform: 'capitalize',
|
|
32
|
+
'&:hover, &.active': Object.assign(Object.assign({}, (!isDropdown && { backgroundColor: theme.palette.common.white, boxShadow: theme.shadows[2] })), { cursor: 'pointer', position: 'relative', color: 'transparent', '&:after': Object.assign(Object.assign({}, (title && { content: `"${title}"` })), { color: theme.palette.text.primary, fontWeight: theme.typography.fontWeightBold, overflow: 'hidden', position: 'absolute', top: 0, bottom: 0, right: 0, left: 0, display: 'flex', alignItems: 'center', justifyContent: isDropdown ? 'flex-start' : 'center', letterSpacing: browserName === 'safari' ? '-1px' : '', padding: 8, borderRadius: theme.shape.borderRadius }) }),
|
|
33
|
+
}));
|
package/package.json
CHANGED