create-skybridge 0.0.0-dev.356dbec → 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 (150) hide show
  1. package/dist/index.js +353 -157
  2. package/package.json +9 -7
  3. package/templates/blank/.dockerignore +4 -0
  4. package/templates/blank/AGENTS.md +1 -0
  5. package/templates/blank/Dockerfile +53 -0
  6. package/templates/blank/README.md +92 -0
  7. package/templates/blank/_gitignore +7 -0
  8. package/templates/blank/alpic.json +3 -0
  9. package/templates/blank/node_modules/.bin/alpic +21 -0
  10. package/templates/blank/node_modules/.bin/sb +21 -0
  11. package/templates/blank/node_modules/.bin/skybridge +21 -0
  12. package/templates/blank/node_modules/.bin/tsc +21 -0
  13. package/templates/blank/node_modules/.bin/tsserver +21 -0
  14. package/templates/blank/node_modules/.bin/tsx +21 -0
  15. package/templates/blank/node_modules/.bin/vite +21 -0
  16. package/templates/blank/package.json +29 -0
  17. package/templates/blank/src/helpers.ts +4 -0
  18. package/templates/blank/src/server.ts +16 -0
  19. package/templates/blank/tsconfig.json +5 -0
  20. package/templates/blank/vite.config.ts +6 -0
  21. package/templates/demo/.dockerignore +4 -0
  22. package/templates/demo/AGENTS.md +1 -0
  23. package/templates/demo/Dockerfile +53 -0
  24. package/templates/demo/README.md +95 -0
  25. package/templates/demo/_gitignore +7 -0
  26. package/templates/demo/alpic.json +3 -0
  27. package/templates/demo/node_modules/.bin/alpic +21 -0
  28. package/templates/demo/node_modules/.bin/sb +21 -0
  29. package/templates/demo/node_modules/.bin/skybridge +21 -0
  30. package/templates/demo/node_modules/.bin/tsc +21 -0
  31. package/templates/demo/node_modules/.bin/tsserver +21 -0
  32. package/templates/demo/node_modules/.bin/tsx +21 -0
  33. package/templates/demo/node_modules/.bin/vite +21 -0
  34. package/templates/demo/package.json +41 -0
  35. package/templates/demo/src/helpers.ts +4 -0
  36. package/templates/demo/src/index.css +59 -0
  37. package/templates/demo/src/server.ts +94 -0
  38. package/templates/demo/src/views/components/doc-link.tsx +22 -0
  39. package/templates/demo/src/views/components/doc.tsx +21 -0
  40. package/templates/demo/src/views/components/nav.tsx +31 -0
  41. package/templates/demo/src/views/components/progress.tsx +35 -0
  42. package/templates/demo/src/views/components/steps/outro.tsx +68 -0
  43. package/templates/demo/src/views/components/steps/state.tsx +47 -0
  44. package/templates/demo/src/views/components/steps/tool-call.tsx +53 -0
  45. package/templates/demo/src/views/components/steps/tool-output.tsx +40 -0
  46. package/templates/demo/src/views/images/mascot/beret.png +0 -0
  47. package/templates/demo/src/views/images/mascot/chapka.png +0 -0
  48. package/templates/demo/src/views/images/mascot/cowboy-hat.png +0 -0
  49. package/templates/demo/src/views/images/mascot/fez.png +0 -0
  50. package/templates/demo/src/views/images/mascot/jester-hat.png +0 -0
  51. package/templates/demo/src/views/images/mascot/mitre.png +0 -0
  52. package/templates/demo/src/views/images/mascot/non-la.png +0 -0
  53. package/templates/demo/src/views/images/mascot/original.png +0 -0
  54. package/templates/demo/src/views/images/mascot/propeller-beanie.png +0 -0
  55. package/templates/demo/src/views/images/mascot/ski-mask.png +0 -0
  56. package/templates/demo/src/views/images/mascot/sombrero.png +0 -0
  57. package/templates/demo/src/views/images/mascot/top-hat.png +0 -0
  58. package/templates/demo/src/views/images/mascot/viking-helmet.png +0 -0
  59. package/templates/demo/src/views/onboarding.tsx +63 -0
  60. package/templates/demo/src/views/use-mascot.ts +60 -0
  61. package/templates/demo/tsconfig.json +11 -0
  62. package/{template/web → templates/demo}/vite.config.ts +3 -4
  63. package/templates/ecom/.dockerignore +4 -0
  64. package/templates/ecom/.env.template +2 -0
  65. package/templates/ecom/.ladle/components.tsx +26 -0
  66. package/templates/ecom/.ladle/config.mjs +11 -0
  67. package/templates/ecom/.ladle/vite.config.ts +11 -0
  68. package/templates/ecom/AGENTS.md +2 -0
  69. package/templates/ecom/Dockerfile +53 -0
  70. package/templates/ecom/README.md +92 -0
  71. package/templates/ecom/_gitignore +9 -0
  72. package/templates/ecom/alpic.json +3 -0
  73. package/templates/ecom/node_modules/.bin/alpic +21 -0
  74. package/templates/ecom/node_modules/.bin/ladle +21 -0
  75. package/templates/ecom/node_modules/.bin/sb +21 -0
  76. package/templates/ecom/node_modules/.bin/skybridge +21 -0
  77. package/templates/ecom/node_modules/.bin/tsc +21 -0
  78. package/templates/ecom/node_modules/.bin/tsserver +21 -0
  79. package/templates/ecom/node_modules/.bin/tsx +21 -0
  80. package/templates/ecom/node_modules/.bin/vite +21 -0
  81. package/templates/ecom/package.json +41 -0
  82. package/templates/ecom/src/components/chip.css.ts +56 -0
  83. package/templates/ecom/src/components/chip.stories.tsx +26 -0
  84. package/templates/ecom/src/components/chip.tsx +41 -0
  85. package/templates/ecom/src/components/empty-state.stories.tsx +3 -0
  86. package/templates/ecom/src/components/empty-state.tsx +12 -0
  87. package/templates/ecom/src/components/expandable-text.css.ts +49 -0
  88. package/templates/ecom/src/components/expandable-text.stories.tsx +20 -0
  89. package/templates/ecom/src/components/expandable-text.tsx +53 -0
  90. package/templates/ecom/src/components/image-gallery.css.ts +172 -0
  91. package/templates/ecom/src/components/image-gallery.stories.tsx +30 -0
  92. package/templates/ecom/src/components/image-gallery.tsx +162 -0
  93. package/templates/ecom/src/components/product-card.css.ts +155 -0
  94. package/templates/ecom/src/components/product-card.stories.tsx +58 -0
  95. package/templates/ecom/src/components/product-card.tsx +101 -0
  96. package/templates/ecom/src/components/product-carousel.css.ts +134 -0
  97. package/templates/ecom/src/components/product-carousel.stories.tsx +64 -0
  98. package/templates/ecom/src/components/product-carousel.tsx +202 -0
  99. package/templates/ecom/src/components/variant-picker.css.ts +27 -0
  100. package/templates/ecom/src/components/variant-picker.stories.tsx +64 -0
  101. package/templates/ecom/src/components/variant-picker.tsx +82 -0
  102. package/templates/ecom/src/components/view-frame.css.ts +22 -0
  103. package/templates/ecom/src/components/view-frame.tsx +27 -0
  104. package/templates/ecom/src/config.ts +12 -0
  105. package/templates/ecom/src/design/contract.css.ts +39 -0
  106. package/templates/ecom/src/design/fonts.css +15 -0
  107. package/templates/ecom/src/design/primitives.css.ts +101 -0
  108. package/templates/ecom/src/design/recipes/typography.css.ts +75 -0
  109. package/templates/ecom/src/design/sprinkles.css.ts +128 -0
  110. package/templates/ecom/src/design/themes/dark.css.ts +36 -0
  111. package/templates/ecom/src/design/themes/light.css.ts +36 -0
  112. package/templates/ecom/src/design/tokens.ts +8 -0
  113. package/templates/ecom/src/helpers.ts +4 -0
  114. package/templates/ecom/src/i18n.ts +34 -0
  115. package/templates/ecom/src/index.css +9 -0
  116. package/templates/ecom/src/lib/cx.ts +9 -0
  117. package/templates/ecom/src/lib/format.ts +9 -0
  118. package/templates/ecom/src/lib/variants.ts +79 -0
  119. package/templates/ecom/src/server.ts +43 -0
  120. package/templates/ecom/src/tools/render-carousel.ts +242 -0
  121. package/templates/ecom/src/tools/search-products.ts +182 -0
  122. package/templates/ecom/src/types.ts +13 -0
  123. package/templates/ecom/src/views/carousel/detail/detail.css.ts +100 -0
  124. package/templates/ecom/src/views/carousel/detail/detail.stories.tsx +114 -0
  125. package/templates/ecom/src/views/carousel/detail/index.tsx +215 -0
  126. package/templates/ecom/src/views/carousel/index.tsx +234 -0
  127. package/templates/ecom/tsconfig.json +11 -0
  128. package/templates/ecom/vite.config.ts +8 -0
  129. package/dist/index.test.d.ts +0 -1
  130. package/dist/index.test.js +0 -23
  131. package/template/README.md +0 -77
  132. package/template/_gitignore +0 -4
  133. package/template/alpic.json +0 -4
  134. package/template/node_modules/.bin/mcp-inspector +0 -21
  135. package/template/node_modules/.bin/nodemon +0 -21
  136. package/template/node_modules/.bin/shx +0 -21
  137. package/template/node_modules/.bin/tsc +0 -21
  138. package/template/node_modules/.bin/tsserver +0 -21
  139. package/template/node_modules/.bin/tsx +0 -21
  140. package/template/node_modules/.bin/vite +0 -21
  141. package/template/nodemon.json +0 -5
  142. package/template/package.json +0 -42
  143. package/template/server/src/index.ts +0 -39
  144. package/template/server/src/middleware.ts +0 -54
  145. package/template/server/src/server.ts +0 -61
  146. package/template/tsconfig.json +0 -23
  147. package/template/tsconfig.server.json +0 -11
  148. package/template/web/src/helpers.ts +0 -4
  149. package/template/web/src/index.css +0 -31
  150. package/template/web/src/widgets/magic-8-ball.tsx +0 -24
@@ -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
+ }
@@ -0,0 +1,134 @@
1
+ import { globalStyle, style } from "@vanilla-extract/css";
2
+ import { recipe } from "@vanilla-extract/recipes";
3
+ import { colors, primitives } from "../design/tokens";
4
+
5
+ // Carousel tuning knobs. @todo: tune to your card design.
6
+ const gap = primitives.space["2xs"]; // gap between cards
7
+ // Cards visible at each width; the fractional part is the peek that signals the
8
+ // row scrolls. If you change a count, adjust the gap multiplier in its
9
+ // `--card-width` calc (full gaps visible = the whole-number part).
10
+ const CARDS_VISIBLE = 2.5;
11
+ const CARDS_VISIBLE_COMPACT = 1.5;
12
+ // Below this container width, switch to the compact count.
13
+ const COMPACT_MAX_WIDTH = "560px";
14
+
15
+ // Structural wrapper (kept as a plain class so the nav-reveal globalStyle below
16
+ // can target it). The recipe composes it as its base.
17
+ const carouselBase = style({
18
+ position: "relative",
19
+ // Size cards against the carousel width, not the iframe viewport.
20
+ containerType: "inline-size",
21
+ });
22
+
23
+ // `framed: true` frames the whole carousel; the default is flush (pair it with
24
+ // framed cards instead). Pick one of the two.
25
+ export const carousel = recipe({
26
+ base: carouselBase,
27
+ variants: {
28
+ framed: {
29
+ // @todo: tune the outer frame to your brand. Soften the shadow in dark
30
+ // mode if the strip reads as a hard box against the host.
31
+ true: {
32
+ // Pad top/bottom only; the leading/trailing inset lives on the track's
33
+ // own `framed` variant so it scrolls away. Cards bleed to the left/right
34
+ // border, and `overflow: hidden` masks them to the rounded corners, so
35
+ // a scrolled card disappears exactly at the frame edge.
36
+ paddingBlock: primitives.space.xs,
37
+ borderRadius: primitives.radius.l,
38
+ border: `${primitives.stroke.thin} solid ${colors.border.thin}`,
39
+ backgroundColor: colors.surface.extraLight,
40
+ boxShadow: "0 10px 20px -20px rgba(0, 0, 0, 0.18)",
41
+ overflow: "hidden",
42
+ },
43
+ false: {},
44
+ },
45
+ },
46
+ defaultVariants: { framed: false },
47
+ });
48
+
49
+ // Kept as a plain class so the scrollbar-hiding globalStyle below can target it.
50
+ // The recipe composes it as its base.
51
+ const trackBase = style({
52
+ display: "flex",
53
+ gap,
54
+ overflowX: "auto",
55
+ scrollSnapType: "x mandatory",
56
+ scrollBehavior: "smooth",
57
+ scrollbarWidth: "none",
58
+ vars: { "--card-width": `calc((100% - 2 * ${gap}) / ${CARDS_VISIBLE})` },
59
+ "@container": {
60
+ [`(max-width: ${COMPACT_MAX_WIDTH})`]: {
61
+ vars: {
62
+ "--card-width": `calc((100% - ${gap}) / ${CARDS_VISIBLE_COMPACT})`,
63
+ },
64
+ },
65
+ },
66
+ "@media": {
67
+ "(prefers-reduced-motion: reduce)": { scrollBehavior: "auto" },
68
+ },
69
+ });
70
+
71
+ globalStyle(`${trackBase}::-webkit-scrollbar`, { display: "none" });
72
+
73
+ // `framed: true` adds an inset on both ends. Padding on the scroll track (not on
74
+ // the frame) so it shows before the first card and after the last at rest, but
75
+ // scrolls away in between: a card scrolled past clips at the border, not at a
76
+ // fixed gutter. scroll-padding keeps mandatory snap from collapsing the inset.
77
+ export const track = recipe({
78
+ base: trackBase,
79
+ variants: {
80
+ framed: {
81
+ true: {
82
+ paddingInline: primitives.space.xs,
83
+ scrollPaddingInline: primitives.space.xs,
84
+ },
85
+ false: {},
86
+ },
87
+ // Skeleton state: lock the scroll, there is nothing to scroll to yet.
88
+ loading: {
89
+ true: { overflowX: "hidden" },
90
+ false: {},
91
+ },
92
+ },
93
+ defaultVariants: { framed: false, loading: false },
94
+ });
95
+
96
+ export const cell = style({
97
+ flex: "0 0 var(--card-width)",
98
+ scrollSnapAlign: "start",
99
+ });
100
+
101
+ // Prev/next buttons: desktop only. Hidden on touch, revealed on hover/focus,
102
+ // disabled at the scroll ends.
103
+ export const nav = style({
104
+ position: "absolute",
105
+ top: "50%",
106
+ transform: "translateY(-50%)",
107
+ display: "grid",
108
+ placeItems: "center",
109
+ width: "36px",
110
+ height: "36px",
111
+ padding: 0,
112
+ borderRadius: primitives.radius.full,
113
+ border: `${primitives.stroke.thin} solid ${colors.border.subtle}`,
114
+ backgroundColor: colors.surface.extraLight,
115
+ color: colors.content.intense,
116
+ cursor: "pointer",
117
+ opacity: 0,
118
+ transition: "opacity 150ms ease",
119
+ selectors: {
120
+ "&:disabled": { opacity: 0, pointerEvents: "none" },
121
+ },
122
+ "@media": {
123
+ "(hover: none)": { display: "none" },
124
+ },
125
+ });
126
+
127
+ export const navPrev = style({ left: primitives.space["3xs"] });
128
+ export const navNext = style({ right: primitives.space["3xs"] });
129
+
130
+ // Reveal the (enabled) buttons on hover or keyboard focus within the carousel.
131
+ globalStyle(
132
+ `${carouselBase}:hover ${nav}:not(:disabled), ${carouselBase}:focus-within ${nav}:not(:disabled)`,
133
+ { opacity: 1 },
134
+ );
@@ -0,0 +1,64 @@
1
+ import type { ReactNode } from "react";
2
+ import type { Price } from "../types.js";
3
+ import { ProductCard, ProductCardSkeleton } from "./product-card";
4
+ import { ProductCarousel } from "./product-carousel";
5
+
6
+ const IMAGE =
7
+ "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";
8
+
9
+ type Sample = { title: string; price: Price; outOfStock?: boolean };
10
+
11
+ const SAMPLE: Sample[] = [
12
+ { title: "Merino wool sweater", price: { amount: 129.9, currency: "EUR" } },
13
+ { title: "Oxford cotton shirt", price: { amount: 79, currency: "EUR" } },
14
+ { title: "Slim chino trousers", price: { amount: 89.5, currency: "EUR" } },
15
+ {
16
+ title: "Leather derby shoes",
17
+ price: { amount: 210, currency: "EUR" },
18
+ outOfStock: true,
19
+ },
20
+ { title: "Cashmere scarf", price: { amount: 145, currency: "EUR" } },
21
+ { title: "Quilted field jacket", price: { amount: 320, currency: "EUR" } },
22
+ ];
23
+
24
+ function sampleCards(): ReactNode[] {
25
+ const cards: ReactNode[] = [];
26
+ for (let i = 0; i < SAMPLE.length; i++) {
27
+ const item = SAMPLE[i];
28
+ cards.push(
29
+ <ProductCard
30
+ key={i}
31
+ title={item.title}
32
+ price={item.price}
33
+ media={[IMAGE]}
34
+ outOfStock={item.outOfStock}
35
+ />,
36
+ );
37
+ }
38
+ return cards;
39
+ }
40
+
41
+ export const Default = () => <ProductCarousel>{sampleCards()}</ProductCarousel>;
42
+
43
+ export const Loading = () => {
44
+ const skeletons: ReactNode[] = [];
45
+ for (let i = 0; i < 4; i++) {
46
+ skeletons.push(<ProductCardSkeleton key={i} />);
47
+ }
48
+ return <ProductCarousel loading>{skeletons}</ProductCarousel>;
49
+ };
50
+
51
+ export const FewItems = () => (
52
+ <ProductCarousel>
53
+ <ProductCard
54
+ title="Merino wool sweater"
55
+ price={{ amount: 129.9, currency: "EUR" }}
56
+ media={[IMAGE]}
57
+ />
58
+ <ProductCard
59
+ title="Oxford cotton shirt"
60
+ price={{ amount: 79, currency: "EUR" }}
61
+ media={[IMAGE]}
62
+ />
63
+ </ProductCarousel>
64
+ );