@tapcart/mobile-components 0.8.24 → 0.8.25
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.
|
@@ -8,11 +8,13 @@ interface UseCollectionProps {
|
|
|
8
8
|
language: string;
|
|
9
9
|
getCollections?: boolean;
|
|
10
10
|
limit?: number;
|
|
11
|
+
fetchMaxProduct?: boolean;
|
|
11
12
|
metafields?: string;
|
|
12
13
|
}
|
|
13
|
-
export declare const useCollection: ({ apiUrl, appId, collectionId, collectionHandle, collectionIdList, language, limit, getCollections, metafields, }: UseCollectionProps) => {
|
|
14
|
+
export declare const useCollection: ({ apiUrl, appId, collectionId, collectionHandle, collectionIdList, language, limit, getCollections, metafields, fetchMaxProduct, }: UseCollectionProps) => {
|
|
14
15
|
collections: Collection[];
|
|
15
16
|
specificCollection: Collection | null;
|
|
17
|
+
maxProductCollection: Collection | null;
|
|
16
18
|
loading: boolean;
|
|
17
19
|
error: string | null;
|
|
18
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-collection.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-collection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAG7C,UAAU,kBAAkB;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;
|
|
1
|
+
{"version":3,"file":"use-collection.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-collection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAG7C,UAAU,kBAAkB;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AA2GD,eAAO,MAAM,aAAa,uIAWvB,kBAAkB;;;;;;CA8EpB,CAAA"}
|
|
@@ -43,14 +43,26 @@ const fetchAllCollections = (apiUrl, setError, limit = 100) => __awaiter(void 0,
|
|
|
43
43
|
}).toString();
|
|
44
44
|
return yield fetchWrapper(`${apiUrl}/collections/by-app-id?${limitParam}`, setError);
|
|
45
45
|
});
|
|
46
|
-
|
|
46
|
+
const fetchCollectionWithMaxProduct = (apiUrl, setError, limit = 100) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
const params = new URLSearchParams({
|
|
48
|
+
limit: `${limit}`,
|
|
49
|
+
fetchMaxProduct: "true",
|
|
50
|
+
}).toString();
|
|
51
|
+
return yield fetchWrapper(`${apiUrl}/collections/by-app-id?${params}`, setError);
|
|
52
|
+
});
|
|
53
|
+
export const useCollection = ({ apiUrl, appId, collectionId, collectionHandle, collectionIdList, language, limit = 100, getCollections = false, metafields, fetchMaxProduct = false, }) => {
|
|
47
54
|
const [collections, setCollections] = useState([]);
|
|
48
55
|
const [specificCollection, setSpecificCollection] = useState(null);
|
|
56
|
+
const [maxProductCollection, setMaxProductCollection] = useState(null);
|
|
49
57
|
const [loading, setLoading] = useState(true);
|
|
50
58
|
const [error, setError] = useState(null);
|
|
51
59
|
useEffect(() => {
|
|
52
60
|
const fetchAllOrSumCollections = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
61
|
try {
|
|
62
|
+
if (fetchMaxProduct) {
|
|
63
|
+
const collection = yield fetchCollectionWithMaxProduct(apiUrl, setError, limit);
|
|
64
|
+
return setMaxProductCollection(collection);
|
|
65
|
+
}
|
|
54
66
|
if (getCollections) {
|
|
55
67
|
const collections = yield fetchAllCollections(apiUrl, setError, limit);
|
|
56
68
|
return setCollections(collections !== null && collections !== void 0 ? collections : []);
|
|
@@ -85,5 +97,11 @@ export const useCollection = ({ apiUrl, appId, collectionId, collectionHandle, c
|
|
|
85
97
|
collectionIdList,
|
|
86
98
|
metafields,
|
|
87
99
|
]);
|
|
88
|
-
return {
|
|
100
|
+
return {
|
|
101
|
+
collections,
|
|
102
|
+
specificCollection,
|
|
103
|
+
maxProductCollection,
|
|
104
|
+
loading,
|
|
105
|
+
error,
|
|
106
|
+
};
|
|
89
107
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../../components/ui/button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAGL,KAAK,EAEL,SAAS,EAET,oBAAoB,EACrB,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"button.d.ts","sourceRoot":"","sources":["../../../components/ui/button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAGL,KAAK,EAEL,SAAS,EAET,oBAAoB,EACrB,MAAM,iBAAiB,CAAA;AAMxB,QAAA,MAAM,cAAc;;;mFAgCnB,CAAA;AAwCD,MAAM,WAAW,WACf,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EACnD,YAAY,CAAC,OAAO,cAAc,CAAC;IACrC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,KAAK,CAAC,aAAa,GAAG,SAAS,CAAA;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAA;IACvD,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC/B,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAA;CAC9D;AAED,QAAA,MAAM,MAAM,uFA0GX,CAAA;AAGD,QAAA,MAAM,cAAc,iBACJ,SAAS,GACrB,oBAAoB,GAAG;IACrB,SAAS,EAAE,KAAK,CAAA;IAChB,WAAW,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAA;IAC5B,gBAAgB,EAAE,OAAO,CAAA;CAC1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkBJ,CAAA;AAED,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,CAAA"}
|
|
@@ -16,6 +16,8 @@ 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
|
+
import { useTap } from "./tap";
|
|
20
|
+
import { useMergeRefs } from "../hooks/use-merge-refs";
|
|
19
21
|
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 disabled:opacity-70 cursor-pointer", {
|
|
20
22
|
variants: {
|
|
21
23
|
size: {
|
|
@@ -80,6 +82,8 @@ const labelVariants = cva("truncate", {
|
|
|
80
82
|
});
|
|
81
83
|
const Button = React.forwardRef((_a, ref) => {
|
|
82
84
|
var { className, labelClassName, labelStyle, variant, size, asChild = false, loading, icon, iconColor, iconStrokeColor, iconPosition, iconSize, iconUrl, iconClassName, onClick } = _a, props = __rest(_a, ["className", "labelClassName", "labelStyle", "variant", "size", "asChild", "loading", "icon", "iconColor", "iconStrokeColor", "iconPosition", "iconSize", "iconUrl", "iconClassName", "onClick"]);
|
|
85
|
+
const { onTap, isPressed, ref: tapRef } = useTap();
|
|
86
|
+
const mergedRef = useMergeRefs(ref, tapRef);
|
|
83
87
|
const Comp = asChild ? Slot : "button";
|
|
84
88
|
const IconButton = () => icon || iconUrl ? (_jsx(Icon, { name: icon, url: iconUrl, size: "sm", style: { color: iconColor } })) : null;
|
|
85
89
|
// TODO: need to refactor icon sizing. This isnt extensible.
|
|
@@ -91,7 +95,7 @@ const Button = React.forwardRef((_a, ref) => {
|
|
|
91
95
|
return (_jsx(Comp, Object.assign({ className: cn(buttonVariants({ variant, size }), className, {
|
|
92
96
|
"pointer-events-none": loading,
|
|
93
97
|
"flex-row-reverse": (icon || iconUrl) && iconPosition === "right",
|
|
94
|
-
}), ref:
|
|
98
|
+
}), ref: mergedRef, onClick: onTap(onClick) }, props, { children: loading ? (_jsx(LoadingButton, {})) : typeof props.children === "object" &&
|
|
95
99
|
React.isValidElement(props.children) ? ( // if children are passed as a valid React element
|
|
96
100
|
props.children // render it
|
|
97
101
|
) : // otherwise use props
|