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.
- package/dist/index.js +353 -157
- package/package.json +9 -7
- package/templates/blank/.dockerignore +4 -0
- package/templates/blank/AGENTS.md +1 -0
- package/templates/blank/Dockerfile +53 -0
- package/templates/blank/README.md +92 -0
- package/templates/blank/_gitignore +7 -0
- package/templates/blank/alpic.json +3 -0
- package/templates/blank/node_modules/.bin/alpic +21 -0
- package/templates/blank/node_modules/.bin/sb +21 -0
- package/templates/blank/node_modules/.bin/skybridge +21 -0
- package/templates/blank/node_modules/.bin/tsc +21 -0
- package/templates/blank/node_modules/.bin/tsserver +21 -0
- package/templates/blank/node_modules/.bin/tsx +21 -0
- package/templates/blank/node_modules/.bin/vite +21 -0
- package/templates/blank/package.json +29 -0
- package/templates/blank/src/helpers.ts +4 -0
- package/templates/blank/src/server.ts +16 -0
- package/templates/blank/tsconfig.json +5 -0
- package/templates/blank/vite.config.ts +6 -0
- package/templates/demo/.dockerignore +4 -0
- package/templates/demo/AGENTS.md +1 -0
- package/templates/demo/Dockerfile +53 -0
- package/templates/demo/README.md +95 -0
- package/templates/demo/_gitignore +7 -0
- package/templates/demo/alpic.json +3 -0
- package/templates/demo/node_modules/.bin/alpic +21 -0
- package/templates/demo/node_modules/.bin/sb +21 -0
- package/templates/demo/node_modules/.bin/skybridge +21 -0
- package/templates/demo/node_modules/.bin/tsc +21 -0
- package/templates/demo/node_modules/.bin/tsserver +21 -0
- package/templates/demo/node_modules/.bin/tsx +21 -0
- package/templates/demo/node_modules/.bin/vite +21 -0
- package/templates/demo/package.json +41 -0
- package/templates/demo/src/helpers.ts +4 -0
- package/templates/demo/src/index.css +59 -0
- package/templates/demo/src/server.ts +94 -0
- package/templates/demo/src/views/components/doc-link.tsx +22 -0
- package/templates/demo/src/views/components/doc.tsx +21 -0
- package/templates/demo/src/views/components/nav.tsx +31 -0
- package/templates/demo/src/views/components/progress.tsx +35 -0
- package/templates/demo/src/views/components/steps/outro.tsx +68 -0
- package/templates/demo/src/views/components/steps/state.tsx +47 -0
- package/templates/demo/src/views/components/steps/tool-call.tsx +53 -0
- package/templates/demo/src/views/components/steps/tool-output.tsx +40 -0
- package/templates/demo/src/views/images/mascot/beret.png +0 -0
- package/templates/demo/src/views/images/mascot/chapka.png +0 -0
- package/templates/demo/src/views/images/mascot/cowboy-hat.png +0 -0
- package/templates/demo/src/views/images/mascot/fez.png +0 -0
- package/templates/demo/src/views/images/mascot/jester-hat.png +0 -0
- package/templates/demo/src/views/images/mascot/mitre.png +0 -0
- package/templates/demo/src/views/images/mascot/non-la.png +0 -0
- package/templates/demo/src/views/images/mascot/original.png +0 -0
- package/templates/demo/src/views/images/mascot/propeller-beanie.png +0 -0
- package/templates/demo/src/views/images/mascot/ski-mask.png +0 -0
- package/templates/demo/src/views/images/mascot/sombrero.png +0 -0
- package/templates/demo/src/views/images/mascot/top-hat.png +0 -0
- package/templates/demo/src/views/images/mascot/viking-helmet.png +0 -0
- package/templates/demo/src/views/onboarding.tsx +63 -0
- package/templates/demo/src/views/use-mascot.ts +60 -0
- package/templates/demo/tsconfig.json +11 -0
- package/{template/web → templates/demo}/vite.config.ts +3 -4
- package/templates/ecom/.dockerignore +4 -0
- package/templates/ecom/.env.template +2 -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 +41 -0
- package/templates/ecom/src/components/chip.css.ts +56 -0
- package/templates/ecom/src/components/chip.stories.tsx +26 -0
- package/templates/ecom/src/components/chip.tsx +41 -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 +162 -0
- package/templates/ecom/src/components/product-card.css.ts +155 -0
- package/templates/ecom/src/components/product-card.stories.tsx +58 -0
- package/templates/ecom/src/components/product-card.tsx +101 -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 +64 -0
- package/templates/ecom/src/components/variant-picker.tsx +82 -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 +34 -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 +79 -0
- package/templates/ecom/src/server.ts +43 -0
- package/templates/ecom/src/tools/render-carousel.ts +242 -0
- package/templates/ecom/src/tools/search-products.ts +182 -0
- package/templates/ecom/src/types.ts +13 -0
- package/templates/ecom/src/views/carousel/detail/detail.css.ts +100 -0
- package/templates/ecom/src/views/carousel/detail/detail.stories.tsx +114 -0
- package/templates/ecom/src/views/carousel/detail/index.tsx +215 -0
- package/templates/ecom/src/views/carousel/index.tsx +234 -0
- package/templates/ecom/tsconfig.json +11 -0
- package/templates/ecom/vite.config.ts +8 -0
- package/dist/index.test.d.ts +0 -1
- package/dist/index.test.js +0 -23
- package/template/README.md +0 -77
- package/template/_gitignore +0 -4
- package/template/alpic.json +0 -4
- package/template/node_modules/.bin/mcp-inspector +0 -21
- package/template/node_modules/.bin/nodemon +0 -21
- package/template/node_modules/.bin/shx +0 -21
- package/template/node_modules/.bin/tsc +0 -21
- package/template/node_modules/.bin/tsserver +0 -21
- package/template/node_modules/.bin/tsx +0 -21
- package/template/node_modules/.bin/vite +0 -21
- package/template/nodemon.json +0 -5
- package/template/package.json +0 -42
- package/template/server/src/index.ts +0 -39
- package/template/server/src/middleware.ts +0 -54
- package/template/server/src/server.ts +0 -61
- package/template/tsconfig.json +0 -23
- package/template/tsconfig.server.json +0 -11
- package/template/web/src/helpers.ts +0 -4
- package/template/web/src/index.css +0 -31
- package/template/web/src/widgets/magic-8-ball.tsx +0 -24
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as styles from "./chip.css";
|
|
2
|
+
|
|
3
|
+
type ChipProps = {
|
|
4
|
+
label: string;
|
|
5
|
+
selected?: boolean;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
onSelect?: () => void;
|
|
8
|
+
// Optional swatch image (e.g. one per color); omit for a plain text chip.
|
|
9
|
+
media?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* One option value as a selectable pill. Rendered as a `radio` inside the
|
|
14
|
+
* variant picker's `radiogroup`; the picker owns selection state and passes
|
|
15
|
+
* `selected`/`disabled` computed from the sparse variant list.
|
|
16
|
+
*/
|
|
17
|
+
export function Chip({
|
|
18
|
+
label,
|
|
19
|
+
selected,
|
|
20
|
+
disabled,
|
|
21
|
+
onSelect,
|
|
22
|
+
media,
|
|
23
|
+
}: ChipProps) {
|
|
24
|
+
return (
|
|
25
|
+
// biome-ignore lint/a11y/useSemanticElements: custom radio; a styled button carries the swatch and disabled state a native radio cannot, inside the picker radiogroup.
|
|
26
|
+
<button
|
|
27
|
+
type="button"
|
|
28
|
+
role="radio"
|
|
29
|
+
aria-checked={selected ?? false}
|
|
30
|
+
aria-disabled={disabled ?? false}
|
|
31
|
+
disabled={disabled}
|
|
32
|
+
className={styles.chip({ selected, disabled })}
|
|
33
|
+
onClick={disabled ? undefined : onSelect}
|
|
34
|
+
>
|
|
35
|
+
{media ? (
|
|
36
|
+
<img className={styles.swatch} src={media} alt="" draggable={false} />
|
|
37
|
+
) : null}
|
|
38
|
+
{label}
|
|
39
|
+
</button>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -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
|
+
);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
import { text } from "../design/tokens";
|
|
3
|
+
import { useLabels } from "../i18n";
|
|
4
|
+
import { cx } from "../lib/cx";
|
|
5
|
+
import * as styles from "./expandable-text.css";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Clamps long copy to a few lines with a "read more" toggle. Truncation is
|
|
9
|
+
* measured, not assumed: the toggle only appears when the text actually
|
|
10
|
+
* overflows the collapsed height, so short copy shows no button.
|
|
11
|
+
*/
|
|
12
|
+
export function ExpandableText({ children }: { children: string }) {
|
|
13
|
+
const labels = useLabels();
|
|
14
|
+
const bodyRef = useRef<HTMLParagraphElement>(null);
|
|
15
|
+
const [expanded, setExpanded] = useState(false);
|
|
16
|
+
const [overflows, setOverflows] = useState(false);
|
|
17
|
+
|
|
18
|
+
const collapsed = !expanded;
|
|
19
|
+
|
|
20
|
+
// Measure against the collapsed height (the clamp is applied whenever
|
|
21
|
+
// collapsed, so scrollHeight vs clientHeight is meaningful). Re-run when the
|
|
22
|
+
// text changes (e.g. the client switches variant) so the toggle tracks it.
|
|
23
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: children re-triggers the measure, it is not read in the body.
|
|
24
|
+
useLayoutEffect(() => {
|
|
25
|
+
const el = bodyRef.current;
|
|
26
|
+
if (el && collapsed) {
|
|
27
|
+
setOverflows(el.scrollHeight > el.clientHeight + 1);
|
|
28
|
+
}
|
|
29
|
+
}, [children, collapsed]);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div className={styles.container}>
|
|
33
|
+
<p
|
|
34
|
+
ref={bodyRef}
|
|
35
|
+
className={cx(
|
|
36
|
+
text({ style: "bodyS" }),
|
|
37
|
+
styles.body({ clamp: collapsed, fade: collapsed && overflows }),
|
|
38
|
+
)}
|
|
39
|
+
>
|
|
40
|
+
{children}
|
|
41
|
+
</p>
|
|
42
|
+
{overflows ? (
|
|
43
|
+
<button
|
|
44
|
+
type="button"
|
|
45
|
+
className={styles.toggle}
|
|
46
|
+
onClick={() => setExpanded((v) => !v)}
|
|
47
|
+
>
|
|
48
|
+
{expanded ? labels.readLess : labels.readMore}
|
|
49
|
+
</button>
|
|
50
|
+
) : null}
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -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
|
+
}
|