@tap-payments/os-micro-frontend-shared 0.0.157-alpha.10 → 0.0.157-alpha.11
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.
|
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
-
import { memo, useCallback, useMemo, useRef, useState } from 'react';
|
|
13
|
+
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
14
14
|
import { useTranslation } from 'react-i18next';
|
|
15
15
|
import StyledBadge, { BadgeVariants } from '../../../CountBadge';
|
|
16
16
|
import { convertToNumber, formatNumber } from '../../../../utils/index.js';
|
|
@@ -20,12 +20,13 @@ import { statusButtonIcons } from './constant';
|
|
|
20
20
|
export const StatusButton = memo((props) => {
|
|
21
21
|
var _a;
|
|
22
22
|
const { variant = 'inActive', badgeCount, icon, label, dropdownOptions, onButtonBodyClick } = props, restProps = __rest(props, ["variant", "badgeCount", "icon", "label", "dropdownOptions", "onButtonBodyClick"]);
|
|
23
|
+
const [buttonClicks, setButtonClicks] = useState(0);
|
|
23
24
|
const { t } = useTranslation();
|
|
24
25
|
const buttonRef = useRef(null);
|
|
25
26
|
const [anchorEl, setAnchorEl] = useState(null);
|
|
26
27
|
const [selectedStatus, setSelectedStatus] = useState((_a = dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions[0]) === null || _a === void 0 ? void 0 : _a.status);
|
|
27
28
|
const hasDropdown = useMemo(() => Boolean(dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions.length), [dropdownOptions]);
|
|
28
|
-
const isDropdownOpen = Boolean(anchorEl);
|
|
29
|
+
const isDropdownOpen = Boolean(anchorEl) && buttonClicks > 1;
|
|
29
30
|
const isActiveVariant = variant === 'active';
|
|
30
31
|
const badgeVariant = useMemo(() => (isActiveVariant ? BadgeVariants.ACTIVE : BadgeVariants.INACTIVE), [isActiveVariant]);
|
|
31
32
|
const statusIcon = useMemo(() => (icon ? _jsx(StyledStatusIcon, { icon: icon, variant: variant, src: statusButtonIcons[icon], alt: `${icon}-icon` }) : null), [icon, variant]);
|
|
@@ -35,6 +36,12 @@ export const StatusButton = memo((props) => {
|
|
|
35
36
|
return _jsx(StyledBadge, Object.assign({ variant: badgeVariant }, { children: formatNumber(Number(badgeCount)) }));
|
|
36
37
|
}, [badgeCount, badgeVariant]);
|
|
37
38
|
const dropdownIcon = useMemo(() => (hasDropdown ? _jsx(ChevronIcon, { isActive: isActiveVariant }) : null), [hasDropdown, isActiveVariant]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!isActiveVariant) {
|
|
41
|
+
setButtonClicks(0);
|
|
42
|
+
setAnchorEl(null);
|
|
43
|
+
}
|
|
44
|
+
}, [isActiveVariant]);
|
|
38
45
|
const handleDropdownClose = useCallback(() => {
|
|
39
46
|
setAnchorEl(null);
|
|
40
47
|
}, []);
|
|
@@ -49,6 +56,7 @@ export const StatusButton = memo((props) => {
|
|
|
49
56
|
(_a = props === null || props === void 0 ? void 0 : props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, e);
|
|
50
57
|
onButtonBodyClick === null || onButtonBodyClick === void 0 ? void 0 : onButtonBodyClick(selectedStatus || ((_b = dropdownOptions === null || dropdownOptions === void 0 ? void 0 : dropdownOptions[0]) === null || _b === void 0 ? void 0 : _b.status) || 'all');
|
|
51
58
|
handleDropdownToggle();
|
|
59
|
+
setButtonClicks((prev) => prev + 1);
|
|
52
60
|
}, [props, onButtonBodyClick, selectedStatus, dropdownOptions, handleDropdownToggle]);
|
|
53
61
|
const handleMenuItemClick = useCallback((item) => (e) => {
|
|
54
62
|
var _a;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.157-alpha.
|
|
4
|
+
"version": "0.0.157-alpha.11",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "build/index.js",
|
|
7
7
|
"module": "build/index.js",
|