@tap-payments/os-micro-frontend-shared 0.1.271 → 0.1.273

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,6 +7,7 @@ type ColorPickerProps = {
7
7
  sx?: SxProps;
8
8
  options?: {
9
9
  hideReset?: boolean;
10
+ disableAlpha?: boolean;
10
11
  };
11
12
  };
12
13
  declare const ColorPicker: ({ id, value, onChange, onReset, sx, options }: ColorPickerProps) => import("react/jsx-runtime").JSX.Element;
@@ -8,8 +8,14 @@ import { StyledCloseButtonWrapper } from './style';
8
8
  import { closeXIcon } from '../../constants/index.js';
9
9
  import ColorPickerPanel from './ColorPickerPanel';
10
10
  import { Popper } from '@mui/material';
11
- const ColorPicker = ({ id, value = '#ffffff', onChange, onReset, sx, options }) => {
11
+ const DEFAULT_OPTIONS = {
12
+ hideReset: false,
13
+ disableAlpha: false,
14
+ };
15
+ const ColorPicker = ({ id, value = '#ffffff', onChange, onReset, sx, options = DEFAULT_OPTIONS }) => {
12
16
  const [anchorEl, setAnchorEl] = useState(null);
17
+ const { disableAlpha = false, hideReset = false } = Object.assign(Object.assign({}, DEFAULT_OPTIONS), options);
18
+ console.log('disableAlpha', disableAlpha);
13
19
  const rootRef = useRef(null);
14
20
  const handleOpen = useCallback(() => {
15
21
  setAnchorEl(rootRef.current);
@@ -18,9 +24,9 @@ const ColorPicker = ({ id, value = '#ffffff', onChange, onReset, sx, options })
18
24
  setAnchorEl(null);
19
25
  }, []);
20
26
  const handleConfirm = useCallback((newValue) => {
21
- onChange(newValue);
27
+ onChange(disableAlpha ? newValue.substring(0, 7) : newValue);
22
28
  setAnchorEl(null);
23
- }, [onChange]);
24
- return (_jsx(ClickAwayListener, Object.assign({ onClickAway: () => setAnchorEl(null) }, { children: _jsxs(Stack, Object.assign({ ref: rootRef, bgcolor: "grey.400", borderRadius: "4px", p: "4px", pr: "12px", direction: "row", justifyContent: "space-between", spacing: 1, alignItems: "center", className: "color-picker", sx: sx }, { children: [_jsxs(Stack, Object.assign({ direction: "row", spacing: 1, alignItems: "center", className: "color-picker__controls-wrapper" }, { children: [_jsx(Box, { borderRadius: "5px", width: 32, height: 32, sx: { backgroundColor: value }, className: "color-picker__viewer" }), _jsxs(Box, Object.assign({ className: "color-picker__actions-wrapper" }, { children: [_jsx(Typography, Object.assign({ className: "color-picker__label", fontWeight: 500, fontSize: 9, color: "text.primary", textTransform: "uppercase" }, { children: value })), _jsx(Typography, Object.assign({ className: "color-picker__edit-btn", role: "button", onClick: handleOpen, htmlFor: id, fontWeight: 500, fontSize: 9, color: "info.dark", component: "label", sx: { textDecoration: 'underline', cursor: 'pointer' } }, { children: "Edit" }))] }))] })), !(options === null || options === void 0 ? void 0 : options.hideReset) ? (_jsx(StyledCloseButtonWrapper, Object.assign({ className: "color-picker__close-btn", type: "button", onClick: onReset }, { children: _jsx(Box, { component: "img", src: closeXIcon, width: 10, height: 10 }) }))) : (_jsx("div", {})), _jsx(Popper, Object.assign({ anchorEl: anchorEl, open: !!anchorEl, placement: "top" }, { children: _jsx(ColorPickerPanel, { initialValue: value, onCancel: handleCancel, onConfirm: handleConfirm }) }))] })) })));
29
+ }, [onChange, disableAlpha]);
30
+ return (_jsx(ClickAwayListener, Object.assign({ onClickAway: () => setAnchorEl(null) }, { children: _jsxs(Stack, Object.assign({ ref: rootRef, bgcolor: "grey.400", borderRadius: "4px", p: "4px", pr: "12px", direction: "row", justifyContent: "space-between", spacing: 1, alignItems: "center", className: "color-picker", sx: sx }, { children: [_jsxs(Stack, Object.assign({ direction: "row", spacing: 1, alignItems: "center", className: "color-picker__controls-wrapper" }, { children: [_jsx(Box, { borderRadius: "5px", width: 32, height: 32, sx: { backgroundColor: value }, className: "color-picker__viewer" }), _jsxs(Box, Object.assign({ className: "color-picker__actions-wrapper" }, { children: [_jsx(Typography, Object.assign({ className: "color-picker__label", fontWeight: 500, fontSize: 9, color: "text.primary", textTransform: "uppercase" }, { children: value })), _jsx(Typography, Object.assign({ className: "color-picker__edit-btn", role: "button", onClick: handleOpen, htmlFor: id, fontWeight: 500, fontSize: 9, color: "info.dark", component: "label", sx: { textDecoration: 'underline', cursor: 'pointer' } }, { children: "Edit" }))] }))] })), !hideReset ? (_jsx(StyledCloseButtonWrapper, Object.assign({ className: "color-picker__close-btn", type: "button", onClick: onReset }, { children: _jsx(Box, { component: "img", src: closeXIcon, width: 10, height: 10 }) }))) : (_jsx("div", {})), _jsx(Popper, Object.assign({ anchorEl: anchorEl, open: !!anchorEl, placement: "top" }, { children: _jsx(ColorPickerPanel, { initialValue: value, onCancel: handleCancel, onConfirm: handleConfirm, disableAlpha: disableAlpha }) }))] })) })));
25
31
  };
26
32
  export default ColorPicker;
@@ -2,6 +2,7 @@ export type ColorPickerPanelProps = {
2
2
  initialValue?: string;
3
3
  onCancel: () => void;
4
4
  onConfirm: (newValue: string) => void;
5
+ disableAlpha?: boolean;
5
6
  };
6
- declare const ColorPickerPanel: ({ initialValue, onCancel, onConfirm }: ColorPickerPanelProps) => import("react/jsx-runtime").JSX.Element;
7
+ declare const ColorPickerPanel: ({ initialValue, onCancel, onConfirm, disableAlpha }: ColorPickerPanelProps) => import("react/jsx-runtime").JSX.Element;
7
8
  export default ColorPickerPanel;
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import { useCallback, useState } from 'react';
14
14
  import { useTranslation } from 'react-i18next';
15
- import { RgbaColorPicker } from 'react-colorful';
15
+ import { RgbaColorPicker, RgbColorPicker } from 'react-colorful';
16
16
  import Stack from '@mui/material/Stack';
17
17
  import Divider from '@mui/material/Divider';
18
18
  import { hexa2Rgba, rgba2Hexa } from '../../utils/index.js';
@@ -20,7 +20,7 @@ import { CancelButton, ConfirmButton, Footer, StyledColorWidgetWrapper } from '.
20
20
  import ColorSchemeSelect from './ColorSchemeSelect';
21
21
  import RGBAFields from './RGBAFields';
22
22
  import HexaFields from './HexaFields';
23
- const ColorPickerPanel = ({ initialValue = '#ffffff', onCancel, onConfirm }) => {
23
+ const ColorPickerPanel = ({ initialValue = '#ffffff', onCancel, onConfirm, disableAlpha = false }) => {
24
24
  const [colorScheme, setColorScheme] = useState('RGB');
25
25
  const [color, setColor] = useState(() => {
26
26
  const _a = hexa2Rgba(initialValue).value, { alpha: a } = _a, rest = __rest(_a, ["alpha"]);
@@ -34,8 +34,23 @@ const ColorPickerPanel = ({ initialValue = '#ffffff', onCancel, onConfirm }) =>
34
34
  }, [initialValue, onCancel]);
35
35
  const handleConfirm = useCallback(() => {
36
36
  const { a: alpha } = color, rest = __rest(color, ["a"]);
37
- onConfirm(rgba2Hexa(Object.assign(Object.assign({}, rest), { alpha })));
38
- }, [color, onConfirm]);
39
- return (_jsxs(StyledColorWidgetWrapper, Object.assign({ className: "color-picker__widget" }, { children: [_jsx(RgbaColorPicker, { color: color, onChange: setColor }), _jsxs(Stack, Object.assign({ mt: 2, spacing: 1, direction: "row" }, { children: [_jsx(ColorSchemeSelect, { scheme: colorScheme, setScheme: setColorScheme }), colorScheme === 'RGB' ? (_jsx(RGBAFields, { value: Object.assign(Object.assign({}, color), { a: Math.round(color.a * 100) }), onChange: (newColor) => setColor(Object.assign(Object.assign({}, newColor), { a: newColor.a / 100 })) })) : (_jsx(HexaFields, { value: Object.assign(Object.assign({}, color), { a: color.a }), onChange: (newColor) => setColor(Object.assign(Object.assign({}, newColor), { a: newColor.a })) }))] })), _jsx(Divider, { sx: { my: '12px' } }), _jsxs(Footer, Object.assign({ className: "color-picker__widget-actions" }, { children: [_jsx(CancelButton, Object.assign({ className: "color-picker__widget-actions__cancel", onClick: handleCancel }, { children: t('cancel') })), _jsx(ConfirmButton, Object.assign({ className: "color-picker__widget-actions__confirm", onClick: handleConfirm }, { children: t('okay') }))] }))] })));
37
+ onConfirm(rgba2Hexa(Object.assign(Object.assign({}, rest), { alpha: disableAlpha ? 1 : alpha })));
38
+ }, [color, onConfirm, disableAlpha]);
39
+ const handleColorChange = useCallback((newColor) => {
40
+ if (disableAlpha) {
41
+ setColor(Object.assign(Object.assign({}, newColor), { a: 1 }));
42
+ }
43
+ else {
44
+ setColor(newColor);
45
+ }
46
+ }, [disableAlpha]);
47
+ const handleRGBAFieldsChange = useCallback((newColor) => {
48
+ setColor(Object.assign(Object.assign({}, newColor), { a: newColor.a / 100 }));
49
+ }, []);
50
+ const handleHexaFieldsChange = useCallback((newColor) => {
51
+ setColor(Object.assign(Object.assign({}, newColor), { a: newColor.a }));
52
+ }, []);
53
+ const PickerArea = disableAlpha ? RgbColorPicker : RgbaColorPicker;
54
+ return (_jsxs(StyledColorWidgetWrapper, Object.assign({ className: "color-picker__widget" }, { children: [_jsx(PickerArea, { color: color, onChange: handleColorChange }), _jsxs(Stack, Object.assign({ mt: 2, spacing: 1, direction: "row" }, { children: [_jsx(ColorSchemeSelect, { scheme: colorScheme, setScheme: setColorScheme }), colorScheme === 'RGB' ? (_jsx(RGBAFields, { value: Object.assign(Object.assign({}, color), { a: Math.round(color.a * 100) }), onChange: handleRGBAFieldsChange, disableAlpha: disableAlpha })) : (_jsx(HexaFields, { value: Object.assign(Object.assign({}, color), { a: color.a }), onChange: handleHexaFieldsChange, disableAlpha: disableAlpha }))] })), _jsx(Divider, { sx: { my: '12px' } }), _jsxs(Footer, Object.assign({ className: "color-picker__widget-actions" }, { children: [_jsx(CancelButton, Object.assign({ className: "color-picker__widget-actions__cancel", onClick: handleCancel }, { children: t('cancel') })), _jsx(ConfirmButton, Object.assign({ className: "color-picker__widget-actions__confirm", onClick: handleConfirm }, { children: t('okay') }))] }))] })));
40
55
  };
41
56
  export default ColorPickerPanel;
@@ -2,6 +2,7 @@ import { RgbaColor } from 'react-colorful';
2
2
  type HexaFieldsProps = {
3
3
  value: RgbaColor;
4
4
  onChange: (newValue: RgbaColor) => void;
5
+ disableAlpha?: boolean;
5
6
  };
6
- declare const HexaFields: ({ value, onChange }: HexaFieldsProps) => import("react/jsx-runtime").JSX.Element;
7
+ declare const HexaFields: ({ value, onChange, disableAlpha }: HexaFieldsProps) => import("react/jsx-runtime").JSX.Element;
7
8
  export default HexaFields;
@@ -6,7 +6,7 @@ import Stack from '@mui/material/Stack';
6
6
  import Typography from '@mui/material/Typography';
7
7
  import InputAdornment from '@mui/material/InputAdornment';
8
8
  import { StyledInput } from './style';
9
- const HexaFields = ({ value, onChange }) => {
9
+ const HexaFields = ({ value, onChange, disableAlpha = false }) => {
10
10
  const colorAsHex = useMemo(() => {
11
11
  const color = Color.rgb(value.r, value.g, value.b, value.a);
12
12
  return color.hex().replace('#', '');
@@ -71,13 +71,13 @@ const HexaFields = ({ value, onChange }) => {
71
71
  },
72
72
  }, InputProps: {
73
73
  startAdornment: (_jsx(InputAdornment, Object.assign({ position: "start", sx: { m: 0 } }, { children: _jsx(Typography, Object.assign({ component: "span", color: (theme) => alpha(theme.palette.text.primary, 0.5), display: "inline-block", fontSize: 12, fontWeight: 500 }, { children: "#" })) }))),
74
- } }), _jsx(StyledInput, { type: "number", value: alphaPercent, onChange: handleAlphaChange, inputProps: { min: 0, max: 100 }, sx: {
74
+ } }), !disableAlpha && (_jsx(StyledInput, { type: "number", value: alphaPercent, onChange: handleAlphaChange, inputProps: { min: 0, max: 100 }, sx: {
75
75
  flex: 0.8,
76
76
  '& .MuiOutlinedInput-root': {
77
77
  pr: 1,
78
78
  },
79
79
  }, InputProps: {
80
80
  endAdornment: (_jsx(InputAdornment, Object.assign({ position: "end", sx: { m: 0 } }, { children: _jsx(Typography, Object.assign({ component: "span", color: "text.primary", display: "inline-block", fontSize: 12, fontWeight: 500 }, { children: "%" })) }))),
81
- } })] })));
81
+ } }))] })));
82
82
  };
83
83
  export default HexaFields;
@@ -2,6 +2,7 @@ import { RgbaColor } from 'react-colorful';
2
2
  type RGBAFieldsProps = {
3
3
  value: RgbaColor;
4
4
  onChange: (newValue: RgbaColor) => void;
5
+ disableAlpha?: boolean;
5
6
  };
6
- declare const RGBAFields: ({ value, onChange }: RGBAFieldsProps) => import("react/jsx-runtime").JSX.Element;
7
+ declare const RGBAFields: ({ value, onChange, disableAlpha }: RGBAFieldsProps) => import("react/jsx-runtime").JSX.Element;
7
8
  export default RGBAFields;
@@ -1,25 +1,37 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState, useEffect, useCallback } from 'react';
2
3
  import Stack from '@mui/material/Stack';
3
4
  import Typography from '@mui/material/Typography';
4
5
  import InputAdornment from '@mui/material/InputAdornment';
5
6
  import { StyledInput } from './style';
6
- const RGBAFields = ({ value, onChange }) => {
7
- const handleChange = (key, max) => (event) => {
8
- let num = parseInt(event.target.value, 10);
7
+ const RGBAFields = ({ value, onChange, disableAlpha = false }) => {
8
+ const [internalValue, setInternalValue] = useState(value);
9
+ const { r, g, b, a } = internalValue;
10
+ useEffect(() => {
11
+ setInternalValue(value);
12
+ }, [value]);
13
+ const handleValueBoundaries = useCallback((num, max) => {
9
14
  if (isNaN(num))
10
15
  num = 0;
11
16
  if (num < 0)
12
17
  num = 0;
13
18
  if (num > max)
14
19
  num = max;
15
- onChange(Object.assign(Object.assign({}, value), { [key]: num }));
16
- };
17
- return (_jsxs(Stack, Object.assign({ direction: "row", spacing: 1 }, { children: [_jsx(StyledInput, { type: "number", value: value.r, onChange: handleChange('r', 255), inputProps: { min: 0, max: 255, style: { textAlign: 'center' } }, variant: "outlined", size: "small" }), _jsx(StyledInput, { type: "number", value: value.g, onChange: handleChange('g', 255), inputProps: { min: 0, max: 255, style: { textAlign: 'center' } }, variant: "outlined", size: "small" }), _jsx(StyledInput, { type: "number", value: value.b, onChange: handleChange('b', 255), inputProps: { min: 0, max: 255, style: { textAlign: 'center' } }, variant: "outlined", size: "small" }), _jsx(StyledInput, { type: "number", value: value.a, onChange: handleChange('a', 100), inputProps: { min: 0, max: 100, style: { textAlign: 'center' } }, variant: "outlined", sx: {
20
+ console.log('num', num);
21
+ return num;
22
+ }, []);
23
+ const handleChange = useCallback((key, max) => (event) => {
24
+ setInternalValue(Object.assign(Object.assign({}, internalValue), { [key]: handleValueBoundaries(+event.target.value, max) }));
25
+ }, [internalValue, handleValueBoundaries]);
26
+ const handleBlur = useCallback((key, max) => {
27
+ onChange(Object.assign(Object.assign({}, internalValue), { [key]: handleValueBoundaries(internalValue[key], max) }));
28
+ }, [onChange, internalValue, handleValueBoundaries]);
29
+ return (_jsxs(Stack, Object.assign({ direction: "row", spacing: 1 }, (disableAlpha && { flex: 1 }), { children: [_jsx(StyledInput, Object.assign({ type: "number", value: r, onBlur: () => handleBlur('r', 255), onChange: handleChange('r', 255), inputProps: { min: 0, max: 255, style: { textAlign: 'center' } }, variant: "outlined", size: "small" }, (disableAlpha && { sx: { flex: 1 } }))), _jsx(StyledInput, Object.assign({ type: "number", value: g, onBlur: () => handleBlur('g', 255), onChange: handleChange('g', 255), inputProps: { min: 0, max: 255, style: { textAlign: 'center' } }, variant: "outlined", size: "small" }, (disableAlpha && { sx: { flex: 1 } }))), _jsx(StyledInput, Object.assign({ type: "number", value: b, onBlur: () => handleBlur('b', 255), onChange: handleChange('b', 255), inputProps: { min: 0, max: 255, style: { textAlign: 'center' } }, variant: "outlined", size: "small" }, (disableAlpha && { sx: { flex: 1 } }))), !disableAlpha && (_jsx(StyledInput, { type: "number", value: a, onBlur: () => handleBlur('a', 100), onChange: handleChange('a', 100), inputProps: { min: 0, max: 100, style: { textAlign: 'center' } }, variant: "outlined", sx: {
18
30
  '& .MuiOutlinedInput-root': {
19
31
  pr: 1,
20
32
  },
21
33
  }, InputProps: {
22
34
  endAdornment: (_jsx(InputAdornment, Object.assign({ position: "end", sx: { m: 0 } }, { children: _jsx(Typography, Object.assign({ component: "span", display: "inline-block", fontSize: 12, fontWeight: 500 }, { children: "%" })) }))),
23
- }, size: "small" })] })));
35
+ }, size: "small" }))] })));
24
36
  };
25
37
  export default RGBAFields;
@@ -34,18 +34,19 @@ export const StyledColorWidgetWrapper = styled(Box)(({ theme }) => ({
34
34
  },
35
35
  },
36
36
  '&__hue': {
37
- marginBottom: theme.spacing(2),
38
37
  borderRadius: '4px',
39
- height: '16px',
38
+ height: '8px',
40
39
  '&-pointer': {
41
40
  width: 10,
42
41
  height: 10,
43
42
  },
44
43
  },
45
44
  '&__alpha': {
45
+ marginTop: theme.spacing(2),
46
+ marginBottom: 0,
46
47
  border: 0,
47
48
  borderRadius: '4px',
48
- height: '16px',
49
+ height: '8px',
49
50
  '&-pointer': {
50
51
  width: 10,
51
52
  height: 10,
@@ -9,10 +9,11 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import Box from '@mui/material/Box';
13
14
  import { StyledTooltip } from './styles';
14
15
  function Tooltip(_a) {
15
16
  var { className, title, placement = 'top', children } = _a, rest = __rest(_a, ["className", "title", "placement", "children"]);
16
- return (_jsx(StyledTooltip, Object.assign({ classes: { popper: className }, title: title, placement: placement, arrow: true }, rest, { children: children || _jsx(_Fragment, {}) })));
17
+ return (_jsx(StyledTooltip, Object.assign({ classes: { popper: className }, title: title, placement: placement, arrow: true }, rest, { children: _jsx(Box, Object.assign({ display: "flex" }, { children: children })) })));
17
18
  }
18
19
  export default Tooltip;
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.271",
4
+ "version": "0.1.273",
5
5
  "testVersion": 0,
6
6
  "type": "module",
7
7
  "main": "build/index.js",