@tap-payments/os-micro-frontend-shared 0.0.233-test.20 → 0.0.233-test.22
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { MultiSelectStatusButtonProps } from './type';
|
|
3
|
-
declare function MultiSelectStatusButton({ options, selectedValues, onSelectionChange, label, variant
|
|
3
|
+
declare function MultiSelectStatusButton({ options, selectedValues, onSelectionChange, label, variant }: MultiSelectStatusButtonProps): import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
declare const _default: import("react").MemoExoticComponent<typeof MultiSelectStatusButton>;
|
|
5
5
|
export default _default;
|
|
@@ -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
|
-
|
|
10
|
-
|
|
11
|
-
function MultiSelectStatusButton({ options = [], selectedValues, onSelectionChange, label, variant = 'inActive', render, }) {
|
|
9
|
+
import { ChevronContainer, Label, LabelWrapper, StyledDropdown, MenuItemContainer, CheckboxStyles, StyledStatusButton, ClearIcon, ChevronIconWrapper, } from './style';
|
|
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);
|
|
@@ -5,6 +5,7 @@ export interface CurrencyOption {
|
|
|
5
5
|
name: string;
|
|
6
6
|
flagCode?: string;
|
|
7
7
|
status: TableHeaderStatus;
|
|
8
|
+
render?: () => JSX.Element;
|
|
8
9
|
}
|
|
9
10
|
export interface MultiSelectStatusButtonProps {
|
|
10
11
|
options: CurrencyOption[];
|
|
@@ -12,5 +13,4 @@ export interface MultiSelectStatusButtonProps {
|
|
|
12
13
|
onSelectionChange: (selected: TableHeaderStatus[]) => void;
|
|
13
14
|
label?: string;
|
|
14
15
|
variant?: 'active' | 'inActive';
|
|
15
|
-
render?: () => JSX.Element;
|
|
16
16
|
}
|
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.22",
|
|
5
|
+
"testVersion": 22,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
8
8
|
"module": "build/index.js",
|