@tap-payments/os-micro-frontend-shared 0.1.30-test.3 → 0.1.31-test.4

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 (29) hide show
  1. package/build/components/RadioButton/RadioButton.d.ts +5 -0
  2. package/build/components/RadioButton/RadioButton.js +19 -0
  3. package/build/components/RadioButton/index.d.ts +2 -0
  4. package/build/components/RadioButton/index.js +1 -0
  5. package/build/components/RadioButton/style.d.ts +27 -0
  6. package/build/components/RadioButton/style.js +64 -0
  7. package/build/components/RadioButton/type.d.ts +12 -0
  8. package/build/components/RadioButton/type.js +1 -0
  9. package/build/components/RadioGroup/RadioGroup.d.ts +5 -0
  10. package/build/components/RadioGroup/RadioGroup.js +31 -0
  11. package/build/components/RadioGroup/index.d.ts +2 -0
  12. package/build/components/RadioGroup/index.js +1 -0
  13. package/build/components/RadioGroup/style.d.ts +6 -0
  14. package/build/components/RadioGroup/style.js +15 -0
  15. package/build/components/RadioGroup/type.d.ts +33 -0
  16. package/build/components/RadioGroup/type.js +1 -0
  17. package/build/components/RightLeftExpandingCenterChip/RightLeftExpandingCenterChip.d.ts +3 -0
  18. package/build/components/RightLeftExpandingCenterChip/RightLeftExpandingCenterChip.js +43 -0
  19. package/build/components/RightLeftExpandingCenterChip/index.d.ts +2 -0
  20. package/build/components/RightLeftExpandingCenterChip/index.js +2 -0
  21. package/build/components/RightLeftExpandingCenterChip/style.d.ts +3415 -0
  22. package/build/components/RightLeftExpandingCenterChip/style.js +104 -0
  23. package/build/components/RightLeftExpandingCenterChip/type.d.ts +10 -0
  24. package/build/components/RightLeftExpandingCenterChip/type.js +1 -0
  25. package/build/components/RightLeftExpandingCenterChip/useRightLeftExpandingCenterChip.d.ts +31 -0
  26. package/build/components/RightLeftExpandingCenterChip/useRightLeftExpandingCenterChip.js +156 -0
  27. package/build/components/index.d.ts +3 -0
  28. package/build/components/index.js +3 -0
  29. package/package.json +2 -2
@@ -0,0 +1,104 @@
1
+ import { styled } from '@mui/material/styles';
2
+ import { motion } from 'framer-motion';
3
+ export const CHIP_GAP = 3;
4
+ export const CenterIconWrapper = styled(motion.div)(({ theme }) => ({
5
+ display: 'flex',
6
+ alignItems: 'center',
7
+ justifyContent: 'center',
8
+ gap: 0,
9
+ minWidth: 0,
10
+ height: 'auto',
11
+ lineHeight: 1,
12
+ position: 'relative',
13
+ zIndex: 1001,
14
+ fontSize: '12px',
15
+ color: theme.palette.text.primary,
16
+ }));
17
+ export const CenterShiftWrapper = styled(motion.div)(() => ({
18
+ display: 'inline-flex',
19
+ }));
20
+ export const LeftExpandIcon = styled(motion.span)(({ theme }) => ({
21
+ position: 'static',
22
+ display: 'inline-flex',
23
+ alignItems: 'center',
24
+ justifyContent: 'center',
25
+ width: 0,
26
+ overflow: 'visible',
27
+ margin: 0,
28
+ padding: 0,
29
+ fontSize: '10px',
30
+ lineHeight: 1,
31
+ color: theme.palette.text.secondary,
32
+ fontWeight: 'bold',
33
+ userSelect: 'none',
34
+ }));
35
+ export const RightExpandIcon = styled(motion.span)(({ theme }) => ({
36
+ position: 'static',
37
+ display: 'inline-flex',
38
+ alignItems: 'center',
39
+ justifyContent: 'center',
40
+ width: 0,
41
+ overflow: 'visible',
42
+ margin: 0,
43
+ padding: 0,
44
+ fontSize: '10px',
45
+ lineHeight: 1,
46
+ color: theme.palette.text.secondary,
47
+ fontWeight: 'bold',
48
+ userSelect: 'none',
49
+ }));
50
+ export const ExpandedSection = styled(motion.div)(({ side }) => (Object.assign(Object.assign(Object.assign({ position: 'absolute', display: 'flex', alignItems: 'center' }, (side === 'left' ? { right: '100%', flexDirection: 'row-reverse', transformOrigin: 'right center' } : {})), (side === 'right' ? { left: '100%', flexDirection: 'row', transformOrigin: 'left center' } : {})), { top: '50%', transform: 'translateY(-50%)', gap: 0, pointerEvents: 'auto', overflow: 'visible' })));
51
+ export const HoverBridge = styled('div')(({ side }) => (Object.assign(Object.assign({ position: 'absolute', top: 0, bottom: 0 }, (side === 'left' ? { right: '100%' } : { left: '100%' })), { pointerEvents: 'auto', background: 'transparent' })));
52
+ export const PeekContainer = styled(motion.div)(() => ({
53
+ position: 'relative',
54
+ display: 'inline-flex',
55
+ alignItems: 'center',
56
+ justifyContent: 'center',
57
+ height: 24,
58
+ overflow: 'visible',
59
+ }));
60
+ const baseChipStyles = (theme) => ({
61
+ border: `1px solid ${theme.palette.divider}`,
62
+ borderRadius: '12px',
63
+ backgroundColor: theme.palette.background.paper,
64
+ paddingInline: '8px',
65
+ height: '24px',
66
+ display: 'flex',
67
+ alignItems: 'center',
68
+ justifyContent: 'center',
69
+ lineHeight: 1,
70
+ fontSize: 12,
71
+ boxSizing: 'border-box',
72
+ whiteSpace: 'nowrap',
73
+ overflow: 'visible',
74
+ });
75
+ export const CenterChip = styled(motion.div)(({ theme }) => (Object.assign(Object.assign({}, baseChipStyles(theme)), { position: 'relative', zIndex: 2, minWidth: 24, flex: '0 0 auto', display: 'inline-flex', overflow: 'hidden', willChange: 'transform' })));
76
+ export const CenterContent = styled(motion.span)(() => ({
77
+ display: 'inline-flex',
78
+ alignItems: 'center',
79
+ transform: 'translateZ(0)',
80
+ }));
81
+ export const ExpandableContainer = styled(motion.span)(() => ({
82
+ display: 'inline-flex',
83
+ whiteSpace: 'nowrap',
84
+ overflow: 'hidden',
85
+ boxSizing: 'border-box',
86
+ willChange: 'width',
87
+ }));
88
+ export const ExpandableInner = styled(motion.span)(() => ({
89
+ display: 'inline-flex',
90
+ whiteSpace: 'nowrap',
91
+ paddingLeft: `${CHIP_GAP}px`,
92
+ }));
93
+ export const LeftPeekChip = styled(motion.div)(({ theme }) => (Object.assign(Object.assign({}, baseChipStyles(theme)), { position: 'absolute', left: 0, zIndex: 1, pointerEvents: 'none', minWidth: 24, paddingInline: 0 })));
94
+ export const RightPeekChip = styled(motion.div)(({ theme }) => (Object.assign(Object.assign({}, baseChipStyles(theme)), { position: 'absolute', right: 0, zIndex: 1, pointerEvents: 'none', minWidth: 24, paddingInline: 0 })));
95
+ export const ExpandChip = styled(motion.div)(({ theme }) => (Object.assign(Object.assign({}, baseChipStyles(theme)), { minWidth: 24, flex: '0 0 auto', display: 'inline-flex' })));
96
+ export const tableCellSx = {
97
+ position: 'relative',
98
+ overflow: 'visible',
99
+ zIndex: 101,
100
+ display: 'flex',
101
+ alignItems: 'center',
102
+ justifyContent: 'center',
103
+ minHeight: '20px',
104
+ };
@@ -0,0 +1,10 @@
1
+ import type React from 'react';
2
+ import type { SxProps } from '@mui/material';
3
+ export interface RightLeftExpandingCenterChipProps {
4
+ leftIcons?: React.ReactNode[];
5
+ rightIcons?: React.ReactNode[];
6
+ centerIcon: React.ReactNode;
7
+ expandableCenter?: React.ReactNode;
8
+ sx?: SxProps;
9
+ expandedZIndex?: number;
10
+ }
@@ -0,0 +1,31 @@
1
+ import { type ReactNode } from 'react';
2
+ export declare const DEFAULT_CHIP_MIN_WIDTH = 24;
3
+ export type UseRightLeftExpandingCenterChipArgs = {
4
+ leftIcons: ReactNode[];
5
+ rightIcons: ReactNode[];
6
+ centerIcon: ReactNode;
7
+ expandableCenter?: ReactNode;
8
+ };
9
+ export declare function useRightLeftExpandingCenterChip({ leftIcons, rightIcons, centerIcon, expandableCenter }: UseRightLeftExpandingCenterChipArgs): {
10
+ isHovering: boolean;
11
+ handleMouseEnter: () => void;
12
+ handleMouseLeave: () => void;
13
+ centerWrapRef: import("react").MutableRefObject<HTMLDivElement | null>;
14
+ centerContentRef: import("react").MutableRefObject<HTMLSpanElement | null>;
15
+ centerChipRef: import("react").MutableRefObject<HTMLDivElement | null>;
16
+ anchors: {
17
+ left: number;
18
+ right: number;
19
+ };
20
+ leftChipRefs: import("react").MutableRefObject<(HTMLDivElement | null)[]>;
21
+ rightChipRefs: import("react").MutableRefObject<(HTMLDivElement | null)[]>;
22
+ leftOffsets: number[];
23
+ rightOffsets: number[];
24
+ expandableInnerRef: import("react").MutableRefObject<HTMLSpanElement | null>;
25
+ expandableWidth: number;
26
+ expandedMV: import("framer-motion").MotionValue<number>;
27
+ shiftX: import("framer-motion").MotionValue<number>;
28
+ rightShift: number;
29
+ leftHoverWidth: number;
30
+ rightHoverWidth: number;
31
+ };
@@ -0,0 +1,156 @@
1
+ import { useRef, useEffect, useState, useMemo, useCallback } from 'react';
2
+ import { animate, useMotionValue, useTransform } from 'framer-motion';
3
+ import { CHIP_GAP } from './style';
4
+ export const DEFAULT_CHIP_MIN_WIDTH = 24;
5
+ export function useRightLeftExpandingCenterChip({ leftIcons, rightIcons, centerIcon, expandableCenter }) {
6
+ const [isHovering, setIsHovering] = useState(false);
7
+ const [anchors, setAnchors] = useState({ left: 0, right: 0 });
8
+ const [leftWidths, setLeftWidths] = useState([]);
9
+ const [rightWidths, setRightWidths] = useState([]);
10
+ const [expandableWidth, setExpandableWidth] = useState(0);
11
+ const hoverTimeoutRef = useRef(null);
12
+ const centerWrapRef = useRef(null);
13
+ const centerContentRef = useRef(null);
14
+ const centerChipRef = useRef(null);
15
+ const leftChipRefs = useRef([]);
16
+ const rightChipRefs = useRef([]);
17
+ const expandableInnerRef = useRef(null);
18
+ const resizeRaf = useRef(null);
19
+ const expandedMV = useMotionValue(0);
20
+ const shiftX = useTransform(expandedMV, (v) => v / 2);
21
+ const leftOffsets = useMemo(() => {
22
+ if (!leftWidths.length)
23
+ return [];
24
+ const acc = [];
25
+ let sum = CHIP_GAP + leftWidths[0] / 2;
26
+ acc.push(sum);
27
+ for (let i = 1; i < leftWidths.length; i++) {
28
+ sum += leftWidths[i - 1] / 2 + CHIP_GAP + leftWidths[i] / 2;
29
+ acc.push(sum);
30
+ }
31
+ return acc;
32
+ }, [leftWidths]);
33
+ const rightOffsets = useMemo(() => {
34
+ if (!rightWidths.length)
35
+ return [];
36
+ const acc = [];
37
+ let sum = CHIP_GAP + rightWidths[0] / 2;
38
+ acc.push(sum);
39
+ for (let i = 1; i < rightWidths.length; i++) {
40
+ sum += rightWidths[i - 1] / 2 + CHIP_GAP + rightWidths[i] / 2;
41
+ acc.push(sum);
42
+ }
43
+ return acc;
44
+ }, [rightWidths]);
45
+ const rightShift = isHovering && expandableCenter ? expandableWidth + CHIP_GAP : 0;
46
+ const maxRightShift = expandableCenter ? expandableWidth + CHIP_GAP : 0;
47
+ const handleMouseEnter = useCallback(() => {
48
+ if (hoverTimeoutRef.current)
49
+ clearTimeout(hoverTimeoutRef.current);
50
+ setIsHovering(true);
51
+ }, []);
52
+ const handleMouseLeave = useCallback(() => {
53
+ if (hoverTimeoutRef.current)
54
+ clearTimeout(hoverTimeoutRef.current);
55
+ hoverTimeoutRef.current = setTimeout(() => setIsHovering(false), 120);
56
+ }, []);
57
+ const measureAnchors = useCallback(() => {
58
+ var _a;
59
+ const wrap = centerWrapRef.current;
60
+ const chip = centerChipRef.current;
61
+ const content = centerContentRef.current;
62
+ if (!wrap)
63
+ return;
64
+ const wrapRect = wrap.getBoundingClientRect();
65
+ const targetRect = (_a = (chip !== null && chip !== void 0 ? chip : content)) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
66
+ if (!targetRect)
67
+ return;
68
+ const left = targetRect.left - wrapRect.left;
69
+ const right = targetRect.right - wrapRect.left;
70
+ setAnchors({ left, right });
71
+ }, []);
72
+ const measureStackChipWidths = useCallback(() => {
73
+ setLeftWidths(leftChipRefs.current.map((el) => (el ? el.offsetWidth : DEFAULT_CHIP_MIN_WIDTH)));
74
+ setRightWidths(rightChipRefs.current.map((el) => (el ? el.offsetWidth : DEFAULT_CHIP_MIN_WIDTH)));
75
+ }, []);
76
+ const measureExpandableWidth = useCallback(() => {
77
+ var _a, _b;
78
+ setExpandableWidth((_b = (_a = expandableInnerRef.current) === null || _a === void 0 ? void 0 : _a.scrollWidth) !== null && _b !== void 0 ? _b : 0);
79
+ }, []);
80
+ const onResize = useCallback(() => {
81
+ if (resizeRaf.current)
82
+ cancelAnimationFrame(resizeRaf.current);
83
+ resizeRaf.current = requestAnimationFrame(() => {
84
+ measureAnchors();
85
+ measureStackChipWidths();
86
+ measureExpandableWidth();
87
+ });
88
+ }, [measureAnchors, measureStackChipWidths, measureExpandableWidth]);
89
+ useEffect(() => {
90
+ return () => {
91
+ if (hoverTimeoutRef.current)
92
+ clearTimeout(hoverTimeoutRef.current);
93
+ };
94
+ }, []);
95
+ useEffect(() => {
96
+ measureAnchors();
97
+ }, [centerIcon, measureAnchors]);
98
+ useEffect(() => {
99
+ measureStackChipWidths();
100
+ }, [leftIcons, rightIcons, measureStackChipWidths]);
101
+ useEffect(() => {
102
+ measureExpandableWidth();
103
+ }, [expandableCenter, measureExpandableWidth]);
104
+ useEffect(() => {
105
+ onResize();
106
+ window.addEventListener('resize', onResize);
107
+ return () => {
108
+ window.removeEventListener('resize', onResize);
109
+ if (resizeRaf.current)
110
+ cancelAnimationFrame(resizeRaf.current);
111
+ };
112
+ }, [onResize]);
113
+ useEffect(() => {
114
+ const target = isHovering && expandableCenter ? expandableWidth + CHIP_GAP : 0;
115
+ const controls = animate(expandedMV, target, { duration: 0.2, ease: 'easeOut' });
116
+ return () => controls.stop();
117
+ }, [isHovering, expandableCenter, expandableWidth, expandedMV]);
118
+ const leftHoverWidth = useMemo(() => {
119
+ var _a;
120
+ if (!leftOffsets.length)
121
+ return 0;
122
+ const last = leftOffsets.length - 1;
123
+ const lastWidth = (_a = leftWidths[last]) !== null && _a !== void 0 ? _a : DEFAULT_CHIP_MIN_WIDTH;
124
+ const farthest = leftOffsets[last] + lastWidth / 2;
125
+ return farthest + CHIP_GAP;
126
+ }, [leftOffsets, leftWidths]);
127
+ const rightHoverWidth = useMemo(() => {
128
+ var _a;
129
+ if (!rightOffsets.length)
130
+ return 0;
131
+ const last = rightOffsets.length - 1;
132
+ const lastWidth = (_a = rightWidths[last]) !== null && _a !== void 0 ? _a : DEFAULT_CHIP_MIN_WIDTH;
133
+ const farthest = maxRightShift + rightOffsets[last] + lastWidth / 2;
134
+ return farthest + CHIP_GAP;
135
+ }, [rightOffsets, rightWidths, maxRightShift]);
136
+ return {
137
+ isHovering,
138
+ handleMouseEnter,
139
+ handleMouseLeave,
140
+ centerWrapRef,
141
+ centerContentRef,
142
+ centerChipRef,
143
+ anchors,
144
+ leftChipRefs,
145
+ rightChipRefs,
146
+ leftOffsets,
147
+ rightOffsets,
148
+ expandableInnerRef,
149
+ expandableWidth,
150
+ expandedMV,
151
+ shiftX,
152
+ rightShift,
153
+ leftHoverWidth,
154
+ rightHoverWidth,
155
+ };
156
+ }
@@ -97,3 +97,6 @@ export { default as AppServices } from './AppServices';
97
97
  export { default as ScrollLoader } from './ScrollLoader';
98
98
  export * from './ScrollLoader';
99
99
  export * from './TooltipChip';
100
+ export * from './RightLeftExpandingCenterChip';
101
+ export * from './RadioButton';
102
+ export * from './RadioGroup';
@@ -97,3 +97,6 @@ export { default as AppServices } from './AppServices';
97
97
  export { default as ScrollLoader } from './ScrollLoader';
98
98
  export * from './ScrollLoader';
99
99
  export * from './TooltipChip';
100
+ export * from './RightLeftExpandingCenterChip';
101
+ export * from './RadioButton';
102
+ export * from './RadioGroup';
package/package.json CHANGED
@@ -1,8 +1,8 @@
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.30-test.3",
5
- "testVersion": 3,
4
+ "version": "0.1.31-test.4",
5
+ "testVersion": 4,
6
6
  "type": "module",
7
7
  "main": "build/index.js",
8
8
  "module": "build/index.js",