create-skybridge 0.0.0-dev.08be486 → 0.0.0-dev.09043e8
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/index.js +52 -26
- package/package.json +1 -1
- package/templates/blank/package.json +2 -1
- package/templates/blank/vite.config.ts +1 -1
- package/templates/demo/package.json +2 -1
- package/templates/demo/vite.config.ts +1 -1
- package/templates/ecom/.dockerignore +4 -0
- package/templates/ecom/.env.template +7 -0
- package/templates/ecom/.ladle/components.tsx +26 -0
- package/templates/ecom/.ladle/config.mjs +11 -0
- package/templates/ecom/.ladle/vite.config.ts +11 -0
- package/templates/ecom/AGENTS.md +2 -0
- package/templates/ecom/Dockerfile +53 -0
- package/templates/ecom/README.md +92 -0
- package/templates/ecom/_gitignore +9 -0
- package/templates/ecom/alpic.json +3 -0
- package/templates/ecom/node_modules/.bin/alpic +21 -0
- package/templates/ecom/node_modules/.bin/ladle +21 -0
- package/templates/ecom/node_modules/.bin/sb +21 -0
- package/templates/ecom/node_modules/.bin/skybridge +21 -0
- package/templates/ecom/node_modules/.bin/tsc +21 -0
- package/templates/ecom/node_modules/.bin/tsserver +21 -0
- package/templates/ecom/node_modules/.bin/tsx +21 -0
- package/templates/ecom/node_modules/.bin/vite +21 -0
- package/templates/ecom/package.json +42 -0
- package/templates/ecom/src/catalog/index.ts +19 -0
- package/templates/ecom/src/catalog/mock.ts +134 -0
- package/templates/ecom/src/catalog/shopify.ts +264 -0
- package/templates/ecom/src/components/chip.css.ts +63 -0
- package/templates/ecom/src/components/chip.stories.tsx +27 -0
- package/templates/ecom/src/components/chip.tsx +49 -0
- package/templates/ecom/src/components/empty-state.stories.tsx +3 -0
- package/templates/ecom/src/components/empty-state.tsx +12 -0
- package/templates/ecom/src/components/expandable-text.css.ts +49 -0
- package/templates/ecom/src/components/expandable-text.stories.tsx +20 -0
- package/templates/ecom/src/components/expandable-text.tsx +53 -0
- package/templates/ecom/src/components/image-gallery.css.ts +172 -0
- package/templates/ecom/src/components/image-gallery.stories.tsx +30 -0
- package/templates/ecom/src/components/image-gallery.tsx +163 -0
- package/templates/ecom/src/components/product-card.css.ts +159 -0
- package/templates/ecom/src/components/product-card.stories.tsx +58 -0
- package/templates/ecom/src/components/product-card.tsx +102 -0
- package/templates/ecom/src/components/product-carousel.css.ts +134 -0
- package/templates/ecom/src/components/product-carousel.stories.tsx +64 -0
- package/templates/ecom/src/components/product-carousel.tsx +202 -0
- package/templates/ecom/src/components/variant-picker.css.ts +27 -0
- package/templates/ecom/src/components/variant-picker.stories.tsx +67 -0
- package/templates/ecom/src/components/variant-picker.tsx +70 -0
- package/templates/ecom/src/components/view-frame.css.ts +22 -0
- package/templates/ecom/src/components/view-frame.tsx +27 -0
- package/templates/ecom/src/config.ts +12 -0
- package/templates/ecom/src/design/contract.css.ts +39 -0
- package/templates/ecom/src/design/fonts.css +15 -0
- package/templates/ecom/src/design/primitives.css.ts +101 -0
- package/templates/ecom/src/design/recipes/typography.css.ts +75 -0
- package/templates/ecom/src/design/sprinkles.css.ts +128 -0
- package/templates/ecom/src/design/themes/dark.css.ts +36 -0
- package/templates/ecom/src/design/themes/light.css.ts +36 -0
- package/templates/ecom/src/design/tokens.ts +8 -0
- package/templates/ecom/src/helpers.ts +4 -0
- package/templates/ecom/src/i18n.ts +35 -0
- package/templates/ecom/src/index.css +9 -0
- package/templates/ecom/src/lib/cx.ts +9 -0
- package/templates/ecom/src/lib/format.ts +9 -0
- package/templates/ecom/src/lib/variants.ts +150 -0
- package/templates/ecom/src/server.ts +43 -0
- package/templates/ecom/src/tools/render-carousel.ts +161 -0
- package/templates/ecom/src/tools/search-products.ts +196 -0
- package/templates/ecom/src/types.ts +87 -0
- package/templates/ecom/src/views/carousel/detail/detail.css.ts +115 -0
- package/templates/ecom/src/views/carousel/detail/detail.stories.tsx +133 -0
- package/templates/ecom/src/views/carousel/detail/index.tsx +254 -0
- package/templates/ecom/src/views/carousel/index.tsx +233 -0
- package/templates/ecom/tsconfig.json +11 -0
- package/templates/ecom/vite.config.ts +8 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// The catalog: the app's single data seam. Both tools read products through
|
|
2
|
+
// these two functions, and nothing else in the app touches a backend.
|
|
3
|
+
//
|
|
4
|
+
// @todo: pick your provider. Ship one of the modules next to this file, or add
|
|
5
|
+
// your own (same two exports, same types) and re-export it here:
|
|
6
|
+
// ./mock.js placeholder catalog, no backend needed (default)
|
|
7
|
+
// ./shopify.js Shopify Storefront API, set the SHOPIFY_* vars in .env
|
|
8
|
+
//
|
|
9
|
+
// Writing your own: `search(input)` returns a `SearchResult`, `getProducts(ids)`
|
|
10
|
+
// resolves ids in the requested order (that is the display order, so resolve by
|
|
11
|
+
// id, never by catalog order). Both map your backend's rows into `Product`s, and
|
|
12
|
+
// how you group them depends on your catalog:
|
|
13
|
+
// - simple products: one `Product` with a single variant, `options: []`
|
|
14
|
+
// - grouped: one `Product` per product, `card` = union of its variants
|
|
15
|
+
// - one card per variant: `card` = that variant
|
|
16
|
+
// Either way `variants` holds ALL variants the source returns for the product;
|
|
17
|
+
// the detail view reads them so the client can switch variant. Order `options`
|
|
18
|
+
// with the imagery-driving axis first (see `Product`: order is semantic).
|
|
19
|
+
export { getProducts, search } from "./mock.js";
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { SearchInput } from "../tools/search-products.js";
|
|
2
|
+
import type { Product, SearchResult, Spec } from "../types.js";
|
|
3
|
+
|
|
4
|
+
// Placeholder catalog provider, so both tools answer before a backend exists.
|
|
5
|
+
// Images are inline SVG placeholders, so no CSP domain is needed.
|
|
6
|
+
// @todo: delete this module once you point `./index.js` at a real provider.
|
|
7
|
+
|
|
8
|
+
function shot(fill: string): string {
|
|
9
|
+
return `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Crect width='400' height='400' fill='%23${fill}'/%3E%3C/svg%3E`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const JACKET_SPECS: Spec[] = [
|
|
13
|
+
{ label: "Material", value: "Water-repellent cotton" },
|
|
14
|
+
{ label: "Fit", value: "Relaxed" },
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
// Deliberately long, to exercise the detail page's scroll and "read more".
|
|
18
|
+
const JACKET_DESCRIPTION = "Relaxed-fit jacket in water-repellent cotton.";
|
|
19
|
+
|
|
20
|
+
const MOCK_PRODUCTS: Product[] = [
|
|
21
|
+
{
|
|
22
|
+
id: "field-jacket",
|
|
23
|
+
options: [
|
|
24
|
+
{
|
|
25
|
+
id: "color",
|
|
26
|
+
label: "Color",
|
|
27
|
+
values: [
|
|
28
|
+
{ id: "black", label: "Black", media: shot("2b2b2b") },
|
|
29
|
+
{ id: "sand", label: "Sand", media: shot("d8c7a8") },
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
variants: [
|
|
34
|
+
{
|
|
35
|
+
id: "fj-black",
|
|
36
|
+
selection: { color: "black" },
|
|
37
|
+
title: "Field jacket — Black",
|
|
38
|
+
description: JACKET_DESCRIPTION,
|
|
39
|
+
price: { amount: 229, currency: "EUR" },
|
|
40
|
+
media: [shot("2b2b2b")],
|
|
41
|
+
url: "https://example.com/field-jacket-black",
|
|
42
|
+
specs: JACKET_SPECS,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "fj-sand",
|
|
46
|
+
selection: { color: "sand" },
|
|
47
|
+
title: "Field jacket — Sand",
|
|
48
|
+
description: JACKET_DESCRIPTION,
|
|
49
|
+
price: { amount: 249, currency: "EUR" },
|
|
50
|
+
media: [shot("d8c7a8")],
|
|
51
|
+
url: "https://example.com/field-jacket-sand",
|
|
52
|
+
specs: JACKET_SPECS,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
card: {
|
|
56
|
+
title: "Field jacket",
|
|
57
|
+
description: "Relaxed-fit jacket in water-repellent cotton.",
|
|
58
|
+
price: { amount: 229, currency: "EUR" },
|
|
59
|
+
media: [shot("2b2b2b")],
|
|
60
|
+
specs: JACKET_SPECS,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "canvas-tote",
|
|
65
|
+
options: [],
|
|
66
|
+
variants: [
|
|
67
|
+
{
|
|
68
|
+
id: "canvas-tote",
|
|
69
|
+
selection: {},
|
|
70
|
+
title: "Canvas tote",
|
|
71
|
+
description: "Sturdy everyday tote with an inner pocket.",
|
|
72
|
+
price: { amount: 39, currency: "EUR" },
|
|
73
|
+
media: [shot("e1e1e1")],
|
|
74
|
+
url: "https://example.com/canvas-tote",
|
|
75
|
+
specs: [{ label: "Material", value: "Cotton canvas" }],
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
card: {
|
|
79
|
+
title: "Canvas tote",
|
|
80
|
+
description: "Sturdy everyday tote with an inner pocket.",
|
|
81
|
+
price: { amount: 39, currency: "EUR" },
|
|
82
|
+
media: [shot("e1e1e1")],
|
|
83
|
+
specs: [{ label: "Material", value: "Cotton canvas" }],
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
id: "wool-beanie",
|
|
88
|
+
options: [],
|
|
89
|
+
variants: [
|
|
90
|
+
{
|
|
91
|
+
id: "wool-beanie",
|
|
92
|
+
selection: {},
|
|
93
|
+
title: "Wool beanie",
|
|
94
|
+
description: "Ribbed merino beanie with a folded brim.",
|
|
95
|
+
price: { amount: 45, currency: "EUR" },
|
|
96
|
+
media: [shot("6b7f9e")],
|
|
97
|
+
url: "https://example.com/wool-beanie",
|
|
98
|
+
outOfStock: true,
|
|
99
|
+
specs: [{ label: "Material", value: "Merino wool" }],
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
card: {
|
|
103
|
+
title: "Wool beanie",
|
|
104
|
+
description: "Ribbed merino beanie with a folded brim.",
|
|
105
|
+
price: { amount: 45, currency: "EUR" },
|
|
106
|
+
media: [shot("6b7f9e")],
|
|
107
|
+
outOfStock: true,
|
|
108
|
+
specs: [{ label: "Material", value: "Merino wool" }],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
|
|
113
|
+
// Ignores the input: every mock product matches every query.
|
|
114
|
+
export async function search(_input: SearchInput): Promise<SearchResult> {
|
|
115
|
+
return {
|
|
116
|
+
products: MOCK_PRODUCTS,
|
|
117
|
+
pages: { current: 1, total: 1 },
|
|
118
|
+
totalHits: MOCK_PRODUCTS.length,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Requested order is the display order, so resolve by id, not catalog order.
|
|
123
|
+
export async function getProducts(ids: string[]): Promise<Product[]> {
|
|
124
|
+
const products: Product[] = [];
|
|
125
|
+
for (const id of ids) {
|
|
126
|
+
for (const product of MOCK_PRODUCTS) {
|
|
127
|
+
if (product.id === id) {
|
|
128
|
+
products.push(product);
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return products;
|
|
134
|
+
}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
import type { SearchInput } from "../tools/search-products.js";
|
|
2
|
+
import type {
|
|
3
|
+
Option,
|
|
4
|
+
Price,
|
|
5
|
+
Product,
|
|
6
|
+
SearchResult,
|
|
7
|
+
Spec,
|
|
8
|
+
Variant,
|
|
9
|
+
} from "../types.js";
|
|
10
|
+
|
|
11
|
+
// Shopify Storefront API provider. To use it:
|
|
12
|
+
// 1. re-export this module from `./index.js` instead of `./mock.js`
|
|
13
|
+
// 2. set SHOPIFY_STORE_DOMAIN and SHOPIFY_STOREFRONT_TOKEN in .env
|
|
14
|
+
// 3. uncomment the `csp` block in `src/tools/render-carousel.ts` with
|
|
15
|
+
// `https://cdn.shopify.com` and your store domain
|
|
16
|
+
//
|
|
17
|
+
// Product ids are Shopify handles, not GIDs: stable, readable, and far cheaper
|
|
18
|
+
// in model context than `gid://shopify/Product/8123456789`.
|
|
19
|
+
|
|
20
|
+
const API_VERSION = "2026-07";
|
|
21
|
+
const PAGE_SIZE = 20;
|
|
22
|
+
|
|
23
|
+
// Only the fields this app renders. Options are derived from the variants'
|
|
24
|
+
// `selectedOptions`, so the product-level `options` field is not queried.
|
|
25
|
+
const PRODUCT_FIELDS = `
|
|
26
|
+
fragment ProductFields on Product {
|
|
27
|
+
handle
|
|
28
|
+
title
|
|
29
|
+
description
|
|
30
|
+
vendor
|
|
31
|
+
productType
|
|
32
|
+
onlineStoreUrl
|
|
33
|
+
availableForSale
|
|
34
|
+
priceRange { minVariantPrice { amount currencyCode } }
|
|
35
|
+
images(first: 10) { nodes { url } }
|
|
36
|
+
variants(first: 100) {
|
|
37
|
+
nodes {
|
|
38
|
+
id
|
|
39
|
+
title
|
|
40
|
+
availableForSale
|
|
41
|
+
price { amount currencyCode }
|
|
42
|
+
image { url }
|
|
43
|
+
selectedOptions { name value }
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}`;
|
|
47
|
+
|
|
48
|
+
type ShopifyMoney = { amount: string; currencyCode: string };
|
|
49
|
+
|
|
50
|
+
type ShopifyProduct = {
|
|
51
|
+
handle: string;
|
|
52
|
+
title: string;
|
|
53
|
+
description: string;
|
|
54
|
+
vendor: string;
|
|
55
|
+
productType: string;
|
|
56
|
+
onlineStoreUrl: string | null;
|
|
57
|
+
availableForSale: boolean;
|
|
58
|
+
priceRange: { minVariantPrice: ShopifyMoney };
|
|
59
|
+
images: { nodes: { url: string }[] };
|
|
60
|
+
variants: {
|
|
61
|
+
nodes: {
|
|
62
|
+
id: string;
|
|
63
|
+
title: string;
|
|
64
|
+
availableForSale: boolean;
|
|
65
|
+
price: ShopifyMoney;
|
|
66
|
+
image: { url: string } | null;
|
|
67
|
+
selectedOptions: { name: string; value: string }[];
|
|
68
|
+
}[];
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
async function storefront(query: string, variables: Record<string, unknown>) {
|
|
73
|
+
const domain = process.env.SHOPIFY_STORE_DOMAIN;
|
|
74
|
+
const token = process.env.SHOPIFY_STOREFRONT_TOKEN;
|
|
75
|
+
if (!domain || !token) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
"Missing SHOPIFY_STORE_DOMAIN or SHOPIFY_STOREFRONT_TOKEN in the environment.",
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const response = await fetch(
|
|
82
|
+
`https://${domain}/api/${API_VERSION}/graphql.json`,
|
|
83
|
+
{
|
|
84
|
+
method: "POST",
|
|
85
|
+
headers: {
|
|
86
|
+
"Content-Type": "application/json",
|
|
87
|
+
"X-Shopify-Storefront-Access-Token": token,
|
|
88
|
+
},
|
|
89
|
+
body: JSON.stringify({ query, variables }),
|
|
90
|
+
},
|
|
91
|
+
);
|
|
92
|
+
if (!response.ok) {
|
|
93
|
+
throw new Error(`Shopify ${response.status}: ${await response.text()}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const { data, errors } = await response.json();
|
|
97
|
+
if (errors) {
|
|
98
|
+
throw new Error(`Shopify: ${JSON.stringify(errors)}`);
|
|
99
|
+
}
|
|
100
|
+
return data;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function toPrice(money: ShopifyMoney): Price {
|
|
104
|
+
return { amount: Number(money.amount), currency: money.currencyCode };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// @todo: Shopify has no generic "specs" field. Vendor and product type are a
|
|
108
|
+
// starting point; swap in your own metafields once you know their namespace.
|
|
109
|
+
function toSpecs(node: ShopifyProduct): Spec[] {
|
|
110
|
+
const specs: Spec[] = [];
|
|
111
|
+
if (node.vendor) {
|
|
112
|
+
specs.push({ label: "Brand", value: node.vendor });
|
|
113
|
+
}
|
|
114
|
+
if (node.productType) {
|
|
115
|
+
specs.push({ label: "Type", value: node.productType });
|
|
116
|
+
}
|
|
117
|
+
return specs;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function toProduct(node: ShopifyProduct): Product {
|
|
121
|
+
const specs = toSpecs(node);
|
|
122
|
+
const images: string[] = [];
|
|
123
|
+
for (const image of node.images.nodes) {
|
|
124
|
+
images.push(image.url);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Walk the variants once, building both the variants and the axes they vary
|
|
128
|
+
// on. Shopify option names are used as-is for ids, so a variant's
|
|
129
|
+
// `selectedOptions` maps straight onto `selection`.
|
|
130
|
+
const options: Option[] = [];
|
|
131
|
+
const variants: Variant[] = [];
|
|
132
|
+
for (const variant of node.variants.nodes) {
|
|
133
|
+
const selection: Record<string, string> = {};
|
|
134
|
+
for (const selected of variant.selectedOptions) {
|
|
135
|
+
selection[selected.name] = selected.value;
|
|
136
|
+
|
|
137
|
+
let option: Option | undefined;
|
|
138
|
+
for (const candidate of options) {
|
|
139
|
+
if (candidate.id === selected.name) {
|
|
140
|
+
option = candidate;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (!option) {
|
|
145
|
+
option = { id: selected.name, label: selected.name, values: [] };
|
|
146
|
+
options.push(option);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let known = false;
|
|
150
|
+
for (const value of option.values) {
|
|
151
|
+
if (value.id === selected.value) {
|
|
152
|
+
known = true;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (!known) {
|
|
157
|
+
option.values.push({
|
|
158
|
+
id: selected.value,
|
|
159
|
+
label: selected.value,
|
|
160
|
+
media: variant.image?.url,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
variants.push({
|
|
166
|
+
id: variant.id,
|
|
167
|
+
selection,
|
|
168
|
+
title: variant.title === "Default Title" ? node.title : variant.title,
|
|
169
|
+
description: node.description,
|
|
170
|
+
price: toPrice(variant.price),
|
|
171
|
+
media: variant.image ? [variant.image.url] : images,
|
|
172
|
+
url: node.onlineStoreUrl ?? undefined,
|
|
173
|
+
outOfStock: !variant.availableForSale,
|
|
174
|
+
specs,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// A single-variant product has no axes to pick from.
|
|
179
|
+
if (variants.length < 2) {
|
|
180
|
+
options.length = 0;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return {
|
|
184
|
+
id: node.handle,
|
|
185
|
+
options,
|
|
186
|
+
variants,
|
|
187
|
+
card: {
|
|
188
|
+
title: node.title,
|
|
189
|
+
description: node.description,
|
|
190
|
+
price: toPrice(node.priceRange.minVariantPrice),
|
|
191
|
+
media: images,
|
|
192
|
+
url: node.onlineStoreUrl ?? undefined,
|
|
193
|
+
outOfStock: !node.availableForSale,
|
|
194
|
+
specs,
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export async function search({
|
|
200
|
+
keyword,
|
|
201
|
+
sort,
|
|
202
|
+
priceRange,
|
|
203
|
+
}: SearchInput): Promise<SearchResult> {
|
|
204
|
+
// Shopify's search DSL: a bare term matches title, vendor, type and tags;
|
|
205
|
+
// extra clauses narrow it. @todo: add your own (`tag:`, `product_type:`…).
|
|
206
|
+
let query = keyword;
|
|
207
|
+
if (priceRange) {
|
|
208
|
+
const [min, max] = priceRange.split("-");
|
|
209
|
+
query += ` variants.price:>=${min} variants.price:<=${max}`;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const data = await storefront(
|
|
213
|
+
`${PRODUCT_FIELDS}
|
|
214
|
+
query Search($query: String!, $sortKey: ProductSortKeys!, $reverse: Boolean!, $first: Int!) {
|
|
215
|
+
products(query: $query, sortKey: $sortKey, reverse: $reverse, first: $first) {
|
|
216
|
+
nodes { ...ProductFields }
|
|
217
|
+
}
|
|
218
|
+
}`,
|
|
219
|
+
{
|
|
220
|
+
query,
|
|
221
|
+
sortKey: sort ? "PRICE" : "RELEVANCE",
|
|
222
|
+
reverse: sort === "price-desc",
|
|
223
|
+
first: PAGE_SIZE,
|
|
224
|
+
},
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
const products: Product[] = [];
|
|
228
|
+
for (const node of data.products.nodes) {
|
|
229
|
+
products.push(toProduct(node));
|
|
230
|
+
}
|
|
231
|
+
// Storefront paginates by cursor and reports no total, so both counts are
|
|
232
|
+
// left out rather than faked.
|
|
233
|
+
return { products };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export async function getProducts(ids: string[]): Promise<Product[]> {
|
|
237
|
+
// One aliased lookup per handle, so the response comes back in the order the
|
|
238
|
+
// model asked for.
|
|
239
|
+
const declarations: string[] = [];
|
|
240
|
+
const fields: string[] = [];
|
|
241
|
+
const variables: Record<string, string> = {};
|
|
242
|
+
for (let index = 0; index < ids.length; index++) {
|
|
243
|
+
declarations.push(`$h${index}: String!`);
|
|
244
|
+
fields.push(`p${index}: product(handle: $h${index}) { ...ProductFields }`);
|
|
245
|
+
variables[`h${index}`] = ids[index];
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const data = await storefront(
|
|
249
|
+
`${PRODUCT_FIELDS}
|
|
250
|
+
query Products(${declarations.join(", ")}) {
|
|
251
|
+
${fields.join("\n ")}
|
|
252
|
+
}`,
|
|
253
|
+
variables,
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
const products: Product[] = [];
|
|
257
|
+
for (let index = 0; index < ids.length; index++) {
|
|
258
|
+
const node = data[`p${index}`];
|
|
259
|
+
if (node) {
|
|
260
|
+
products.push(toProduct(node));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return products;
|
|
264
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { style } from "@vanilla-extract/css";
|
|
2
|
+
import { recipe } from "@vanilla-extract/recipes";
|
|
3
|
+
import { colors, primitives } from "../design/tokens";
|
|
4
|
+
|
|
5
|
+
// A selectable pill used for option values (sizes, colors…). `selected`,
|
|
6
|
+
// `outOfStock` and `nonExistent` are driven by the variant picker from the
|
|
7
|
+
// sparse variant list.
|
|
8
|
+
// @todo: tune the chip to your brand (radius, borders, selected treatment).
|
|
9
|
+
export const chip = recipe({
|
|
10
|
+
base: {
|
|
11
|
+
display: "inline-flex",
|
|
12
|
+
alignItems: "center",
|
|
13
|
+
gap: primitives.space["4xs"],
|
|
14
|
+
minHeight: "44px", // touch target
|
|
15
|
+
padding: `${primitives.space["4xs"]} ${primitives.space["3xs"]}`,
|
|
16
|
+
borderRadius: primitives.radius.m,
|
|
17
|
+
border: `${primitives.stroke.thin} solid ${colors.border.subtle}`,
|
|
18
|
+
backgroundColor: colors.surface.extraLight,
|
|
19
|
+
color: colors.content.intense,
|
|
20
|
+
fontFamily: primitives.font.family.primary,
|
|
21
|
+
fontSize: primitives.font.size.s,
|
|
22
|
+
cursor: "pointer",
|
|
23
|
+
transition: "border-color 150ms ease",
|
|
24
|
+
"@media": {
|
|
25
|
+
"(prefers-reduced-motion: reduce)": { transition: "none" },
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
variants: {
|
|
29
|
+
selected: {
|
|
30
|
+
true: {
|
|
31
|
+
borderColor: colors.common.accent,
|
|
32
|
+
borderWidth: primitives.stroke.medium,
|
|
33
|
+
},
|
|
34
|
+
false: {},
|
|
35
|
+
},
|
|
36
|
+
outOfStock: {
|
|
37
|
+
// Struck but still clickable; the buy CTA carries the state.
|
|
38
|
+
true: {
|
|
39
|
+
color: colors.content.subtle,
|
|
40
|
+
textDecoration: "line-through",
|
|
41
|
+
},
|
|
42
|
+
false: {},
|
|
43
|
+
},
|
|
44
|
+
nonExistent: {
|
|
45
|
+
// Faded and non-interactive, distinct from sold out above.
|
|
46
|
+
true: {
|
|
47
|
+
opacity: 0.35,
|
|
48
|
+
cursor: "default",
|
|
49
|
+
},
|
|
50
|
+
false: {},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
defaultVariants: { selected: false, outOfStock: false, nonExistent: false },
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Small color/material swatch shown before the label on image chips.
|
|
57
|
+
export const swatch = style({
|
|
58
|
+
width: "20px",
|
|
59
|
+
height: "20px",
|
|
60
|
+
borderRadius: primitives.radius.full,
|
|
61
|
+
objectFit: "cover",
|
|
62
|
+
display: "block",
|
|
63
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Chip } from "./chip";
|
|
2
|
+
|
|
3
|
+
const SWATCH =
|
|
4
|
+
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20'%3E%3Crect width='20' height='20' fill='%233b6cf0'/%3E%3C/svg%3E";
|
|
5
|
+
|
|
6
|
+
const row = {
|
|
7
|
+
display: "flex",
|
|
8
|
+
gap: 8,
|
|
9
|
+
flexWrap: "wrap" as const,
|
|
10
|
+
maxWidth: 320,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const States = () => (
|
|
14
|
+
<div style={row}>
|
|
15
|
+
<Chip label="M" />
|
|
16
|
+
<Chip label="L" selected />
|
|
17
|
+
<Chip label="XL" outOfStock /> {/* exists, sold out: clickable */}
|
|
18
|
+
<Chip label="XXL" nonExistent /> {/* combination does not exist */}
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
export const WithSwatch = () => (
|
|
23
|
+
<div style={row}>
|
|
24
|
+
<Chip label="Blue" media={SWATCH} selected />
|
|
25
|
+
<Chip label="Black" media={SWATCH} />
|
|
26
|
+
</div>
|
|
27
|
+
);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as styles from "./chip.css";
|
|
2
|
+
|
|
3
|
+
type ChipProps = {
|
|
4
|
+
label: string;
|
|
5
|
+
selected?: boolean;
|
|
6
|
+
// Exists but sold out: struck-through and greyed, still clickable
|
|
7
|
+
outOfStock?: boolean;
|
|
8
|
+
// The combination does not exist at all (hole in the variant matrix):
|
|
9
|
+
// faded and non-interactive
|
|
10
|
+
nonExistent?: boolean;
|
|
11
|
+
onSelect?: () => void;
|
|
12
|
+
// Optional swatch image (e.g. one per color); omit for a plain text chip.
|
|
13
|
+
media?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* One option value as a selectable pill. Rendered as a `radio` inside the
|
|
18
|
+
* variant picker's `radiogroup`; the picker owns selection state and passes
|
|
19
|
+
* `selected`/`outOfStock`/`nonExistent` computed from the sparse variant list.
|
|
20
|
+
* An out-of-stock chip stays operable: aria-disabled announces the state to
|
|
21
|
+
* assistive tech without blocking activation. A nonexistent chip is natively
|
|
22
|
+
* disabled: the combination cannot be composed.
|
|
23
|
+
*/
|
|
24
|
+
export function Chip({
|
|
25
|
+
label,
|
|
26
|
+
selected,
|
|
27
|
+
outOfStock,
|
|
28
|
+
nonExistent,
|
|
29
|
+
onSelect,
|
|
30
|
+
media,
|
|
31
|
+
}: ChipProps) {
|
|
32
|
+
return (
|
|
33
|
+
// biome-ignore lint/a11y/useSemanticElements: custom radio; a styled button carries the swatch and availability states a native radio cannot, inside the picker radiogroup.
|
|
34
|
+
<button
|
|
35
|
+
type="button"
|
|
36
|
+
role="radio"
|
|
37
|
+
aria-checked={selected ?? false}
|
|
38
|
+
aria-disabled={outOfStock ?? false}
|
|
39
|
+
disabled={nonExistent ?? false}
|
|
40
|
+
className={styles.chip({ selected, outOfStock, nonExistent })}
|
|
41
|
+
onClick={onSelect}
|
|
42
|
+
>
|
|
43
|
+
{media ? (
|
|
44
|
+
<img className={styles.swatch} src={media} alt="" draggable={false} />
|
|
45
|
+
) : null}
|
|
46
|
+
{label}
|
|
47
|
+
</button>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { sprinkles, text } from "../design/tokens";
|
|
2
|
+
|
|
3
|
+
/** Centered message shown when there is nothing to render (e.g. no results). */
|
|
4
|
+
export function EmptyState({ message }: { message: string }) {
|
|
5
|
+
return (
|
|
6
|
+
<div
|
|
7
|
+
className={sprinkles({ p: "l", textAlign: "center", color: "subtle" })}
|
|
8
|
+
>
|
|
9
|
+
<p className={text({ style: "bodyM" })}>{message}</p>
|
|
10
|
+
</div>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { style } from "@vanilla-extract/css";
|
|
2
|
+
import { recipe } from "@vanilla-extract/recipes";
|
|
3
|
+
import { colors, primitives } from "../design/tokens";
|
|
4
|
+
|
|
5
|
+
// @todo: collapsed height before "read more" appears. Tune to your type scale.
|
|
6
|
+
const COLLAPSED_MAX_HEIGHT = "6em";
|
|
7
|
+
|
|
8
|
+
export const container = style({
|
|
9
|
+
display: "flex",
|
|
10
|
+
flexDirection: "column",
|
|
11
|
+
alignItems: "flex-start",
|
|
12
|
+
gap: primitives.space["4xs"],
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// `clamp` caps the height (applied whenever collapsed, so overflow can be
|
|
16
|
+
// measured); `fade` masks the last line to a soft cutoff instead of an ellipsis
|
|
17
|
+
// and is applied only when the text actually overflows (never on short copy).
|
|
18
|
+
export const body = recipe({
|
|
19
|
+
base: {
|
|
20
|
+
color: colors.content.intense,
|
|
21
|
+
whiteSpace: "pre-line", // preserve paragraph breaks from the source
|
|
22
|
+
},
|
|
23
|
+
variants: {
|
|
24
|
+
clamp: {
|
|
25
|
+
true: { maxHeight: COLLAPSED_MAX_HEIGHT, overflow: "hidden" },
|
|
26
|
+
false: {},
|
|
27
|
+
},
|
|
28
|
+
fade: {
|
|
29
|
+
true: {
|
|
30
|
+
maskImage:
|
|
31
|
+
"linear-gradient(to bottom, black 0%, black 55%, transparent 100%)",
|
|
32
|
+
WebkitMaskImage:
|
|
33
|
+
"linear-gradient(to bottom, black 0%, black 55%, transparent 100%)",
|
|
34
|
+
},
|
|
35
|
+
false: {},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
defaultVariants: { clamp: false, fade: false },
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export const toggle = style({
|
|
42
|
+
padding: 0,
|
|
43
|
+
border: "none",
|
|
44
|
+
background: "none",
|
|
45
|
+
color: colors.common.accent,
|
|
46
|
+
fontFamily: primitives.font.family.primary,
|
|
47
|
+
fontSize: primitives.font.size.s,
|
|
48
|
+
cursor: "pointer",
|
|
49
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ExpandableText } from "./expandable-text";
|
|
2
|
+
|
|
3
|
+
const frame = { maxWidth: 360 };
|
|
4
|
+
|
|
5
|
+
const LONG =
|
|
6
|
+
"A relaxed-fit jacket in water-repellent cotton.\n\nDropped shoulders, a two-way zip, and ribbed cuffs. Fully lined, with two zip pockets at the front and one inside. Designed to layer over a knit through the cooler months, and cut long enough to sit past the hip.";
|
|
7
|
+
|
|
8
|
+
export const Long = () => (
|
|
9
|
+
<div style={frame}>
|
|
10
|
+
<ExpandableText>{LONG}</ExpandableText>
|
|
11
|
+
</div>
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
export const Short = () => (
|
|
15
|
+
<div style={frame}>
|
|
16
|
+
<ExpandableText>
|
|
17
|
+
A short description that never needs a toggle.
|
|
18
|
+
</ExpandableText>
|
|
19
|
+
</div>
|
|
20
|
+
);
|