@tapcart/mobile-components 0.8.64 → 0.8.66
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-order-details.d.ts.map +1 -1
- package/dist/components/hooks/use-order-details.js +27 -17
- package/dist/components/hooks/use-products.d.ts.map +1 -1
- package/dist/components/hooks/use-products.js +16 -9
- package/dist/components/hooks/use-recommendations.d.ts +4 -2
- package/dist/components/hooks/use-recommendations.d.ts.map +1 -1
- package/dist/components/hooks/use-recommendations.js +37 -8
- package/dist/components/ui/icon.d.ts.map +1 -1
- package/dist/components/ui/icon.js +1 -18
- package/dist/components/ui/star-rating.d.ts +1 -0
- package/dist/components/ui/star-rating.d.ts.map +1 -1
- package/dist/components/ui/star-rating.js +12 -6
- package/dist/styles.css +0 -4
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-order-details.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-order-details.ts"],"names":[],"mappings":"AAKA,KAAK,oBAAoB,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,OAAO,CAAA;CACf,CAAA;AAED,KAAK,iBAAiB,GAAG;IACvB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAClC,CAAA;
|
|
1
|
+
{"version":3,"file":"use-order-details.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-order-details.ts"],"names":[],"mappings":"AAKA,KAAK,oBAAoB,GAAG;IAC1B,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,CAAC,EAAE,OAAO,CAAA;CACf,CAAA;AAED,KAAK,iBAAiB,GAAG;IACvB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAClC,CAAA;AA0LD,eAAO,MAAM,qBAAqB,UACzB,OAAO,MAAM,EAAE,GAAG,CAAC;kBACT,OAAO,MAAM,EAAE,GAAG,CAAC;kBAAgB,OAAO,MAAM,EAAE,GAAG,CAAC;CA+NxE,CAAA;AAED,wBAAgB,eAAe,CAAC,EAC9B,SAAS,EACT,MAAM,EACN,KAAK,EACL,QAAQ,EACR,OAAO,EACP,IAAY,GACb,EAAE,oBAAoB,GAAG,iBAAiB,CA4D1C"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useMemo, useState } from "react";
|
|
3
3
|
import { useProducts } from "./use-products";
|
|
4
|
-
const getProductIds = (lines) => lines
|
|
4
|
+
const getProductIds = (lines) => (lines !== null && lines !== void 0 ? lines : [])
|
|
5
|
+
.map((line) => line.productId)
|
|
6
|
+
.filter((id) => id && id !== "undefined");
|
|
5
7
|
const calculateCompareAtPrice = (variant) => {
|
|
6
8
|
var _a, _b, _c, _d;
|
|
7
9
|
return ({
|
|
@@ -72,8 +74,9 @@ const calculateCartPrice = (lines) => {
|
|
|
72
74
|
};
|
|
73
75
|
};
|
|
74
76
|
const updateOrderDetails = (orderDetails, products) => {
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
+
var _a;
|
|
78
|
+
const product = products === null || products === void 0 ? void 0 : products[0];
|
|
79
|
+
const variant = (_a = product === null || product === void 0 ? void 0 : product.variants) === null || _a === void 0 ? void 0 : _a[0];
|
|
77
80
|
const compareAtPrice = calculateCompareAtPrice(variant);
|
|
78
81
|
orderDetails.paymentMethods = createPaymentMethods();
|
|
79
82
|
orderDetails.cart = {
|
|
@@ -235,12 +238,16 @@ export const transformOrderDetails = (order) => {
|
|
|
235
238
|
currencyCode: currencyCode || order.currency || order.currencyCode || "USD",
|
|
236
239
|
});
|
|
237
240
|
// Transform checkout data (minimal for price/line updates)
|
|
238
|
-
const subtotal = order.
|
|
241
|
+
const subtotal = order.subtotal ||
|
|
242
|
+
order.subtotalAmount ||
|
|
243
|
+
order.subtotalPrice ||
|
|
244
|
+
order.currentSubtotalPrice;
|
|
239
245
|
const total = order.totalAmount || order.totalPrice || order.currentTotalPrice;
|
|
240
246
|
const taxes = order.taxAmount || order.totalTax || order.currentTotalTax;
|
|
241
247
|
const shipping = order.shippingAmount ||
|
|
242
248
|
order.totalShippingPrice ||
|
|
243
|
-
order.currentTotalShippingPrice
|
|
249
|
+
order.currentTotalShippingPrice ||
|
|
250
|
+
order.totalShipping;
|
|
244
251
|
const currencyCode = order.currency || order.currencyCode || "USD";
|
|
245
252
|
const checkoutData = {
|
|
246
253
|
shippingLine: {
|
|
@@ -256,20 +263,23 @@ export const transformOrderDetails = (order) => {
|
|
|
256
263
|
})),
|
|
257
264
|
subtotalPrice: wrapMoney(subtotal, currencyCode),
|
|
258
265
|
lineItems: (order.lineItems || []).map((lineItem) => {
|
|
259
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
266
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
|
|
260
267
|
const variant = lineItem.variant || {};
|
|
261
268
|
const product = variant.product || {};
|
|
262
269
|
const currencyCode = ((_a = lineItem.discountedTotalPrice) === null || _a === void 0 ? void 0 : _a.currencyCode) ||
|
|
263
270
|
((_b = lineItem.originalTotalPrice) === null || _b === void 0 ? void 0 : _b.currencyCode) ||
|
|
271
|
+
((_d = (_c = lineItem.price) === null || _c === void 0 ? void 0 : _c.amount) === null || _d === void 0 ? void 0 : _d.currencyCode) ||
|
|
264
272
|
order.currency ||
|
|
265
273
|
order.currencyCode ||
|
|
266
274
|
"USD";
|
|
267
275
|
// Calculate finalLinePrice with full-discount logic
|
|
268
|
-
let finalLinePriceAmount = parseAmount((
|
|
276
|
+
let finalLinePriceAmount = parseAmount(((_e = lineItem.discountedTotalPrice) === null || _e === void 0 ? void 0 : _e.amount) ||
|
|
277
|
+
((_f = lineItem.finalLinePrice) === null || _f === void 0 ? void 0 : _f.amount) ||
|
|
278
|
+
((_g = lineItem.price) === null || _g === void 0 ? void 0 : _g.amount));
|
|
269
279
|
if (Array.isArray(lineItem.discountAllocations) &&
|
|
270
280
|
lineItem.discountAllocations.length > 0) {
|
|
271
281
|
const totalDiscount = lineItem.discountAllocations.reduce((sum, discount) => { var _a; return sum + parseAmount((_a = discount.allocatedAmount) === null || _a === void 0 ? void 0 : _a.amount); }, 0);
|
|
272
|
-
const original = parseAmount((
|
|
282
|
+
const original = parseAmount((_h = lineItem.originalTotalPrice) === null || _h === void 0 ? void 0 : _h.amount);
|
|
273
283
|
if (totalDiscount >= original && original > 0) {
|
|
274
284
|
finalLinePriceAmount = 0;
|
|
275
285
|
}
|
|
@@ -283,17 +293,17 @@ export const transformOrderDetails = (order) => {
|
|
|
283
293
|
product: {
|
|
284
294
|
type: product.type || "",
|
|
285
295
|
vendor: product.vendor || lineItem.vendor || "Unknown",
|
|
286
|
-
id: ((
|
|
287
|
-
((
|
|
296
|
+
id: ((_j = product.id) === null || _j === void 0 ? void 0 : _j.split("/").pop()) ||
|
|
297
|
+
((_k = lineItem.productId) === null || _k === void 0 ? void 0 : _k.split("/").pop()),
|
|
288
298
|
untranslatedTitle: lineItem.title || product.title,
|
|
289
299
|
title: lineItem.title || product.title,
|
|
290
300
|
url: `/products/${product.handle || ""}`,
|
|
291
301
|
},
|
|
292
|
-
id: ((
|
|
293
|
-
((
|
|
294
|
-
price: wrapMoney(((
|
|
302
|
+
id: ((_l = variant.id) === null || _l === void 0 ? void 0 : _l.split("/").pop()) ||
|
|
303
|
+
((_m = lineItem.variantId) === null || _m === void 0 ? void 0 : _m.split("/").pop()),
|
|
304
|
+
price: wrapMoney(((_o = variant.price) === null || _o === void 0 ? void 0 : _o.amount) || ((_p = lineItem.price) === null || _p === void 0 ? void 0 : _p.amount), currencyCode),
|
|
295
305
|
image: {
|
|
296
|
-
src: ((
|
|
306
|
+
src: ((_q = variant.image) === null || _q === void 0 ? void 0 : _q.url) || ((_r = lineItem.image) === null || _r === void 0 ? void 0 : _r.url),
|
|
297
307
|
},
|
|
298
308
|
},
|
|
299
309
|
discountAllocations: (lineItem.discountAllocations || []).map((allocation) => {
|
|
@@ -305,7 +315,7 @@ export const transformOrderDetails = (order) => {
|
|
|
305
315
|
}),
|
|
306
316
|
quantity: lineItem.quantity || 1,
|
|
307
317
|
title: lineItem.title || product.title,
|
|
308
|
-
id: ((
|
|
318
|
+
id: ((_s = variant.id) === null || _s === void 0 ? void 0 : _s.split("/").pop()) || ((_t = lineItem.variantId) === null || _t === void 0 ? void 0 : _t.split("/").pop()),
|
|
309
319
|
};
|
|
310
320
|
}),
|
|
311
321
|
totalPrice: wrapMoney(total, currencyCode),
|
|
@@ -329,9 +339,9 @@ export function useOrderDetails({ variables, apiUrl, appId, language, country, m
|
|
|
329
339
|
});
|
|
330
340
|
useEffect(() => {
|
|
331
341
|
var _a, _b;
|
|
332
|
-
if (
|
|
342
|
+
if ((orderVariables === null || orderVariables === void 0 ? void 0 : orderVariables.orderDetails) && (orderVariables === null || orderVariables === void 0 ? void 0 : orderVariables.checkoutData)) {
|
|
333
343
|
const updatedOrderDetails = Object.assign({}, orderVariables === null || orderVariables === void 0 ? void 0 : orderVariables.orderDetails);
|
|
334
|
-
if (mock) {
|
|
344
|
+
if (mock && products.length > 0) {
|
|
335
345
|
updateOrderDetails(updatedOrderDetails, products);
|
|
336
346
|
}
|
|
337
347
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-products.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-products.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO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 : props.productIds,
|
|
40
40
|
productHandles: props === null || props === void 0 ? void 0 : props.productHandles,
|
|
41
41
|
}));
|
|
42
|
+
const [isProductResponseReady, setIsProductResponseReady] = React.useState((productResponse === null || productResponse === void 0 ? void 0 : productResponse.length) > 0);
|
|
42
43
|
if (isUseProductsProps(props)) {
|
|
43
44
|
let { baseURL, productIds, variantIds, productHandles, metafields, collection, queryVariables, } = props;
|
|
44
45
|
if (shouldMockProducts) {
|
|
@@ -109,23 +110,29 @@ export function useProducts(props) {
|
|
|
109
110
|
const cachedProduct = productsLocalStorage.setCacheItem(product);
|
|
110
111
|
return cachedProduct;
|
|
111
112
|
};
|
|
112
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Sync local state with incoming swr response data.
|
|
115
|
+
* If the response contains a `products` envelope, it will be extracted.
|
|
116
|
+
*/
|
|
113
117
|
React.useEffect(() => {
|
|
114
|
-
if (
|
|
118
|
+
if (isLoading) {
|
|
115
119
|
return;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
}
|
|
121
|
+
if (data) {
|
|
122
|
+
const productsArray = Array.isArray(data) ? data : data.products || [];
|
|
123
|
+
if (productsArray.length > 0) {
|
|
124
|
+
setProductResponse(productsArray);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
setIsProductResponseReady(true);
|
|
128
|
+
}, [isLoading, data]);
|
|
122
129
|
return {
|
|
123
130
|
products: formatProductData({
|
|
124
131
|
data: productResponse,
|
|
125
132
|
onlyAvailableProducts: (props === null || props === void 0 ? void 0 : props.mock) && (props === null || props === void 0 ? void 0 : props.onlyAvailableProducts),
|
|
126
133
|
}),
|
|
127
134
|
error,
|
|
128
|
-
isLoading: !
|
|
135
|
+
isLoading: !isProductResponseReady,
|
|
129
136
|
isRefreshing: isLoading,
|
|
130
137
|
cacheProduct,
|
|
131
138
|
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Collection, Product } from "app-studio-types";
|
|
1
|
+
import { Collection, Product, BaseSearchClient } from "app-studio-types";
|
|
2
2
|
interface UseRecommendationProps {
|
|
3
|
+
searchClient?: BaseSearchClient<Product>;
|
|
4
|
+
query?: string;
|
|
3
5
|
queryVariables: Record<string, any>;
|
|
4
6
|
apiURL: string;
|
|
5
7
|
}
|
|
@@ -10,6 +12,6 @@ interface UseRecommendationReturn {
|
|
|
10
12
|
isLoading: boolean;
|
|
11
13
|
error: any;
|
|
12
14
|
}
|
|
13
|
-
declare const useRecommendations: ({ queryVariables, apiURL, }: UseRecommendationProps) => UseRecommendationReturn;
|
|
15
|
+
declare const useRecommendations: ({ searchClient, query, queryVariables, apiURL, }: UseRecommendationProps) => UseRecommendationReturn;
|
|
14
16
|
export { useRecommendations };
|
|
15
17
|
//# sourceMappingURL=use-recommendations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-recommendations.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-recommendations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"use-recommendations.d.ts","sourceRoot":"","sources":["../../../components/hooks/use-recommendations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAOxE,UAAU,sBAAsB;IAE9B,YAAY,CAAC,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAA;IACxC,KAAK,CAAC,EAAE,MAAM,CAAA;IAGd,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACnC,MAAM,EAAE,MAAM,CAAA;CACf;AASD,UAAU,uBAAuB;IAC/B,QAAQ,EAAE,OAAO,EAAE,CAAA;IACnB,WAAW,EAAE,UAAU,EAAE,CAAA;IACzB,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,SAAS,EAAE,OAAO,CAAA;IAClB,KAAK,EAAE,GAAG,CAAA;CACX;AAiBD,QAAA,MAAM,kBAAkB,qDAQrB,sBAAsB,KAAG,uBA6F3B,CAAA;AAED,OAAO,EAAE,kBAAkB,EAAE,CAAA"}
|
|
@@ -22,13 +22,33 @@ const getCollections = (collections) => {
|
|
|
22
22
|
: [];
|
|
23
23
|
};
|
|
24
24
|
const recommendationsLocalStorage = new RecommendationsLocalStorage();
|
|
25
|
-
const useRecommendations = ({
|
|
25
|
+
const useRecommendations = ({
|
|
26
|
+
// Search client props
|
|
27
|
+
searchClient, query = "",
|
|
28
|
+
// API props (backwards compatibility)
|
|
29
|
+
queryVariables, apiURL, }) => {
|
|
30
|
+
// When searchClient is provided, use search client approach
|
|
31
|
+
const usingSearchClient = Boolean(searchClient);
|
|
26
32
|
const searchParams = useSearchParams();
|
|
27
|
-
const recommendation =
|
|
33
|
+
const recommendation = usingSearchClient
|
|
34
|
+
? query
|
|
35
|
+
: (searchParams === null || searchParams === void 0 ? void 0 : searchParams.get("recommendation")) || "";
|
|
28
36
|
const [cachedRecommendation, setCachedRecommendations] = React.useState(recommendationsLocalStorage.getCacheItem({
|
|
29
37
|
id: `${recommendation}-${queryVariables === null || queryVariables === void 0 ? void 0 : queryVariables.language}`,
|
|
30
38
|
}));
|
|
31
|
-
|
|
39
|
+
// Search client fetcher
|
|
40
|
+
const searchClientFetcher = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
if (!searchClient)
|
|
42
|
+
return null;
|
|
43
|
+
// Call searchClient.getRecommendations (returns string[] directly)
|
|
44
|
+
const recommendations = yield searchClient.getRecommendations({
|
|
45
|
+
query: recommendation,
|
|
46
|
+
});
|
|
47
|
+
// Format as expected by the hook
|
|
48
|
+
return Object.assign(Object.assign({}, recommendations), { collections: [] });
|
|
49
|
+
});
|
|
50
|
+
// API fetcher (backwards compatibility)
|
|
51
|
+
const apiFetcher = (body) => fetch(constructURL(apiURL), {
|
|
32
52
|
method: "POST",
|
|
33
53
|
body: JSON.stringify(body),
|
|
34
54
|
}).then((res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -38,11 +58,20 @@ const useRecommendations = ({ queryVariables, apiURL, }) => {
|
|
|
38
58
|
}
|
|
39
59
|
return data;
|
|
40
60
|
}));
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
61
|
+
// Determine which approach to use
|
|
62
|
+
const swrKey = usingSearchClient
|
|
63
|
+
? {
|
|
64
|
+
type: "searchClient",
|
|
65
|
+
query: recommendation,
|
|
66
|
+
language: queryVariables === null || queryVariables === void 0 ? void 0 : queryVariables.language,
|
|
67
|
+
}
|
|
68
|
+
: {
|
|
69
|
+
appId: queryVariables.appId,
|
|
70
|
+
query: recommendation,
|
|
71
|
+
language: queryVariables.language,
|
|
72
|
+
};
|
|
73
|
+
const fetcher = usingSearchClient ? searchClientFetcher : apiFetcher;
|
|
74
|
+
const { data, error, isLoading } = useSWR(swrKey, usingSearchClient ? fetcher : (body) => apiFetcher(body), {
|
|
46
75
|
revalidateOnFocus: false,
|
|
47
76
|
revalidateOnReconnect: false,
|
|
48
77
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icon.d.ts","sourceRoot":"","sources":["../../../components/ui/icon.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAEL,eAAe,EAyChB,MAAM,qBAAqB,CAAA;AAI5B,QAAA,MAAM,YAAY;;;mFAiBjB,CAAA;AA+DD,MAAM,WAAW,SACf,SAAQ,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,EACzD,YAAY,CAAC,OAAO,YAAY,CAAC;IACnC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,GAAG,CAAC,EAAE,MAAM,GAAG,I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cAAc,EACd,GAAG,KAAK,EACT,EAAE,SAAS,2CA+BX;AAED,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,eAAe,EAAE,CAAA"}
|
|
@@ -116,6 +116,7 @@ const CustomIcon = ({ url, size, color, strokeColor, strokeWidth, fillColor, fil
|
|
|
116
116
|
if (path.hasAttribute("stroke")) {
|
|
117
117
|
path.setAttribute("stroke-width", strokeWidthMapping[size].toString());
|
|
118
118
|
}
|
|
119
|
+
// Override stroke width if one is provided
|
|
119
120
|
if (strokeWidth != null && path.hasAttribute("stroke")) {
|
|
120
121
|
path.setAttribute("stroke-width", strokeWidth.toString());
|
|
121
122
|
}
|
|
@@ -124,7 +125,6 @@ const CustomIcon = ({ url, size, color, strokeColor, strokeWidth, fillColor, fil
|
|
|
124
125
|
const percentage = Math.min(Math.max(fillPercentage, 0), 1);
|
|
125
126
|
const uniqueId = crypto.randomUUID();
|
|
126
127
|
const fillGradientId = `fill-gradient-${uniqueId}`;
|
|
127
|
-
const strokeGradientId = `stroke-gradient-${uniqueId}`;
|
|
128
128
|
let defs = svg.querySelector("defs");
|
|
129
129
|
if (!defs) {
|
|
130
130
|
defs = document.createElementNS("http://www.w3.org/2000/svg", "defs");
|
|
@@ -145,24 +145,7 @@ const CustomIcon = ({ url, size, color, strokeColor, strokeWidth, fillColor, fil
|
|
|
145
145
|
fillStop2.setAttribute("stop-color", secondaryFillColor || "transparent");
|
|
146
146
|
fillGradient.appendChild(fillStop2);
|
|
147
147
|
defs.appendChild(fillGradient);
|
|
148
|
-
const strokeGradient = document.createElementNS("http://www.w3.org/2000/svg", "linearGradient");
|
|
149
|
-
strokeGradient.setAttribute("id", strokeGradientId);
|
|
150
|
-
strokeGradient.setAttribute("x1", "0%");
|
|
151
|
-
strokeGradient.setAttribute("y1", "0%");
|
|
152
|
-
strokeGradient.setAttribute("x2", "100%");
|
|
153
|
-
strokeGradient.setAttribute("y2", "0%");
|
|
154
|
-
const strokeStop1 = document.createElementNS("http://www.w3.org/2000/svg", "stop");
|
|
155
|
-
strokeStop1.setAttribute("offset", `${percentage * 100}%`);
|
|
156
|
-
strokeStop1.setAttribute("stop-color", color || strokeColor || fillColor || "currentColor");
|
|
157
|
-
strokeGradient.appendChild(strokeStop1);
|
|
158
|
-
const strokeStop2 = document.createElementNS("http://www.w3.org/2000/svg", "stop");
|
|
159
|
-
strokeStop2.setAttribute("offset", `${percentage * 100}%`);
|
|
160
|
-
strokeStop2.setAttribute("stop-color", secondaryFillColor || "currentColor");
|
|
161
|
-
strokeGradient.appendChild(strokeStop2);
|
|
162
|
-
defs.appendChild(strokeGradient);
|
|
163
148
|
path.setAttribute("fill", `url(#${fillGradientId})`);
|
|
164
|
-
path.setAttribute("stroke", `url(#${strokeGradientId})`);
|
|
165
|
-
path.setAttribute("stroke-width", strokeWidthMapping[size].toString());
|
|
166
149
|
}
|
|
167
150
|
});
|
|
168
151
|
} }));
|
|
@@ -6,6 +6,7 @@ export interface StarRatingProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
|
6
6
|
filledColor?: string;
|
|
7
7
|
emptyColor?: string;
|
|
8
8
|
designOptions?: "condensed" | "expanded";
|
|
9
|
+
strokeOnEmpty?: boolean;
|
|
9
10
|
}
|
|
10
11
|
declare const StarRating: React.ForwardRefExoticComponent<StarRatingProps & React.RefAttributes<HTMLDivElement>>;
|
|
11
12
|
export { StarRating };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"star-rating.d.ts","sourceRoot":"","sources":["../../../components/ui/star-rating.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,MAAM,WAAW,eAAgB,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IAC3E,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;IACpC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,WAAW,GAAG,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"star-rating.d.ts","sourceRoot":"","sources":["../../../components/ui/star-rating.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,MAAM,WAAW,eAAgB,SAAQ,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC;IAC3E,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;IACpC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,WAAW,GAAG,UAAU,CAAA;IACxC,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,QAAA,MAAM,UAAU,wFAuHf,CAAA;AAID,OAAO,EAAE,UAAU,EAAE,CAAA"}
|
|
@@ -16,37 +16,43 @@ import { Icon } from "./icon";
|
|
|
16
16
|
const StarRating = React.forwardRef((_a, ref) => {
|
|
17
17
|
var { className, score, iconSize = "sm", iconUrl, filledColor = "#facc15", // default to yellow-400
|
|
18
18
|
emptyColor = "#e5e7eb", // default to gray-200
|
|
19
|
-
designOptions } = _a, props = __rest(_a, ["className", "score", "iconSize", "iconUrl", "filledColor", "emptyColor", "designOptions"]);
|
|
19
|
+
designOptions, strokeOnEmpty = false } = _a, props = __rest(_a, ["className", "score", "iconSize", "iconUrl", "filledColor", "emptyColor", "designOptions", "strokeOnEmpty"]);
|
|
20
20
|
const getIconProps = (isFilled) => {
|
|
21
21
|
if (iconUrl) {
|
|
22
22
|
return { url: iconUrl };
|
|
23
23
|
}
|
|
24
24
|
return { name: isFilled ? "star-filled" : "star" };
|
|
25
25
|
};
|
|
26
|
+
const strokeStyle = strokeOnEmpty
|
|
27
|
+
? {
|
|
28
|
+
strokeColor: filledColor,
|
|
29
|
+
strokeWidth: 2,
|
|
30
|
+
}
|
|
31
|
+
: {};
|
|
26
32
|
if (designOptions === "condensed") {
|
|
27
|
-
return (_jsx(Icon, Object.assign({ size: iconSize }, getIconProps(score > 0), {
|
|
33
|
+
return (_jsx(Icon, Object.assign({ size: iconSize }, getIconProps(score > 0), { fillColor: score > 0 ? filledColor : emptyColor }, strokeStyle)));
|
|
28
34
|
}
|
|
29
35
|
return (_jsx("div", Object.assign({ className: cn("flex flex-row gap-1", className), ref: ref }, props, { children: Array.from({ length: 5 }).map((_, index) => {
|
|
30
36
|
const starNumber = index + 1;
|
|
31
37
|
if (score >= starNumber) {
|
|
32
38
|
// Fully filled star
|
|
33
|
-
return (_jsx(Icon, Object.assign({ size: iconSize }, getIconProps(true), {
|
|
39
|
+
return (_jsx(Icon, Object.assign({ size: iconSize }, getIconProps(true), { fillColor: filledColor }, strokeStyle), index));
|
|
34
40
|
}
|
|
35
41
|
else if (score > index && score < starNumber) {
|
|
36
42
|
// Partial star - create overlay effect
|
|
37
43
|
const fillPercentage = score - index;
|
|
38
44
|
if (iconUrl) {
|
|
39
45
|
// Use fillPercentage for custom icons
|
|
40
|
-
return (_jsx(Icon, { size: iconSize, url: iconUrl, fillColor: filledColor, secondaryFillColor: emptyColor, fillPercentage: fillPercentage }, index));
|
|
46
|
+
return (_jsx(Icon, Object.assign({ size: iconSize, url: iconUrl, fillColor: filledColor, secondaryFillColor: emptyColor, fillPercentage: fillPercentage }, strokeStyle), index));
|
|
41
47
|
}
|
|
42
48
|
else {
|
|
43
49
|
// For Tabler icons, create overlay effect
|
|
44
|
-
return (_jsxs("div", Object.assign({ className: "relative" }, { children: [_jsx(Icon, { size: iconSize, name: "star",
|
|
50
|
+
return (_jsxs("div", Object.assign({ className: "relative" }, { children: [_jsx(Icon, Object.assign({ size: iconSize, name: "star", fillColor: emptyColor }, strokeStyle)), _jsx("div", Object.assign({ className: "absolute inset-0 overflow-hidden", style: { width: `${fillPercentage * 100}%` } }, { children: _jsx(Icon, Object.assign({ size: iconSize, name: "star-filled", fillColor: filledColor }, strokeStyle)) }))] }), index));
|
|
45
51
|
}
|
|
46
52
|
}
|
|
47
53
|
else {
|
|
48
54
|
// Empty star
|
|
49
|
-
return (_jsx(Icon, Object.assign({ size: iconSize }, getIconProps(false), {
|
|
55
|
+
return (_jsx(Icon, Object.assign({ size: iconSize }, getIconProps(false), { fillColor: emptyColor }, strokeStyle), index));
|
|
50
56
|
}
|
|
51
57
|
}) })));
|
|
52
58
|
});
|
package/dist/styles.css
CHANGED
|
@@ -2630,10 +2630,6 @@ body::-webkit-scrollbar {
|
|
|
2630
2630
|
background-color: rgb(243 244 246 / var(--tw-bg-opacity, 1));
|
|
2631
2631
|
}
|
|
2632
2632
|
|
|
2633
|
-
.hover\:no-underline:hover {
|
|
2634
|
-
text-decoration-line: none;
|
|
2635
|
-
}
|
|
2636
|
-
|
|
2637
2633
|
.hover\:opacity-90:hover {
|
|
2638
2634
|
opacity: 0.9;
|
|
2639
2635
|
}
|