@tapcart/mobile-components 0.6.6 → 0.6.7
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/ThemeProvider.d.ts +3 -0
- package/dist/components/ThemeProvider.d.ts.map +1 -0
- package/dist/components/ThemeProvider.js +18 -0
- package/dist/components/ThemeToggle.d.ts +2 -0
- package/dist/components/ThemeToggle.d.ts.map +1 -0
- package/dist/components/ThemeToggle.js +8 -0
- package/dist/components/hooks/use-sort-filter.d.ts +26 -0
- package/dist/components/hooks/use-sort-filter.d.ts.map +1 -0
- package/dist/components/hooks/use-sort-filter.js +31 -0
- package/dist/components/libs/sort-filter/beyond-search.d.ts +15 -0
- package/dist/components/libs/sort-filter/beyond-search.d.ts.map +1 -0
- package/dist/components/libs/sort-filter/beyond-search.js +78 -0
- package/dist/components/libs/sort-filter/kmp.d.ts +15 -0
- package/dist/components/libs/sort-filter/kmp.d.ts.map +1 -0
- package/dist/components/libs/sort-filter/kmp.js +55 -0
- package/dist/components/libs/sort-filter/nosto-search.d.ts +9 -0
- package/dist/components/libs/sort-filter/nosto-search.d.ts.map +1 -0
- package/dist/components/libs/sort-filter/nosto-search.js +8 -0
- package/dist/components/libs/sort-filter/search-integration.d.ts +50 -0
- package/dist/components/libs/sort-filter/search-integration.d.ts.map +1 -0
- package/dist/components/libs/sort-filter/search-integration.js +38 -0
- package/dist/components/libs/sort-filter/search-spring.d.ts +9 -0
- package/dist/components/libs/sort-filter/search-spring.d.ts.map +1 -0
- package/dist/components/libs/sort-filter/search-spring.js +8 -0
- package/dist/components/libs/sort-filter/shopify-search-and-discovery.d.ts +64 -0
- package/dist/components/libs/sort-filter/shopify-search-and-discovery.d.ts.map +1 -0
- package/dist/components/libs/sort-filter/shopify-search-and-discovery.js +172 -0
- package/dist/components/ui/empty-message.d.ts.map +1 -1
- package/dist/components/ui/empty-message.js +47 -1
- package/dist/components/ui/input.d.ts +17 -0
- package/dist/components/ui/input.d.ts.map +1 -0
- package/dist/components/ui/input.js +35 -0
- package/dist/components/ui/product-grid.d.ts +15 -0
- package/dist/components/ui/product-grid.d.ts.map +1 -0
- package/dist/components/ui/product-grid.js +22 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/styles.css +17 -0
- package/package.json +1 -1
- package/dist/components/hooks/use-click-outside.d.ts +0 -8
- package/dist/components/hooks/use-click-outside.d.ts.map +0 -1
- package/dist/components/hooks/use-click-outside.js +0 -46
- package/dist/components/hooks/use-pull-to-refresh.d.ts +0 -9
- package/dist/components/hooks/use-pull-to-refresh.d.ts.map +0 -1
- package/dist/components/hooks/use-pull-to-refresh.js +0 -88
- package/dist/components/ui/favorite/favorite.d.ts +0 -16
- package/dist/components/ui/favorite/favorite.d.ts.map +0 -1
- package/dist/components/ui/favorite/favorite.js +0 -156
- package/dist/components/ui/favorite/favorite.spec.d.ts +0 -2
- package/dist/components/ui/favorite/favorite.spec.d.ts.map +0 -1
- package/dist/components/ui/favorite/favorite.spec.js +0 -6
- package/dist/components/ui/favorite/index.d.ts +0 -2
- package/dist/components/ui/favorite/index.d.ts.map +0 -1
- package/dist/components/ui/favorite/index.js +0 -1
- package/dist/components/ui/select.d.ts +0 -39
- package/dist/components/ui/select.d.ts.map +0 -1
- package/dist/components/ui/select.js +0 -87
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
export class ShopifySearchAndDiscovery {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.collectionSortOptions = [
|
|
4
|
+
{
|
|
5
|
+
sortName: "manual",
|
|
6
|
+
name: "collection-sort-recommended",
|
|
7
|
+
sortKey: ProductCollectionSortKeys.COLLECTION_DEFAULT,
|
|
8
|
+
isReverse: false,
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
sortName: "created-descending",
|
|
12
|
+
name: "collection-sort-new",
|
|
13
|
+
sortKey: ProductCollectionSortKeys.CREATED,
|
|
14
|
+
isReverse: true,
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
sortName: "best-selling",
|
|
18
|
+
name: "collection-sort-best",
|
|
19
|
+
sortKey: ProductCollectionSortKeys.BEST_SELLING,
|
|
20
|
+
isReverse: false,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
sortName: "price-ascending",
|
|
24
|
+
name: "collection-sort-ascending-price",
|
|
25
|
+
sortKey: ProductCollectionSortKeys.PRICE,
|
|
26
|
+
isReverse: false,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
sortName: "price-descending",
|
|
30
|
+
name: "collection-sort-descending-price",
|
|
31
|
+
sortKey: ProductCollectionSortKeys.PRICE,
|
|
32
|
+
isReverse: true,
|
|
33
|
+
},
|
|
34
|
+
];
|
|
35
|
+
this.getSortSearchParamKey = () => {
|
|
36
|
+
return "sort_by";
|
|
37
|
+
};
|
|
38
|
+
this.convertFilterCategoriesToSearchParams = (filters, searchParams) => {
|
|
39
|
+
const filtersToApply = filters.flatMap((it) => it.filters
|
|
40
|
+
.filter((it) => it.isSelected)
|
|
41
|
+
.map((it) => {
|
|
42
|
+
const input = JSON.parse(it.tag);
|
|
43
|
+
const key = it.collectionId;
|
|
44
|
+
if (input.hasOwnProperty("available")) {
|
|
45
|
+
//ex {title: 'In stock', amount: 38, isSelected: true, tag: '{"available":true}', collectionId: 'filter.v.availability'}
|
|
46
|
+
return `filter.v.availability=${input.available ? 1 : 0}`;
|
|
47
|
+
}
|
|
48
|
+
else if (input.productVendor) {
|
|
49
|
+
//ex {title: 'vendor', amount: 12, isSelected: true, tag: '{"productVendor":"vendor"}', collectionId: 'filter.p.vendor'}
|
|
50
|
+
return `${key}=${input.productVendor}`;
|
|
51
|
+
}
|
|
52
|
+
else if (input.tag) {
|
|
53
|
+
//ex {title: 'Accessory', amount: 1, isSelected: true, tag: '{"tag":"Accessory"}', collectionId: 'filter.p.tag'}
|
|
54
|
+
return `${key}=${input.tag}`;
|
|
55
|
+
}
|
|
56
|
+
else if (input.productType) {
|
|
57
|
+
//ex {title: 'Bag', amount: 1, isSelected: true, tag: '{"productType":"Bag"}', collectionId: 'filter.p.product_type'}
|
|
58
|
+
return `${key}=${input.productType}`;
|
|
59
|
+
}
|
|
60
|
+
else if (key) {
|
|
61
|
+
//ex {title: 'Optimistic', amount: 1, isSelected: true, tag: '{"productMetafield":{"namespace":"test_data","key":"binding_mount","value":"Optimistic"}}', collectionId: 'filter.p.m.test_data.binding_mount'}
|
|
62
|
+
//ex {title: 'Velour', amount: 1, isSelected: true, tag: '{"variantOption":{"name":"fabric","value":"Velour"}}', collectionId: 'filter.v.option.fabric'}
|
|
63
|
+
const child = Object.keys(input)[0];
|
|
64
|
+
if (!child)
|
|
65
|
+
return "";
|
|
66
|
+
return `${key}=${input[child].value}`;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
return "";
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
.filter((it) => it !== ""));
|
|
73
|
+
const oldParams = new URLSearchParams(searchParams.toString());
|
|
74
|
+
const newParams = new URLSearchParams();
|
|
75
|
+
//remove old filters
|
|
76
|
+
oldParams.forEach((value, key) => {
|
|
77
|
+
if (!key.startsWith("filter.")) {
|
|
78
|
+
newParams.append(key, value);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
//build new filters
|
|
82
|
+
filtersToApply.forEach((param) => {
|
|
83
|
+
const [key, value] = param.split("=");
|
|
84
|
+
if (key && value) {
|
|
85
|
+
newParams.append(key, value);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return newParams.toString();
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
convertSortToSearchParams({ sortOption, existingParams, }) {
|
|
92
|
+
var _a;
|
|
93
|
+
const name = sortOption === null || sortOption === void 0 ? void 0 : sortOption.name;
|
|
94
|
+
const input = (_a = this.collectionSortOptions.find((it) => it.name == name)) === null || _a === void 0 ? void 0 : _a.sortName;
|
|
95
|
+
const newParams = new URLSearchParams();
|
|
96
|
+
existingParams.forEach((value, key) => {
|
|
97
|
+
if (!key.startsWith(this.getSortSearchParamKey())) {
|
|
98
|
+
newParams.append(key, value);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
if (input && input.length) {
|
|
102
|
+
newParams.append(this.getSortSearchParamKey(), input);
|
|
103
|
+
}
|
|
104
|
+
return newParams;
|
|
105
|
+
}
|
|
106
|
+
getActiveSortFromSearchParams({ searchParams, sortOptions, }) {
|
|
107
|
+
var _a, _b;
|
|
108
|
+
const sortInput = searchParams.get(this.getSortSearchParamKey());
|
|
109
|
+
const name = (_a = this.collectionSortOptions.find((it) => it.sortName == sortInput)) === null || _a === void 0 ? void 0 : _a.name;
|
|
110
|
+
return (_b = sortOptions.find((it) => (it === null || it === void 0 ? void 0 : it.name) == name)) !== null && _b !== void 0 ? _b : null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export var SearchSortKeys;
|
|
114
|
+
(function (SearchSortKeys) {
|
|
115
|
+
/**
|
|
116
|
+
* Sort by the price value.
|
|
117
|
+
*/
|
|
118
|
+
SearchSortKeys["PRICE"] = "PRICE";
|
|
119
|
+
/*
|
|
120
|
+
* Sort by relevance to the search terms.
|
|
121
|
+
*/
|
|
122
|
+
SearchSortKeys["RELEVANCE"] = "RELEVANCE";
|
|
123
|
+
})(SearchSortKeys || (SearchSortKeys = {}));
|
|
124
|
+
export var SearchUnavailableProductsType;
|
|
125
|
+
(function (SearchUnavailableProductsType) {
|
|
126
|
+
/*
|
|
127
|
+
*Show unavailable products in the order that they're found.
|
|
128
|
+
*/
|
|
129
|
+
SearchUnavailableProductsType["SHOW"] = "SHOW";
|
|
130
|
+
/*
|
|
131
|
+
* Exclude unavailable products.
|
|
132
|
+
*/
|
|
133
|
+
SearchUnavailableProductsType["HIDE"] = "HIDE";
|
|
134
|
+
})(SearchUnavailableProductsType || (SearchUnavailableProductsType = {}));
|
|
135
|
+
export var ProductCollectionSortKeys;
|
|
136
|
+
(function (ProductCollectionSortKeys) {
|
|
137
|
+
/**
|
|
138
|
+
* Sort by the `title` value.
|
|
139
|
+
*/
|
|
140
|
+
ProductCollectionSortKeys["TITLE"] = "TITLE";
|
|
141
|
+
/**
|
|
142
|
+
* Sort by the `price` value.
|
|
143
|
+
*/
|
|
144
|
+
ProductCollectionSortKeys["PRICE"] = "PRICE";
|
|
145
|
+
/**
|
|
146
|
+
* Sort by the `best-selling` value.
|
|
147
|
+
*/
|
|
148
|
+
ProductCollectionSortKeys["BEST_SELLING"] = "BEST_SELLING";
|
|
149
|
+
/**
|
|
150
|
+
* Sort by the `created` value.
|
|
151
|
+
*/
|
|
152
|
+
ProductCollectionSortKeys["CREATED"] = "CREATED";
|
|
153
|
+
/**
|
|
154
|
+
* Sort by the `id` value.
|
|
155
|
+
*/
|
|
156
|
+
ProductCollectionSortKeys["ID"] = "ID";
|
|
157
|
+
/**
|
|
158
|
+
* Sort by the `manual` value.
|
|
159
|
+
*/
|
|
160
|
+
ProductCollectionSortKeys["MANUAL"] = "MANUAL";
|
|
161
|
+
/**
|
|
162
|
+
* Sort by the `collection-default` value.
|
|
163
|
+
*/
|
|
164
|
+
ProductCollectionSortKeys["COLLECTION_DEFAULT"] = "COLLECTION_DEFAULT";
|
|
165
|
+
/**
|
|
166
|
+
* During a search (i.e. when the `query` parameter has been specified on the connection) this sorts the
|
|
167
|
+
* results by relevance to the search term(s). When no search query is specified, this sort key is not
|
|
168
|
+
* deterministic and should not be used.
|
|
169
|
+
*
|
|
170
|
+
*/
|
|
171
|
+
ProductCollectionSortKeys["RELEVANCE"] = "RELEVANCE";
|
|
172
|
+
})(ProductCollectionSortKeys || (ProductCollectionSortKeys = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"empty-message.d.ts","sourceRoot":"","sources":["../../../components/ui/empty-message.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"empty-message.d.ts","sourceRoot":"","sources":["../../../components/ui/empty-message.tsx"],"names":[],"mappings":"AAOA,UAAU,iBAAiB;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,UAAU,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAA;IAC9C,WAAW,EAAE,MAAM,MAAM,CAAA;IACzB,SAAS,EAAE,MAAM,MAAM,EAAE,CAAA;IACzB,eAAe,EAAE,MAAM,MAAM,CAAA;CAC9B;AAED,UAAU,WAAW;IACnB,IAAI,EAAE,UAAU,GAAG,UAAU,CAAA;IAC7B,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,UAAU,gBAAgB;IACxB,WAAW,EAAE,WAAW,CAAA;CACzB;AAED,iBAAS,YAAY,CAAC,EACpB,QAAQ,EACR,KAAK,EACL,WAAW,EACX,SAAS,EACT,WAAW,EACX,UAAU,EACV,WAAsB,EACtB,SAAoB,EACpB,eAA0B,GAC3B,EAAE,iBAAiB,2CAmGnB;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
|
@@ -4,10 +4,56 @@ import { Button } from "./button";
|
|
|
4
4
|
import { Icon } from "./icon";
|
|
5
5
|
import { Text } from "./text";
|
|
6
6
|
import { cn } from "../../lib/utils";
|
|
7
|
+
import { useState, useEffect } from "react";
|
|
7
8
|
function EmptyMessage({ iconName, title, description, className, buttonLabel, openScreen, usePathname = () => "", useRouter = () => [], useSearchParams = () => "", }) {
|
|
9
|
+
const [clickCount, setClickCount] = useState(0);
|
|
8
10
|
const router = useRouter();
|
|
9
11
|
const pathname = usePathname();
|
|
10
12
|
const searchParams = useSearchParams();
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const timer = setTimeout(() => {
|
|
15
|
+
setClickCount(0);
|
|
16
|
+
}, 2000);
|
|
17
|
+
return () => clearTimeout(timer);
|
|
18
|
+
}, [clickCount]);
|
|
19
|
+
const handlePageClick = () => {
|
|
20
|
+
setClickCount((prevCount) => {
|
|
21
|
+
const newCount = prevCount + 1;
|
|
22
|
+
if (newCount === 10) {
|
|
23
|
+
const fullUrl = `${window.location.origin}${pathname}?${searchParams.toString()}`;
|
|
24
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
25
|
+
navigator.clipboard
|
|
26
|
+
.writeText(fullUrl)
|
|
27
|
+
.then(() => alert("Full URL copied to clipboard!"))
|
|
28
|
+
.catch(() => fallbackCopyTextToClipboard(fullUrl));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
fallbackCopyTextToClipboard(fullUrl);
|
|
32
|
+
}
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
return newCount;
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const fallbackCopyTextToClipboard = (text) => {
|
|
39
|
+
const textArea = document.createElement("textarea");
|
|
40
|
+
textArea.value = text;
|
|
41
|
+
textArea.style.position = "fixed"; // Avoid scrolling to bottom
|
|
42
|
+
document.body.appendChild(textArea);
|
|
43
|
+
textArea.focus();
|
|
44
|
+
textArea.select();
|
|
45
|
+
try {
|
|
46
|
+
const successful = document.execCommand("copy");
|
|
47
|
+
const msg = successful
|
|
48
|
+
? "Full URL copied to clipboard!"
|
|
49
|
+
: "Unable to copy URL";
|
|
50
|
+
alert(msg);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
alert("Failed to copy URL");
|
|
54
|
+
}
|
|
55
|
+
document.body.removeChild(textArea);
|
|
56
|
+
};
|
|
11
57
|
const onClick = () => {
|
|
12
58
|
const newParams = new URLSearchParams(searchParams.toString());
|
|
13
59
|
const filters = newParams.get("filters");
|
|
@@ -24,6 +70,6 @@ function EmptyMessage({ iconName, title, description, className, buttonLabel, op
|
|
|
24
70
|
});
|
|
25
71
|
}
|
|
26
72
|
};
|
|
27
|
-
return (_jsxs("div", Object.assign({ className: cn("flex-grow flex flex-col justify-center items-center gap-4 h-full", className) }, { children: [_jsxs("div", Object.assign({ className: "flex flex-col justify-center items-center gap-2" }, { children: [_jsx(Icon, { name: iconName, size: "md", color: "coreColors-secondaryIcon" }), _jsx(Text, Object.assign({ type: "h2", className: "text-textColors-primaryColor text-center" }, { children: title })), _jsx(Text, Object.assign({ type: "body-primary", className: "text-textColors-secondaryColor text-center" }, { children: description }))] })), buttonLabel ? (_jsx(Button, Object.assign({ variant: "default", onClick: onClick, className: "w-auto" }, { children: buttonLabel }))) : null] })));
|
|
73
|
+
return (_jsxs("div", Object.assign({ className: cn("flex-grow flex flex-col justify-center items-center gap-4 h-full", className), onClick: handlePageClick }, { children: [_jsxs("div", Object.assign({ className: "flex flex-col justify-center items-center gap-2" }, { children: [_jsx(Icon, { name: iconName, size: "md", color: "coreColors-secondaryIcon" }), _jsx(Text, Object.assign({ type: "h2", className: "text-textColors-primaryColor text-center" }, { children: title })), _jsx(Text, Object.assign({ type: "body-primary", className: "text-textColors-secondaryColor text-center" }, { children: description }))] })), buttonLabel ? (_jsx(Button, Object.assign({ variant: "default", onClick: onClick, className: "w-auto" }, { children: buttonLabel }))) : null] })));
|
|
28
74
|
}
|
|
29
75
|
export { EmptyMessage };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type VariantProps } from "class-variance-authority";
|
|
3
|
+
declare const inputVariants: (props?: ({
|
|
4
|
+
error?: boolean | null | undefined;
|
|
5
|
+
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
6
|
+
export interface InputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange">, VariantProps<typeof inputVariants> {
|
|
7
|
+
id: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
icon?: string;
|
|
10
|
+
asChild?: boolean;
|
|
11
|
+
value: string;
|
|
12
|
+
placeholder: string;
|
|
13
|
+
onChange: (_: string) => void;
|
|
14
|
+
}
|
|
15
|
+
declare const Input: React.ForwardRefExoticComponent<InputProps & React.RefAttributes<HTMLInputElement>>;
|
|
16
|
+
export { Input };
|
|
17
|
+
//# sourceMappingURL=input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../../../components/ui/input.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAIjE,QAAA,MAAM,aAAa;;mFAalB,CAAA;AAED,MAAM,WAAW,UACf,SAAQ,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,gBAAgB,CAAC,EAAE,UAAU,CAAC,EACnE,YAAY,CAAC,OAAO,aAAa,CAAC;IACpC,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAA;CAC9B;AAED,QAAA,MAAM,KAAK,qFAkDV,CAAA;AAGD,OAAO,EAAE,KAAK,EAAE,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import * as React from "react";
|
|
14
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
15
|
+
import { cva } from "class-variance-authority";
|
|
16
|
+
import { cn } from "../../lib/utils";
|
|
17
|
+
import { Icon } from "./icon";
|
|
18
|
+
const inputVariants = cva("flex h-14 w-full rounded border border-coreColors-dividingLines bg-coreColors-inputBackground px-4 pt-5 pb-2 placeholder-shown:p-4 text-textColors-primaryColor text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-textColors-secondaryColor focus-visible:outline-none focus-visible:ring-0 disabled:cursor-not-allowed disabled:opacity-50 focus:border-coreColors-brandColorPrimary peer data-[icon=true]:pr-10", {
|
|
19
|
+
variants: {
|
|
20
|
+
error: {
|
|
21
|
+
true: "border-stateColors-error text-stateColors-error placeholder:text-stateColors-error focus:border-stateColors-error [&+label]:text-stateColors-error",
|
|
22
|
+
false: "",
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
defaultVariants: {
|
|
26
|
+
error: false,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const Input = React.forwardRef((_a, ref) => {
|
|
30
|
+
var { className, error = false, id, type, label, icon, asChild, value, placeholder, onChange } = _a, props = __rest(_a, ["className", "error", "id", "type", "label", "icon", "asChild", "value", "placeholder", "onChange"]);
|
|
31
|
+
const Comp = asChild ? Slot : "div";
|
|
32
|
+
return (_jsxs(Comp, Object.assign({ className: "relative group" }, { children: [_jsx("input", Object.assign({ placeholder: placeholder, value: value, onChange: (e) => onChange(e.target.value), id: id, type: type, className: cn(inputVariants({ error }), className), "data-icon": !!icon, ref: ref }, props)), label ? (_jsx("label", Object.assign({ htmlFor: id, className: "absolute text-[10px] text-textColors-secondaryColor group-active:text-coreColors-brandColorPrimary top-2 z-10 h-4 origin-[0] start-4 opacity-100 peer-placeholder-shown:opacity-0" }, { children: label }))) : null, icon ? (_jsx(Icon, { name: icon, "data-error": error, size: "sm", className: "absolute w-5 aspect-square fill-current text-textColors-secondaryColor top-[18px] z-10 origin-[0] end-4 peer-pr-8 icon data-[error=true]:text-stateColors-error" })) : null] })));
|
|
33
|
+
});
|
|
34
|
+
Input.displayName = "Input";
|
|
35
|
+
export { Input };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type Product = any;
|
|
2
|
+
interface PageData {
|
|
3
|
+
products: Product[];
|
|
4
|
+
cursorBlob?: string;
|
|
5
|
+
filtersData: any;
|
|
6
|
+
}
|
|
7
|
+
interface ProductGridItemsProps {
|
|
8
|
+
initialData: PageData;
|
|
9
|
+
loadMoreProducts: (params: any) => Promise<PageData>;
|
|
10
|
+
queryVariables: Record<string, any>;
|
|
11
|
+
config: Record<string, any>;
|
|
12
|
+
}
|
|
13
|
+
declare function ProductGrid({ loadMoreProducts, initialData, queryVariables, config, }: ProductGridItemsProps): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export { ProductGrid };
|
|
15
|
+
//# sourceMappingURL=product-grid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product-grid.d.ts","sourceRoot":"","sources":["../../../components/ui/product-grid.tsx"],"names":[],"mappings":"AAkBA,KAAK,OAAO,GAAG,GAAG,CAAA;AAClB,UAAU,QAAQ;IAChB,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,GAAG,CAAA;CACjB;AAED,UAAU,qBAAqB;IAC7B,WAAW,EAAE,QAAQ,CAAA;IACrB,gBAAgB,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IACpD,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC5B;AAED,iBAAS,WAAW,CAAC,EACnB,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,MAAM,GACP,EAAE,qBAAqB,2CAmCvB;AAED,OAAO,EAAE,WAAW,EAAE,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useInfiniteScroll } from "../hooks/use-infinite-scroll";
|
|
4
|
+
import { ProductCard } from "./product-card";
|
|
5
|
+
const Loader = () => (_jsx("div", Object.assign({ className: "grid-cols-2 lg:grid-cols-3" }, { children: Array(4)
|
|
6
|
+
.fill(0)
|
|
7
|
+
.map((_, index) => (_jsx("div", { className: "aspect-[2/3] animate-pulse bg-neutral-100 dark:bg-neutral-900" }, index))) })));
|
|
8
|
+
function ProductGrid({ loadMoreProducts, initialData, queryVariables, config, }) {
|
|
9
|
+
const { data, error, isLoadingInitialData, isLoadingMore, isEmpty, isReachingEnd, ref, products, } = useInfiniteScroll({
|
|
10
|
+
initialData,
|
|
11
|
+
loadMoreProducts,
|
|
12
|
+
queryVariables,
|
|
13
|
+
});
|
|
14
|
+
if (error)
|
|
15
|
+
return _jsx("div", { children: "Failed to load data" });
|
|
16
|
+
if (isLoadingInitialData)
|
|
17
|
+
return _jsx(Loader, {});
|
|
18
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", Object.assign({ className: "grid-cols-2 lg:grid-cols-3" }, { children: products.map((product, i) => (_jsx(ProductCard, {
|
|
19
|
+
// @ts-expect-error
|
|
20
|
+
product: product, config: config, isLoading: false }, product.handle))) })), isLoadingMore ? _jsx(Loader, {}) : _jsx("div", { ref: ref })] }));
|
|
21
|
+
}
|
|
22
|
+
export { ProductGrid };
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./components/hooks/use-recommendations";
|
|
|
5
5
|
export * from "./components/hooks/use-products";
|
|
6
6
|
export * from "./components/hooks/use-products";
|
|
7
7
|
export * from "./components/hooks/use-scroll-direction";
|
|
8
|
+
export * from "./components/hooks/use-sort-filter";
|
|
8
9
|
export * from "./components/ui/accordion";
|
|
9
10
|
export * from "./components/ui/aspect-ratio";
|
|
10
11
|
export * from "./components/ui/badge";
|
|
@@ -48,4 +49,5 @@ export * from "./components/ui/video";
|
|
|
48
49
|
export * from "./components/ui/wishlist";
|
|
49
50
|
export * from "./components/hooks/use-product-options";
|
|
50
51
|
export * from "./components/ui/wishlist-select";
|
|
52
|
+
export * from "./components/libs/sort-filter/search-integration";
|
|
51
53
|
//# 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,GAC7B,MAAM,aAAa,CAAA;AACpB,cAAc,mCAAmC,CAAA;AACjD,cAAc,wCAAwC,CAAA;AACtD,cAAc,wCAAwC,CAAA;AACtD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,yCAAyC,CAAA;AACvD,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;AAC3C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA;AACzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,0BAA0B,CAAA;AACxC,cAAc,uBAAuB,CAAA;AACrC,cAAc,yBAAyB,CAAA;AACvC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wCAAwC,CAAA;AACtD,cAAc,iCAAiC,CAAA"}
|
|
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,GAC7B,MAAM,aAAa,CAAA;AACpB,cAAc,mCAAmC,CAAA;AACjD,cAAc,wCAAwC,CAAA;AACtD,cAAc,wCAAwC,CAAA;AACtD,cAAc,iCAAiC,CAAA;AAC/C,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;AAC3C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA;AACzC,cAAc,2BAA2B,CAAA;AACzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wBAAwB,CAAA;AACtC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AACpC,cAAc,0BAA0B,CAAA;AACxC,cAAc,uBAAuB,CAAA;AACrC,cAAc,yBAAyB,CAAA;AACvC,cAAc,8BAA8B,CAAA;AAC5C,cAAc,wBAAwB,CAAA;AACtC,cAAc,2BAA2B,CAAA;AACzC,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,wCAAwC,CAAA;AACtD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,kDAAkD,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export * from "./components/hooks/use-recommendations";
|
|
|
6
6
|
export * from "./components/hooks/use-products";
|
|
7
7
|
export * from "./components/hooks/use-products";
|
|
8
8
|
export * from "./components/hooks/use-scroll-direction";
|
|
9
|
+
export * from "./components/hooks/use-sort-filter";
|
|
9
10
|
export * from "./components/ui/accordion";
|
|
10
11
|
export * from "./components/ui/aspect-ratio";
|
|
11
12
|
export * from "./components/ui/badge";
|
|
@@ -49,3 +50,4 @@ export * from "./components/ui/video";
|
|
|
49
50
|
export * from "./components/ui/wishlist";
|
|
50
51
|
export * from "./components/hooks/use-product-options";
|
|
51
52
|
export * from "./components/ui/wishlist-select";
|
|
53
|
+
export * from "./components/libs/sort-filter/search-integration";
|
package/dist/styles.css
CHANGED
|
@@ -782,6 +782,9 @@ video {
|
|
|
782
782
|
.z-10 {
|
|
783
783
|
z-index: 10;
|
|
784
784
|
}
|
|
785
|
+
.z-20 {
|
|
786
|
+
z-index: 20;
|
|
787
|
+
}
|
|
785
788
|
.z-50 {
|
|
786
789
|
z-index: 50;
|
|
787
790
|
}
|
|
@@ -1057,6 +1060,10 @@ video {
|
|
|
1057
1060
|
.w-auto {
|
|
1058
1061
|
width: auto;
|
|
1059
1062
|
}
|
|
1063
|
+
.w-fit {
|
|
1064
|
+
width: -moz-fit-content;
|
|
1065
|
+
width: fit-content;
|
|
1066
|
+
}
|
|
1060
1067
|
.w-full {
|
|
1061
1068
|
width: 100%;
|
|
1062
1069
|
}
|
|
@@ -1785,6 +1792,9 @@ video {
|
|
|
1785
1792
|
.capitalize {
|
|
1786
1793
|
text-transform: capitalize;
|
|
1787
1794
|
}
|
|
1795
|
+
.leading-6 {
|
|
1796
|
+
line-height: 1.5rem;
|
|
1797
|
+
}
|
|
1788
1798
|
.leading-\[130\%\] {
|
|
1789
1799
|
line-height: 130%;
|
|
1790
1800
|
}
|
|
@@ -2039,6 +2049,9 @@ video {
|
|
|
2039
2049
|
.outline-stateColors-skeleton {
|
|
2040
2050
|
outline-color: var(--stateColors-skeleton);
|
|
2041
2051
|
}
|
|
2052
|
+
.outline-transparent {
|
|
2053
|
+
outline-color: transparent;
|
|
2054
|
+
}
|
|
2042
2055
|
.ring-0 {
|
|
2043
2056
|
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
|
|
2044
2057
|
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color);
|
|
@@ -2355,6 +2368,10 @@ body::-webkit-scrollbar {
|
|
|
2355
2368
|
outline-color: var(--coreColors-brandColorPrimary);
|
|
2356
2369
|
}
|
|
2357
2370
|
|
|
2371
|
+
.active\:outline-transparent:active {
|
|
2372
|
+
outline-color: transparent;
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2358
2375
|
.disabled\:pointer-events-none:disabled {
|
|
2359
2376
|
pointer-events: none;
|
|
2360
2377
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { RefObject } from "react";
|
|
2
|
-
type Handler = () => void;
|
|
3
|
-
interface UseClickOutsideOptions {
|
|
4
|
-
enabled?: boolean;
|
|
5
|
-
}
|
|
6
|
-
declare function useClickOutside<T extends HTMLElement = HTMLElement>(handler: Handler, options?: UseClickOutsideOptions): RefObject<T>;
|
|
7
|
-
export default useClickOutside;
|
|
8
|
-
//# sourceMappingURL=use-click-outside.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-click-outside.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-click-outside.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,SAAS,EAAE,MAAM,OAAO,CAAA;AAEpD,KAAK,OAAO,GAAG,MAAM,IAAI,CAAA;AAEzB,UAAU,sBAAsB;IAC9B,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,iBAAS,eAAe,CAAC,CAAC,SAAS,WAAW,GAAG,WAAW,EAC1D,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,sBAA2B,GACnC,SAAS,CAAC,CAAC,CAAC,CAqDd;AAED,eAAe,eAAe,CAAA"}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
2
|
-
function useClickOutside(handler, options = {}) {
|
|
3
|
-
const { enabled = true } = options;
|
|
4
|
-
const ref = useRef(null);
|
|
5
|
-
const touchStartRef = useRef(null);
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
if (!enabled)
|
|
8
|
-
return;
|
|
9
|
-
const handleOutsideInteraction = (event) => {
|
|
10
|
-
if (!ref.current || ref.current.contains(event.target))
|
|
11
|
-
return;
|
|
12
|
-
handler();
|
|
13
|
-
};
|
|
14
|
-
const handleTouchStart = (event) => {
|
|
15
|
-
touchStartRef.current = {
|
|
16
|
-
x: event.touches[0].clientX,
|
|
17
|
-
y: event.touches[0].clientY,
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
const handleTouchEnd = (event) => {
|
|
21
|
-
if (!touchStartRef.current)
|
|
22
|
-
return;
|
|
23
|
-
const touchEnd = {
|
|
24
|
-
x: event.changedTouches[0].clientX,
|
|
25
|
-
y: event.changedTouches[0].clientY,
|
|
26
|
-
};
|
|
27
|
-
const distance = Math.sqrt(Math.pow(touchEnd.x - touchStartRef.current.x, 2) +
|
|
28
|
-
Math.pow(touchEnd.y - touchStartRef.current.y, 2));
|
|
29
|
-
if (distance < 10) {
|
|
30
|
-
// Treat as a tap if the finger didn't move much
|
|
31
|
-
handleOutsideInteraction(event);
|
|
32
|
-
}
|
|
33
|
-
touchStartRef.current = null;
|
|
34
|
-
};
|
|
35
|
-
document.addEventListener("mousedown", handleOutsideInteraction);
|
|
36
|
-
document.addEventListener("touchstart", handleTouchStart);
|
|
37
|
-
document.addEventListener("touchend", handleTouchEnd);
|
|
38
|
-
return () => {
|
|
39
|
-
document.removeEventListener("mousedown", handleOutsideInteraction);
|
|
40
|
-
document.removeEventListener("touchstart", handleTouchStart);
|
|
41
|
-
document.removeEventListener("touchend", handleTouchEnd);
|
|
42
|
-
};
|
|
43
|
-
}, [handler, enabled]);
|
|
44
|
-
return ref;
|
|
45
|
-
}
|
|
46
|
-
export default useClickOutside;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
declare function usePullToRefresh(ref: React.RefObject<HTMLDivElement>, onTrigger: () => Promise<void>): boolean;
|
|
3
|
-
interface PullToRefreshProps {
|
|
4
|
-
onRefresh: () => Promise<void>;
|
|
5
|
-
children: React.ReactNode;
|
|
6
|
-
}
|
|
7
|
-
declare const PullToRefresh: React.FC<PullToRefreshProps>;
|
|
8
|
-
export { usePullToRefresh, PullToRefresh };
|
|
9
|
-
//# sourceMappingURL=use-pull-to-refresh.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-pull-to-refresh.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-pull-to-refresh.tsx"],"names":[],"mappings":"AACA,OAAO,KAAmD,MAAM,OAAO,CAAA;AAKvE,iBAAS,gBAAgB,CACvB,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,EACpC,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,WAuF/B;AAED,UAAU,kBAAkB;IAC1B,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC9B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B;AAED,QAAA,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAiB/C,CAAA;AAED,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,CAAA"}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
-
import { useEffect, useState, useCallback, useRef } from "react";
|
|
13
|
-
import { Icon } from "../ui/icon";
|
|
14
|
-
const TRIGGER_THRESHOLD = 250;
|
|
15
|
-
function usePullToRefresh(ref, onTrigger) {
|
|
16
|
-
const [loading, setLoading] = useState(false);
|
|
17
|
-
const handleTouchStartRef = useRef();
|
|
18
|
-
const handleTouchMoveRef = useRef();
|
|
19
|
-
const handleTouchEndRef = useRef();
|
|
20
|
-
const onTransitionEndRef = useRef();
|
|
21
|
-
const appr = useCallback((x) => {
|
|
22
|
-
const MAX = 128;
|
|
23
|
-
const k = 0.4;
|
|
24
|
-
return MAX * (1 - Math.exp((-k * x) / MAX));
|
|
25
|
-
}, []);
|
|
26
|
-
const handleTouchStart = useCallback((startEvent) => {
|
|
27
|
-
const el = ref.current;
|
|
28
|
-
if (!el)
|
|
29
|
-
return;
|
|
30
|
-
const initialY = startEvent.touches[0].clientY;
|
|
31
|
-
handleTouchMoveRef.current = (moveEvent) => {
|
|
32
|
-
const el = ref.current;
|
|
33
|
-
if (!el)
|
|
34
|
-
return;
|
|
35
|
-
const currentY = moveEvent.touches[0].clientY;
|
|
36
|
-
const dy = currentY - initialY;
|
|
37
|
-
if (dy < 0)
|
|
38
|
-
return;
|
|
39
|
-
el.style.transform = `translateY(${appr(dy)}px)`;
|
|
40
|
-
};
|
|
41
|
-
handleTouchEndRef.current = (endEvent) => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
const el = ref.current;
|
|
43
|
-
if (!el)
|
|
44
|
-
return;
|
|
45
|
-
el.style.transform = "translateY(0)";
|
|
46
|
-
el.style.transition = "transform 0.2s";
|
|
47
|
-
const y = endEvent.changedTouches[0].clientY;
|
|
48
|
-
const dy = y - initialY;
|
|
49
|
-
if (dy > TRIGGER_THRESHOLD &&
|
|
50
|
-
document.documentElement.scrollTop <= 20) {
|
|
51
|
-
setLoading(true);
|
|
52
|
-
const delay = new Promise((resolve) => setTimeout(resolve, 500)); // Wait for half a second to show the loading spinner
|
|
53
|
-
yield Promise.all([onTrigger(), delay]);
|
|
54
|
-
setLoading(false);
|
|
55
|
-
}
|
|
56
|
-
el.addEventListener("transitionend", onTransitionEndRef.current);
|
|
57
|
-
el.removeEventListener("touchmove", handleTouchMoveRef.current);
|
|
58
|
-
el.removeEventListener("touchend", handleTouchEndRef.current);
|
|
59
|
-
});
|
|
60
|
-
el.addEventListener("touchmove", handleTouchMoveRef.current);
|
|
61
|
-
el.addEventListener("touchend", handleTouchEndRef.current);
|
|
62
|
-
}, [appr, onTrigger, ref]);
|
|
63
|
-
const onTransitionEnd = useCallback(() => {
|
|
64
|
-
const el = ref.current;
|
|
65
|
-
if (!el)
|
|
66
|
-
return;
|
|
67
|
-
el.style.transition = "";
|
|
68
|
-
el.removeEventListener("transitionend", onTransitionEndRef.current);
|
|
69
|
-
}, [ref]);
|
|
70
|
-
handleTouchStartRef.current = handleTouchStart;
|
|
71
|
-
onTransitionEndRef.current = onTransitionEnd;
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
const el = ref.current;
|
|
74
|
-
if (!el)
|
|
75
|
-
return;
|
|
76
|
-
el.addEventListener("touchstart", handleTouchStartRef.current);
|
|
77
|
-
return () => {
|
|
78
|
-
el.removeEventListener("touchstart", handleTouchStartRef.current);
|
|
79
|
-
};
|
|
80
|
-
}, [ref]);
|
|
81
|
-
return loading;
|
|
82
|
-
}
|
|
83
|
-
const PullToRefresh = ({ onRefresh, children, }) => {
|
|
84
|
-
const ref = useRef(null);
|
|
85
|
-
const loading = usePullToRefresh(ref, onRefresh);
|
|
86
|
-
return (_jsxs("div", Object.assign({ ref: ref, className: "relative" }, { children: [loading && (_jsx("div", Object.assign({ className: "flex w-full justify-center my-4 h-10" }, { children: _jsx(Icon, { name: "loader", className: "animate-spin" }) }))), children] })));
|
|
87
|
-
};
|
|
88
|
-
export { usePullToRefresh, PullToRefresh };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { type VariantProps } from "class-variance-authority";
|
|
3
|
-
declare const favoriteVariants: (props?: ({
|
|
4
|
-
size?: "small" | "large" | null | undefined;
|
|
5
|
-
showBackground?: boolean | null | undefined;
|
|
6
|
-
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
|
7
|
-
export interface FavoriteProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof favoriteVariants> {
|
|
8
|
-
selected?: boolean;
|
|
9
|
-
onClick?: (event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
10
|
-
icon?: string;
|
|
11
|
-
showBackground?: boolean;
|
|
12
|
-
isAnimated?: boolean;
|
|
13
|
-
}
|
|
14
|
-
declare const Favorite: React.ForwardRefExoticComponent<FavoriteProps & React.RefAttributes<HTMLButtonElement>>;
|
|
15
|
-
export { Favorite, favoriteVariants };
|
|
16
|
-
//# sourceMappingURL=favorite.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"favorite.d.ts","sourceRoot":"","sources":["../../../../components/ui/favorite/favorite.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAKjE,QAAA,MAAM,gBAAgB;;;mFAkBrB,CAAA;AAED,MAAM,WAAW,aACf,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EACnD,YAAY,CAAC,OAAO,gBAAgB,CAAC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAA;IAC9D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AA+ND,QAAA,MAAM,QAAQ,yFAiCb,CAAA;AAGD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAA"}
|