@tapcart/mobile-components 0.7.96 → 0.7.97
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.
- package/dist/components/hooks/use-reviews.d.ts +4 -0
- package/dist/components/hooks/use-reviews.d.ts.map +1 -1
- package/dist/components/hooks/use-reviews.js +8 -0
- package/dist/components/ui/swipeable-list-item.d.ts.map +1 -1
- package/dist/components/ui/swipeable-list-item.js +67 -30
- package/package.json +1 -1
|
@@ -20,6 +20,10 @@ type UseReviewsReturn = {
|
|
|
20
20
|
isLoading: boolean;
|
|
21
21
|
reviewsMockData?: any;
|
|
22
22
|
mockStarDistribution?: any;
|
|
23
|
+
mockSummaryData?: {
|
|
24
|
+
averageScore: number;
|
|
25
|
+
totalReviewCount: number;
|
|
26
|
+
};
|
|
23
27
|
};
|
|
24
28
|
export declare function useReviews(props: UseReviewsProps | null): UseReviewsReturn;
|
|
25
29
|
type UseReviewsInfiniteReturn = UseReviewsReturn & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-reviews.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-reviews.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EACjB,MAAM,kBAAkB,CAAA;AAGzB,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,CAAC,CAAA;IACvC,QAAQ,EAAE,SAAS,GAAG,UAAU,GAAG,QAAQ,CAAA;IAC3C,UAAU,EAAE,MAAM,CAAA;IAClB,OAAO,EAAE,CAAC,MAAM,CAAC,CAAA;IACjB,MAAM,EAAE,CAAC,MAAM,CAAC,CAAA;IAChB,MAAM,EACF,MAAM,GACN,UAAU,GACV,YAAY,GACZ,MAAM,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,CAAA;IAClE,KAAK,EAAE,GAAG,CAAA;IACV,SAAS,EAAE,OAAO,CAAA;IAClB,eAAe,CAAC,EAAE,GAAG,CAAA;IACrB,oBAAoB,CAAC,EAAE,GAAG,CAAA;IAC1B,eAAe,CAAC,EAAE;QAChB,YAAY,EAAE,MAAM,CAAA;QACpB,gBAAgB,EAAE,MAAM,CAAA;KACzB,CAAA;CACF,CAAA;AAqED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,GAAG,gBAAgB,CAyE1E;AAED,KAAK,wBAAwB,GAAG,gBAAgB,GAAG;IACjD,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,KAAK,IAAI,CAAA;CACrC,CAAA;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,eAAe,GAAG,IAAI,GAC5B,wBAAwB,CAmK1B"}
|
|
@@ -48,6 +48,13 @@ const mockStarDistribution = {
|
|
|
48
48
|
4: 2,
|
|
49
49
|
5: 0,
|
|
50
50
|
};
|
|
51
|
+
const mockTotalScores = Object.entries(mockStarDistribution).reduce((sum, [score, count]) => sum + Number(score) * count, 0);
|
|
52
|
+
const mockTotalCount = Object.values(mockStarDistribution).reduce((sum, count) => sum + count, 0);
|
|
53
|
+
const mockAverageScore = mockTotalCount > 0 ? mockTotalScores / mockTotalCount : 0;
|
|
54
|
+
const mockSummaryData = {
|
|
55
|
+
averageScore: mockAverageScore,
|
|
56
|
+
totalReviewCount: mockTotalCount,
|
|
57
|
+
};
|
|
51
58
|
export function useReviews(props) {
|
|
52
59
|
let url = null;
|
|
53
60
|
if (props) {
|
|
@@ -99,6 +106,7 @@ export function useReviews(props) {
|
|
|
99
106
|
isLoading: !data && !error,
|
|
100
107
|
reviewsMockData,
|
|
101
108
|
mockStarDistribution,
|
|
109
|
+
mockSummaryData,
|
|
102
110
|
};
|
|
103
111
|
}
|
|
104
112
|
export function useReviewsInfinite(props) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swipeable-list-item.d.ts","sourceRoot":"","sources":["../../../components/ui/swipeable-list-item.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAA+B,SAAS,EAAE,MAAM,OAAO,CAAA;AAGrE,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,SAAS,CAAA;IACnB,OAAO,EAAE,WAAW,EAAE,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,
|
|
1
|
+
{"version":3,"file":"swipeable-list-item.d.ts","sourceRoot":"","sources":["../../../components/ui/swipeable-list-item.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,EAA+B,SAAS,EAAE,MAAM,OAAO,CAAA;AAGrE,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,SAAS,CAAA;IACnB,OAAO,EAAE,WAAW,EAAE,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,QAAA,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAiKvD,CAAA;AAID,OAAO,EAAE,iBAAiB,EAAE,CAAA"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useState, useRef, useEffect } from "react";
|
|
4
4
|
import { useSwipeable } from "react-swipeable";
|
|
5
5
|
const SwipeableListItem = ({ children, actions = [], actionWidth = 52, threshold = 0.3, }) => {
|
|
6
6
|
const [offset, setOffset] = useState(0);
|
|
7
7
|
const [isOpen, setIsOpen] = useState(false);
|
|
8
|
+
const [initialDirection, setInitialDirection] = useState(null);
|
|
8
9
|
const totalActionsWidth = actionWidth * actions.length;
|
|
9
10
|
const thresholdPixels = totalActionsWidth * threshold;
|
|
10
11
|
const itemRef = useRef(null);
|
|
@@ -25,56 +26,92 @@ const SwipeableListItem = ({ children, actions = [], actionWidth = 52, threshold
|
|
|
25
26
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
26
27
|
};
|
|
27
28
|
}, [isOpen]);
|
|
29
|
+
const isHorizontalSwipe = (deltaX, deltaY) => {
|
|
30
|
+
return Math.abs(deltaX) > Math.abs(deltaY) * 1.5;
|
|
31
|
+
};
|
|
28
32
|
const handlers = useSwipeable({
|
|
33
|
+
onSwipeStart: (event) => {
|
|
34
|
+
if (Math.abs(event.deltaX) > 10 || Math.abs(event.deltaY) > 10) {
|
|
35
|
+
const isHorizontal = isHorizontalSwipe(event.deltaX, event.deltaY);
|
|
36
|
+
setInitialDirection(isHorizontal ? "horizontal" : "vertical");
|
|
37
|
+
if (!isHorizontal && event.event.cancelable) {
|
|
38
|
+
event.event.stopPropagation();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
29
42
|
onSwiping: (event) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
43
|
+
if (initialDirection === "vertical")
|
|
44
|
+
return;
|
|
45
|
+
if (!initialDirection &&
|
|
46
|
+
(Math.abs(event.deltaX) > 10 || Math.abs(event.deltaY) > 10)) {
|
|
47
|
+
const isHorizontal = isHorizontalSwipe(event.deltaX, event.deltaY);
|
|
48
|
+
setInitialDirection(isHorizontal ? "horizontal" : "vertical");
|
|
49
|
+
if (!isHorizontal)
|
|
50
|
+
return;
|
|
33
51
|
}
|
|
34
|
-
|
|
35
|
-
newOffset =
|
|
52
|
+
if (initialDirection === "horizontal") {
|
|
53
|
+
let newOffset = 0;
|
|
54
|
+
if (event.event.cancelable) {
|
|
55
|
+
event.event.preventDefault();
|
|
56
|
+
event.event.stopPropagation();
|
|
57
|
+
}
|
|
58
|
+
if (event.dir === "Left") {
|
|
59
|
+
newOffset = Math.min(event.absX, totalActionsWidth);
|
|
60
|
+
}
|
|
61
|
+
else if (event.dir === "Right" && isOpen) {
|
|
62
|
+
newOffset = Math.max(totalActionsWidth - event.absX, 0);
|
|
63
|
+
}
|
|
64
|
+
setOffset(newOffset);
|
|
36
65
|
}
|
|
37
|
-
setOffset(newOffset);
|
|
38
66
|
},
|
|
39
67
|
onSwipedLeft: () => {
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
68
|
+
if (initialDirection === "horizontal") {
|
|
69
|
+
if (offset > thresholdPixels) {
|
|
70
|
+
setIsOpen(true);
|
|
71
|
+
setOffset(totalActionsWidth);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
closeItem();
|
|
75
|
+
}
|
|
43
76
|
}
|
|
44
|
-
|
|
77
|
+
setInitialDirection(null);
|
|
78
|
+
},
|
|
79
|
+
onSwipedRight: () => {
|
|
80
|
+
if (initialDirection === "horizontal") {
|
|
45
81
|
closeItem();
|
|
46
82
|
}
|
|
83
|
+
setInitialDirection(null);
|
|
84
|
+
},
|
|
85
|
+
onSwiped: () => {
|
|
86
|
+
setInitialDirection(null);
|
|
47
87
|
},
|
|
48
|
-
onSwipedRight: () => closeItem(),
|
|
49
88
|
trackMouse: true,
|
|
50
89
|
trackTouch: true,
|
|
51
|
-
delta:
|
|
52
|
-
preventScrollOnSwipe:
|
|
90
|
+
delta: 5,
|
|
91
|
+
preventScrollOnSwipe: false,
|
|
53
92
|
rotationAngle: 0,
|
|
54
93
|
});
|
|
55
|
-
return (_jsxs("div", Object.assign({ ref: itemRef, className: "relative overflow-hidden" }, { children: [_jsx("div", Object.assign({
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
: "none",
|
|
60
|
-
}, role: "button", "aria-expanded": isOpen }, { children: children })), _jsx("div", Object.assign({ className: "absolute right-0 top-0 h-full flex", "aria-label": "Action buttons", style: { visibility: offset > 0 ? "visible" : "hidden" } }, { children: actions.map((action, index) => {
|
|
61
|
-
const actionStartPosition = index * actionWidth;
|
|
62
|
-
const isActionVisible = offset > actionStartPosition;
|
|
63
|
-
return (_jsx("div", Object.assign({ className: "h-full flex items-center justify-center overflow-hidden", style: {
|
|
94
|
+
return (_jsxs("div", Object.assign({ ref: itemRef, className: "relative overflow-hidden" }, { children: [_jsx("div", Object.assign({ className: "absolute top-0 right-0 h-full flex", "aria-label": "Action buttons", style: {
|
|
95
|
+
width: `${totalActionsWidth}px`,
|
|
96
|
+
} }, { children: actions.map((action, index) => {
|
|
97
|
+
return (_jsx("div", Object.assign({ className: "h-full flex items-center justify-center", style: {
|
|
64
98
|
width: `${actionWidth}px`,
|
|
65
99
|
backgroundColor: action.color || "#e5e5e5",
|
|
66
|
-
maxWidth: isActionVisible
|
|
67
|
-
? `${Math.min(offset - actionStartPosition, actionWidth)}px`
|
|
68
|
-
: "0px",
|
|
69
|
-
opacity: isActionVisible ? 1 : 0,
|
|
70
|
-
transition: "max-width 0.1s ease-out, opacity 0.1s ease-out",
|
|
71
100
|
} }, { children: _jsx("button", Object.assign({ onClick: () => {
|
|
72
101
|
action.onPress();
|
|
73
102
|
if (action.closeOnAction !== false) {
|
|
74
103
|
closeItem();
|
|
75
104
|
}
|
|
76
|
-
}, className: "w-full h-full flex items-center justify-center"
|
|
77
|
-
}) }))
|
|
105
|
+
}, className: "w-full h-full flex items-center justify-center" }, { children: action.icon && _jsx(_Fragment, { children: action.icon }) })) }), action.key || index));
|
|
106
|
+
}) })), _jsx("div", Object.assign({}, handlers, { className: "w-full transition-transform duration-200 ease-out relative", style: {
|
|
107
|
+
transform: `translateX(-${offset}px)`,
|
|
108
|
+
transition: offset === 0 || offset === totalActionsWidth
|
|
109
|
+
? "transform 0.2s ease-out"
|
|
110
|
+
: "none",
|
|
111
|
+
zIndex: 10,
|
|
112
|
+
backgroundColor: "inherit",
|
|
113
|
+
touchAction: initialDirection === "horizontal" ? "none" : "auto",
|
|
114
|
+
}, role: "button", "aria-expanded": isOpen }, { children: children }))] })));
|
|
78
115
|
};
|
|
79
116
|
SwipeableListItem.displayName = "SwipeableListItem";
|
|
80
117
|
export { SwipeableListItem };
|