@tap-payments/os-micro-frontend-shared 0.0.233-test.21 → 0.0.233-test.25
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.
|
@@ -17,6 +17,7 @@ export const MenuItemStyled = styled(Box, { shouldForwardProp: (props) => props
|
|
|
17
17
|
}));
|
|
18
18
|
export const CheckboxStyled = styled(Checkbox)(({ theme }) => ({
|
|
19
19
|
padding: 0,
|
|
20
|
+
paddingRight: '4px',
|
|
20
21
|
width: '14px !important',
|
|
21
22
|
svg: {
|
|
22
23
|
width: '12px !important',
|
|
@@ -1,25 +1,44 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { memo, useState, useRef } from 'react';
|
|
3
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { memo, useState, useRef, useEffect } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { Typography, Checkbox } from '@mui/material';
|
|
4
5
|
import { ChevronIcon } from '../StatusButton/ChevronIcon';
|
|
5
6
|
import StyledBadge, { BadgeVariants } from '../CountBadge';
|
|
6
7
|
import { formatNumber } from '../../utils/index.js';
|
|
7
8
|
import { closeXIcon } from '../../constants/index.js';
|
|
8
|
-
import { ChevronContainer, Label, LabelWrapper, StyledStatusButton, ClearIcon, ChevronIconWrapper, } from './style';
|
|
9
|
-
import Menu from '../Menu';
|
|
10
|
-
import MenuItem from '../MenuItem';
|
|
9
|
+
import { ChevronContainer, Label, LabelWrapper, StyledDropdown, MenuItemContainer, CheckboxStyles, StyledStatusButton, ClearIcon, ChevronIconWrapper, } from './style';
|
|
11
10
|
function MultiSelectStatusButton({ options = [], selectedValues, onSelectionChange, label, variant = 'inActive' }) {
|
|
11
|
+
const { t } = useTranslation();
|
|
12
12
|
const [anchorEl, setAnchorEl] = useState(null);
|
|
13
13
|
const buttonRef = useRef(null);
|
|
14
14
|
const [internalSelectedValues, setInternalSelectedValues] = useState(selectedValues);
|
|
15
|
+
const [dropdownWidth, setDropdownWidth] = useState(0);
|
|
15
16
|
const [isHovered, setIsHovered] = useState(false);
|
|
16
17
|
const isOpen = Boolean(anchorEl);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!isOpen) {
|
|
20
|
+
setInternalSelectedValues(selectedValues);
|
|
21
|
+
}
|
|
22
|
+
}, [selectedValues, isOpen]);
|
|
17
23
|
const handleDropdownClick = (event) => {
|
|
24
|
+
var _a;
|
|
25
|
+
event.stopPropagation();
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
if (isOpen) {
|
|
28
|
+
handleClose();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
18
31
|
setAnchorEl(buttonRef.current);
|
|
32
|
+
const buttonWidth = ((_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth) || 200;
|
|
33
|
+
setDropdownWidth(Math.max(buttonWidth, 200));
|
|
19
34
|
};
|
|
20
35
|
const handleClose = () => {
|
|
36
|
+
const hasChanged = JSON.stringify([...internalSelectedValues].sort()) !== JSON.stringify([...selectedValues].sort());
|
|
37
|
+
if (hasChanged) {
|
|
38
|
+
onSelectionChange(internalSelectedValues);
|
|
39
|
+
}
|
|
21
40
|
setAnchorEl(null);
|
|
22
|
-
|
|
41
|
+
setDropdownWidth(0);
|
|
23
42
|
};
|
|
24
43
|
const handleClearAll = (event) => {
|
|
25
44
|
event.stopPropagation();
|
|
@@ -27,33 +46,47 @@ function MultiSelectStatusButton({ options = [], selectedValues, onSelectionChan
|
|
|
27
46
|
setInternalSelectedValues([]);
|
|
28
47
|
onSelectionChange([]);
|
|
29
48
|
};
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (isOptionSelected(optionStatus)) {
|
|
35
|
-
setInternalSelectedValues(internalSelectedValues.filter((status) => status !== optionStatus));
|
|
36
|
-
return;
|
|
49
|
+
const handleOptionToggle = (optionStatus, event) => {
|
|
50
|
+
if (event) {
|
|
51
|
+
event.stopPropagation();
|
|
52
|
+
event.preventDefault();
|
|
37
53
|
}
|
|
38
|
-
|
|
54
|
+
const newSelection = internalSelectedValues.includes(optionStatus)
|
|
55
|
+
? internalSelectedValues.filter((status) => status !== optionStatus)
|
|
56
|
+
: [...internalSelectedValues, optionStatus];
|
|
57
|
+
setInternalSelectedValues(newSelection);
|
|
39
58
|
};
|
|
40
|
-
return (_jsxs(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
minWidth: 200,
|
|
51
|
-
width: 'auto',
|
|
52
|
-
marginTop: '
|
|
59
|
+
return (_jsxs(_Fragment, { children: [_jsx(StyledStatusButton, Object.assign({ buttonVariant: variant, ref: buttonRef, sx: {
|
|
60
|
+
paddingInlineEnd: '27px',
|
|
61
|
+
}, "data-testid": "MultiSelectStatusButton", onClick: handleDropdownClick, onMouseEnter: () => setIsHovered(true), onMouseLeave: () => setIsHovered(false), disabled: !options.length }, { children: _jsxs(LabelWrapper, { children: [_jsxs(Label, Object.assign({ variant: variant }, { children: [_jsx(Typography, Object.assign({ fontWeight: 400, fontSize: "11px", variant: "inherit" }, { children: label })), _jsx(StyledBadge, Object.assign({ pointer: true, variant: variant === 'active' ? BadgeVariants.ACTIVE : BadgeVariants.INACTIVE }, { children: formatNumber(selectedValues.length > 0 ? selectedValues.length : options.length) }))] })), _jsxs(ChevronContainer, Object.assign({ onClick: isHovered && internalSelectedValues.length > 0 ? handleClearAll : undefined, sx: {
|
|
62
|
+
'&:hover': {
|
|
63
|
+
backgroundColor: 'transparent',
|
|
64
|
+
},
|
|
65
|
+
} }, { children: [_jsx(ClearIcon, { variant: variant, src: closeXIcon, alt: "clear all", sx: {
|
|
66
|
+
opacity: isHovered && internalSelectedValues.length > 0 ? 1 : 0,
|
|
67
|
+
pointerEvents: isHovered && internalSelectedValues.length > 0 ? 'auto' : 'none',
|
|
68
|
+
} }), _jsx(ChevronIconWrapper, Object.assign({ isVisible: !(isHovered && internalSelectedValues.length > 0) }, { children: _jsx(ChevronIcon, { disableHover: true, isActive: variant === 'active' }) }))] }))] }) })), isOpen && anchorEl && (_jsx(StyledDropdown, { open: isOpen, onClose: handleClose, anchorEl: anchorEl, allowShadows: false, style: {
|
|
69
|
+
minWidth: dropdownWidth || 200,
|
|
70
|
+
width: dropdownWidth || 'auto',
|
|
71
|
+
marginTop: '6px',
|
|
53
72
|
maxWidth: 300,
|
|
54
|
-
}
|
|
73
|
+
}, sx: {
|
|
74
|
+
boxShadow: 'none !important',
|
|
75
|
+
'&:hover': {
|
|
76
|
+
boxShadow: 'none !important',
|
|
77
|
+
},
|
|
78
|
+
}, menuItems: options.map((option) => ({
|
|
79
|
+
label: (_jsxs(MenuItemContainer, { children: [_jsx(Checkbox, { checked: internalSelectedValues.includes(option.status), size: "small", sx: CheckboxStyles, onClick: (e) => {
|
|
80
|
+
var _a;
|
|
81
|
+
e.stopPropagation();
|
|
82
|
+
handleOptionToggle((_a = option.status) !== null && _a !== void 0 ? _a : '', e);
|
|
83
|
+
} }), option.render ? option.render() : _jsx(Typography, Object.assign({ variant: "body2" }, { children: option.name }))] })),
|
|
84
|
+
onClick: (e) => {
|
|
55
85
|
var _a;
|
|
56
|
-
|
|
57
|
-
|
|
86
|
+
e.preventDefault();
|
|
87
|
+
e.stopPropagation();
|
|
88
|
+
handleOptionToggle((_a = option.status) !== null && _a !== void 0 ? _a : '', e);
|
|
89
|
+
},
|
|
90
|
+
})) }))] }));
|
|
58
91
|
}
|
|
59
92
|
export default memo(MultiSelectStatusButton);
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tap-payments/os-micro-frontend-shared",
|
|
3
3
|
"description": "Shared components and utilities for Tap Payments micro frontends",
|
|
4
|
-
"version": "0.0.233-test.
|
|
5
|
-
"testVersion":
|
|
4
|
+
"version": "0.0.233-test.25",
|
|
5
|
+
"testVersion": 25,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
8
8
|
"module": "build/index.js",
|