@shopify/shop-minis-react 0.0.18 → 0.0.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/_virtual/index2.js +2 -3
- package/dist/_virtual/index2.js.map +1 -1
- package/dist/_virtual/index3.js +3 -2
- package/dist/_virtual/index3.js.map +1 -1
- package/dist/components/atoms/alert-dialog.js +41 -0
- package/dist/components/atoms/alert-dialog.js.map +1 -0
- package/dist/components/atoms/thumbhash-image.js +54 -0
- package/dist/components/atoms/thumbhash-image.js.map +1 -0
- package/dist/components/commerce/merchant-card-skeleton.js +29 -0
- package/dist/components/commerce/merchant-card-skeleton.js.map +1 -0
- package/dist/components/commerce/merchant-card.js +28 -22
- package/dist/components/commerce/merchant-card.js.map +1 -1
- package/dist/components/commerce/product-card-skeleton.js +20 -0
- package/dist/components/commerce/product-card-skeleton.js.map +1 -0
- package/dist/components/commerce/product-card.js +105 -78
- package/dist/components/commerce/product-card.js.map +1 -1
- package/dist/components/navigation/transition-container.js +8 -0
- package/dist/components/navigation/transition-container.js.map +1 -0
- package/dist/components/navigation/transition-link.js +27 -0
- package/dist/components/navigation/transition-link.js.map +1 -0
- package/dist/components/ui/skeleton.js +16 -0
- package/dist/components/ui/skeleton.js.map +1 -0
- package/dist/hooks/navigation/useNavigateWithTransition.js +43 -0
- package/dist/hooks/navigation/useNavigateWithTransition.js.map +1 -0
- package/dist/hooks/navigation/useViewTransitions.js +45 -0
- package/dist/hooks/navigation/useViewTransitions.js.map +1 -0
- package/dist/index.js +215 -196
- package/dist/index.js.map +1 -1
- package/dist/shop-minis-react/node_modules/.pnpm/@radix-ui_react-use-is-hydrated@0.1.0_@types_react@19.1.6_react@19.1.0/node_modules/@radix-ui/react-use-is-hydrated/dist/index.js +1 -1
- package/dist/shop-minis-react/node_modules/.pnpm/js-base64@3.7.7/node_modules/js-base64/base64.js +21 -0
- package/dist/shop-minis-react/node_modules/.pnpm/js-base64@3.7.7/node_modules/js-base64/base64.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/querystringify@2.2.0/node_modules/querystringify/index.js +1 -1
- package/dist/shop-minis-react/node_modules/.pnpm/react-router@7.7.0_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-router/dist/development/chunk-EF7DTUVF.js +1298 -0
- package/dist/shop-minis-react/node_modules/.pnpm/react-router@7.7.0_react-dom@19.1.0_react@19.1.0__react@19.1.0/node_modules/react-router/dist/development/chunk-EF7DTUVF.js.map +1 -0
- package/dist/shop-minis-react/node_modules/.pnpm/thumbhash@0.1.1/node_modules/thumbhash/thumbhash.js +145 -0
- package/dist/shop-minis-react/node_modules/.pnpm/thumbhash@0.1.1/node_modules/thumbhash/thumbhash.js.map +1 -0
- package/dist/types/index.js +10 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/image.js +15 -0
- package/dist/utils/image.js.map +1 -0
- package/package.json +13 -3
- package/src/components/atoms/alert-dialog.tsx +67 -0
- package/src/components/atoms/thumbhash-image.tsx +66 -0
- package/src/components/commerce/merchant-card-skeleton.tsx +31 -0
- package/src/components/commerce/merchant-card.tsx +5 -2
- package/src/components/commerce/product-card-skeleton.tsx +30 -0
- package/src/components/commerce/product-card.tsx +49 -8
- package/src/components/index.ts +8 -0
- package/src/components/navigation/transition-container.tsx +7 -0
- package/src/components/navigation/transition-link.tsx +48 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/navigation/useNavigateWithTransition.ts +62 -0
- package/src/hooks/navigation/useViewTransitions.ts +79 -0
- package/src/index.css +1 -0
- package/src/mocks.ts +8 -2
- package/src/stories/Accordion.stories.tsx +124 -0
- package/src/stories/Alert.stories.tsx +38 -0
- package/src/stories/AlertDialog.stories.tsx +48 -0
- package/src/stories/Avatar.stories.tsx +29 -0
- package/src/stories/Badge.stories.tsx +46 -0
- package/src/stories/Button.stories.tsx +81 -0
- package/src/stories/Card.stories.tsx +40 -0
- package/src/stories/Checkbox.stories.tsx +44 -0
- package/src/stories/FavoriteButton.stories.tsx +58 -0
- package/src/stories/IconButton.stories.tsx +68 -0
- package/src/stories/Input.stories.tsx +44 -0
- package/src/stories/Label.stories.tsx +19 -0
- package/src/stories/MerchantCard.stories.tsx +55 -0
- package/src/stories/ProductCard.stories.tsx +85 -0
- package/src/stories/ProductLink.stories.tsx +46 -0
- package/src/stories/Progress.stories.tsx +30 -0
- package/src/stories/RadioGroup.stories.tsx +51 -0
- package/src/stories/Select.stories.tsx +85 -0
- package/src/stories/Skeleton.stories.tsx +19 -0
- package/src/stories/Toaster.stories.tsx +46 -0
- package/src/stories/Touchable.stories.tsx +40 -0
- package/src/styles/animations.css +90 -0
- package/src/styles/globals.css +8 -0
- package/src/styles/theme.css +1 -1
- package/src/types/index.ts +7 -1
- package/src/utils/image.ts +18 -0
package/dist/shop-minis-react/node_modules/.pnpm/thumbhash@0.1.1/node_modules/thumbhash/thumbhash.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
function W(t) {
|
|
2
|
+
let { PI: r, min: p, max: l, cos: u, round: c } = Math, _ = t[0] | t[1] << 8 | t[2] << 16, n = t[3] | t[4] << 8, s = (_ & 63) / 63, y = (_ >> 6 & 63) / 31.5 - 1, i = (_ >> 12 & 63) / 31.5 - 1, a = (_ >> 18 & 31) / 31, o = _ >> 23, v = (n >> 3 & 63) / 63, z = (n >> 9 & 63) / 63, G = n >> 15, B = l(3, G ? o ? 5 : 7 : n & 7), A = l(3, G ? n & 7 : o ? 5 : 7), E = o ? (t[5] & 15) / 15 : 1, F = (t[5] >> 4) / 15, J = o ? 6 : 5, I = 0, j = (L, x, R) => {
|
|
3
|
+
let m = [];
|
|
4
|
+
for (let b = 0; b < x; b++)
|
|
5
|
+
for (let g = b ? 0 : 1; g * x < L * (x - b); g++)
|
|
6
|
+
m.push(((t[J + (I >> 1)] >> ((I++ & 1) << 2) & 15) / 7.5 - 1) * R);
|
|
7
|
+
return m;
|
|
8
|
+
}, K = j(B, A, a), N = j(3, 3, v * 1.25), O = j(3, 3, z * 1.25), Q = o && j(5, 5, F), C = X(t), H = c(C > 1 ? 32 : 32 * C), U = c(C > 1 ? 32 / C : 32), q = new Uint8Array(H * U * 4), w = [], D = [];
|
|
9
|
+
for (let L = 0, x = 0; L < U; L++)
|
|
10
|
+
for (let R = 0; R < H; R++, x += 4) {
|
|
11
|
+
let m = s, b = y, g = i, M = E;
|
|
12
|
+
for (let e = 0, f = l(B, o ? 5 : 3); e < f; e++)
|
|
13
|
+
w[e] = u(r / H * (R + 0.5) * e);
|
|
14
|
+
for (let e = 0, f = l(A, o ? 5 : 3); e < f; e++)
|
|
15
|
+
D[e] = u(r / U * (L + 0.5) * e);
|
|
16
|
+
for (let e = 0, f = 0; e < A; e++)
|
|
17
|
+
for (let d = e ? 0 : 1, T = D[e] * 2; d * A < B * (A - e); d++, f++)
|
|
18
|
+
m += K[f] * w[d] * T;
|
|
19
|
+
for (let e = 0, f = 0; e < 3; e++)
|
|
20
|
+
for (let d = e ? 0 : 1, T = D[e] * 2; d < 3 - e; d++, f++) {
|
|
21
|
+
let k = w[d] * T;
|
|
22
|
+
b += N[f] * k, g += O[f] * k;
|
|
23
|
+
}
|
|
24
|
+
if (o)
|
|
25
|
+
for (let e = 0, f = 0; e < 5; e++)
|
|
26
|
+
for (let d = e ? 0 : 1, T = D[e] * 2; d < 5 - e; d++, f++)
|
|
27
|
+
M += Q[f] * w[d] * T;
|
|
28
|
+
let P = m - 2 / 3 * b, S = (3 * m - P + g) / 2, V = S - g;
|
|
29
|
+
q[x] = l(0, 255 * p(1, S)), q[x + 1] = l(0, 255 * p(1, V)), q[x + 2] = l(0, 255 * p(1, P)), q[x + 3] = l(0, 255 * p(1, M));
|
|
30
|
+
}
|
|
31
|
+
return { w: H, h: U, rgba: q };
|
|
32
|
+
}
|
|
33
|
+
function X(t) {
|
|
34
|
+
let r = t[3], p = t[2] & 128, l = t[4] & 128, u = l ? p ? 5 : 7 : r & 7, c = l ? r & 7 : p ? 5 : 7;
|
|
35
|
+
return u / c;
|
|
36
|
+
}
|
|
37
|
+
function Y(t, r, p) {
|
|
38
|
+
let l = t * 4 + 1, u = 6 + r * (5 + l), c = [
|
|
39
|
+
137,
|
|
40
|
+
80,
|
|
41
|
+
78,
|
|
42
|
+
71,
|
|
43
|
+
13,
|
|
44
|
+
10,
|
|
45
|
+
26,
|
|
46
|
+
10,
|
|
47
|
+
0,
|
|
48
|
+
0,
|
|
49
|
+
0,
|
|
50
|
+
13,
|
|
51
|
+
73,
|
|
52
|
+
72,
|
|
53
|
+
68,
|
|
54
|
+
82,
|
|
55
|
+
0,
|
|
56
|
+
0,
|
|
57
|
+
t >> 8,
|
|
58
|
+
t & 255,
|
|
59
|
+
0,
|
|
60
|
+
0,
|
|
61
|
+
r >> 8,
|
|
62
|
+
r & 255,
|
|
63
|
+
8,
|
|
64
|
+
6,
|
|
65
|
+
0,
|
|
66
|
+
0,
|
|
67
|
+
0,
|
|
68
|
+
0,
|
|
69
|
+
0,
|
|
70
|
+
0,
|
|
71
|
+
0,
|
|
72
|
+
u >>> 24,
|
|
73
|
+
u >> 16 & 255,
|
|
74
|
+
u >> 8 & 255,
|
|
75
|
+
u & 255,
|
|
76
|
+
73,
|
|
77
|
+
68,
|
|
78
|
+
65,
|
|
79
|
+
84,
|
|
80
|
+
120,
|
|
81
|
+
1
|
|
82
|
+
], _ = [
|
|
83
|
+
0,
|
|
84
|
+
498536548,
|
|
85
|
+
997073096,
|
|
86
|
+
651767980,
|
|
87
|
+
1994146192,
|
|
88
|
+
1802195444,
|
|
89
|
+
1303535960,
|
|
90
|
+
1342533948,
|
|
91
|
+
-306674912,
|
|
92
|
+
-267414716,
|
|
93
|
+
-690576408,
|
|
94
|
+
-882789492,
|
|
95
|
+
-1687895376,
|
|
96
|
+
-2032938284,
|
|
97
|
+
-1609899400,
|
|
98
|
+
-1111625188
|
|
99
|
+
], n = 1, s = 0;
|
|
100
|
+
for (let y = 0, i = 0, a = l - 1; y < r; y++, a += l - 1)
|
|
101
|
+
for (c.push(y + 1 < r ? 0 : 1, l & 255, l >> 8, ~l & 255, l >> 8 ^ 255, 0), s = (s + n) % 65521; i < a; i++) {
|
|
102
|
+
let o = p[i] & 255;
|
|
103
|
+
c.push(o), n = (n + o) % 65521, s = (s + n) % 65521;
|
|
104
|
+
}
|
|
105
|
+
c.push(
|
|
106
|
+
s >> 8,
|
|
107
|
+
s & 255,
|
|
108
|
+
n >> 8,
|
|
109
|
+
n & 255,
|
|
110
|
+
0,
|
|
111
|
+
0,
|
|
112
|
+
0,
|
|
113
|
+
0,
|
|
114
|
+
0,
|
|
115
|
+
0,
|
|
116
|
+
0,
|
|
117
|
+
0,
|
|
118
|
+
73,
|
|
119
|
+
69,
|
|
120
|
+
78,
|
|
121
|
+
68,
|
|
122
|
+
174,
|
|
123
|
+
66,
|
|
124
|
+
96,
|
|
125
|
+
130
|
|
126
|
+
);
|
|
127
|
+
for (let [y, i] of [[12, 29], [37, 41 + u]]) {
|
|
128
|
+
let a = -1;
|
|
129
|
+
for (let o = y; o < i; o++)
|
|
130
|
+
a ^= c[o], a = a >>> 4 ^ _[a & 15], a = a >>> 4 ^ _[a & 15];
|
|
131
|
+
a = ~a, c[i++] = a >>> 24, c[i++] = a >> 16 & 255, c[i++] = a >> 8 & 255, c[i++] = a & 255;
|
|
132
|
+
}
|
|
133
|
+
return "data:image/png;base64," + btoa(String.fromCharCode(...c));
|
|
134
|
+
}
|
|
135
|
+
function Z(t) {
|
|
136
|
+
let r = W(t);
|
|
137
|
+
return Y(r.w, r.h, r.rgba);
|
|
138
|
+
}
|
|
139
|
+
export {
|
|
140
|
+
Y as rgbaToDataURL,
|
|
141
|
+
X as thumbHashToApproximateAspectRatio,
|
|
142
|
+
Z as thumbHashToDataURL,
|
|
143
|
+
W as thumbHashToRGBA
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=thumbhash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thumbhash.js","sources":["../../../../../../../node_modules/.pnpm/thumbhash@0.1.1/node_modules/thumbhash/thumbhash.js"],"sourcesContent":["/**\n * Encodes an RGBA image to a ThumbHash. RGB should not be premultiplied by A.\n *\n * @param w The width of the input image. Must be ≤100px.\n * @param h The height of the input image. Must be ≤100px.\n * @param rgba The pixels in the input image, row-by-row. Must have w*h*4 elements.\n * @returns The ThumbHash as a Uint8Array.\n */\nexport function rgbaToThumbHash(w, h, rgba) {\n // Encoding an image larger than 100x100 is slow with no benefit\n if (w > 100 || h > 100) throw new Error(`${w}x${h} doesn't fit in 100x100`)\n let { PI, round, max, cos, abs } = Math\n\n // Determine the average color\n let avg_r = 0, avg_g = 0, avg_b = 0, avg_a = 0\n for (let i = 0, j = 0; i < w * h; i++, j += 4) {\n let alpha = rgba[j + 3] / 255\n avg_r += alpha / 255 * rgba[j]\n avg_g += alpha / 255 * rgba[j + 1]\n avg_b += alpha / 255 * rgba[j + 2]\n avg_a += alpha\n }\n if (avg_a) {\n avg_r /= avg_a\n avg_g /= avg_a\n avg_b /= avg_a\n }\n\n let hasAlpha = avg_a < w * h\n let l_limit = hasAlpha ? 5 : 7 // Use fewer luminance bits if there's alpha\n let lx = max(1, round(l_limit * w / max(w, h)))\n let ly = max(1, round(l_limit * h / max(w, h)))\n let l = [] // luminance\n let p = [] // yellow - blue\n let q = [] // red - green\n let a = [] // alpha\n\n // Convert the image from RGBA to LPQA (composite atop the average color)\n for (let i = 0, j = 0; i < w * h; i++, j += 4) {\n let alpha = rgba[j + 3] / 255\n let r = avg_r * (1 - alpha) + alpha / 255 * rgba[j]\n let g = avg_g * (1 - alpha) + alpha / 255 * rgba[j + 1]\n let b = avg_b * (1 - alpha) + alpha / 255 * rgba[j + 2]\n l[i] = (r + g + b) / 3\n p[i] = (r + g) / 2 - b\n q[i] = r - g\n a[i] = alpha\n }\n\n // Encode using the DCT into DC (constant) and normalized AC (varying) terms\n let encodeChannel = (channel, nx, ny) => {\n let dc = 0, ac = [], scale = 0, fx = []\n for (let cy = 0; cy < ny; cy++) {\n for (let cx = 0; cx * ny < nx * (ny - cy); cx++) {\n let f = 0\n for (let x = 0; x < w; x++)\n fx[x] = cos(PI / w * cx * (x + 0.5))\n for (let y = 0; y < h; y++)\n for (let x = 0, fy = cos(PI / h * cy * (y + 0.5)); x < w; x++)\n f += channel[x + y * w] * fx[x] * fy\n f /= w * h\n if (cx || cy) {\n ac.push(f)\n scale = max(scale, abs(f))\n } else {\n dc = f\n }\n }\n }\n if (scale)\n for (let i = 0; i < ac.length; i++)\n ac[i] = 0.5 + 0.5 / scale * ac[i]\n return [dc, ac, scale]\n }\n let [l_dc, l_ac, l_scale] = encodeChannel(l, max(3, lx), max(3, ly))\n let [p_dc, p_ac, p_scale] = encodeChannel(p, 3, 3)\n let [q_dc, q_ac, q_scale] = encodeChannel(q, 3, 3)\n let [a_dc, a_ac, a_scale] = hasAlpha ? encodeChannel(a, 5, 5) : []\n\n // Write the constants\n let isLandscape = w > h\n let header24 = round(63 * l_dc) | (round(31.5 + 31.5 * p_dc) << 6) | (round(31.5 + 31.5 * q_dc) << 12) | (round(31 * l_scale) << 18) | (hasAlpha << 23)\n let header16 = (isLandscape ? ly : lx) | (round(63 * p_scale) << 3) | (round(63 * q_scale) << 9) | (isLandscape << 15)\n let hash = [header24 & 255, (header24 >> 8) & 255, header24 >> 16, header16 & 255, header16 >> 8]\n let ac_start = hasAlpha ? 6 : 5\n let ac_index = 0\n if (hasAlpha) hash.push(round(15 * a_dc) | (round(15 * a_scale) << 4))\n\n // Write the varying factors\n for (let ac of hasAlpha ? [l_ac, p_ac, q_ac, a_ac] : [l_ac, p_ac, q_ac])\n for (let f of ac)\n hash[ac_start + (ac_index >> 1)] |= round(15 * f) << ((ac_index++ & 1) << 2)\n return new Uint8Array(hash)\n}\n\n/**\n * Decodes a ThumbHash to an RGBA image. RGB is not be premultiplied by A.\n *\n * @param hash The bytes of the ThumbHash.\n * @returns The width, height, and pixels of the rendered placeholder image.\n */\nexport function thumbHashToRGBA(hash) {\n let { PI, min, max, cos, round } = Math\n\n // Read the constants\n let header24 = hash[0] | (hash[1] << 8) | (hash[2] << 16)\n let header16 = hash[3] | (hash[4] << 8)\n let l_dc = (header24 & 63) / 63\n let p_dc = ((header24 >> 6) & 63) / 31.5 - 1\n let q_dc = ((header24 >> 12) & 63) / 31.5 - 1\n let l_scale = ((header24 >> 18) & 31) / 31\n let hasAlpha = header24 >> 23\n let p_scale = ((header16 >> 3) & 63) / 63\n let q_scale = ((header16 >> 9) & 63) / 63\n let isLandscape = header16 >> 15\n let lx = max(3, isLandscape ? hasAlpha ? 5 : 7 : header16 & 7)\n let ly = max(3, isLandscape ? header16 & 7 : hasAlpha ? 5 : 7)\n let a_dc = hasAlpha ? (hash[5] & 15) / 15 : 1\n let a_scale = (hash[5] >> 4) / 15\n\n // Read the varying factors (boost saturation by 1.25x to compensate for quantization)\n let ac_start = hasAlpha ? 6 : 5\n let ac_index = 0\n let decodeChannel = (nx, ny, scale) => {\n let ac = []\n for (let cy = 0; cy < ny; cy++)\n for (let cx = cy ? 0 : 1; cx * ny < nx * (ny - cy); cx++)\n ac.push((((hash[ac_start + (ac_index >> 1)] >> ((ac_index++ & 1) << 2)) & 15) / 7.5 - 1) * scale)\n return ac\n }\n let l_ac = decodeChannel(lx, ly, l_scale)\n let p_ac = decodeChannel(3, 3, p_scale * 1.25)\n let q_ac = decodeChannel(3, 3, q_scale * 1.25)\n let a_ac = hasAlpha && decodeChannel(5, 5, a_scale)\n\n // Decode using the DCT into RGB\n let ratio = thumbHashToApproximateAspectRatio(hash)\n let w = round(ratio > 1 ? 32 : 32 * ratio)\n let h = round(ratio > 1 ? 32 / ratio : 32)\n let rgba = new Uint8Array(w * h * 4), fx = [], fy = []\n for (let y = 0, i = 0; y < h; y++) {\n for (let x = 0; x < w; x++, i += 4) {\n let l = l_dc, p = p_dc, q = q_dc, a = a_dc\n\n // Precompute the coefficients\n for (let cx = 0, n = max(lx, hasAlpha ? 5 : 3); cx < n; cx++)\n fx[cx] = cos(PI / w * (x + 0.5) * cx)\n for (let cy = 0, n = max(ly, hasAlpha ? 5 : 3); cy < n; cy++)\n fy[cy] = cos(PI / h * (y + 0.5) * cy)\n\n // Decode L\n for (let cy = 0, j = 0; cy < ly; cy++)\n for (let cx = cy ? 0 : 1, fy2 = fy[cy] * 2; cx * ly < lx * (ly - cy); cx++, j++)\n l += l_ac[j] * fx[cx] * fy2\n\n // Decode P and Q\n for (let cy = 0, j = 0; cy < 3; cy++) {\n for (let cx = cy ? 0 : 1, fy2 = fy[cy] * 2; cx < 3 - cy; cx++, j++) {\n let f = fx[cx] * fy2\n p += p_ac[j] * f\n q += q_ac[j] * f\n }\n }\n\n // Decode A\n if (hasAlpha)\n for (let cy = 0, j = 0; cy < 5; cy++)\n for (let cx = cy ? 0 : 1, fy2 = fy[cy] * 2; cx < 5 - cy; cx++, j++)\n a += a_ac[j] * fx[cx] * fy2\n\n // Convert to RGB\n let b = l - 2 / 3 * p\n let r = (3 * l - b + q) / 2\n let g = r - q\n rgba[i] = max(0, 255 * min(1, r))\n rgba[i + 1] = max(0, 255 * min(1, g))\n rgba[i + 2] = max(0, 255 * min(1, b))\n rgba[i + 3] = max(0, 255 * min(1, a))\n }\n }\n return { w, h, rgba }\n}\n\n/**\n * Extracts the average color from a ThumbHash. RGB is not be premultiplied by A.\n *\n * @param hash The bytes of the ThumbHash.\n * @returns The RGBA values for the average color. Each value ranges from 0 to 1.\n */\nexport function thumbHashToAverageRGBA(hash) {\n let { min, max } = Math\n let header = hash[0] | (hash[1] << 8) | (hash[2] << 16)\n let l = (header & 63) / 63\n let p = ((header >> 6) & 63) / 31.5 - 1\n let q = ((header >> 12) & 63) / 31.5 - 1\n let hasAlpha = header >> 23\n let a = hasAlpha ? (hash[5] & 15) / 15 : 1\n let b = l - 2 / 3 * p\n let r = (3 * l - b + q) / 2\n let g = r - q\n return {\n r: max(0, min(1, r)),\n g: max(0, min(1, g)),\n b: max(0, min(1, b)),\n a\n }\n}\n\n/**\n * Extracts the approximate aspect ratio of the original image.\n *\n * @param hash The bytes of the ThumbHash.\n * @returns The approximate aspect ratio (i.e. width / height).\n */\nexport function thumbHashToApproximateAspectRatio(hash) {\n let header = hash[3]\n let hasAlpha = hash[2] & 0x80\n let isLandscape = hash[4] & 0x80\n let lx = isLandscape ? hasAlpha ? 5 : 7 : header & 7\n let ly = isLandscape ? header & 7 : hasAlpha ? 5 : 7\n return lx / ly\n}\n\n/**\n * Encodes an RGBA image to a PNG data URL. RGB should not be premultiplied by\n * A. This is optimized for speed and simplicity and does not optimize for size\n * at all. This doesn't do any compression (all values are stored uncompressed).\n *\n * @param w The width of the input image. Must be ≤100px.\n * @param h The height of the input image. Must be ≤100px.\n * @param rgba The pixels in the input image, row-by-row. Must have w*h*4 elements.\n * @returns A data URL containing a PNG for the input image.\n */\nexport function rgbaToDataURL(w, h, rgba) {\n let row = w * 4 + 1\n let idat = 6 + h * (5 + row)\n let bytes = [\n 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0,\n w >> 8, w & 255, 0, 0, h >> 8, h & 255, 8, 6, 0, 0, 0, 0, 0, 0, 0,\n idat >>> 24, (idat >> 16) & 255, (idat >> 8) & 255, idat & 255,\n 73, 68, 65, 84, 120, 1\n ]\n let table = [\n 0, 498536548, 997073096, 651767980, 1994146192, 1802195444, 1303535960,\n 1342533948, -306674912, -267414716, -690576408, -882789492, -1687895376,\n -2032938284, -1609899400, -1111625188\n ]\n let a = 1, b = 0\n for (let y = 0, i = 0, end = row - 1; y < h; y++, end += row - 1) {\n bytes.push(y + 1 < h ? 0 : 1, row & 255, row >> 8, ~row & 255, (row >> 8) ^ 255, 0)\n for (b = (b + a) % 65521; i < end; i++) {\n let u = rgba[i] & 255\n bytes.push(u)\n a = (a + u) % 65521\n b = (b + a) % 65521\n }\n }\n bytes.push(\n b >> 8, b & 255, a >> 8, a & 255, 0, 0, 0, 0,\n 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130\n )\n for (let [start, end] of [[12, 29], [37, 41 + idat]]) {\n let c = ~0\n for (let i = start; i < end; i++) {\n c ^= bytes[i]\n c = (c >>> 4) ^ table[c & 15]\n c = (c >>> 4) ^ table[c & 15]\n }\n c = ~c\n bytes[end++] = c >>> 24\n bytes[end++] = (c >> 16) & 255\n bytes[end++] = (c >> 8) & 255\n bytes[end++] = c & 255\n }\n return 'data:image/png;base64,' + btoa(String.fromCharCode(...bytes))\n}\n\n/**\n * Decodes a ThumbHash to a PNG data URL. This is a convenience function that\n * just calls \"thumbHashToRGBA\" followed by \"rgbaToDataURL\".\n *\n * @param hash The bytes of the ThumbHash.\n * @returns A data URL containing a PNG for the rendered ThumbHash.\n */\nexport function thumbHashToDataURL(hash) {\n let image = thumbHashToRGBA(hash)\n return rgbaToDataURL(image.w, image.h, image.rgba)\n}\n"],"names":["thumbHashToRGBA","hash","PI","min","max","cos","round","header24","header16","l_dc","p_dc","q_dc","l_scale","hasAlpha","p_scale","q_scale","isLandscape","lx","ly","a_dc","a_scale","ac_start","ac_index","decodeChannel","nx","ny","scale","ac","cy","cx","l_ac","p_ac","q_ac","a_ac","ratio","thumbHashToApproximateAspectRatio","w","h","rgba","fx","fy","y","i","x","l","p","q","a","n","j","fy2","f","b","r","g","header","rgbaToDataURL","row","idat","bytes","table","end","u","start","c","thumbHashToDataURL","image"],"mappings":"AAqGO,SAASA,EAAgBC,GAAM;AACpC,MAAI,EAAE,IAAAC,GAAI,KAAAC,GAAK,KAAAC,GAAK,KAAAC,GAAK,OAAAC,EAAK,IAAK,MAG/BC,IAAWN,EAAK,CAAC,IAAKA,EAAK,CAAC,KAAK,IAAMA,EAAK,CAAC,KAAK,IAClDO,IAAWP,EAAK,CAAC,IAAKA,EAAK,CAAC,KAAK,GACjCQ,KAAQF,IAAW,MAAM,IACzBG,KAASH,KAAY,IAAK,MAAM,OAAO,GACvCI,KAASJ,KAAY,KAAM,MAAM,OAAO,GACxCK,KAAYL,KAA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AAG,CAAC,IAAI,KAAKH,CAAI,CAAC,GAAG;AACpD,QAAIM,IAAI;AACR,aAAStB,IAAIqB,GAAOrB,IAAImB,GAAKnB;AAC3B,MAAAsB,KAAKL,EAAMjB,CAAC,GACZsB,IAAKA,MAAM,IAAKJ,EAAMI,IAAI,EAAE,GAC5BA,IAAKA,MAAM,IAAKJ,EAAMI,IAAI,EAAE;AAE9B,IAAAA,IAAI,CAACA,GACLL,EAAME,GAAK,IAAIG,MAAM,IACrBL,EAAME,GAAK,IAAKG,KAAK,KAAM,KAC3BL,EAAME,GAAK,IAAKG,KAAK,IAAK,KAC1BL,EAAME,GAAK,IAAIG,IAAI;AAAA,EACvB;AACE,SAAO,2BAA2B,KAAK,OAAO,aAAa,GAAGL,CAAK,CAAC;AACtE;AASO,SAASM,EAAmBhE,GAAM;AACvC,MAAIiE,IAAQlE,EAAgBC,CAAI;AAChC,SAAOuD,EAAcU,EAAM,GAAGA,EAAM,GAAGA,EAAM,IAAI;AACnD;","x_google_ignoreList":[0]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/types/index.ts"],"sourcesContent":["export * from '@shopify/shop-minis-platform'\n\nexport interface BaseComponentProps {\n className?: string\n children?: React.ReactNode\n}\n\n// Theme types\nexport interface ThemeConfig {\n colors?: {[key: string]: string}\n spacing?: {[key: string]: string}\n typography?: {[key: string]: string}\n}\n\n// Navigation\nexport const DATA_NAVIGATION_TYPE_ATTRIBUTE = 'data-navigation-type' as const\nexport const NAVIGATION_TYPES = {\n forward: 'forward',\n backward: 'backward',\n none: 'none',\n} as const\n"],"names":["DATA_NAVIGATION_TYPE_ATTRIBUTE","NAVIGATION_TYPES"],"mappings":"AAeO,MAAMA,IAAiC,wBACjCC,IAAmB;AAAA,EAC9B,SAAS;AAAA,EACT,UAAU;AAAA,EACV,MAAM;AACR;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { toUint8Array as o } from "../shop-minis-react/node_modules/.pnpm/js-base64@3.7.7/node_modules/js-base64/base64.js";
|
|
2
|
+
import { thumbHashToDataURL as a } from "../shop-minis-react/node_modules/.pnpm/thumbhash@0.1.1/node_modules/thumbhash/thumbhash.js";
|
|
3
|
+
function n(r) {
|
|
4
|
+
if (r)
|
|
5
|
+
try {
|
|
6
|
+
const t = o(r);
|
|
7
|
+
return a(t);
|
|
8
|
+
} catch (t) {
|
|
9
|
+
console.warn("Failed to decode thumbhash to data URL", t);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
n as getThumbhashDataURL
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.js","sources":["../../src/utils/image.ts"],"sourcesContent":["import {toUint8Array} from 'js-base64'\nimport {thumbHashToDataURL} from 'thumbhash'\n\n/**\n * Converts a thumbhash string to a data URL for use as an image placeholder\n * @param thumbhash Base64 encoded thumbhash string\n * @returns Data URL that can be used as image source or undefined if conversion fails\n */\nexport function getThumbhashDataURL(thumbhash?: string): string | undefined {\n if (!thumbhash) return\n\n try {\n const thumbhashArray = toUint8Array(thumbhash)\n return thumbHashToDataURL(thumbhashArray)\n } catch (error) {\n console.warn('Failed to decode thumbhash to data URL', error)\n }\n}\n"],"names":["getThumbhashDataURL","thumbhash","thumbhashArray","toUint8Array","thumbHashToDataURL","error"],"mappings":";;AAQO,SAASA,EAAoBC,GAAwC;AAC1E,MAAKA;AAED,QAAA;AACI,YAAAC,IAAiBC,EAAaF,CAAS;AAC7C,aAAOG,EAAmBF,CAAc;AAAA,aACjCG,GAAO;AACN,cAAA,KAAK,0CAA0CA,CAAK;AAAA,IAAA;AAEhE;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shopify/shop-minis-react",
|
|
3
3
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.19",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"engines": {
|
|
@@ -38,33 +38,41 @@
|
|
|
38
38
|
"typescript": ">=5.0.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@shopify/shop-minis-platform": "0.0.
|
|
41
|
+
"@shopify/shop-minis-platform": "0.0.6",
|
|
42
42
|
"@tailwindcss/vite": "4.1.8",
|
|
43
43
|
"@types/url-parse": "1.4.9",
|
|
44
44
|
"@vitejs/plugin-react": "4.5.1",
|
|
45
45
|
"class-variance-authority": "0.7.1",
|
|
46
46
|
"clsx": "2.1.1",
|
|
47
47
|
"embla-carousel-react": "8.6.0",
|
|
48
|
+
"js-base64": "^3.7.7",
|
|
48
49
|
"lodash": "4.17.21",
|
|
49
50
|
"lucide-react": "0.513.0",
|
|
50
51
|
"motion": "12.17.3",
|
|
51
52
|
"next-themes": "0.4.6",
|
|
52
53
|
"radix-ui": "1.4.2",
|
|
53
54
|
"react-resizable-panels": "3.0.2",
|
|
55
|
+
"react-router": "^7.7.0",
|
|
54
56
|
"sonner": "2.0.5",
|
|
55
57
|
"tailwind-merge": "2.6.0",
|
|
56
58
|
"tailwindcss": "4.1.8",
|
|
59
|
+
"thumbhash": "^0.1.1",
|
|
57
60
|
"tw-animate-css": "1.3.4",
|
|
58
61
|
"url-parse": "1.5.10",
|
|
59
62
|
"vaul": "1.1.2"
|
|
60
63
|
},
|
|
61
64
|
"devDependencies": {
|
|
62
65
|
"@shopify/generate-docs": "^0.16.6",
|
|
66
|
+
"@storybook/addon-docs": "^9.0.16",
|
|
67
|
+
"@storybook/react-vite": "^9.0.16",
|
|
63
68
|
"@types/node": "^20.12.1",
|
|
64
69
|
"@types/react": "^19.1.6",
|
|
65
70
|
"@types/react-dom": "^19.1.2",
|
|
71
|
+
"eslint": "^9.31.0",
|
|
72
|
+
"eslint-plugin-storybook": "^9.0.16",
|
|
66
73
|
"react": "^19.1.0",
|
|
67
74
|
"react-dom": "^19.1.0",
|
|
75
|
+
"storybook": "^9.0.16",
|
|
68
76
|
"typescript": "^5.8.3",
|
|
69
77
|
"vite": "^6.3.3",
|
|
70
78
|
"vite-plugin-dts": "^4.3.0"
|
|
@@ -92,6 +100,8 @@
|
|
|
92
100
|
"build": "vite build --mode lib",
|
|
93
101
|
"build:watch": "vite build --mode lib --watch",
|
|
94
102
|
"type-check": "tsc --noEmit",
|
|
95
|
-
"clean": "rm -rf dist"
|
|
103
|
+
"clean": "rm -rf dist",
|
|
104
|
+
"storybook": "storybook dev -p 6006",
|
|
105
|
+
"build-storybook": "storybook build"
|
|
96
106
|
}
|
|
97
107
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import {useState} from 'react'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AlertDialogTrigger,
|
|
5
|
+
AlertDialogContent,
|
|
6
|
+
AlertDialogHeader,
|
|
7
|
+
AlertDialogTitle,
|
|
8
|
+
AlertDialogDescription,
|
|
9
|
+
AlertDialogFooter,
|
|
10
|
+
AlertDialogCancel,
|
|
11
|
+
AlertDialogAction,
|
|
12
|
+
AlertDialog as AlertDialogPrimitive,
|
|
13
|
+
} from '../ui/alert-dialog'
|
|
14
|
+
|
|
15
|
+
export const AlertDialogAtom = ({
|
|
16
|
+
children,
|
|
17
|
+
title,
|
|
18
|
+
description,
|
|
19
|
+
cancelButtonText,
|
|
20
|
+
confirmationButtonText,
|
|
21
|
+
open,
|
|
22
|
+
onOpenChange,
|
|
23
|
+
onConfirmationAction,
|
|
24
|
+
}: {
|
|
25
|
+
/** The trigger element that opens the alert dialog */
|
|
26
|
+
children: React.ReactNode
|
|
27
|
+
/** The title text shown in the alert dialog header */
|
|
28
|
+
title: string
|
|
29
|
+
/** The description text shown in the alert dialog body */
|
|
30
|
+
description: string
|
|
31
|
+
/** The text shown in the cancel button */
|
|
32
|
+
cancelButtonText: string
|
|
33
|
+
/** The text shown in the confirmation button */
|
|
34
|
+
confirmationButtonText: string
|
|
35
|
+
/** Whether the alert dialog is open */
|
|
36
|
+
open: boolean
|
|
37
|
+
/** Callback fired when the alert dialog open state changes */
|
|
38
|
+
onOpenChange: (open: boolean) => void
|
|
39
|
+
/** Callback fired when the confirmation button is clicked */
|
|
40
|
+
onConfirmationAction: () => void
|
|
41
|
+
}) => {
|
|
42
|
+
const [isOpen, setIsOpen] = useState(open)
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<AlertDialogPrimitive
|
|
46
|
+
open={isOpen}
|
|
47
|
+
onOpenChange={open => {
|
|
48
|
+
setIsOpen(open)
|
|
49
|
+
onOpenChange(open)
|
|
50
|
+
}}
|
|
51
|
+
>
|
|
52
|
+
<AlertDialogTrigger asChild>{children}</AlertDialogTrigger>
|
|
53
|
+
<AlertDialogContent>
|
|
54
|
+
<AlertDialogHeader>
|
|
55
|
+
<AlertDialogTitle>{title}</AlertDialogTitle>
|
|
56
|
+
<AlertDialogDescription>{description}</AlertDialogDescription>
|
|
57
|
+
</AlertDialogHeader>
|
|
58
|
+
<AlertDialogFooter>
|
|
59
|
+
<AlertDialogCancel>{cancelButtonText}</AlertDialogCancel>
|
|
60
|
+
<AlertDialogAction onClick={onConfirmationAction}>
|
|
61
|
+
{confirmationButtonText}
|
|
62
|
+
</AlertDialogAction>
|
|
63
|
+
</AlertDialogFooter>
|
|
64
|
+
</AlertDialogContent>
|
|
65
|
+
</AlertDialogPrimitive>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
|
|
2
|
+
import {ImgHTMLAttributes, useCallback, useMemo, memo, useState} from 'react'
|
|
3
|
+
|
|
4
|
+
import {cn} from '../../lib/utils'
|
|
5
|
+
import {getThumbhashDataURL} from '../../utils/image'
|
|
6
|
+
|
|
7
|
+
type ThumbhashImageProps = ImgHTMLAttributes<HTMLImageElement> & {
|
|
8
|
+
src: string
|
|
9
|
+
thumbhash: string
|
|
10
|
+
alt?: string | null
|
|
11
|
+
aspectRatio?: number | string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const ThumbhashImage = memo(function ThumbhashImage(
|
|
15
|
+
props: ThumbhashImageProps
|
|
16
|
+
) {
|
|
17
|
+
const {
|
|
18
|
+
src,
|
|
19
|
+
alt,
|
|
20
|
+
thumbhash,
|
|
21
|
+
onLoad,
|
|
22
|
+
className,
|
|
23
|
+
style,
|
|
24
|
+
aspectRatio = 'auto',
|
|
25
|
+
...restProps
|
|
26
|
+
} = props
|
|
27
|
+
|
|
28
|
+
const [isLoaded, setIsLoaded] = useState(false)
|
|
29
|
+
|
|
30
|
+
const dataURL = useMemo(
|
|
31
|
+
() => getThumbhashDataURL(thumbhash ?? undefined),
|
|
32
|
+
[thumbhash]
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
const handleLoad = useCallback(
|
|
36
|
+
(event: React.SyntheticEvent<HTMLImageElement, Event>) => {
|
|
37
|
+
setIsLoaded(true)
|
|
38
|
+
onLoad?.(event)
|
|
39
|
+
},
|
|
40
|
+
[onLoad]
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div
|
|
45
|
+
className={cn('relative w-full ', className)}
|
|
46
|
+
style={{
|
|
47
|
+
...style,
|
|
48
|
+
aspectRatio,
|
|
49
|
+
backgroundImage: dataURL ? `url(${dataURL})` : undefined,
|
|
50
|
+
backgroundSize: 'cover',
|
|
51
|
+
backgroundPosition: 'center',
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
<img
|
|
55
|
+
className={cn(
|
|
56
|
+
'absolute inset-0 w-full h-full opacity-0 object-cover',
|
|
57
|
+
isLoaded && 'opacity-100'
|
|
58
|
+
)}
|
|
59
|
+
src={src}
|
|
60
|
+
alt={alt}
|
|
61
|
+
onLoad={handleLoad}
|
|
62
|
+
{...restProps}
|
|
63
|
+
/>
|
|
64
|
+
</div>
|
|
65
|
+
)
|
|
66
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
|
|
3
|
+
import {cn} from '../../lib/utils'
|
|
4
|
+
import {Skeleton} from '../ui/skeleton'
|
|
5
|
+
|
|
6
|
+
interface MerchantCardSkeletonProps extends React.ComponentProps<'div'> {}
|
|
7
|
+
|
|
8
|
+
function MerchantCardSkeleton({
|
|
9
|
+
className,
|
|
10
|
+
...props
|
|
11
|
+
}: MerchantCardSkeletonProps) {
|
|
12
|
+
return (
|
|
13
|
+
<div
|
|
14
|
+
className={cn(
|
|
15
|
+
'relative w-full aspect-square overflow-hidden rounded-xl border border-gray-100',
|
|
16
|
+
className
|
|
17
|
+
)}
|
|
18
|
+
{...props}
|
|
19
|
+
>
|
|
20
|
+
<div className="w-full h-2/3">
|
|
21
|
+
<Skeleton className="w-full h-full" />
|
|
22
|
+
</div>
|
|
23
|
+
<div className="mt-3 mb-3 ml-3">
|
|
24
|
+
<Skeleton className="mb-2 h-4 w-2/3" />
|
|
25
|
+
<Skeleton className="mb-2 h-5 w-1/3" />
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export {MerchantCardSkeleton}
|
|
@@ -202,6 +202,7 @@ function MerchantCardRating({
|
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
export interface MerchantCardProps {
|
|
205
|
+
variant?: 'default' | 'compact'
|
|
205
206
|
shop: Shop
|
|
206
207
|
touchable?: boolean
|
|
207
208
|
}
|
|
@@ -225,8 +226,10 @@ function MerchantCard({shop, touchable = true}: MerchantCardProps) {
|
|
|
225
226
|
return (
|
|
226
227
|
<MerchantCardRoot touchable={touchable} onPress={handlePress}>
|
|
227
228
|
<MerchantCardImageContainer>
|
|
228
|
-
|
|
229
|
-
|
|
229
|
+
<MerchantCardImage
|
|
230
|
+
src={visualTheme?.featuredImages?.[0]?.url}
|
|
231
|
+
alt={`${name} featured image`}
|
|
232
|
+
/>
|
|
230
233
|
<MerchantCardLogo
|
|
231
234
|
src={visualTheme?.logoImage?.url}
|
|
232
235
|
alt={`${name} logo`}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
|
|
3
|
+
import {cn} from '../../lib/utils'
|
|
4
|
+
import {Skeleton} from '../ui/skeleton'
|
|
5
|
+
|
|
6
|
+
interface ProductCardSkeletonProps extends React.ComponentProps<'div'> {
|
|
7
|
+
variant?: 'default' | 'priceOverlay' | 'compact'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function ProductCardSkeleton({
|
|
11
|
+
className,
|
|
12
|
+
variant = 'default',
|
|
13
|
+
...props
|
|
14
|
+
}: ProductCardSkeletonProps) {
|
|
15
|
+
return (
|
|
16
|
+
<div className={cn('relative w-full', className)} {...props}>
|
|
17
|
+
<div className="aspect-square w-full overflow-hidden rounded-xl border border-gray-100">
|
|
18
|
+
<Skeleton className="h-full w-full" />
|
|
19
|
+
</div>
|
|
20
|
+
{variant === 'default' ? (
|
|
21
|
+
<div className="mt-3 mb-3">
|
|
22
|
+
<Skeleton className="mb-2 h-4 w-2/3" />
|
|
23
|
+
<Skeleton className="mb-2 h-5 w-1/3" />
|
|
24
|
+
</div>
|
|
25
|
+
) : null}
|
|
26
|
+
</div>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {ProductCardSkeleton}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
|
+
import {useCallback} from 'react'
|
|
2
3
|
|
|
3
4
|
import {type Product, type ProductVariant} from '@shopify/shop-minis-platform'
|
|
4
5
|
import {cva, type VariantProps} from 'class-variance-authority'
|
|
5
|
-
import {Heart} from 'lucide-react'
|
|
6
6
|
import {Slot as SlotPrimitive} from 'radix-ui'
|
|
7
7
|
|
|
8
8
|
import {useShopNavigation} from '../../hooks/navigation/useShopNavigation'
|
|
@@ -10,6 +10,7 @@ import {useSavedProductsActions} from '../../hooks/user/useSavedProductsActions'
|
|
|
10
10
|
import {formatMoney} from '../../lib/formatMoney'
|
|
11
11
|
import {cn} from '../../lib/utils'
|
|
12
12
|
import {FavoriteButton} from '../atoms/favorite-button'
|
|
13
|
+
import {ThumbhashImage} from '../atoms/thumbhash-image'
|
|
13
14
|
import {Touchable} from '../atoms/touchable'
|
|
14
15
|
import {Badge} from '../ui/badge'
|
|
15
16
|
|
|
@@ -96,7 +97,7 @@ function ProductCardImageContainer({
|
|
|
96
97
|
// Ensure the product image is stretched to the full size of the container (can't use width/height: 100% because of flex)
|
|
97
98
|
'flex justify-stretch items-stretch',
|
|
98
99
|
'relative overflow-hidden rounded-xl border border-gray-200',
|
|
99
|
-
'w-full
|
|
100
|
+
'w-full aspect-square',
|
|
100
101
|
variant === 'compact' ? 'min-h-[104px]' : 'min-h-[134px]',
|
|
101
102
|
className
|
|
102
103
|
)}
|
|
@@ -109,23 +110,50 @@ function ProductCardImage({
|
|
|
109
110
|
className,
|
|
110
111
|
src,
|
|
111
112
|
alt,
|
|
113
|
+
aspectRatio,
|
|
114
|
+
thumbhash,
|
|
112
115
|
...props
|
|
113
116
|
}: React.ComponentProps<'img'> & {
|
|
114
117
|
src?: string
|
|
115
118
|
alt?: string
|
|
119
|
+
aspectRatio?: number
|
|
120
|
+
thumbhash?: string
|
|
116
121
|
}) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
122
|
+
const renderImageElement = useCallback(
|
|
123
|
+
(src: string) => {
|
|
124
|
+
if (thumbhash) {
|
|
125
|
+
return (
|
|
126
|
+
<ThumbhashImage
|
|
127
|
+
data-slot="product-card-image"
|
|
128
|
+
src={src}
|
|
129
|
+
alt={alt}
|
|
130
|
+
aspectRatio={aspectRatio}
|
|
131
|
+
thumbhash={thumbhash}
|
|
132
|
+
className={cn('w-full h-full object-cover', className)}
|
|
133
|
+
{...props}
|
|
134
|
+
/>
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return (
|
|
120
139
|
<img
|
|
121
140
|
data-slot="product-card-image"
|
|
122
141
|
src={src}
|
|
123
142
|
alt={alt}
|
|
124
|
-
className={cn('w-full h-full
|
|
143
|
+
className={cn('w-full h-full', className)}
|
|
125
144
|
{...props}
|
|
126
145
|
/>
|
|
146
|
+
)
|
|
147
|
+
},
|
|
148
|
+
[alt, aspectRatio, className, props, thumbhash]
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
return (
|
|
152
|
+
<div className="bg-gray-100 flex items-center justify-center w-full h-full">
|
|
153
|
+
{src ? (
|
|
154
|
+
renderImageElement(src)
|
|
127
155
|
) : (
|
|
128
|
-
<div className="text-gray-400 text-sm">No Image</div>
|
|
156
|
+
<div className="text-gray-400 text-sm w-full text-center">No Image</div>
|
|
129
157
|
)}
|
|
130
158
|
</div>
|
|
131
159
|
)
|
|
@@ -249,13 +277,21 @@ function ProductCardOriginalPrice({
|
|
|
249
277
|
}
|
|
250
278
|
|
|
251
279
|
export interface ProductCardProps {
|
|
280
|
+
/** The product to display in the card */
|
|
252
281
|
product: Product
|
|
282
|
+
/** Optional selected variant of the product to show specific variant data */
|
|
253
283
|
selectedProductVariant?: ProductVariant
|
|
284
|
+
/** Visual style variant of the card */
|
|
254
285
|
variant?: 'default' | 'priceOverlay' | 'compact'
|
|
286
|
+
/** Whether the card can be clicked/tapped to navigate to product details */
|
|
255
287
|
touchable?: boolean
|
|
288
|
+
/** Optional text to display in a badge on the card */
|
|
256
289
|
badgeText?: string
|
|
290
|
+
/** Visual style variant for the badge */
|
|
257
291
|
badgeVariant?: 'default' | 'secondary' | 'destructive' | 'outline'
|
|
292
|
+
/** Callback fired when the favorite button is toggled */
|
|
258
293
|
onFavoriteToggled?: (isFavorited: boolean) => void
|
|
294
|
+
/** Optional ID for the section containing this card */
|
|
259
295
|
sectionId?: string
|
|
260
296
|
}
|
|
261
297
|
|
|
@@ -351,7 +387,12 @@ function ProductCard({
|
|
|
351
387
|
onPress={handlePress}
|
|
352
388
|
>
|
|
353
389
|
<ProductCardImageContainer variant={variant}>
|
|
354
|
-
<ProductCardImage
|
|
390
|
+
<ProductCardImage
|
|
391
|
+
src={imageUrl}
|
|
392
|
+
alt={imageAltText}
|
|
393
|
+
aspectRatio={1}
|
|
394
|
+
thumbhash={featuredImage?.thumbhash ?? undefined}
|
|
395
|
+
/>
|
|
355
396
|
|
|
356
397
|
{/* Price overlay badge for priceOverlay variant */}
|
|
357
398
|
{variant === 'priceOverlay' && currencyCode && amount && (
|
package/src/components/index.ts
CHANGED
|
@@ -3,11 +3,18 @@ export * from './MinisContainer'
|
|
|
3
3
|
export * from './commerce/product-card'
|
|
4
4
|
export * from './commerce/product-link'
|
|
5
5
|
export * from './commerce/merchant-card'
|
|
6
|
+
export * from './commerce/product-card-skeleton'
|
|
7
|
+
export * from './commerce/merchant-card-skeleton'
|
|
8
|
+
|
|
9
|
+
export * from './navigation/transition-container'
|
|
10
|
+
export * from './navigation/transition-link'
|
|
6
11
|
|
|
7
12
|
export * from './atoms/button'
|
|
8
13
|
export * from './atoms/favorite-button'
|
|
9
14
|
export * from './atoms/icon-button'
|
|
15
|
+
export * from './atoms/thumbhash-image'
|
|
10
16
|
export * from './atoms/touchable'
|
|
17
|
+
export * from './atoms/alert-dialog'
|
|
11
18
|
|
|
12
19
|
export * from './ui/accordion'
|
|
13
20
|
export * from './ui/alert'
|
|
@@ -28,3 +35,4 @@ export * from './ui/select'
|
|
|
28
35
|
export * from './ui/separator'
|
|
29
36
|
export * from './ui/sheet'
|
|
30
37
|
export * from './ui/sonner'
|
|
38
|
+
export * from './ui/skeleton'
|