create-skybridge 0.0.0-dev.3581704 → 0.0.0-dev.35a7b38

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.
Files changed (88) hide show
  1. package/dist/index.js +46 -24
  2. package/package.json +4 -4
  3. package/templates/blank/Dockerfile +3 -3
  4. package/templates/blank/_gitignore +2 -1
  5. package/templates/blank/node_modules/.bin/alpic +2 -2
  6. package/templates/blank/node_modules/.bin/tsc +2 -2
  7. package/templates/blank/node_modules/.bin/tsserver +2 -2
  8. package/templates/blank/node_modules/.bin/tsx +21 -0
  9. package/templates/blank/node_modules/.bin/vite +2 -2
  10. package/templates/blank/package.json +8 -7
  11. package/templates/blank/src/server.ts +0 -5
  12. package/templates/demo/Dockerfile +3 -3
  13. package/templates/demo/_gitignore +2 -1
  14. package/templates/demo/node_modules/.bin/alpic +2 -2
  15. package/templates/demo/node_modules/.bin/tsc +2 -2
  16. package/templates/demo/node_modules/.bin/tsserver +2 -2
  17. package/templates/demo/node_modules/.bin/tsx +2 -2
  18. package/templates/demo/node_modules/.bin/vite +2 -2
  19. package/templates/demo/package.json +17 -17
  20. package/templates/demo/src/server.ts +0 -5
  21. package/templates/ecom/.dockerignore +4 -0
  22. package/templates/ecom/.env.template +2 -0
  23. package/templates/ecom/.ladle/components.tsx +26 -0
  24. package/templates/ecom/.ladle/config.mjs +11 -0
  25. package/templates/ecom/.ladle/vite.config.ts +11 -0
  26. package/templates/ecom/AGENTS.md +2 -0
  27. package/templates/ecom/Dockerfile +53 -0
  28. package/templates/ecom/README.md +92 -0
  29. package/templates/ecom/_gitignore +9 -0
  30. package/templates/ecom/alpic.json +3 -0
  31. package/templates/ecom/node_modules/.bin/alpic +21 -0
  32. package/templates/ecom/node_modules/.bin/ladle +21 -0
  33. package/templates/ecom/node_modules/.bin/sb +21 -0
  34. package/templates/ecom/node_modules/.bin/skybridge +21 -0
  35. package/templates/ecom/node_modules/.bin/tsc +21 -0
  36. package/templates/ecom/node_modules/.bin/tsserver +21 -0
  37. package/templates/ecom/node_modules/.bin/tsx +21 -0
  38. package/templates/ecom/node_modules/.bin/vite +21 -0
  39. package/templates/ecom/package.json +41 -0
  40. package/templates/ecom/src/components/chip.css.ts +56 -0
  41. package/templates/ecom/src/components/chip.stories.tsx +26 -0
  42. package/templates/ecom/src/components/chip.tsx +41 -0
  43. package/templates/ecom/src/components/empty-state.stories.tsx +3 -0
  44. package/templates/ecom/src/components/empty-state.tsx +12 -0
  45. package/templates/ecom/src/components/expandable-text.css.ts +49 -0
  46. package/templates/ecom/src/components/expandable-text.stories.tsx +20 -0
  47. package/templates/ecom/src/components/expandable-text.tsx +53 -0
  48. package/templates/ecom/src/components/image-gallery.css.ts +172 -0
  49. package/templates/ecom/src/components/image-gallery.stories.tsx +30 -0
  50. package/templates/ecom/src/components/image-gallery.tsx +162 -0
  51. package/templates/ecom/src/components/product-card.css.ts +155 -0
  52. package/templates/ecom/src/components/product-card.stories.tsx +58 -0
  53. package/templates/ecom/src/components/product-card.tsx +101 -0
  54. package/templates/ecom/src/components/product-carousel.css.ts +134 -0
  55. package/templates/ecom/src/components/product-carousel.stories.tsx +64 -0
  56. package/templates/ecom/src/components/product-carousel.tsx +202 -0
  57. package/templates/ecom/src/components/variant-picker.css.ts +27 -0
  58. package/templates/ecom/src/components/variant-picker.stories.tsx +64 -0
  59. package/templates/ecom/src/components/variant-picker.tsx +82 -0
  60. package/templates/ecom/src/components/view-frame.css.ts +22 -0
  61. package/templates/ecom/src/components/view-frame.tsx +27 -0
  62. package/templates/ecom/src/config.ts +12 -0
  63. package/templates/ecom/src/design/contract.css.ts +39 -0
  64. package/templates/ecom/src/design/fonts.css +15 -0
  65. package/templates/ecom/src/design/primitives.css.ts +101 -0
  66. package/templates/ecom/src/design/recipes/typography.css.ts +75 -0
  67. package/templates/ecom/src/design/sprinkles.css.ts +128 -0
  68. package/templates/ecom/src/design/themes/dark.css.ts +36 -0
  69. package/templates/ecom/src/design/themes/light.css.ts +36 -0
  70. package/templates/ecom/src/design/tokens.ts +8 -0
  71. package/templates/ecom/src/helpers.ts +4 -0
  72. package/templates/ecom/src/i18n.ts +34 -0
  73. package/templates/ecom/src/index.css +9 -0
  74. package/templates/ecom/src/lib/cx.ts +9 -0
  75. package/templates/ecom/src/lib/format.ts +9 -0
  76. package/templates/ecom/src/lib/variants.ts +79 -0
  77. package/templates/ecom/src/server.ts +43 -0
  78. package/templates/ecom/src/tools/render-carousel.ts +242 -0
  79. package/templates/ecom/src/tools/search-products.ts +182 -0
  80. package/templates/ecom/src/types.ts +13 -0
  81. package/templates/ecom/src/views/carousel/detail/detail.css.ts +100 -0
  82. package/templates/ecom/src/views/carousel/detail/detail.stories.tsx +114 -0
  83. package/templates/ecom/src/views/carousel/detail/index.tsx +215 -0
  84. package/templates/ecom/src/views/carousel/index.tsx +234 -0
  85. package/templates/ecom/tsconfig.json +11 -0
  86. package/templates/ecom/vite.config.ts +8 -0
  87. package/templates/blank/src/vite-manifest.d.ts +0 -4
  88. package/templates/demo/src/vite-manifest.d.ts +0 -4
@@ -0,0 +1,172 @@
1
+ import { globalStyle, style } from "@vanilla-extract/css";
2
+ import { colors, primitives } from "../design/tokens";
3
+
4
+ export const gallery = style({
5
+ position: "relative",
6
+ });
7
+
8
+ // Rail mode only (THUMBNAIL_RAIL): lay the rail beside the image on desktop. The
9
+ // breakpoint matches the PDP's two-column grid and resolves against the same
10
+ // `.detail` container, so the rail appears exactly when the page goes two-column.
11
+ export const galleryRail = style({
12
+ "@container": {
13
+ "(min-width: 560px)": {
14
+ display: "flex",
15
+ flexDirection: "row",
16
+ gap: primitives.space["2xs"],
17
+ // Top-align so the rail sits beside the image; the rail's own max-height
18
+ // (set from the measured image height) caps it and scrolls the excess.
19
+ alignItems: "flex-start",
20
+ },
21
+ },
22
+ });
23
+
24
+ // Image column: the positioning context for the overlaid chevrons, and the flex
25
+ // child that takes the width left of the rail on desktop.
26
+ export const mainCol = style({
27
+ position: "relative",
28
+ minWidth: 0,
29
+ "@container": {
30
+ "(min-width: 560px)": { flex: 1 },
31
+ },
32
+ });
33
+
34
+ // Scroll-snap track: one image per view. Native swipe on touch; the chevrons
35
+ // are the pointer affordance. Scrollbar hidden.
36
+ export const track = style({
37
+ display: "flex",
38
+ overflowX: "auto",
39
+ scrollSnapType: "x mandatory",
40
+ scrollBehavior: "smooth",
41
+ scrollbarWidth: "none",
42
+ borderRadius: primitives.radius.m,
43
+ "@media": {
44
+ "(prefers-reduced-motion: reduce)": { scrollBehavior: "auto" },
45
+ },
46
+ });
47
+
48
+ globalStyle(`${track}::-webkit-scrollbar`, { display: "none" });
49
+
50
+ export const slide = style({
51
+ flex: "0 0 100%",
52
+ scrollSnapAlign: "start",
53
+ // Reserve a square box so images load without shifting the page. @todo: match
54
+ // the carousel card's aspect ratio / fit if you changed them there.
55
+ aspectRatio: "1",
56
+ backgroundColor: colors.surface.subtle,
57
+ });
58
+
59
+ export const image = style({
60
+ width: "100%",
61
+ height: "100%",
62
+ objectFit: "contain",
63
+ display: "block",
64
+ pointerEvents: "none",
65
+ userSelect: "none",
66
+ });
67
+
68
+ // Prev/next chevrons, vertically centered, disabled at the ends.
69
+ export const nav = style({
70
+ position: "absolute",
71
+ top: "50%",
72
+ transform: "translateY(-50%)",
73
+ display: "grid",
74
+ placeItems: "center",
75
+ width: "36px",
76
+ height: "36px",
77
+ padding: 0,
78
+ borderRadius: primitives.radius.full,
79
+ border: `${primitives.stroke.thin} solid ${colors.border.subtle}`,
80
+ backgroundColor: colors.surface.extraLight,
81
+ color: colors.content.intense,
82
+ cursor: "pointer",
83
+ transition: "opacity 150ms ease",
84
+ selectors: {
85
+ "&:disabled": { opacity: 0, pointerEvents: "none" },
86
+ },
87
+ });
88
+
89
+ export const navPrev = style({ left: primitives.space["3xs"] });
90
+ export const navNext = style({ right: primitives.space["3xs"] });
91
+
92
+ // Position indicator: a thin track with a fill sized to (index + 1) / count.
93
+ // @todo: style to your brand — height, track/fill colors, radius, width, and placement.
94
+ export const progress = style({
95
+ height: "3px",
96
+ marginTop: primitives.space["3xs"],
97
+ borderRadius: primitives.radius.full,
98
+ backgroundColor: colors.border.thin,
99
+ overflow: "hidden",
100
+ });
101
+
102
+ export const progressFill = style({
103
+ height: "100%",
104
+ borderRadius: primitives.radius.full,
105
+ backgroundColor: colors.content.intense,
106
+ transition: "width 200ms ease",
107
+ "@media": {
108
+ "(prefers-reduced-motion: reduce)": { transition: "none" },
109
+ },
110
+ });
111
+
112
+ // In rail mode the rail conveys position on desktop, so the progress bar is
113
+ // mobile-only there.
114
+ export const progressMobileOnly = style({
115
+ "@container": {
116
+ "(min-width: 560px)": { display: "none" },
117
+ },
118
+ });
119
+
120
+ // Desktop thumbnail rail (THUMBNAIL_RAIL). Hidden on mobile, where the swipe
121
+ // track + progress bar own navigation. Capped to the image height via an inline
122
+ // max-height and scrolls the excess. @todo: tune the rail width / thumb size.
123
+ export const rail = style({
124
+ display: "none",
125
+ "@container": {
126
+ "(min-width: 560px)": {
127
+ display: "flex",
128
+ flexDirection: "column",
129
+ flexShrink: 0,
130
+ gap: primitives.space["2xs"],
131
+ width: "64px",
132
+ minHeight: 0,
133
+ overflowY: "auto",
134
+ scrollbarWidth: "none",
135
+ },
136
+ },
137
+ });
138
+
139
+ globalStyle(`${rail}::-webkit-scrollbar`, { display: "none" });
140
+
141
+ export const thumb = style({
142
+ boxSizing: "border-box",
143
+ flexShrink: 0,
144
+ width: "100%",
145
+ aspectRatio: "1",
146
+ minHeight: 0, // let aspect-ratio win over the flex-item default min-height
147
+ padding: primitives.space["4xs"],
148
+ borderRadius: primitives.radius.m,
149
+ border: `${primitives.stroke.thin} solid ${colors.border.subtle}`,
150
+ backgroundColor: colors.surface.extraLight,
151
+ cursor: "pointer",
152
+ transition: "border-color 150ms ease",
153
+ "@media": {
154
+ "(prefers-reduced-motion: reduce)": { transition: "none" },
155
+ },
156
+ });
157
+
158
+ // Selected thumb: thicker, accented border. border-box keeps the width swap from
159
+ // shifting the rail layout.
160
+ export const thumbActive = style({
161
+ borderColor: colors.common.accent,
162
+ borderWidth: primitives.stroke.medium,
163
+ });
164
+
165
+ export const thumbImage = style({
166
+ width: "100%",
167
+ height: "100%",
168
+ objectFit: "contain",
169
+ display: "block",
170
+ pointerEvents: "none",
171
+ userSelect: "none",
172
+ });
@@ -0,0 +1,30 @@
1
+ import { ImageGallery } from "./image-gallery";
2
+
3
+ function shot(fill: string) {
4
+ 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%3Ccircle cx='200' cy='200' r='110' fill='%23ffffff' fill-opacity='0.5'/%3E%3C/svg%3E`;
5
+ }
6
+
7
+ // The gallery's desktop layout (and the optional THUMBNAIL_RAIL) query a
8
+ // `container-type` host, which the PDP's `.detail` provides in the app. The
9
+ // story supplies its own so it previews at a realistic width and renders
10
+ // correctly whichever way THUMBNAIL_RAIL is set — swipe when off, rail when on.
11
+ const frame = {
12
+ containerType: "inline-size" as const,
13
+ width: 600,
14
+ maxWidth: "100%",
15
+ };
16
+
17
+ export const Multiple = () => (
18
+ <div style={frame}>
19
+ <ImageGallery
20
+ media={[shot("e1e1e1"), shot("c9d4f5"), shot("f5d4c9")]}
21
+ alt="Product"
22
+ />
23
+ </div>
24
+ );
25
+
26
+ export const Single = () => (
27
+ <div style={frame}>
28
+ <ImageGallery media={[shot("e1e1e1")]} alt="Product" />
29
+ </div>
30
+ );
@@ -0,0 +1,162 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ import { useLabels } from "../i18n";
3
+ import { cx } from "../lib/cx";
4
+ import * as styles from "./image-gallery.css";
5
+
6
+ // @todo: show a thumbnail rail beside the image on desktop (at the two-column
7
+ // breakpoint); swipe-only when false. Off by default. When true, tune the rail
8
+ // width / thumb size in image-gallery.css.ts. The rail is capped to the image
9
+ // height and scrolls its excess; deferred polish (add if it earns it): an
10
+ // edge-fade mask and auto-centering the active thumb.
11
+ const THUMBNAIL_RAIL: boolean = true;
12
+
13
+ function Chevron({ direction }: { direction: "left" | "right" }) {
14
+ const d = direction === "left" ? "M15 18l-6-6 6-6" : "M9 18l6-6-6-6";
15
+ return (
16
+ <svg
17
+ width="20"
18
+ height="20"
19
+ viewBox="0 0 24 24"
20
+ fill="none"
21
+ stroke="currentColor"
22
+ strokeWidth="2"
23
+ strokeLinecap="round"
24
+ strokeLinejoin="round"
25
+ aria-hidden="true"
26
+ >
27
+ <path d={d} />
28
+ </svg>
29
+ );
30
+ }
31
+
32
+ /**
33
+ * Product image gallery: a native scroll-snap track with prev/next chevrons and
34
+ * a progress bar; the current index is read from scroll position (no library).
35
+ * With the rail on, a desktop thumbnail rail is added as a second controller of
36
+ * the SAME track (shared index, click = scroll). Mobile is always the swipe
37
+ * track.
38
+ */
39
+ export function ImageGallery({ media, alt }: { media: string[]; alt: string }) {
40
+ const labels = useLabels();
41
+ const trackRef = useRef<HTMLDivElement>(null);
42
+ const [index, setIndex] = useState(0);
43
+ const [imageHeight, setImageHeight] = useState<number>();
44
+
45
+ function onScroll() {
46
+ const el = trackRef.current;
47
+ if (el) {
48
+ setIndex(Math.round(el.scrollLeft / el.clientWidth));
49
+ }
50
+ }
51
+
52
+ function scrollToIndex(i: number) {
53
+ const el = trackRef.current;
54
+ if (el) {
55
+ el.scrollTo({ left: i * el.clientWidth });
56
+ }
57
+ }
58
+
59
+ // Rail only: cap the rail to the main image's height so its extra thumbnails
60
+ // scroll instead of dangling past the image. A vertical scroll container needs
61
+ // a definite height; the square image provides it, measured here.
62
+ useEffect(() => {
63
+ if (!THUMBNAIL_RAIL) {
64
+ return;
65
+ }
66
+ const el = trackRef.current;
67
+ if (!el) {
68
+ return;
69
+ }
70
+ const measure = () => setImageHeight(el.clientHeight);
71
+ measure();
72
+ const observer = new ResizeObserver(measure);
73
+ observer.observe(el);
74
+ return () => observer.disconnect();
75
+ }, []);
76
+
77
+ const multiple = media.length > 1;
78
+
79
+ return (
80
+ <section
81
+ className={cx(styles.gallery, THUMBNAIL_RAIL && styles.galleryRail)}
82
+ aria-roledescription={labels.carousel}
83
+ aria-label={alt}
84
+ >
85
+ {THUMBNAIL_RAIL && multiple ? (
86
+ <div
87
+ className={styles.rail}
88
+ style={{ maxHeight: imageHeight ? `${imageHeight}px` : undefined }}
89
+ >
90
+ {media.map((src, i) => (
91
+ <button
92
+ key={src}
93
+ type="button"
94
+ className={cx(styles.thumb, i === index && styles.thumbActive)}
95
+ aria-label={`${alt} (${i + 1})`}
96
+ aria-current={i === index}
97
+ onClick={() => scrollToIndex(i)}
98
+ >
99
+ <img
100
+ className={styles.thumbImage}
101
+ src={src}
102
+ alt=""
103
+ draggable={false}
104
+ />
105
+ </button>
106
+ ))}
107
+ </div>
108
+ ) : null}
109
+
110
+ <div className={styles.mainCol}>
111
+ <div ref={trackRef} className={styles.track} onScroll={onScroll}>
112
+ {media.map((src, i) => (
113
+ <div key={src} className={styles.slide}>
114
+ <img
115
+ className={styles.image}
116
+ src={src}
117
+ alt={i === 0 ? alt : ""}
118
+ loading={i === 0 ? "eager" : "lazy"}
119
+ draggable={false}
120
+ />
121
+ </div>
122
+ ))}
123
+ </div>
124
+
125
+ {multiple ? (
126
+ <>
127
+ <button
128
+ type="button"
129
+ aria-label={labels.previous}
130
+ className={cx(styles.nav, styles.navPrev)}
131
+ disabled={index === 0}
132
+ onClick={() => scrollToIndex(index - 1)}
133
+ >
134
+ <Chevron direction="left" />
135
+ </button>
136
+ <button
137
+ type="button"
138
+ aria-label={labels.next}
139
+ className={cx(styles.nav, styles.navNext)}
140
+ disabled={index === media.length - 1}
141
+ onClick={() => scrollToIndex(index + 1)}
142
+ >
143
+ <Chevron direction="right" />
144
+ </button>
145
+ <div
146
+ className={cx(
147
+ styles.progress,
148
+ THUMBNAIL_RAIL && styles.progressMobileOnly,
149
+ )}
150
+ aria-hidden="true"
151
+ >
152
+ <div
153
+ className={styles.progressFill}
154
+ style={{ width: `${((index + 1) / media.length) * 100}%` }}
155
+ />
156
+ </div>
157
+ </>
158
+ ) : null}
159
+ </div>
160
+ </section>
161
+ );
162
+ }
@@ -0,0 +1,155 @@
1
+ import { keyframes, style } from "@vanilla-extract/css";
2
+ import { recipe } from "@vanilla-extract/recipes";
3
+ import { colors, primitives } from "../design/tokens";
4
+
5
+ // @todo: number of title lines before it truncates with an ellipsis. Exported
6
+ // so the skeleton reserves the same number of lines.
7
+ export const TITLE_LINES = 2;
8
+
9
+ // `framed: true` gives each card its own container; the default is a plain
10
+ // layout shell (pair it with a framed carousel instead). Pick one, not both.
11
+ export const card = recipe({
12
+ base: {
13
+ display: "flex",
14
+ flexDirection: "column",
15
+ gap: primitives.space["3xs"],
16
+ width: "100%",
17
+ textAlign: "left",
18
+ },
19
+ variants: {
20
+ framed: {
21
+ // @todo: tune the card container to your brand.
22
+ true: {
23
+ padding: primitives.space["3xs"],
24
+ borderRadius: primitives.radius.m,
25
+ border: `${primitives.stroke.thin} solid ${colors.border.thin}`,
26
+ backgroundColor: colors.surface.extraLight,
27
+ },
28
+ false: {},
29
+ },
30
+ },
31
+ defaultVariants: { framed: false },
32
+ });
33
+
34
+ // Turns a whole card into one tap target (opens the detail view) using the
35
+ // stretched-link pattern: the card renders normally, and a transparent <button>
36
+ // overlays it. A real button (not role="button") gives keyboard + screen-reader
37
+ // support for free, and it holds no flow content, so the markup stays valid
38
+ // (a <button> wrapping the card's <article>/<p> would not be).
39
+ export const cardClickable = style({ position: "relative" });
40
+
41
+ export const cardButton = style({
42
+ position: "absolute",
43
+ inset: 0,
44
+ width: "100%",
45
+ height: "100%",
46
+ padding: 0,
47
+ border: "none",
48
+ background: "none",
49
+ cursor: "pointer",
50
+ borderRadius: primitives.radius.m,
51
+ });
52
+
53
+ export const imageBox = style({
54
+ position: "relative",
55
+ aspectRatio: "1",
56
+ overflow: "hidden",
57
+ borderRadius: primitives.radius.m,
58
+ // Stage behind the product image. @todo: pick the surface token that suits
59
+ // your imagery (a neutral grey for transparent cutouts, `extraLight`/white
60
+ // for full-bleed photos).
61
+ backgroundColor: colors.surface.subtle,
62
+ });
63
+
64
+ export const image = style({
65
+ width: "100%",
66
+ height: "100%",
67
+ // @todo: `contain` never crops; switch to `cover` for uniform, bleed-friendly
68
+ // cutout images.
69
+ objectFit: "contain",
70
+ display: "block",
71
+ // Keep image drag from hijacking the swipe/scroll gesture.
72
+ pointerEvents: "none",
73
+ userSelect: "none",
74
+ });
75
+
76
+ export const imageDimmed = style({ opacity: 0.5 });
77
+
78
+ export const placeholder = style({
79
+ width: "100%",
80
+ height: "100%",
81
+ backgroundColor: colors.surface.subtle,
82
+ });
83
+
84
+ export const oosBadge = style({
85
+ position: "absolute",
86
+ top: primitives.space["3xs"],
87
+ left: primitives.space["3xs"],
88
+ padding: `${primitives.space["5xs"]} ${primitives.space["3xs"]}`,
89
+ borderRadius: primitives.radius.s,
90
+ backgroundColor: colors.surface.extraLight,
91
+ color: colors.content.intense,
92
+ fontFamily: primitives.font.family.primary,
93
+ fontSize: primitives.font.size.xs,
94
+ });
95
+
96
+ export const body = style({
97
+ display: "flex",
98
+ flexDirection: "column",
99
+ gap: primitives.space["5xs"],
100
+ });
101
+
102
+ export const title = style({
103
+ color: colors.content.intense,
104
+ display: "-webkit-box",
105
+ WebkitLineClamp: TITLE_LINES,
106
+ WebkitBoxOrient: "vertical",
107
+ overflow: "hidden",
108
+ // Reserve the clamp height (title line-height is 1.5) so prices line up
109
+ // across cards whatever the title length.
110
+ minHeight: `calc(${TITLE_LINES} * 1.5em)`,
111
+ });
112
+
113
+ export const price = style({ color: colors.content.subtle });
114
+
115
+ // Skeleton (loading state).
116
+ const pulse = keyframes({
117
+ "0%": { opacity: 1 },
118
+ "50%": { opacity: 0.4 },
119
+ "100%": { opacity: 1 },
120
+ });
121
+
122
+ export const skeletonBox = style({
123
+ backgroundColor: colors.surface.subtle,
124
+ borderRadius: primitives.radius.s,
125
+ animation: `${pulse} 1.5s ease-in-out infinite`,
126
+ "@media": {
127
+ "(prefers-reduced-motion: reduce)": { animation: "none" },
128
+ },
129
+ });
130
+
131
+ export const skeletonImage = style({
132
+ aspectRatio: "1",
133
+ borderRadius: primitives.radius.m,
134
+ });
135
+
136
+ // Text rows (title lines + price), evenly spaced. Its own container rather than
137
+ // `body` so the skeleton can breathe a little more without moving the real card.
138
+ export const skeletonBody = style({
139
+ display: "flex",
140
+ flexDirection: "column",
141
+ gap: primitives.space["4xs"],
142
+ });
143
+
144
+ export const skeletonLine = style({ height: primitives.font.size.m });
145
+
146
+ // Last title line and the price row are stubbed short, the way text ends.
147
+ export const skeletonLineShort = style({
148
+ height: primitives.font.size.m,
149
+ width: "60%",
150
+ });
151
+
152
+ export const skeletonPrice = style({
153
+ height: primitives.font.size.m,
154
+ width: "40%",
155
+ });
@@ -0,0 +1,58 @@
1
+ import { ProductCard, ProductCardSkeleton } from "./product-card";
2
+
3
+ const IMAGE =
4
+ "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Crect width='240' height='240' fill='%23e5e5e5'/%3E%3Ccircle cx='120' cy='120' r='70' fill='%23bcbcbc'/%3E%3C/svg%3E";
5
+
6
+ const frame = { maxWidth: 220 };
7
+
8
+ export const Default = () => (
9
+ <div style={frame}>
10
+ <ProductCard
11
+ title="Merino wool sweater"
12
+ price={{ amount: 129.9, currency: "EUR" }}
13
+ media={[IMAGE]}
14
+ />
15
+ </div>
16
+ );
17
+
18
+ export const LongTitle = () => (
19
+ <div style={frame}>
20
+ <ProductCard
21
+ title="Extra long product title that wraps onto two lines and then clamps"
22
+ price={{ amount: 1290, currency: "USD" }}
23
+ media={[IMAGE]}
24
+ />
25
+ </div>
26
+ );
27
+
28
+ export const NoImage = () => (
29
+ <div style={frame}>
30
+ <ProductCard
31
+ title="Product without an image"
32
+ price={{ amount: 49, currency: "EUR" }}
33
+ />
34
+ </div>
35
+ );
36
+
37
+ export const NoPrice = () => (
38
+ <div style={frame}>
39
+ <ProductCard title="Price on request" media={[IMAGE]} />
40
+ </div>
41
+ );
42
+
43
+ export const OutOfStock = () => (
44
+ <div style={frame}>
45
+ <ProductCard
46
+ title="Sold out product"
47
+ price={{ amount: 89, currency: "EUR" }}
48
+ media={[IMAGE]}
49
+ outOfStock
50
+ />
51
+ </div>
52
+ );
53
+
54
+ export const Skeleton = () => (
55
+ <div style={frame}>
56
+ <ProductCardSkeleton />
57
+ </div>
58
+ );
@@ -0,0 +1,101 @@
1
+ import type { ReactNode } from "react";
2
+ import { useUser } from "skybridge/web";
3
+ import { text } from "../design/tokens";
4
+ import { useLabels } from "../i18n";
5
+ import { cx } from "../lib/cx";
6
+ import { formatPrice } from "../lib/format";
7
+ import type { Price } from "../types.js";
8
+ import * as styles from "./product-card.css";
9
+
10
+ type ProductCardProps = {
11
+ title: string;
12
+ price?: Price;
13
+ media?: string[]; // all images; the card decides which to show
14
+ outOfStock?: boolean;
15
+ };
16
+
17
+ // @todo: for boxed cards (border + background), set this to true and leave the
18
+ // carousel unframed. Pick one, not both.
19
+ const FRAMED = false;
20
+
21
+ /**
22
+ * A single product card: image, title, price, and an out-of-stock treatment.
23
+ * Maps a product's display fields to markup; the view passes them in.
24
+ */
25
+ export function ProductCard({
26
+ title,
27
+ price,
28
+ media,
29
+ outOfStock,
30
+ }: ProductCardProps) {
31
+ const { locale } = useUser();
32
+ const labels = useLabels();
33
+ // Show the first image. @todo: the rest of `media` is available here, e.g.
34
+ // to cross-fade to media[1] on hover.
35
+ const cover = media?.[0];
36
+ return (
37
+ <article className={styles.card({ framed: FRAMED })}>
38
+ <div className={styles.imageBox}>
39
+ {cover ? (
40
+ <img
41
+ className={cx(styles.image, outOfStock && styles.imageDimmed)}
42
+ src={cover}
43
+ alt={title}
44
+ loading="lazy"
45
+ draggable={false}
46
+ />
47
+ ) : (
48
+ <div className={styles.placeholder} />
49
+ )}
50
+ {outOfStock ? (
51
+ <span className={styles.oosBadge}>{labels.outOfStock}</span>
52
+ ) : null}
53
+ </div>
54
+
55
+ <div className={styles.body}>
56
+ <p
57
+ className={cx(
58
+ text({ style: "bodyS", weight: "medium" }),
59
+ styles.title,
60
+ )}
61
+ >
62
+ {title}
63
+ </p>
64
+ {price ? (
65
+ <p className={cx(text({ style: "bodyS" }), styles.price)}>
66
+ {formatPrice(price, locale)}
67
+ </p>
68
+ ) : null}
69
+ {/* @todo: extra fields. Render catalog-specific data here, e.g. from the
70
+ product's `attributes`: ratings, discounts, tags, badges. */}
71
+ </div>
72
+ </article>
73
+ );
74
+ }
75
+
76
+ /** Placeholder card shown while the tool resolves. Same footprint as the card
77
+ * so the layout does not jump when data arrives. */
78
+ export function ProductCardSkeleton() {
79
+ const titleLines: ReactNode[] = [];
80
+ for (let i = 0; i < styles.TITLE_LINES; i++) {
81
+ const isLast = i === styles.TITLE_LINES - 1;
82
+ titleLines.push(
83
+ <div
84
+ key={i}
85
+ className={cx(
86
+ styles.skeletonBox,
87
+ isLast ? styles.skeletonLineShort : styles.skeletonLine,
88
+ )}
89
+ />,
90
+ );
91
+ }
92
+ return (
93
+ <div className={styles.card({ framed: FRAMED })} aria-hidden="true">
94
+ <div className={cx(styles.skeletonBox, styles.skeletonImage)} />
95
+ <div className={styles.skeletonBody}>
96
+ {titleLines}
97
+ <div className={cx(styles.skeletonBox, styles.skeletonPrice)} />
98
+ </div>
99
+ </div>
100
+ );
101
+ }