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

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.
Files changed (39) hide show
  1. package/build/components/Amount/TotalAmount/Loading.d.ts +1 -0
  2. package/build/components/Amount/TotalAmount/Loading.js +9 -0
  3. package/build/components/Amount/TotalAmount/TotalAmount.d.ts +15 -0
  4. package/build/components/Amount/TotalAmount/TotalAmount.js +60 -0
  5. package/build/components/Amount/TotalAmount/index.d.ts +1 -0
  6. package/build/components/Amount/TotalAmount/index.js +1 -0
  7. package/build/components/Amount/TotalAmount/style.d.ts +11 -0
  8. package/build/components/Amount/TotalAmount/style.js +26 -0
  9. package/build/components/Amount/index.d.ts +1 -0
  10. package/build/components/Amount/index.js +1 -0
  11. package/build/components/VAT/TotalVAT/TotalVAT.d.ts +12 -0
  12. package/build/components/VAT/TotalVAT/TotalVAT.js +31 -0
  13. package/build/components/VAT/TotalVAT/index.d.ts +1 -0
  14. package/build/components/VAT/TotalVAT/index.js +1 -0
  15. package/build/components/VAT/TotalVAT/style.d.ts +12 -0
  16. package/build/components/VAT/TotalVAT/style.js +5 -0
  17. package/build/components/VAT/VATDropdown/VATDropdown.d.ts +11 -0
  18. package/build/components/VAT/VATDropdown/VATDropdown.js +34 -0
  19. package/build/components/VAT/VATDropdown/index.d.ts +1 -0
  20. package/build/components/VAT/VATDropdown/index.js +1 -0
  21. package/build/components/VAT/VATDropdown/style.d.ts +7 -0
  22. package/build/components/VAT/VATDropdown/style.js +32 -0
  23. package/build/components/VAT/VATRateDropdown/VATRateDropdown.d.ts +10 -0
  24. package/build/components/VAT/VATRateDropdown/VATRateDropdown.js +38 -0
  25. package/build/components/VAT/VATRateDropdown/index.d.ts +1 -0
  26. package/build/components/VAT/VATRateDropdown/index.js +1 -0
  27. package/build/components/VAT/VATRateDropdown/style.d.ts +7 -0
  28. package/build/components/VAT/VATRateDropdown/style.js +30 -0
  29. package/build/components/VAT/index.d.ts +4 -0
  30. package/build/components/VAT/index.js +4 -0
  31. package/build/components/VAT/utils.d.ts +7 -0
  32. package/build/components/VAT/utils.js +8 -0
  33. package/build/components/index.d.ts +2 -0
  34. package/build/components/index.js +2 -0
  35. package/build/constants/index.d.ts +1 -0
  36. package/build/constants/index.js +1 -0
  37. package/build/constants/rate.d.ts +6 -0
  38. package/build/constants/rate.js +6 -0
  39. package/package.json +1 -1
@@ -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';
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { Currency, Vat } from '../../../types/index.js';
3
+ interface TotalVATProps {
4
+ totalGrossAmount: number;
5
+ totalVat: Vat;
6
+ selectedCurrency: Currency;
7
+ isDisabled: boolean;
8
+ onChangeTotalVat: (vat: Vat) => void;
9
+ }
10
+ declare function TotalVAT({ totalGrossAmount, totalVat, selectedCurrency, onChangeTotalVat, isDisabled }: Readonly<TotalVATProps>): import("react/jsx-runtime").JSX.Element;
11
+ declare const _default: import("react").MemoExoticComponent<typeof TotalVAT>;
12
+ export default _default;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { memo, useRef, useState } from 'react';
3
+ import Popper from '@mui/material/Popper';
4
+ import Box from '@mui/material/Box';
5
+ import { useTranslation } from 'react-i18next';
6
+ import { CustomBackdrop, DisplayAmount } from '../../index.js';
7
+ import { actionsIcon, activeActionIcon, taxIcon } from '../../../constants/index.js';
8
+ import { Label, LabelWrapper } from './style';
9
+ import { getVatValue } from '../utils';
10
+ import VATDropdown from '../VATDropdown';
11
+ function TotalVAT({ totalGrossAmount, totalVat, selectedCurrency, onChangeTotalVat, isDisabled }) {
12
+ const [isOpen, setIsOpen] = useState(false);
13
+ const vatButtonRef = useRef();
14
+ const { t } = useTranslation();
15
+ const toggleDropdown = () => {
16
+ if (!isDisabled)
17
+ setIsOpen(!isOpen);
18
+ };
19
+ const modifyTotalVAT = (newVat) => {
20
+ onChangeTotalVat(Object.assign(Object.assign({}, newVat), { value: getVatValue(totalGrossAmount, newVat) }));
21
+ };
22
+ const getLabel = () => {
23
+ if (totalVat.percentage === 0)
24
+ return t('noVat');
25
+ if (!totalVat.isInclusive)
26
+ return _jsx(DisplayAmount, { selectedCurrency: selectedCurrency, amount: totalVat.value });
27
+ return (_jsxs(Box, Object.assign({ sx: { display: 'flex', gap: '4px' } }, { children: [_jsxs("span", { children: [t('inclusive'), " "] }), _jsx(DisplayAmount, { amount: totalVat.value, selectedCurrency: selectedCurrency })] })));
28
+ };
29
+ return (_jsxs(LabelWrapper, Object.assign({ isDisabled: isDisabled, isOpen: isOpen, onClick: toggleDropdown, ref: vatButtonRef, sx: Object.assign({}, (isDisabled && { pointerEvents: 'none', opacity: 0.7 })) }, { children: [_jsx("img", { src: taxIcon, alt: "p" }), _jsx(Label, Object.assign({ isDisabled: isDisabled }, { children: getLabel() })), _jsx(Box, { component: "img", src: isOpen ? activeActionIcon : actionsIcon, alt: "a" }), isOpen && _jsx(CustomBackdrop, { onClick: toggleDropdown }), _jsx(Popper, Object.assign({ open: Boolean(isOpen), anchorEl: vatButtonRef.current, placement: "bottom-start" }, { children: _jsx(VATDropdown, { setIsOpen: setIsOpen, vat: totalVat, setVat: modifyTotalVAT, sx: { position: 'absolute', top: 8, left: 0, display: isOpen ? 'block' : 'none' } }) }))] })));
30
+ }
31
+ export default memo(TotalVAT);
@@ -0,0 +1 @@
1
+ export { default } from './TotalVAT';
@@ -0,0 +1 @@
1
+ export { default } from './TotalVAT';
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ export declare const LabelWrapper: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
3
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
4
+ }, keyof import("@mui/system").BoxOwnProps<import("@mui/material").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
5
+ isDisabled?: boolean | undefined;
6
+ isOpen?: boolean | undefined;
7
+ }, {}, {}>;
8
+ export declare const Label: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
9
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
10
+ }, keyof import("@mui/system").BoxOwnProps<import("@mui/material").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme> & {
11
+ isDisabled: boolean;
12
+ }, {}, {}>;
@@ -0,0 +1,5 @@
1
+ import { Box, styled } from '@mui/material';
2
+ export const LabelWrapper = styled(Box, {
3
+ shouldForwardProp: (props) => props !== 'isDisabled' && props !== 'isOpen',
4
+ })(({ theme, isOpen, isDisabled }) => (Object.assign(Object.assign({ display: 'flex', gap: theme.spacing(1), alignItems: 'center', justifyContent: 'space-between', fontSize: '11px', border: `1px solid ${theme.palette.divider}`, height: 32, padding: theme.spacing(1), borderRadius: '4px' }, (isOpen && { borderColor: theme.palette.info.dark, position: 'relative' })), (isDisabled ? { color: theme.palette.grey[700], cursor: 'not-allowed' } : { cursor: 'pointer' }))));
5
+ export const Label = styled(Box, { shouldForwardProp: (props) => props !== 'isDisabled' })(({ theme, isDisabled }) => (Object.assign({ fontSize: '11px', fontWeight: 600, color: theme.palette.text.primary }, (isDisabled && { color: theme.palette.grey[700] }))));
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { BoxProps } from '@mui/material/Box';
3
+ import { Vat } from '../../../types/index.js';
4
+ interface VATDropdownProps extends BoxProps {
5
+ vat: Vat;
6
+ setVat: (vat: Vat) => void;
7
+ setIsOpen: (value: boolean) => void;
8
+ }
9
+ declare function VATDropdown({ setVat, vat, setIsOpen: setIsDropdownOpen, ...props }: Readonly<VATDropdownProps>): import("react/jsx-runtime").JSX.Element;
10
+ declare const _default: import("react").MemoExoticComponent<typeof VATDropdown>;
11
+ export default _default;
@@ -0,0 +1,34 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { memo, useState } from 'react';
14
+ import { useTranslation } from 'react-i18next';
15
+ import { rightArrow } from '../../../constants/index.js';
16
+ import { Menu } from '../../index.js';
17
+ import { Wrapper, Option } from './style';
18
+ import VATRateDropdown from '../VATRateDropdown';
19
+ function VATDropdown(_a) {
20
+ var { setVat, vat, setIsOpen: setIsDropdownOpen } = _a, props = __rest(_a, ["setVat", "vat", "setIsOpen"]);
21
+ const [anchorEl, setAnchorEl] = useState(null);
22
+ const open = Boolean(anchorEl);
23
+ const { t } = useTranslation();
24
+ const toggleDropdown = (e) => {
25
+ e.stopPropagation();
26
+ if (open) {
27
+ setAnchorEl(null);
28
+ return;
29
+ }
30
+ setAnchorEl(e.currentTarget);
31
+ };
32
+ return (_jsx(Wrapper, Object.assign({ sx: props.sx }, { children: _jsxs(Option, Object.assign({ sx: (theme) => (Object.assign({}, (open && { boxShadow: theme.shadows[3] }))), className: "option", onClick: toggleDropdown }, { children: [_jsx("span", { children: t('rate') }), _jsx("img", { src: rightArrow, alt: "a" }), _jsx(Menu, Object.assign({ anchorEl: anchorEl, open: open, placement: "right-start" }, { children: _jsx(VATRateDropdown, { onChange: setVat, vat: vat, setIsDropdownOpen: setIsDropdownOpen }) }))] })) })));
33
+ }
34
+ export default memo(VATDropdown);
@@ -0,0 +1 @@
1
+ export { default } from './VATDropdown';
@@ -0,0 +1 @@
1
+ export { default } from './VATDropdown';
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ export declare const Wrapper: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
3
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
4
+ }, keyof import("@mui/system").BoxOwnProps<import("@mui/material").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
5
+ export declare const Option: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
6
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
7
+ }, keyof import("@mui/system").BoxOwnProps<import("@mui/material").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, {}, {}>;
@@ -0,0 +1,32 @@
1
+ import { Box, styled } from '@mui/material';
2
+ export const Wrapper = styled(Box)(({ theme }) => ({
3
+ width: 112,
4
+ boxShadow: theme.shadows[16],
5
+ borderRadius: 4,
6
+ backgroundColor: theme.palette.common.white,
7
+ '.option + .option': {
8
+ borderTop: `1px solid ${theme.palette.divider}`,
9
+ },
10
+ zIndex: 3,
11
+ }));
12
+ export const Option = styled(Box)(({ theme }) => ({
13
+ fontSize: '11px',
14
+ paddingInlineStart: theme.spacing(2),
15
+ paddingInlineEnd: theme.spacing(1),
16
+ paddingTop: theme.spacing(1.5),
17
+ paddingBottom: theme.spacing(1.5),
18
+ display: 'flex',
19
+ justifyContent: 'space-between',
20
+ alignItems: 'center',
21
+ gap: theme.spacing(1),
22
+ cursor: 'pointer',
23
+ height: 40,
24
+ input: {
25
+ height: 24,
26
+ width: 47,
27
+ textAlign: 'right',
28
+ },
29
+ '&:hover': {
30
+ boxShadow: theme.shadows[3],
31
+ },
32
+ }));
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { Vat } from '../../../types/index.js';
3
+ interface VATRateDropdownProps {
4
+ vat: Vat;
5
+ onChange: (value: Vat) => void;
6
+ setIsDropdownOpen: (value: boolean) => void;
7
+ }
8
+ declare function VATRateDropdown({ vat, onChange, setIsDropdownOpen }: Readonly<VATRateDropdownProps>): import("react/jsx-runtime").JSX.Element;
9
+ declare const _default: import("react").MemoExoticComponent<typeof VATRateDropdown>;
10
+ export default _default;
@@ -0,0 +1,38 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { memo } from 'react';
3
+ import { useTranslation } from 'react-i18next';
4
+ import { Input } from '../../index.js';
5
+ import { checkIcon, RATES } from '../../../constants/index.js';
6
+ import { removeAllCharsFromNumber } from '../../../utils/index.js';
7
+ import { Wrapper, Option } from './style';
8
+ function VATRateDropdown({ vat, onChange, setIsDropdownOpen }) {
9
+ const { t } = useTranslation();
10
+ const { percentage, isInclusive, value } = vat;
11
+ const isNoVAT = percentage === RATES.ZERO;
12
+ const isFivePercent = percentage === RATES.FIVE;
13
+ const isTenPercent = percentage === RATES.TEN;
14
+ const isFifteenPercent = percentage === RATES.FIFTEEN;
15
+ const isCustomPercent = percentage !== RATES.FIVE && percentage !== RATES.TEN && percentage !== RATES.FIFTEEN && percentage !== RATES.ZERO;
16
+ const vatRates = [
17
+ { label: t('noVat'), value: RATES.ZERO, selected: isNoVAT },
18
+ { label: '5%', value: RATES.FIVE, selected: isFivePercent },
19
+ { label: '10%', value: RATES.TEN, selected: isTenPercent },
20
+ { label: '15%', value: RATES.FIFTEEN, selected: isFifteenPercent },
21
+ ];
22
+ const selectRate = (percentageValue) => {
23
+ onChange({ value, percentage: percentageValue, isInclusive });
24
+ };
25
+ const handleCustomRate = (e) => {
26
+ if (Number(e.target.value) > 100)
27
+ return;
28
+ selectRate(Number(removeAllCharsFromNumber(e.target.value)));
29
+ };
30
+ const renderSelectedIcon = (selected) => {
31
+ return selected ? _jsx("img", { src: checkIcon, alt: "check" }) : _jsx("span", {});
32
+ };
33
+ return (_jsxs(Wrapper, { children: [vatRates.map((rate, index) => (_jsxs(Option, Object.assign({ className: "option", onClick: () => {
34
+ selectRate(rate.value);
35
+ setIsDropdownOpen(false);
36
+ } }, { children: [renderSelectedIcon(rate.selected), _jsx("span", { children: rate.label })] }), `${rate.value}-${index}`))), _jsxs(Option, Object.assign({ className: "option" }, { children: [renderSelectedIcon(isCustomPercent), _jsx(Input, { placeholder: "%", value: isCustomPercent ? String(percentage) : '', onChange: handleCustomRate, sx: { justifyContent: 'flex-end' } })] }))] }));
37
+ }
38
+ export default memo(VATRateDropdown);
@@ -0,0 +1 @@
1
+ export { default } from './VATRateDropdown';
@@ -0,0 +1 @@
1
+ export { default } from './VATRateDropdown';
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ export declare const Wrapper: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
3
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
4
+ }, keyof import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
5
+ export declare const Option: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme> & Omit<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
6
+ ref?: ((instance: HTMLDivElement | null) => void) | import("react").RefObject<HTMLDivElement> | null | undefined;
7
+ }, keyof import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
@@ -0,0 +1,30 @@
1
+ import Box from '@mui/material/Box';
2
+ import { styled } from '@mui/material/styles';
3
+ export const Wrapper = styled(Box)(({ theme }) => ({
4
+ width: 112,
5
+ '.option + .option': {
6
+ borderTop: `1px solid ${theme.palette.divider}`,
7
+ },
8
+ zIndex: 3,
9
+ }));
10
+ export const Option = styled(Box)(({ theme }) => ({
11
+ fontSize: '11px',
12
+ paddingInlineStart: theme.spacing(2),
13
+ paddingInlineEnd: theme.spacing(1),
14
+ paddingTop: theme.spacing(1.5),
15
+ paddingBottom: theme.spacing(1.5),
16
+ display: 'flex',
17
+ justifyContent: 'space-between',
18
+ alignItems: 'center',
19
+ gap: theme.spacing(1),
20
+ cursor: 'pointer',
21
+ height: 40,
22
+ input: {
23
+ height: 24,
24
+ width: 47,
25
+ textAlign: 'right',
26
+ },
27
+ '&:hover': {
28
+ boxShadow: theme.shadows[3],
29
+ },
30
+ }));
@@ -0,0 +1,4 @@
1
+ export * from './utils';
2
+ export { default as TotalVAT } from './TotalVAT';
3
+ export { default as VATDropdown } from './VATDropdown';
4
+ export { default as VATRateDropdown } from './VATRateDropdown';
@@ -0,0 +1,4 @@
1
+ export * from './utils';
2
+ export { default as TotalVAT } from './TotalVAT';
3
+ export { default as VATDropdown } from './VATDropdown';
4
+ export { default as VATRateDropdown } from './VATRateDropdown';
@@ -0,0 +1,7 @@
1
+ import { Vat } from '../../types/index.js';
2
+ export declare const getVatValue: (amount: number, vat: Vat) => number;
3
+ export declare const getItemVat: (vat: Vat, itemPrice: number, quantity: number) => {
4
+ value: number;
5
+ percentage: number;
6
+ isInclusive: boolean;
7
+ };
@@ -0,0 +1,8 @@
1
+ export const getVatValue = (amount, vat) => {
2
+ let newVatValue = 0;
3
+ if (vat.percentage > 0) {
4
+ newVatValue = amount * (vat.percentage / 100);
5
+ }
6
+ return newVatValue;
7
+ };
8
+ export const getItemVat = (vat, itemPrice, quantity) => (Object.assign(Object.assign({}, vat), { value: getVatValue(Number(itemPrice), vat) * quantity }));
@@ -123,3 +123,5 @@ 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';
127
+ export * from './VAT';
@@ -123,3 +123,5 @@ 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';
127
+ export * from './VAT';
@@ -13,3 +13,4 @@ export * from './toggleOptions';
13
13
  export * from './payment';
14
14
  export * from './segment';
15
15
  export * from './chips';
16
+ export * from './rate';
@@ -13,3 +13,4 @@ export * from './toggleOptions';
13
13
  export * from './payment';
14
14
  export * from './segment';
15
15
  export * from './chips';
16
+ export * from './rate';
@@ -0,0 +1,6 @@
1
+ export declare const RATES: {
2
+ ZERO: number;
3
+ FIVE: number;
4
+ TEN: number;
5
+ FIFTEEN: number;
6
+ };
@@ -0,0 +1,6 @@
1
+ export const RATES = {
2
+ ZERO: 0,
3
+ FIVE: 5,
4
+ TEN: 10,
5
+ FIFTEEN: 15,
6
+ };
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.251",
5
5
  "testVersion": 0,
6
6
  "type": "module",
7
7
  "main": "build/index.js",