@tap-payments/os-micro-frontend-shared 0.0.92-multi-select-status-button-v1 → 0.0.92-multi-select-status-button-v3

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.
@@ -7,7 +7,7 @@ import StyledBadge, { BadgeVariants } from '../CountBadge';
7
7
  import CountryFlag from '../CountryFlag';
8
8
  import { formatNumber } from '../../utils/index.js';
9
9
  import { closeXIcon } from '../../constants/index.js';
10
- import { ChevronContainer, Label, LabelWrapper, StyledDropdown, FlagContainer, MenuItemContainer, CheckboxStyles, StyledStatusButton, ClearIcon, } from './style';
10
+ import { ChevronContainer, Label, LabelWrapper, StyledDropdown, MenuItemContainer, CheckboxStyles, StyledStatusButton, ClearIcon, ChevronIconWrapper, } from './style';
11
11
  function MultiSelectStatusButton({ options, selectedValues, onSelectionChange, label, variant = 'inActive' }) {
12
12
  const { t } = useTranslation();
13
13
  const [anchorEl, setAnchorEl] = useState(null);
@@ -34,6 +34,10 @@ function MultiSelectStatusButton({ options, selectedValues, onSelectionChange, l
34
34
  setDropdownWidth(Math.max(buttonWidth, 200));
35
35
  };
36
36
  const handleClose = () => {
37
+ const hasChanged = JSON.stringify([...internalSelectedValues].sort()) !== JSON.stringify([...selectedValues].sort());
38
+ if (hasChanged) {
39
+ onSelectionChange(internalSelectedValues);
40
+ }
37
41
  setAnchorEl(null);
38
42
  setDropdownWidth(0);
39
43
  };
@@ -52,27 +56,21 @@ function MultiSelectStatusButton({ options, selectedValues, onSelectionChange, l
52
56
  ? internalSelectedValues.filter((status) => status !== optionStatus)
53
57
  : [...internalSelectedValues, optionStatus];
54
58
  setInternalSelectedValues(newSelection);
55
- onSelectionChange(newSelection);
56
59
  };
57
60
  const getDisplayLabel = () => {
58
- if (internalSelectedValues.length === 0) {
59
- return (_jsx(Typography, Object.assign({ fontWeight: 400, fontSize: "11px", variant: "inherit" }, { children: label || t('Select currencies') })));
60
- }
61
- if (internalSelectedValues.length === 1) {
62
- const selectedOption = options.find((opt) => opt.status === internalSelectedValues[0]);
63
- return selectedOption ? (_jsxs(FlagContainer, { children: [_jsx(CountryFlag, { code: selectedOption.flagCode || selectedOption.code, sx: { border: '1px solid white', borderRadius: '3px' } }), _jsx(Typography, Object.assign({ variant: "inherit" }, { children: selectedOption.name }))] })) : (internalSelectedValues[0]);
64
- }
65
- const firstOption = options.find((opt) => opt.status === internalSelectedValues[0]);
66
- return firstOption ? (_jsxs(FlagContainer, { children: [_jsx(CountryFlag, { code: firstOption.flagCode || firstOption.code, sx: { border: '1px solid white', borderRadius: '3px' } }), _jsx(Typography, Object.assign({ variant: "inherit" }, { children: firstOption.name }))] })) : (internalSelectedValues[0]);
61
+ return (_jsx(Typography, Object.assign({ fontWeight: 400, fontSize: "11px", variant: "inherit" }, { children: t('Currencies') })));
67
62
  };
68
- const countBadge = (_jsx(StyledBadge, Object.assign({ pointer: true, variant: variant === 'active' ? BadgeVariants.ACTIVE : BadgeVariants.INACTIVE }, { children: formatNumber(internalSelectedValues.length > 0 ? internalSelectedValues.length : options.length) })));
63
+ const countBadge = (_jsx(StyledBadge, Object.assign({ pointer: true, variant: variant === 'active' ? BadgeVariants.ACTIVE : BadgeVariants.INACTIVE }, { children: formatNumber(selectedValues.length > 0 ? selectedValues.length : options.length) })));
69
64
  return (_jsxs(_Fragment, { children: [_jsx(StyledStatusButton, Object.assign({ buttonVariant: variant, ref: buttonRef, sx: {
70
65
  paddingInlineEnd: '27px',
71
- }, "data-testid": "MultiSelectStatusButton", onClick: handleDropdownClick, onMouseEnter: () => setIsHovered(true), onMouseLeave: () => setIsHovered(false) }, { children: _jsxs(LabelWrapper, { children: [_jsxs(Label, Object.assign({ variant: variant }, { children: [getDisplayLabel(), countBadge] })), _jsx(ChevronContainer, Object.assign({ onClick: isHovered && internalSelectedValues.length > 0 ? handleClearAll : undefined, sx: {
66
+ }, "data-testid": "MultiSelectStatusButton", onClick: handleDropdownClick, onMouseEnter: () => setIsHovered(true), onMouseLeave: () => setIsHovered(false) }, { children: _jsxs(LabelWrapper, { children: [_jsxs(Label, Object.assign({ variant: variant }, { children: [getDisplayLabel(), countBadge] })), _jsxs(ChevronContainer, Object.assign({ onClick: isHovered && internalSelectedValues.length > 0 ? handleClearAll : undefined, sx: {
72
67
  '&:hover': {
73
68
  backgroundColor: 'transparent',
74
69
  },
75
- } }, { children: isHovered && internalSelectedValues.length > 0 ? (_jsx(ClearIcon, { variant: variant, src: closeXIcon, alt: "clear all" })) : (_jsx(ChevronIcon, { disableHover: true, isActive: variant === 'active' })) }))] }) })), isOpen && anchorEl && (_jsx(StyledDropdown, { open: isOpen, onClose: handleClose, anchorEl: anchorEl, allowShadows: false, style: {
70
+ } }, { children: [_jsx(ClearIcon, { variant: variant, src: closeXIcon, alt: "clear all", sx: {
71
+ opacity: isHovered && internalSelectedValues.length > 0 ? 1 : 0,
72
+ pointerEvents: isHovered && internalSelectedValues.length > 0 ? 'auto' : 'none',
73
+ } }), _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: {
76
74
  minWidth: dropdownWidth || 200,
77
75
  width: dropdownWidth || 'auto',
78
76
  marginTop: '6px',
@@ -34,3 +34,8 @@ export declare const CheckboxStyles: {
34
34
  export declare const ClearIcon: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<Theme> & {
35
35
  variant: 'active' | 'inActive';
36
36
  }, React.DetailedHTMLProps<React.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, {}>;
37
+ export declare const ChevronIconWrapper: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<Theme> & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
38
+ ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
39
+ }, keyof import("@mui/system").BoxOwnProps<Theme>> & import("@mui/system").MUIStyledCommonProps<Theme> & {
40
+ isVisible: boolean;
41
+ }, {}, {}>;
@@ -1,7 +1,7 @@
1
1
  import { Box, Button } from '@mui/material';
2
2
  import { styled } from '@mui/material/styles';
3
3
  export { statusButtonVariants, ChevronContainer, Label, LabelWrapper, StyledDropdown, } from '../TableHeader_V2/components/StatusButtons/style';
4
- const baseButtonStyle = (theme) => (Object.assign(Object.assign({}, theme.typography.subtitle1), { borderRadius: '50px', borderWidth: '1px', borderStyle: 'solid', minWidth: '135.11px', height: '32px', display: 'flex', justifyContent: 'center', alignItems: 'center', gap: '8px', textTransform: 'none', transition: 'none', paddingInline: theme.spacing(2) }));
4
+ const baseButtonStyle = (theme) => (Object.assign(Object.assign({}, theme.typography.subtitle1), { borderRadius: '50px', borderWidth: '1px', borderStyle: 'solid', minWidth: '135.11px', height: '32px', display: 'flex', justifyContent: 'center', alignItems: 'center', gap: '8px', textTransform: 'none', transition: 'background-color 0.5s ease, color 0.3s ease', paddingInline: theme.spacing(2) }));
5
5
  export const StyledStatusButton = styled(Button, {
6
6
  shouldForwardProp: (prop) => prop !== 'buttonVariant',
7
7
  })(({ theme, buttonVariant }) => (Object.assign(Object.assign({}, baseButtonStyle(theme)), (buttonVariant === 'active'
@@ -56,4 +56,16 @@ export const ClearIcon = styled('img')(({ variant }) => ({
56
56
  top: '50%',
57
57
  left: '47%',
58
58
  transform: 'translate(-50%, -50%)',
59
+ transition: 'opacity 0.2s ease-in-out',
60
+ }));
61
+ export const ChevronIconWrapper = styled(Box, {
62
+ shouldForwardProp: (prop) => prop !== 'isVisible',
63
+ })(({ isVisible }) => ({
64
+ opacity: isVisible ? 1 : 0,
65
+ transition: 'opacity 0.2s ease-in-out',
66
+ display: 'flex',
67
+ alignItems: 'center',
68
+ justifyContent: 'center',
69
+ width: '100%',
70
+ height: '100%',
59
71
  }));
@@ -1,3 +1,2 @@
1
1
  import StatusBar from './StatusBar';
2
2
  export default StatusBar;
3
- export { default as StatusBarExample } from './example';
@@ -1,3 +1,2 @@
1
1
  import StatusBar from './StatusBar';
2
2
  export default StatusBar;
3
- export { default as StatusBarExample } from './example';
@@ -58,6 +58,7 @@ export const ChevronContainer = styled('span')(() => ({
58
58
  right: '0',
59
59
  bottom: '0',
60
60
  overflow: 'hidden',
61
+ transition: 'opacity 1s ease',
61
62
  }));
62
63
  export const Label = styled(Box)(({ variant }) => ({
63
64
  display: 'flex',
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.92-multi-select-status-button-v1",
4
+ "version": "0.0.92-multi-select-status-button-v3",
5
5
  "type": "module",
6
6
  "main": "build/index.js",
7
7
  "module": "build/index.js",
@@ -1,2 +0,0 @@
1
- declare function StatusBarExample(): import("react/jsx-runtime").JSX.Element;
2
- export default StatusBarExample;
@@ -1,72 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useState } from 'react';
3
- import { Box } from '@mui/material';
4
- import StatusBar from './StatusBar';
5
- function StatusBarExample() {
6
- const [selectedStatus, setSelectedStatus] = useState('all');
7
- const [selectedCurrencies, setSelectedCurrencies] = useState([]);
8
- const currencyOptions = [
9
- {
10
- code: 'SAR',
11
- name: 'SAR',
12
- flagCode: 'SA',
13
- status: 'SAR',
14
- },
15
- {
16
- code: 'USD',
17
- name: 'USD',
18
- flagCode: 'US',
19
- status: 'USD',
20
- },
21
- {
22
- code: 'EUR',
23
- name: 'Euro',
24
- flagCode: 'EU',
25
- status: 'eur',
26
- },
27
- {
28
- code: 'GBP',
29
- name: 'GBP',
30
- flagCode: 'GB',
31
- status: 'gbp',
32
- },
33
- {
34
- code: 'JPY',
35
- name: 'JPY',
36
- flagCode: 'JP',
37
- status: 'jpy',
38
- },
39
- ];
40
- const availableStatuses = [
41
- {
42
- status: 'all',
43
- label: 'All',
44
- badgeCount: 150,
45
- },
46
- {
47
- status: 'completed',
48
- label: 'Completed',
49
- badgeCount: 85,
50
- },
51
- {
52
- status: 'pending',
53
- label: 'Pending',
54
- badgeCount: 45,
55
- },
56
- {
57
- status: ['initiated', 'captured', 'authorized'],
58
- label: 'Processing',
59
- badgeCount: 20,
60
- },
61
- ];
62
- const handleStatusChange = (status) => {
63
- console.log('Status changing from:', selectedStatus, 'to:', status);
64
- setSelectedStatus(status);
65
- };
66
- const handleMultiSelectChange = (currencies) => {
67
- setSelectedCurrencies(currencies);
68
- console.log('Selected currencies:', currencies);
69
- };
70
- return (_jsxs(Box, Object.assign({ sx: { padding: 2 } }, { children: [_jsxs(Box, Object.assign({ sx: { marginBottom: 2 } }, { children: [_jsx("h3", { children: "Enhanced StatusBar with Multiselect Currency Dropdown" }), _jsx("p", { children: "This example demonstrates the enhanced StatusBar component with multiselect currency functionality. The currency dropdown shows checkboxes with currency flags and names." }), _jsxs("p", { children: [_jsx("strong", { children: "Features:" }), _jsxs("ul", { children: [_jsx("li", { children: "Button body click behavior same as existing StatusButton" }), _jsx("li", { children: "Dropdown opens only when clicking the chevron icon" }), _jsx("li", { children: "Count badge shows number of selected currencies" }), _jsx("li", { children: "Active state styling matches existing StatusButton" })] })] })] })), _jsx(Box, Object.assign({ sx: { display: 'flex', gap: 1, flexWrap: 'wrap' } }, { children: _jsx(StatusBar, { status: selectedStatus, availableStatuses: availableStatuses, isFilteredIdsShown: false, onStatusChange: handleStatusChange, onMultiSelectChange: handleMultiSelectChange, enableMultiSelectCurrency: true, currencyOptions: currencyOptions, selectedCurrencies: selectedCurrencies }) })), _jsxs(Box, Object.assign({ sx: { marginTop: 2 } }, { children: [_jsx("h4", { children: "Current State:" }), _jsxs("p", { children: [_jsx("strong", { children: "Selected Status:" }), " ", _jsx("code", { children: selectedStatus })] }), _jsxs("p", { children: [_jsx("strong", { children: "Selected Currencies:" }), " ", selectedCurrencies.length > 0 ? selectedCurrencies.join(', ') : 'None'] }), _jsxs("p", { children: [_jsx("strong", { children: "Note:" }), " Only one status button should be active at a time. The active button will have a blue background."] })] }))] })));
71
- }
72
- export default StatusBarExample;