@tapcart/mobile-components 0.7.0 → 0.7.2
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-infinite-scroll.d.ts +3 -1
- package/dist/components/hooks/use-infinite-scroll.d.ts.map +1 -1
- package/dist/components/hooks/use-infinite-scroll.js +34 -11
- package/dist/components/hooks/use-nosto-recommendation.d.ts +8 -0
- package/dist/components/hooks/use-nosto-recommendation.d.ts.map +1 -0
- package/dist/components/hooks/use-nosto-recommendation.js +105 -0
- package/dist/components/hooks/use-products.d.ts +3 -1
- package/dist/components/hooks/use-products.d.ts.map +1 -1
- package/dist/components/hooks/use-products.js +21 -6
- package/dist/components/hooks/use-reviews.d.ts +27 -0
- package/dist/components/hooks/use-reviews.d.ts.map +1 -0
- package/dist/components/hooks/use-reviews.js +130 -0
- package/dist/components/templates/ProductCard/utils.d.ts +78 -0
- package/dist/components/templates/ProductCard/utils.d.ts.map +1 -0
- package/dist/components/templates/ProductCard/utils.js +128 -0
- package/dist/components/templates/ProductGrid/index.d.ts +1 -0
- package/dist/components/templates/ProductGrid/index.d.ts.map +1 -0
- package/dist/components/templates/ProductGrid/index.js +1 -0
- package/dist/components/ui/Input/input.d.ts +1 -1
- package/dist/components/ui/Input/input.d.ts.map +1 -1
- package/dist/components/ui/Input/input.js +23 -5
- package/dist/components/ui/Input/types.d.ts +3 -2
- package/dist/components/ui/Input/types.d.ts.map +1 -1
- package/dist/components/ui/Input/useInput.d.ts +2 -2
- package/dist/components/ui/Input/useInput.d.ts.map +1 -1
- package/dist/components/ui/Input/useInput.js +24 -10
- package/dist/components/ui/ProductCard/utils.d.ts +94 -0
- package/dist/components/ui/ProductCard/utils.d.ts.map +1 -0
- package/dist/components/ui/ProductCard/utils.js +148 -0
- package/dist/components/ui/ProductGrid/index.d.ts +1 -0
- package/dist/components/ui/ProductGrid/index.d.ts.map +1 -0
- package/dist/components/ui/ProductGrid/index.js +1 -0
- package/dist/components/ui/accordion.d.ts +3 -1
- package/dist/components/ui/accordion.d.ts.map +1 -1
- package/dist/components/ui/accordion.js +2 -2
- package/dist/components/ui/button.d.ts +2 -2
- package/dist/components/ui/button.d.ts.map +1 -1
- package/dist/components/ui/button.js +1 -1
- package/dist/components/ui/carousel.d.ts +1 -0
- package/dist/components/ui/carousel.d.ts.map +1 -1
- package/dist/components/ui/carousel.js +62 -2
- package/dist/components/ui/chip.d.ts +2 -2
- package/dist/components/ui/icon.d.ts +4 -1
- package/dist/components/ui/icon.d.ts.map +1 -1
- package/dist/components/ui/icon.js +35 -8
- package/dist/components/ui/image.d.ts.map +1 -1
- package/dist/components/ui/image.js +3 -3
- package/dist/components/ui/radio-group.d.ts +2 -2
- package/dist/components/ui/scroll-area.d.ts +1 -0
- package/dist/components/ui/scroll-area.d.ts.map +1 -1
- package/dist/components/ui/scroll-area.js +2 -2
- package/dist/components/ui/toast.d.ts +2 -2
- package/dist/components/ui/toggle-group.d.ts +2 -2
- package/dist/components/ui/toggle.d.ts +2 -2
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/lib/price.d.ts +29 -0
- package/dist/lib/price.d.ts.map +1 -0
- package/dist/lib/price.js +66 -0
- package/dist/lib/utils.d.ts +18 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +44 -1
- package/dist/styles.css +201 -727
- package/dist/tapcart-mobile-components.umd.js +44 -0
- package/package.json +4 -3
- package/dist/components/templates/product-card.d.ts +0 -33
- package/dist/components/templates/product-card.d.ts.map +0 -1
- package/dist/components/templates/product-card.js +0 -42
- package/dist/components/templates/product-grid.d.ts +0 -14
- package/dist/components/templates/product-grid.d.ts.map +0 -1
- package/dist/components/templates/product-grid.js +0 -22
- package/dist/components/ui/input.d.ts +0 -17
- package/dist/components/ui/input.d.ts.map +0 -1
- package/dist/components/ui/input.js +0 -35
- package/dist/components/ui/product-grid.d.ts +0 -15
- package/dist/components/ui/product-grid.d.ts.map +0 -1
- package/dist/components/ui/product-grid.js +0 -22
- package/dist/components/ui/select.d.ts +0 -14
- package/dist/components/ui/select.d.ts.map +0 -1
- package/dist/components/ui/select.js +0 -59
package/dist/lib/utils.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { clsx } from "clsx";
|
|
2
2
|
import { twMerge } from "tailwind-merge";
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
3
5
|
export function cn(...inputs) {
|
|
4
6
|
return twMerge(clsx(inputs));
|
|
5
7
|
}
|
|
@@ -147,6 +149,28 @@ export function variantGidFromId(id) {
|
|
|
147
149
|
return id;
|
|
148
150
|
return `gid://shopify/ProductVariant/${id}`;
|
|
149
151
|
}
|
|
152
|
+
// Use to prevent multiple clicks in quick succession
|
|
153
|
+
export function throttle(fn, wait) {
|
|
154
|
+
let throttle = false;
|
|
155
|
+
return [
|
|
156
|
+
function () {
|
|
157
|
+
return throttle;
|
|
158
|
+
},
|
|
159
|
+
function (...args) {
|
|
160
|
+
if (!throttle) {
|
|
161
|
+
fn(...args);
|
|
162
|
+
throttle = true;
|
|
163
|
+
setInterval(() => {
|
|
164
|
+
throttle = false;
|
|
165
|
+
}, wait);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
];
|
|
169
|
+
}
|
|
170
|
+
export function formatRelativeTime(inputDate) {
|
|
171
|
+
dayjs.extend(relativeTime);
|
|
172
|
+
return dayjs(inputDate).fromNow();
|
|
173
|
+
}
|
|
150
174
|
export const stringRatioToInt = (string) => {
|
|
151
175
|
const [numerator, denominator] = string
|
|
152
176
|
.replace(":", "/")
|
|
@@ -166,4 +190,23 @@ export const getOverlayStyle = (opacity) => {
|
|
|
166
190
|
backgroundColor: `rgba(0, 0, 0, ${opacityDecimal})`,
|
|
167
191
|
};
|
|
168
192
|
};
|
|
169
|
-
|
|
193
|
+
const DESTINATION_HANDLERS = {
|
|
194
|
+
"app-screen": (location, actions) => actions.openScreen({ destination: { type: "internal", url: location } }),
|
|
195
|
+
url: (location, actions) => actions.openScreen({
|
|
196
|
+
destination: { type: "web", url: `https://${location}` },
|
|
197
|
+
}),
|
|
198
|
+
product: (location, actions) => actions.openProduct({ productId: location }),
|
|
199
|
+
collection: (location, actions) => actions.openCollection({ collectionId: location }),
|
|
200
|
+
none: () => { },
|
|
201
|
+
};
|
|
202
|
+
export const getDestinationHandler = (type) => {
|
|
203
|
+
return DESTINATION_HANDLERS[type];
|
|
204
|
+
};
|
|
205
|
+
export function getProductGidsFromIds(ids) {
|
|
206
|
+
return ids.map((id) => {
|
|
207
|
+
if (id.startsWith("gid://shopify/Product/")) {
|
|
208
|
+
return id;
|
|
209
|
+
}
|
|
210
|
+
return `gid://shopify/Product/${id}`;
|
|
211
|
+
});
|
|
212
|
+
}
|