@tapcart/mobile-components 0.6.18 → 0.6.19
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-merge-refs.d.ts +3 -0
- package/dist/components/hooks/use-merge-refs.d.ts.map +1 -0
- package/dist/components/hooks/use-merge-refs.js +14 -0
- package/dist/components/hooks/use-tap.d.ts +8 -0
- package/dist/components/hooks/use-tap.d.ts.map +1 -0
- package/dist/components/hooks/use-tap.js +100 -0
- package/dist/components/ui/button.js +1 -1
- package/dist/components/ui/favorite.d.ts +1 -1
- package/dist/components/ui/favorite.d.ts.map +1 -1
- package/dist/components/ui/favorite.js +10 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/tapcart-mobile-components.umd.js +44 -0
- package/package.json +15 -15
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-merge-refs.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-merge-refs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,wBAAgB,YAAY,CAAC,CAAC,GAAG,GAAG,EAClC,GAAG,IAAI,EAAE,KAAK,CACZ,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAClE,GACA,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAatB"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export function useMergeRefs(...refs) {
|
|
3
|
+
return React.useCallback((value) => {
|
|
4
|
+
refs.forEach((ref) => {
|
|
5
|
+
if (typeof ref === "function") {
|
|
6
|
+
ref(value);
|
|
7
|
+
}
|
|
8
|
+
else if (ref != null) {
|
|
9
|
+
;
|
|
10
|
+
ref.current = value;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}, [refs]);
|
|
14
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
declare const useTap: (tapThreshold?: number) => {
|
|
3
|
+
onTap: (handler: (event: any) => void) => (event: any) => void;
|
|
4
|
+
isPressed: boolean;
|
|
5
|
+
ref: React.MutableRefObject<null>;
|
|
6
|
+
};
|
|
7
|
+
export { useTap };
|
|
8
|
+
//# sourceMappingURL=use-tap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-tap.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-tap.ts"],"names":[],"mappings":"AACA,OAAO,KAAmD,MAAM,OAAO,CAAA;AAuFvE,QAAA,MAAM,MAAM;6BAuBkC,GAAG,KAAK,IAAI,aACvC,GAAG;;;CAerB,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,CAAA"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState, useEffect, useCallback, useRef } from "react";
|
|
3
|
+
// Shared manager for all instances of the hook
|
|
4
|
+
const tapManager = (() => {
|
|
5
|
+
const elements = new Map();
|
|
6
|
+
let isListening = false;
|
|
7
|
+
const startListening = () => {
|
|
8
|
+
if (isListening)
|
|
9
|
+
return;
|
|
10
|
+
const handleTouchStart = (e) => {
|
|
11
|
+
const touch = e.touches[0];
|
|
12
|
+
elements.forEach((data, el) => {
|
|
13
|
+
if (el.contains(touch.target)) {
|
|
14
|
+
data.touchStarted = true;
|
|
15
|
+
data.touchMoved = false;
|
|
16
|
+
data.startPosition = { x: touch.clientX, y: touch.clientY };
|
|
17
|
+
// Don't set isPressed here, wait to determine if it's a tap or drag
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
const handleTouchMove = (e) => {
|
|
22
|
+
const touch = e.touches[0];
|
|
23
|
+
elements.forEach((data, el) => {
|
|
24
|
+
if (data.touchStarted) {
|
|
25
|
+
const deltaX = Math.abs(touch.clientX - data.startPosition.x);
|
|
26
|
+
const deltaY = Math.abs(touch.clientY - data.startPosition.y);
|
|
27
|
+
if (deltaX > data.tapThreshold || deltaY > data.tapThreshold) {
|
|
28
|
+
data.touchMoved = true;
|
|
29
|
+
data.setIsPressed(false);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const handleTouchEnd = () => {
|
|
35
|
+
elements.forEach((data) => {
|
|
36
|
+
if (data.touchStarted) {
|
|
37
|
+
data.touchStarted = false;
|
|
38
|
+
if (!data.touchMoved) {
|
|
39
|
+
// It's a tap, set isPressed briefly
|
|
40
|
+
data.setIsPressed(true);
|
|
41
|
+
setTimeout(() => data.setIsPressed(false), 100);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
document.addEventListener("touchstart", (e) => handleTouchStart(e), { passive: true });
|
|
47
|
+
document.addEventListener("touchmove", (e) => handleTouchMove(e), { passive: true });
|
|
48
|
+
document.addEventListener("touchend", () => handleTouchEnd(), {
|
|
49
|
+
passive: true,
|
|
50
|
+
});
|
|
51
|
+
isListening = true;
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
register: (el, data) => {
|
|
55
|
+
elements.set(el, data);
|
|
56
|
+
startListening();
|
|
57
|
+
},
|
|
58
|
+
unregister: (el) => {
|
|
59
|
+
elements.delete(el);
|
|
60
|
+
},
|
|
61
|
+
elements,
|
|
62
|
+
};
|
|
63
|
+
})();
|
|
64
|
+
const useTap = (tapThreshold = 10) => {
|
|
65
|
+
const [isPressed, setIsPressed] = useState(false);
|
|
66
|
+
const elementRef = useRef(null);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
const element = elementRef.current;
|
|
69
|
+
if (!element)
|
|
70
|
+
return;
|
|
71
|
+
const data = {
|
|
72
|
+
touchStarted: false,
|
|
73
|
+
touchMoved: false,
|
|
74
|
+
startPosition: { x: 0, y: 0 },
|
|
75
|
+
setIsPressed,
|
|
76
|
+
tapThreshold,
|
|
77
|
+
};
|
|
78
|
+
tapManager.register(element, data);
|
|
79
|
+
return () => {
|
|
80
|
+
tapManager.unregister(element);
|
|
81
|
+
};
|
|
82
|
+
}, [tapThreshold]);
|
|
83
|
+
const onTap = useCallback((handler) => {
|
|
84
|
+
return (event) => {
|
|
85
|
+
const data = tapManager.elements.get(elementRef.current);
|
|
86
|
+
if (!data)
|
|
87
|
+
return;
|
|
88
|
+
if (event.type === "touchend" && !data.touchMoved) {
|
|
89
|
+
handler(event);
|
|
90
|
+
}
|
|
91
|
+
else if (event.type === "click" && !data.touchStarted) {
|
|
92
|
+
handler(event);
|
|
93
|
+
setIsPressed(true);
|
|
94
|
+
setTimeout(() => setIsPressed(false), 100);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}, []);
|
|
98
|
+
return { onTap, isPressed, ref: elementRef };
|
|
99
|
+
};
|
|
100
|
+
export { useTap };
|
|
@@ -16,7 +16,7 @@ import { cva } from "class-variance-authority";
|
|
|
16
16
|
import { cn, getColor, getTextStyle, getBackgroundAndPaddingStyle, } from "../../lib/utils";
|
|
17
17
|
import { Icon } from "./icon";
|
|
18
18
|
import { Text } from "./text";
|
|
19
|
-
const buttonVariants = cva("w-full flex rounded items-center justify-center transition-colors disabled:bg-stateColors-disabled disabled:border-stateColors-disabled disabled:pointer-events-none ring-offset-background overflow-elipse whitespace-nowrap truncate active:opacity-70 disabled:opacity-70", {
|
|
19
|
+
const buttonVariants = cva("w-full flex rounded items-center justify-center transition-colors disabled:bg-stateColors-disabled disabled:border-stateColors-disabled disabled:pointer-events-none ring-offset-background overflow-elipse whitespace-nowrap truncate active:opacity-70 disabled:opacity-70 cursor-pointer", {
|
|
20
20
|
variants: {
|
|
21
21
|
size: {
|
|
22
22
|
default: "py-3 px-4",
|
|
@@ -9,7 +9,7 @@ declare const favoriteVariants: (props?: ({
|
|
|
9
9
|
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
10
10
|
export interface FavoriteProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof favoriteVariants> {
|
|
11
11
|
selected?: boolean;
|
|
12
|
-
onClick
|
|
12
|
+
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
13
13
|
iconUrl?: string;
|
|
14
14
|
showBackground?: boolean;
|
|
15
15
|
showBackgroundShadow?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"favorite.d.ts","sourceRoot":"","sources":["../../../components/ui/favorite.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEjE,OAAO,
|
|
1
|
+
{"version":3,"file":"favorite.d.ts","sourceRoot":"","sources":["../../../components/ui/favorite.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEjE,OAAO,EAGL,OAAO,EAER,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAI3C,QAAA,MAAM,gBAAgB;;;;mFAuBpB,CAAA;AAEF,MAAM,WAAW,aACf,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EACnD,YAAY,CAAC,OAAO,gBAAgB,CAAC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAA;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,CAAC,EACP,sBAAsB,GACtB,WAAW,GACX,UAAU,GACV,aAAa,GACb,cAAc,CAAA;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,aAAa,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,CAAA;CACjC;AAED,QAAA,MAAM,QAAQ,yFA4Db,CAAA;AAGD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -12,8 +12,10 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import * as React from "react";
|
|
14
14
|
import { cva } from "class-variance-authority";
|
|
15
|
-
import { cn, getBorderSidesStyle, getPaddingStyle } from "../../lib/utils";
|
|
15
|
+
import { cn, getBorderSidesStyle, getPaddingStyle, } from "../../lib/utils";
|
|
16
16
|
import { Icon } from "./icon";
|
|
17
|
+
import { useTap } from "../hooks/use-tap";
|
|
18
|
+
import { useMergeRefs } from "../hooks/use-merge-refs";
|
|
17
19
|
const favoriteVariants = cva("flex p-2 gap-2 rounded-[4px]", {
|
|
18
20
|
variants: {
|
|
19
21
|
size: {
|
|
@@ -38,13 +40,17 @@ const favoriteVariants = cva("flex p-2 gap-2 rounded-[4px]", {
|
|
|
38
40
|
layoutType: "below-image-on-right",
|
|
39
41
|
},
|
|
40
42
|
});
|
|
41
|
-
const Favorite = React.forwardRef((_a,
|
|
43
|
+
const Favorite = React.forwardRef((_a, forwardedRef) => {
|
|
42
44
|
var { className, size = "small", selected = false, onClick, iconUrl = "https://storage.googleapis.com/tapcart-asset-uploads-prod/default-icon-options/Heart_1.svg", showBackground = false, showBackgroundShadow = false, cornerRadius = 4, layoutType = "below-image-on-right", favoriteFillColor = "#D91E18", disabledFillColor = "#727272", backgroundColor = "#FFFFFF", borderSides = ["all"], borderColorStyle = undefined, borderPadding = {} } = _a, props = __rest(_a, ["className", "size", "selected", "onClick", "iconUrl", "showBackground", "showBackgroundShadow", "cornerRadius", "layoutType", "favoriteFillColor", "disabledFillColor", "backgroundColor", "borderSides", "borderColorStyle", "borderPadding"]);
|
|
43
|
-
|
|
45
|
+
const { onTap, isPressed, ref: tapRef } = useTap();
|
|
46
|
+
const mergedRef = useMergeRefs(forwardedRef, tapRef);
|
|
47
|
+
return (_jsx("button", Object.assign({ onClick: onTap(onClick), ref: mergedRef, className: cn(favoriteVariants({
|
|
44
48
|
size,
|
|
45
49
|
showBackgroundShadow,
|
|
46
50
|
layoutType,
|
|
47
|
-
}), className), style: Object.assign({}, (showBackground && Object.assign(Object.assign({ borderRadius: `${cornerRadius}px`, backgroundColor: backgroundColor, borderColor: borderColorStyle }, getBorderSidesStyle(borderSides)), getPaddingStyle(borderPadding)))) }, props, { children: _jsx(Icon, { url: iconUrl, color: selected ? "stateColors-favorites" : "stateColors-disabled", size: size === "small" ? "xs" : "sm", fillColor: selected ? favoriteFillColor : disabledFillColor
|
|
51
|
+
}), className), style: Object.assign({}, (showBackground && Object.assign(Object.assign({ borderRadius: `${cornerRadius}px`, backgroundColor: backgroundColor, borderColor: borderColorStyle }, getBorderSidesStyle(borderSides)), getPaddingStyle(borderPadding)))) }, props, { children: _jsx(Icon, { url: iconUrl, color: selected ? "stateColors-favorites" : "stateColors-disabled", size: size === "small" ? "xs" : "sm", fillColor: selected ? favoriteFillColor : disabledFillColor, style: {
|
|
52
|
+
opacity: isPressed ? 0.7 : 1,
|
|
53
|
+
} }) })));
|
|
48
54
|
});
|
|
49
55
|
Favorite.displayName = "Favorite";
|
|
50
56
|
export { Favorite, favoriteVariants };
|
package/dist/index.d.ts
CHANGED
|
@@ -51,4 +51,5 @@ export * from "./components/ui/wishlist-select";
|
|
|
51
51
|
export * from "./components/hooks/use-shop";
|
|
52
52
|
export * from "./components/libs/sort-filter/search-integration";
|
|
53
53
|
export * from "./components/ui/subcollection-tabs";
|
|
54
|
+
export * from "./components/hooks/use-tap";
|
|
54
55
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,EAAE,EACF,GAAG,EACH,QAAQ,EACR,4BAA4B,EAC5B,mBAAmB,EACnB,YAAY,EACZ,yBAAyB,EACzB,4BAA4B,EAC5B,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,aAAa,CAAA;AACpB,cAAc,mCAAmC,CAAA;AACjD,cAAc,wCAAwC,CAAA;AACtD,cAAc,wCAAwC,CAAA;AACtD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,yCAAyC,CAAA;AACvD,cAAc,oCAAoC,CAAA;AAClD,cAAc,2BAA2B,CAAA;AACzC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,uBAAuB,CAAA;AACrC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AACxC,cAAc,sBAAsB,CAAA;AACpC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,2BAA2B,CAAA;AACzC,cAAc,wBAAwB,CAAA;AACtC,cAAc,0BAA0B,CAAA;AACxC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,0BAA0B,CAAA;AACxC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,uBAAuB,CAAA;AACrC,cAAc,sCAAsC,CAAA;AACpD,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,6BAA6B,CAAA;A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