create-magic-storefront 0.1.0 → 0.1.1

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.
@@ -0,0 +1,9 @@
1
+ # Source
2
+
3
+ Vendored unchanged from [Leonxlnx/taste-skill](https://github.com/Leonxlnx/taste-skill),
4
+ `skills/taste-skill/SKILL.md` at commit `ce26fc25c0e5e8cab638f883de62d9a86ee5e45b` (MIT, see
5
+ `LICENSE`).
6
+
7
+ Do not edit `SKILL.md` here: storefront-specific rules and overrides live in
8
+ `../storefront-design/SKILL.md`. To update, copy the upstream file over this one and record the
9
+ new commit above.
@@ -0,0 +1,163 @@
1
+ ---
2
+ name: storefront-design
3
+ description: >-
4
+ Visual design for this MagicStore storefront: brand tokens from the shop's branding, a design
5
+ direction per merchant, commerce page patterns (product card, collection, product page, cart,
6
+ checkout, account), and a pre-flight check. Load it before any work that changes how the
7
+ storefront looks: a new design, a redesign, restyling a page or a home section, a new component.
8
+ It drives the `design-taste-frontend` skill and overrides it wherever the two disagree.
9
+ ---
10
+
11
+ # Storefront design
12
+
13
+ The storefront renders one merchant's shop from the MagicStore API. Its design must look like that
14
+ merchant's own store, not like a template and not like an AI landing page. The data is real and the
15
+ server owns it: prices, stock, discounts, images, reviews. Design never invents or recomputes any of
16
+ it.
17
+
18
+ Two skills work together:
19
+
20
+ - **This skill** decides what a store needs and what is off limits.
21
+ - **`design-taste-frontend`** (next to this one) supplies taste: the design read, the three dials,
22
+ the anti-slop rules (its Sections 0, 1, 4, 9). Load it too.
23
+
24
+ When they disagree, **this skill wins**. The overrides are listed in [Overrides](#overrides).
25
+
26
+ ## 1. Read the shop before designing
27
+
28
+ Design from the merchant's data, not from a guess. Read, through `lib/api.ts`:
29
+
30
+ | What | Why |
31
+ | ------------------------------------------------- | ----------------------------------------------------------------- |
32
+ | `api.shop()`: `name`, `description`, `branding` | Identity: logo, favicon, colors, theme |
33
+ | `api.home()`: the sections in the merchant's order | What the home page must hold; a design never drops or reorders them |
34
+ | `api.collectionsIndex()`, a few `api.productsIndex()` | Category, price range, how many products, how good the photos are |
35
+
36
+ `shop.branding`:
37
+
38
+ - `logo`, `favicon`: `Image | null`. With a logo, the header shows it (via `<Image>`), not the
39
+ shop name in bold text. Without one, set the name as a wordmark in the display face.
40
+ - `colors.main`, `navbarBackground`, `navbarText`, `buttonText`, `labelBackground`, `labelText`:
41
+ each a CSS color **or `null`**. `main` is the accent.
42
+ - `theme`: a free-form name from the merchant's admin. Treat it as a hint, not an enum.
43
+
44
+ Then write the design read from `design-taste-frontend` Section 0.B, in store terms:
45
+
46
+ > Reading this as: a _category_ store for _audience_, with a _vibe_ language, accent from
47
+ > `branding.colors.main`, leaning toward _type pairing + density_.
48
+
49
+ Category and audience come from the catalog (products, collections, price range), not from the
50
+ shop name. A kids' store, a hardware store and a jewellery store must not come out looking alike.
51
+
52
+ ## 2. Brand tokens: from the API, at runtime
53
+
54
+ The merchant changes colors in the admin, and `SHOP_UPDATED` revalidates the shop. So:
55
+
56
+ - **Never hard-code the merchant's colors** into CSS. The starter does this already:
57
+ `app/layout.tsx` puts `brandStyle(shop.branding)` (`lib/brand.ts`) on `<html style>`, and
58
+ `app/globals.css` declares every token with the design's own fallback, used when a color is `null`.
59
+ Keep that wiring; restyle through the tokens.
60
+ - Tokens: `--accent` / `--on-accent` (`colors.main` / `buttonText`), `--nav-bg` / `--nav-fg`
61
+ (header), `--label-bg` / `--label-fg` (badges: "New", "Sale", "Pre-order").
62
+ - One accent, used the same way on every page (the taste skill's Color Consistency Lock).
63
+ - A text color the merchant didn't set is picked by contrast (`readableTextOn`), never assumed
64
+ white. Only hex colors are accepted: anything else is dropped, never written into the style.
65
+ - A pair the merchant did set is theirs, even when its contrast is low; point it out to the owner
66
+ rather than overriding it.
67
+ - Merchant colors are unknown at design time, so check contrast with a light, a dark and a
68
+ saturated accent, not only the one shop you are looking at.
69
+ - Everything else (neutrals, radius, spacing, type scale, shadows) belongs to the design and lives
70
+ in `globals.css` as tokens.
71
+
72
+ ## 3. Page patterns
73
+
74
+ Every page handles its empty, error and not-found states (see `PAGES.md`). The patterns below are
75
+ about how pages look.
76
+
77
+ **Header.** Logo or wordmark, top collections, search, account, cart with a live count. One line at
78
+ desktop. On mobile: logo, search, cart visible; the rest in a menu. Sticky is fine; the header stays
79
+ at most 64px high on mobile.
80
+
81
+ **Product card** (`components/product-grid.tsx`). Image with a fixed aspect ratio (no layout
82
+ shift), title (at most 2 lines), price via `<Money>`, `compareAtPrice` struck through when present.
83
+ Badges come only from data: `isNew`, a `compareAtPrice` above `price`, `preOrder`,
84
+ `availableForSale: false`. At most two badges. `rating` only when present, with its real value.
85
+ The whole card is one link; a quick-add button, if any, is a separate control.
86
+
87
+ **Collection.** Title, product count, then the grid straight away: no hero blocks pushing products
88
+ below the fold. Grid: 2 columns on mobile, 3 to 5 on desktop depending on density. Sorting and
89
+ filters sit above the grid; pagination via `<Pagination>`.
90
+
91
+ **Product page** (`app/products/[handle]`, `components/buy-box.tsx`). Gallery left, buy box right
92
+ on desktop; on mobile gallery, then title, price, options, add to cart. Price and add to cart are
93
+ visible without scrolling on a 390×844 screen. Options: sold-out values stay visible but disabled
94
+ (`isOptionValueAvailable`), never hidden. Stock text comes from `quantityAvailable`; do not add
95
+ urgency the API didn't send. Attributes (SKU, weight, vendor, option values) are allowed and
96
+ wanted: set them as a clean definition list.
97
+
98
+ **Cart.** Lines with a thumbnail (`<Image width={64} height={64}>`), quantity stepper, remove, line
99
+ total from the cart. Subtotal and checkout button visible without scrolling. The empty cart links
100
+ back to the catalog.
101
+
102
+ **Checkout.** Conventional and calm: one column, clear labels above the fields, visible
103
+ errors next to the field (`error.detail`), a summary of lines and totals from the checkout. No
104
+ animation, no decorative imagery, no experimental layout. Trust beats taste here.
105
+
106
+ **Account, search, content pages.** Same tokens, quiet layout. Search results reuse the product
107
+ card.
108
+
109
+ **Home** (`app/page.tsx`, `components/sections/`). The one place for a strong visual idea. Each
110
+ section type keeps its renderer; restyle it, do not replace the data it renders. The merchant's
111
+ banners and stories are the hero imagery.
112
+
113
+ ## 4. Telegram Mini App
114
+
115
+ The same app runs inside Telegram's in-app browser. Design mobile-first for a 360–430px viewport:
116
+ tap targets at least 44px, no hover-only controls, no information that only appears on hover,
117
+ `env(safe-area-inset-*)` padding on fixed bars. `min-height: 100dvh`, never `100vh`.
118
+
119
+ ## 5. Stack
120
+
121
+ Keep the starter's approach: plain CSS with custom properties in `app/globals.css`, no UI
122
+ framework. Add Tailwind v4 or Motion only when the owner of this storefront asks for it. If you add
123
+ Motion, use it only in `'use client'` leaf components on the home page and content pages. Fonts via
124
+ `next/font`. Before importing any package, check `package.json` (taste skill Section 3.F).
125
+
126
+ ## Overrides
127
+
128
+ Where `design-taste-frontend` says otherwise, this is what applies here:
129
+
130
+ | Taste skill | In this storefront |
131
+ | ----------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
132
+ | 4.8: generate images, use Picsum, stock photos | **Never** for products, collections, banners or stories: those images come from the API only. A missing image renders `<Image fallback>`. Generated imagery only for decoration the merchant has no data for, and only when asked. |
133
+ | 4.8 / 9.F: logo walls, "Trusted by", testimonials | Only real data: `api.reviewsSite()` / the store-reviews section, the shop's own logo. No invented brands, customers, ratings or review counts. |
134
+ | 9.D: invent realistic content | Never. Real product titles, prices and copy only. Placeholder copy in a shipped page is a bug. |
135
+ | 4.6 / 13: forms and multi-step flows out of scope | Cart, checkout and account follow Section 3 here: conventional, accessible, no creative layout. |
136
+ | 4.9 / 9.F: spec sheets banned | Product attributes are allowed, as a definition list without a border on every row. |
137
+ | 5: sticky-stack, horizontal pan, GSAP | Home and content pages only. Never on collection, product, cart or checkout pages. |
138
+ | 6.C / 8: dark mode mandatory | One theme per store, chosen from `branding` (Theme Lock still holds). Add a dark variant only if the brand colors pass contrast in it. |
139
+ | 3.A: Tailwind v4 + Motion by default | Section 5 here. |
140
+ | 12: block library files | Ignore: blocks are not shipped with this storefront. |
141
+ | Urgency: countdowns, "only N left", "X people viewing" | Only from data: the deal-of-day and flash-sale sections' end dates, `quantityAvailable`. Never invented. |
142
+
143
+ ## Pre-flight
144
+
145
+ Before calling a design done, tick every box:
146
+
147
+ - [ ] Design read written; category and audience taken from the catalog.
148
+ - [ ] Brand colors read from `shop.branding` at runtime; every token has a fallback for `null`.
149
+ - [ ] Contrast AA for text on accent, on the header and on badges, checked with light, dark and
150
+ saturated accents.
151
+ - [ ] All images from the API via `<Image>`, fixed aspect ratios, no layout shift; the LCP image
152
+ (hero banner or first product image) is not lazy-loaded.
153
+ - [ ] No invented data: prices, badges, ratings, reviews, stock, urgency, customer logos.
154
+ - [ ] Money only through `<Money>` / `formatMoney`.
155
+ - [ ] Every home section type from `api.home()` still renders, in the merchant's order.
156
+ - [ ] Product page: price and add to cart visible without scrolling at 390×844.
157
+ - [ ] Cart and checkout: one column on mobile, labelled fields, errors next to fields, no motion.
158
+ - [ ] Mobile 360px: no horizontal scroll, tap targets ≥ 44px, nothing hover-only.
159
+ - [ ] Keyboard: visible focus ring on every control, logical tab order; `prefers-reduced-motion`
160
+ respected.
161
+ - [ ] Empty, error and not-found states styled, not bare text.
162
+ - [ ] Taste skill Section 14 run for the home page and content pages.
163
+ - [ ] `npm run typecheck`, `npm run build` and `npx create-magic-storefront check` pass.
@@ -31,6 +31,15 @@ each error code means — then `PAGES.md` for how each page type is built, and
31
31
  - Every page handles its empty, error and not-found states (`orNotFound` turns `NOT_FOUND` into
32
32
  the 404 page).
33
33
 
34
+ ## Design
35
+
36
+ Before changing how the storefront looks — a new design, a redesign, restyling a page, section or
37
+ component — read `.claude/skills/storefront-design/SKILL.md` and follow it. It uses
38
+ `.claude/skills/design-taste-frontend/SKILL.md` for taste and overrides it where a store differs
39
+ from a landing page: brand colors come from `shop.branding` at runtime, product and banner images
40
+ come only from the API, nothing is invented (prices, badges, reviews, urgency), and the cart and
41
+ checkout stay conventional.
42
+
34
43
  ## Where things go
35
44
 
36
45
  | Path | What |
package/template/PAGES.md CHANGED
@@ -31,7 +31,10 @@ API's, not the build's. The fetch cache still spares the API.
31
31
  ## Layout — `app/layout.tsx`
32
32
 
33
33
  - Reads `api.shop()` and the navigation (`api.collectionsIndex` or `api.menusShow({ path: { handle: 'main' } })`).
34
- - `generateMetadata`: `shop.seo.title || shop.name`, `shop.seo.description ?? shop.description`.
34
+ - `generateMetadata`: `shop.seo.title || shop.name`, `shop.seo.description ?? shop.description`,
35
+ the favicon from `shop.branding.favicon`.
36
+ - The merchant's colors: `brandStyle(shop.branding)` (`lib/brand.ts`) on `<html style>`, as the
37
+ tokens `app/globals.css` falls back from; the header shows `shop.branding.logo` when there is one.
35
38
  - Wraps the page in `Providers` (`MagicStoreProvider` with `shop` passed in, so the browser does not
36
39
  load it again).
37
40
 
@@ -3,8 +3,14 @@
3
3
  --fg: #16161a;
4
4
  --muted: #6b6b76;
5
5
  --line: #e7e7ec;
6
- --accent: #1f5eff;
7
6
  --danger: #c62828;
7
+ /* Brand tokens: app/layout.tsx overrides them with the merchant's colors (lib/brand.ts). */
8
+ --accent: #1f5eff;
9
+ --on-accent: #fff;
10
+ --nav-bg: var(--bg);
11
+ --nav-fg: var(--fg);
12
+ --label-bg: var(--accent);
13
+ --label-fg: var(--on-accent);
8
14
  font-family:
9
15
  system-ui,
10
16
  -apple-system,
@@ -30,6 +36,8 @@ main {
30
36
  }
31
37
  header.site {
32
38
  border-bottom: 1px solid var(--line);
39
+ background: var(--nav-bg);
40
+ color: var(--nav-fg);
33
41
  }
34
42
  header.site nav {
35
43
  max-width: 1100px;
@@ -45,6 +53,11 @@ header.site .brand {
45
53
  text-decoration: none;
46
54
  margin-right: auto;
47
55
  }
56
+ header.site .brand img {
57
+ display: block;
58
+ width: auto;
59
+ height: 32px;
60
+ }
48
61
  .grid {
49
62
  display: grid;
50
63
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
@@ -110,7 +123,7 @@ button.primary,
110
123
  .button.primary {
111
124
  background: var(--accent);
112
125
  border-color: var(--accent);
113
- color: #fff;
126
+ color: var(--on-accent);
114
127
  }
115
128
  button[aria-pressed='true'] {
116
129
  border-color: var(--fg);
@@ -221,8 +234,8 @@ fieldset {
221
234
  align-self: flex-start;
222
235
  padding: 2px 10px;
223
236
  border-radius: 999px;
224
- background: var(--accent);
225
- color: #fff;
237
+ background: var(--label-bg);
238
+ color: var(--label-fg);
226
239
  }
227
240
  .stories {
228
241
  display: flex;
@@ -1,8 +1,10 @@
1
1
  import type { Metadata } from 'next';
2
2
  import Link from 'next/link';
3
3
  import type { ReactNode } from 'react';
4
+ import { Image } from '@magicstoreai/hydrogen';
4
5
  import { CartLink } from '@/components/cart-link';
5
6
  import { api, locale } from '@/lib/api';
7
+ import { brandStyle } from '@/lib/brand';
6
8
  import { Providers } from './providers';
7
9
  import './globals.css';
8
10
 
@@ -15,6 +17,7 @@ export async function generateMetadata(): Promise<Metadata> {
15
17
  return {
16
18
  title: shop.seo.title || shop.name,
17
19
  description: shop.seo.description ?? shop.description,
20
+ icons: shop.branding.favicon ? { icon: shop.branding.favicon.url } : undefined,
18
21
  };
19
22
  }
20
23
 
@@ -26,13 +29,18 @@ export default async function RootLayout({ children }: { children: ReactNode })
26
29
  ]);
27
30
 
28
31
  return (
29
- <html lang={locale}>
32
+ // The merchant's colors, read per request: a change in the admin shows after SHOP_UPDATED.
33
+ <html lang={locale} style={brandStyle(shop.branding)}>
30
34
  <body>
31
35
  <Providers shop={shop}>
32
36
  <header className="site">
33
37
  <nav>
34
38
  <Link href="/" className="brand">
35
- {shop.name}
39
+ {shop.branding.logo ? (
40
+ <Image data={shop.branding.logo} alt={shop.name} height={32} loading="eager" />
41
+ ) : (
42
+ shop.name
43
+ )}
36
44
  </Link>
37
45
  {collections.map((collection) => (
38
46
  <Link key={collection.id} href={`/collections/${collection.handle}`}>
@@ -2,6 +2,29 @@ import { Image, Money } from '@magicstoreai/hydrogen';
2
2
  import type { Schema } from '@magicstoreai/storefront-client';
3
3
  import Link from 'next/link';
4
4
 
5
+ /** Badges come only from the product's data; at most two, so the card stays readable. */
6
+ function ProductBadges({ product }: { product: Schema<'Product'> }) {
7
+ const badges = [
8
+ product.preOrder && 'Pre-order',
9
+ product.compareAtPrice && 'Sale',
10
+ product.isNew && 'New',
11
+ ]
12
+ .filter((badge): badge is string => typeof badge === 'string')
13
+ .slice(0, 2);
14
+ if (badges.length === 0) {
15
+ return null;
16
+ }
17
+ return (
18
+ <span className="row">
19
+ {badges.map((badge) => (
20
+ <span key={badge} className="badge">
21
+ {badge}
22
+ </span>
23
+ ))}
24
+ </span>
25
+ );
26
+ }
27
+
5
28
  export function ProductGrid({ products }: { products: Schema<'Product'>[] }) {
6
29
  if (products.length === 0) {
7
30
  return <p className="muted">Nothing here yet.</p>;
@@ -15,6 +38,7 @@ export function ProductGrid({ products }: { products: Schema<'Product'>[] }) {
15
38
  alt={product.title}
16
39
  fallback={<div className="noimg" />}
17
40
  />
41
+ <ProductBadges product={product} />
18
42
  <span>{product.title}</span>
19
43
  <span className="row">
20
44
  <Money data={product.price} fallback={<span className="muted">—</span>} />
@@ -0,0 +1,60 @@
1
+ import type { Schema } from '@magicstoreai/storefront-client';
2
+ import type { CSSProperties } from 'react';
3
+
4
+ type Branding = Schema<'Shop'>['branding'];
5
+
6
+ /** `#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`. The admin stores colors as free text; nothing else is trusted. */
7
+ const HEX_COLOR = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
8
+
9
+ function hexColor(value: string | null): string | null {
10
+ return value !== null && HEX_COLOR.test(value) ? value : null;
11
+ }
12
+
13
+ /** WCAG relative luminance of a hex color; alpha is ignored. */
14
+ function luminance(hex: string): number {
15
+ const digits = hex.slice(1);
16
+ const channels =
17
+ digits.length <= 4
18
+ ? [0, 1, 2].map((i) => parseInt(digits[i]! + digits[i]!, 16))
19
+ : [0, 2, 4].map((i) => parseInt(digits.slice(i, i + 2), 16));
20
+ const [r, g, b] = channels.map((channel) => {
21
+ const c = channel / 255;
22
+ return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
23
+ });
24
+ return 0.2126 * r! + 0.7152 * g! + 0.0722 * b!;
25
+ }
26
+
27
+ /** Black or white, whichever contrasts more with the background. */
28
+ export function readableTextOn(background: string): '#000' | '#fff' {
29
+ const l = luminance(background);
30
+ const onBlack = (l + 0.05) / 0.05;
31
+ const onWhite = 1.05 / (l + 0.05);
32
+ return onBlack >= onWhite ? '#000' : '#fff';
33
+ }
34
+
35
+ /**
36
+ * The merchant's colors as CSS custom properties for `<html style>`. A color the merchant didn't
37
+ * set is left out, so the design's fallback in `globals.css` applies; a text color the merchant
38
+ * didn't set is picked for contrast against its background.
39
+ */
40
+ export function brandStyle(branding: Branding): CSSProperties {
41
+ const { colors } = branding;
42
+ const tokens: Record<string, string> = {};
43
+ const pair = (name: string, background: string | null, text: string | null) => {
44
+ const bg = hexColor(background);
45
+ if (bg === null) {
46
+ return;
47
+ }
48
+ tokens[`--${name}-bg`] = bg;
49
+ tokens[`--${name}-fg`] = hexColor(text) ?? readableTextOn(bg);
50
+ };
51
+
52
+ const accent = hexColor(colors.main);
53
+ if (accent !== null) {
54
+ tokens['--accent'] = accent;
55
+ tokens['--on-accent'] = hexColor(colors.buttonText) ?? readableTextOn(accent);
56
+ }
57
+ pair('nav', colors.navbarBackground, colors.navbarText);
58
+ pair('label', colors.labelBackground, colors.labelText);
59
+ return tokens as CSSProperties;
60
+ }