@tap-payments/os-micro-frontend-shared 0.1.249 → 0.1.250

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.
@@ -0,0 +1 @@
1
+ export declare const Loading: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import Skeleton from '@mui/material/Skeleton';
3
+ export const Loading = () => {
4
+ return (_jsx(Skeleton, { sx: {
5
+ height: 32,
6
+ width: 80,
7
+ borderRadius: '4px',
8
+ }, variant: "rectangular" }));
9
+ };
@@ -0,0 +1,15 @@
1
+ /// <reference types="react" />
2
+ import { Currency, Item } from '../../../types/index.js';
3
+ export interface TotalAmountProps {
4
+ totalGrossAmount: number;
5
+ items: Item[];
6
+ selectedCurrency: Currency;
7
+ isAmountIsMissing: boolean;
8
+ isDisabled?: boolean;
9
+ isLoading?: boolean;
10
+ onResetAllItems: () => void;
11
+ onAddFirstItem: (amount: number) => void;
12
+ }
13
+ declare function TotalAmount({ totalGrossAmount, items, selectedCurrency, isAmountIsMissing, isDisabled, isLoading, onResetAllItems, onAddFirstItem, }: Readonly<TotalAmountProps>): import("react/jsx-runtime").JSX.Element;
14
+ declare const _default: import("react").MemoExoticComponent<typeof TotalAmount>;
15
+ export default _default;
@@ -0,0 +1,60 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { memo, useState, useMemo, useEffect } from 'react';
3
+ import { useTranslation } from 'react-i18next';
4
+ import Box from '@mui/material/Box';
5
+ import { removeAllItem, unknownIcon } from '../../../constants/index.js';
6
+ import { useConfirmDialog, DisplayAmount } from '../../index.js';
7
+ import { isSafariBrowser, numberToString, getAmountPlaceholder } from '../../../utils/index.js';
8
+ import { InputStyled, TotalAmountWrapper, Error } from './style';
9
+ import { Loading } from './Loading';
10
+ const isSafari = isSafariBrowser();
11
+ function TotalAmount({ totalGrossAmount, items, selectedCurrency, isAmountIsMissing, isDisabled, isLoading, onResetAllItems, onAddFirstItem, }) {
12
+ const [editMode, setEditMode] = useState(false);
13
+ const [amount, setAmount] = useState();
14
+ const { isConfirmed } = useConfirmDialog();
15
+ const { t } = useTranslation();
16
+ const currencyPlaceholder = useMemo(() => getAmountPlaceholder(selectedCurrency === null || selectedCurrency === void 0 ? void 0 : selectedCurrency.decimals), [selectedCurrency === null || selectedCurrency === void 0 ? void 0 : selectedCurrency.decimals]);
17
+ useEffect(() => {
18
+ if (!totalGrossAmount) {
19
+ setAmount(undefined);
20
+ }
21
+ }, [totalGrossAmount]);
22
+ const removeAllItems = () => {
23
+ isConfirmed({
24
+ message: t('removeTotalAmount'),
25
+ confirmText: _jsx(Box, Object.assign({ sx: (theme) => ({ color: theme.palette.error.light }) }, { children: t('remove') })),
26
+ cancelText: t('cancel') || 'Cancel',
27
+ }).then((confirmed) => {
28
+ if (confirmed) {
29
+ onResetAllItems();
30
+ setAmount(undefined);
31
+ }
32
+ });
33
+ };
34
+ const handleChangeInput = (e) => {
35
+ if (!e.target.value) {
36
+ setAmount(undefined);
37
+ return false;
38
+ }
39
+ setAmount(Number(numberToString(Number(e.target.value), selectedCurrency === null || selectedCurrency === void 0 ? void 0 : selectedCurrency.decimals)));
40
+ };
41
+ const handleBlurInput = (e) => {
42
+ setEditMode(false);
43
+ onAddFirstItem(Number(numberToString(Number(e.target.value), selectedCurrency === null || selectedCurrency === void 0 ? void 0 : selectedCurrency.decimals)));
44
+ };
45
+ const isEditable = totalGrossAmount === 0 || (items.length === 1 && totalGrossAmount === items[0].total);
46
+ if (isLoading) {
47
+ return _jsx(Loading, {});
48
+ }
49
+ return (_jsxs(Box, Object.assign({ sx: Object.assign({}, (isDisabled && { pointerEvents: 'none', opacity: 0.7 })) }, { children: [editMode ? (_jsx(_Fragment, { children: isEditable ? (_jsx(InputStyled, { value: amount, placeholder: currencyPlaceholder, hideArrows: true, inputProps: { step: '0.01' }, onChange: handleChangeInput, onBlur: handleBlurInput, onKeyDown: (evt) => {
50
+ if (isSafari && isNaN(Number(evt.key)) && evt.key !== 'Backspace' && evt.key !== '.') {
51
+ evt.preventDefault();
52
+ }
53
+ }, autoFocus: true })) : (_jsx(DisplayAmount, { sx: { fontSize: '36px', textAlign: 'center' }, amount: totalGrossAmount || 0, selectedCurrency: selectedCurrency, onClick: () => {
54
+ setEditMode(true);
55
+ } })) })) : (_jsxs(TotalAmountWrapper, { children: [_jsx(DisplayAmount, { sx: { fontSize: '36px', textAlign: 'center' }, selectedCurrency: selectedCurrency, amount: totalGrossAmount || 0, onClick: () => {
56
+ if (isEditable)
57
+ setEditMode(true);
58
+ } }), totalGrossAmount > 0 && _jsx(Box, { component: "img", src: removeAllItem, alt: "r", onClick: removeAllItems })] })), isAmountIsMissing && (_jsxs(Error, { children: [_jsx(Box, { component: "img", src: unknownIcon }), _jsx(Box, { children: t('enterAmount') })] }))] })));
59
+ }
60
+ export default memo(TotalAmount);
@@ -0,0 +1 @@
1
+ export { default } from './TotalAmount';
@@ -0,0 +1 @@
1
+ export { default } from './TotalAmount';
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ export declare const InputStyled: import("@emotion/styled").StyledComponent<Omit<Readonly<import("@mui/material").InputProps & {
3
+ isError?: boolean | undefined;
4
+ hideArrows?: boolean | undefined;
5
+ }>, "ref"> & import("react").RefAttributes<HTMLInputElement> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
6
+ export declare const TotalAmountWrapper: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
7
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
8
+ }, keyof import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
9
+ export declare const Error: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
10
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
11
+ }, keyof import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
@@ -0,0 +1,26 @@
1
+ import Box from '@mui/material/Box';
2
+ import { styled } from '@mui/material/styles';
3
+ import { InputNumber } from '../../index.js';
4
+ export const InputStyled = styled(InputNumber)(() => ({
5
+ fontSize: '36px !important',
6
+ textAlign: 'center',
7
+ border: 'none',
8
+ height: 49.5,
9
+ input: {
10
+ textAlign: 'center',
11
+ },
12
+ }));
13
+ export const TotalAmountWrapper = styled(Box)(() => ({
14
+ display: 'flex',
15
+ gap: '5px',
16
+ alignItems: 'center',
17
+ height: 49.5,
18
+ maxWidth: '-webkit-fill-available',
19
+ paddingInline: '24px',
20
+ }));
21
+ export const Error = styled(Box)(({ theme }) => ({
22
+ fontSize: '10px',
23
+ color: theme.palette.error.dark,
24
+ display: 'flex',
25
+ gap: '4px',
26
+ }));
@@ -0,0 +1 @@
1
+ export { default as TotalAmount } from './TotalAmount';
@@ -0,0 +1 @@
1
+ export { default as TotalAmount } from './TotalAmount';
@@ -123,3 +123,4 @@ export { default as MFWidgetLoader } from './MFWidgetLoader';
123
123
  export { default as BetaBanner } from './BetaBanner';
124
124
  export * from './Autocomplete';
125
125
  export * from './BrandLogo';
126
+ export * from './Amount';
@@ -123,3 +123,4 @@ export { default as MFWidgetLoader } from './MFWidgetLoader';
123
123
  export { default as BetaBanner } from './BetaBanner';
124
124
  export * from './Autocomplete';
125
125
  export * from './BrandLogo';
126
+ export * from './Amount';
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.1.249",
4
+ "version": "0.1.250",
5
5
  "testVersion": 0,
6
6
  "type": "module",
7
7
  "main": "build/index.js",