@sdxc/ui 2026.11.17 → 2026.11.22
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/README.md +139 -2
- package/dist/app/index.d.ts +1 -0
- package/dist/app/index.js +1 -0
- package/dist/app/mixins/command-palette.js +10 -2
- package/dist/app/mixins/log-viewer.js +17 -14
- package/dist/app/mixins/route-dialog.d.ts +17 -0
- package/dist/app/mixins/route-dialog.js +53 -0
- package/dist/app/optimistic-toggle.js +6 -0
- package/dist/app/route-dialog.d.ts +38 -0
- package/dist/app/route-dialog.js +49 -0
- package/dist/audio/equalizer.d.ts +24 -0
- package/dist/audio/equalizer.js +57 -0
- package/dist/audio/index.d.ts +16 -0
- package/dist/audio/index.js +16 -0
- package/dist/audio/media-tile.d.ts +38 -0
- package/dist/audio/media-tile.js +98 -0
- package/dist/audio/player-bar.d.ts +108 -0
- package/dist/audio/player-bar.js +338 -0
- package/dist/audio/queue-list.d.ts +56 -0
- package/dist/audio/queue-list.js +102 -0
- package/dist/audio/track-list.d.ts +91 -0
- package/dist/audio/track-list.js +226 -0
- package/dist/audio/utils/media-session.d.ts +44 -0
- package/dist/audio/utils/media-session.js +87 -0
- package/dist/audio/utils/play-queue.d.ts +98 -0
- package/dist/audio/utils/play-queue.js +149 -0
- package/dist/audio/utils/track-time.d.ts +28 -0
- package/dist/audio/utils/track-time.js +36 -0
- package/dist/chat/composer-format.d.ts +35 -0
- package/dist/chat/composer-format.js +84 -0
- package/dist/chat/index.d.ts +6 -0
- package/dist/chat/index.js +6 -0
- package/dist/chat/mention-menu.d.ts +43 -0
- package/dist/chat/mention-menu.js +70 -0
- package/dist/chat/message-group.d.ts +92 -0
- package/dist/chat/message-group.js +222 -0
- package/dist/chat/mixins/composer-format.d.ts +28 -0
- package/dist/chat/mixins/composer-format.js +80 -0
- package/dist/chat/mixins/composer-send.d.ts +2 -2
- package/dist/chat/mixins/composer-send.js +4 -2
- package/dist/chat/mixins/mention-menu.d.ts +41 -0
- package/dist/chat/mixins/mention-menu.js +213 -0
- package/dist/chat/mixins/reaction-sync.d.ts +47 -0
- package/dist/chat/mixins/reaction-sync.js +172 -0
- package/dist/chat/reaction-bar.d.ts +70 -0
- package/dist/chat/reaction-bar.js +108 -0
- package/dist/chat/typing-indicator.d.ts +42 -0
- package/dist/chat/typing-indicator.js +68 -0
- package/dist/chat/utils/composer-text.d.ts +38 -0
- package/dist/chat/utils/composer-text.js +86 -0
- package/dist/chat/utils/markdown-format.d.ts +30 -0
- package/dist/chat/utils/markdown-format.js +158 -0
- package/dist/chat/utils/mention-query.d.ts +55 -0
- package/dist/chat/utils/mention-query.js +60 -0
- package/dist/commerce/cart-drawer.d.ts +69 -0
- package/dist/commerce/cart-drawer.js +163 -0
- package/dist/commerce/cart-line.d.ts +32 -0
- package/dist/commerce/cart-line.js +43 -0
- package/dist/commerce/checkout-layout.d.ts +32 -0
- package/dist/commerce/checkout-layout.js +51 -0
- package/dist/commerce/facet-filters.d.ts +121 -0
- package/dist/commerce/facet-filters.js +318 -0
- package/dist/commerce/fulfilment-note.d.ts +28 -0
- package/dist/commerce/fulfilment-note.js +26 -0
- package/dist/commerce/index.d.ts +27 -0
- package/dist/commerce/index.js +27 -0
- package/dist/commerce/item-options-dialog.d.ts +67 -0
- package/dist/commerce/item-options-dialog.js +150 -0
- package/dist/commerce/menu-item-card.d.ts +37 -0
- package/dist/commerce/menu-item-card.js +96 -0
- package/dist/commerce/option-group.d.ts +62 -0
- package/dist/commerce/option-group.js +121 -0
- package/dist/commerce/order-summary.d.ts +42 -0
- package/dist/commerce/order-summary.js +76 -0
- package/dist/commerce/order-tracker.d.ts +80 -0
- package/dist/commerce/order-tracker.js +178 -0
- package/dist/commerce/price.d.ts +52 -0
- package/dist/commerce/price.js +108 -0
- package/dist/commerce/product-card.d.ts +53 -0
- package/dist/commerce/product-card.js +127 -0
- package/dist/commerce/product-gallery.d.ts +70 -0
- package/dist/commerce/product-gallery.js +186 -0
- package/dist/commerce/promo-code.d.ts +56 -0
- package/dist/commerce/promo-code.js +101 -0
- package/dist/commerce/quantity-stepper.d.ts +42 -0
- package/dist/commerce/quantity-stepper.js +53 -0
- package/dist/commerce/question-list.d.ts +53 -0
- package/dist/commerce/question-list.js +92 -0
- package/dist/commerce/shipping-estimate.d.ts +53 -0
- package/dist/commerce/shipping-estimate.js +39 -0
- package/dist/commerce/sort-select.d.ts +38 -0
- package/dist/commerce/sort-select.js +38 -0
- package/dist/commerce/variant-picker.d.ts +75 -0
- package/dist/commerce/variant-picker.js +135 -0
- package/dist/components/amount.d.ts +46 -0
- package/dist/components/amount.js +34 -0
- package/dist/components/autocomplete.d.ts +82 -0
- package/dist/components/autocomplete.js +114 -0
- package/dist/components/carousel.d.ts +31 -1
- package/dist/components/carousel.js +66 -3
- package/dist/components/index.d.ts +11 -0
- package/dist/components/index.js +11 -0
- package/dist/components/letterbox.d.ts +47 -0
- package/dist/components/letterbox.js +56 -0
- package/dist/components/lightbox.d.ts +88 -0
- package/dist/components/lightbox.js +224 -0
- package/dist/components/media-grid.d.ts +53 -0
- package/dist/components/media-grid.js +89 -0
- package/dist/components/range-months.d.ts +100 -0
- package/dist/components/range-months.js +274 -0
- package/dist/components/rating-input.d.ts +33 -0
- package/dist/components/rating-input.js +63 -0
- package/dist/components/rating.d.ts +38 -0
- package/dist/components/rating.js +66 -0
- package/dist/components/review-card.d.ts +39 -0
- package/dist/components/review-card.js +59 -0
- package/dist/components/section-bar.d.ts +57 -0
- package/dist/components/section-bar.js +140 -0
- package/dist/components/step-indicator.d.ts +46 -0
- package/dist/components/step-indicator.js +96 -0
- package/dist/finance/index.d.ts +10 -0
- package/dist/finance/index.js +10 -0
- package/dist/finance/ledger.d.ts +60 -0
- package/dist/finance/ledger.js +93 -0
- package/dist/finance/payment-card.d.ts +49 -0
- package/dist/finance/payment-card.js +115 -0
- package/dist/map/engine.d.ts +49 -0
- package/dist/map/engine.js +591 -0
- package/dist/map/index.d.ts +12 -0
- package/dist/map/index.js +12 -0
- package/dist/map/map-canvas.d.ts +101 -0
- package/dist/map/map-canvas.js +275 -0
- package/dist/map/map.d.ts +217 -0
- package/dist/map/map.js +598 -0
- package/dist/map/mixins/map-link.d.ts +30 -0
- package/dist/map/mixins/map-link.js +116 -0
- package/dist/map/utils/basemap.d.ts +88 -0
- package/dist/map/utils/basemap.js +84 -0
- package/dist/map/utils/cluster.d.ts +43 -0
- package/dist/map/utils/cluster.js +80 -0
- package/dist/map/utils/mercator.d.ts +66 -0
- package/dist/map/utils/mercator.js +92 -0
- package/dist/map/utils/stage.d.ts +24 -0
- package/dist/map/utils/stage.js +49 -0
- package/dist/mixins/autocomplete.d.ts +28 -0
- package/dist/mixins/autocomplete.js +283 -0
- package/dist/mixins/carousel-controls.d.ts +14 -3
- package/dist/mixins/carousel-controls.js +89 -30
- package/dist/mixins/index.d.ts +2 -0
- package/dist/mixins/index.js +2 -0
- package/dist/mixins/lightbox-controls.d.ts +34 -0
- package/dist/mixins/lightbox-controls.js +176 -0
- package/dist/schedule/agenda.d.ts +63 -0
- package/dist/schedule/agenda.js +221 -0
- package/dist/schedule/day-strip.d.ts +50 -0
- package/dist/schedule/day-strip.js +136 -0
- package/dist/schedule/free-busy.d.ts +96 -0
- package/dist/schedule/free-busy.js +285 -0
- package/dist/schedule/index.d.ts +15 -0
- package/dist/schedule/index.js +15 -0
- package/dist/schedule/mixins/day-strip-scroll.d.ts +16 -0
- package/dist/schedule/mixins/day-strip-scroll.js +40 -0
- package/dist/schedule/mixins/time-grid-drag.d.ts +24 -0
- package/dist/schedule/mixins/time-grid-drag.js +532 -0
- package/dist/schedule/month-view.d.ts +68 -0
- package/dist/schedule/month-view.js +301 -0
- package/dist/schedule/time-grid.d.ts +168 -0
- package/dist/schedule/time-grid.js +417 -0
- package/dist/schedule/utils/time-grid-layout.d.ts +50 -0
- package/dist/schedule/utils/time-grid-layout.js +93 -0
- package/dist/schedule/year-view.d.ts +46 -0
- package/dist/schedule/year-view.js +142 -0
- package/dist/styles/index.d.ts +1 -0
- package/dist/styles/index.js +1 -0
- package/dist/styles/typewriter-text.d.ts +20 -0
- package/dist/styles/typewriter-text.js +23 -0
- package/dist/test/map.d.ts +18 -0
- package/dist/test/map.js +96 -0
- package/dist/test/reels.d.ts +30 -0
- package/dist/test/reels.js +41 -0
- package/dist/test/stories.d.ts +31 -0
- package/dist/test/stories.js +66 -0
- package/dist/travel/boarding-pass.d.ts +107 -0
- package/dist/travel/boarding-pass.js +293 -0
- package/dist/travel/car-offer.d.ts +70 -0
- package/dist/travel/car-offer.js +127 -0
- package/dist/travel/fare-calendar.d.ts +85 -0
- package/dist/travel/fare-calendar.js +233 -0
- package/dist/travel/fare-options.d.ts +84 -0
- package/dist/travel/fare-options.js +142 -0
- package/dist/travel/flight-itinerary.d.ts +84 -0
- package/dist/travel/flight-itinerary.js +112 -0
- package/dist/travel/flight-option.d.ts +58 -0
- package/dist/travel/flight-option.js +111 -0
- package/dist/travel/flight-segment.d.ts +105 -0
- package/dist/travel/flight-segment.js +174 -0
- package/dist/travel/index.d.ts +20 -0
- package/dist/travel/index.js +20 -0
- package/dist/travel/package-savings.d.ts +74 -0
- package/dist/travel/package-savings.js +128 -0
- package/dist/travel/price-breakdown.d.ts +66 -0
- package/dist/travel/price-breakdown.js +102 -0
- package/dist/travel/rating-breakdown.d.ts +81 -0
- package/dist/travel/rating-breakdown.js +132 -0
- package/dist/travel/seat-map.d.ts +108 -0
- package/dist/travel/seat-map.js +371 -0
- package/dist/travel/trip-timeline.d.ts +84 -0
- package/dist/travel/trip-timeline.js +212 -0
- package/dist/utils/gamepad-presses.d.ts +21 -0
- package/dist/utils/gamepad-presses.js +28 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/move-focus.d.ts +20 -0
- package/dist/utils/move-focus.js +28 -0
- package/dist/utils/range-months.d.ts +54 -0
- package/dist/utils/range-months.js +98 -0
- package/dist/utils/swipe-direction.d.ts +23 -0
- package/dist/utils/swipe-direction.js +27 -0
- package/dist/utils/typewriter.d.ts +49 -0
- package/dist/utils/typewriter.js +171 -0
- package/dist/video/index.d.ts +6 -2
- package/dist/video/index.js +6 -2
- package/dist/video/mixins/reel-feed-sync.d.ts +41 -0
- package/dist/video/mixins/reel-feed-sync.js +430 -0
- package/dist/video/mixins/story-viewer-sync.d.ts +31 -0
- package/dist/video/mixins/story-viewer-sync.js +391 -0
- package/dist/video/mixins/video-player-sync.js +138 -5
- package/dist/video/reel-feed.d.ts +95 -0
- package/dist/video/reel-feed.js +124 -0
- package/dist/video/story-ring.d.ts +32 -0
- package/dist/video/story-ring.js +42 -0
- package/dist/video/story-viewer.d.ts +85 -0
- package/dist/video/story-viewer.js +250 -0
- package/dist/video/video-card.d.ts +3 -1
- package/dist/video/video-card.js +15 -5
- package/dist/video/video-player.d.ts +33 -0
- package/dist/video/video-player.js +226 -20
- package/package.json +21 -2
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "remix/component/jsx-runtime";
|
|
2
|
+
import { visuallyHidden } from "@sdxc/u/a11y";
|
|
3
|
+
import { mergeMix, raw } from "@sdxc/u/general";
|
|
4
|
+
import { motionReduce } from "@sdxc/u/responsive";
|
|
5
|
+
import { when } from "@sdxc/u/state";
|
|
6
|
+
/** How many colour dots the card draws before it counts the rest as "+N". */
|
|
7
|
+
const MAX_SWATCHES = 5;
|
|
8
|
+
/** The swatch list's accessible name when `swatchesLabel` is unset. */
|
|
9
|
+
const DEFAULT_SWATCHES_LABEL = "Colours";
|
|
10
|
+
/** The picture and hover picture fill their layer whatever element the caller passes. */
|
|
11
|
+
const MEDIA_FILL = {
|
|
12
|
+
"& > img, & > picture, & > svg": {
|
|
13
|
+
display: "block",
|
|
14
|
+
inlineSize: "100%",
|
|
15
|
+
blockSize: "100%",
|
|
16
|
+
objectFit: "cover",
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Renders the card. The title link's `::after` fills the article, so a click anywhere opens
|
|
21
|
+
* the product, and `badges` and `action` sit on a layer above it to stay reachable.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* <ProductCard href="/posters/dune" title="Dune at dusk" subtitle="Ana Ortiz" media={<img src="/dune.jpg" alt="" />} price={<Price amount={4500} currency="USD" />} swatches={[{ name: "Oak", color: "#b58a5a" }]} />
|
|
25
|
+
*/
|
|
26
|
+
export function ProductCard(handle) {
|
|
27
|
+
return () => {
|
|
28
|
+
let { action, badges, headingLevel = 3, hoverMedia, href, media, mediaBackground, mix, price, ratio = "4 / 5", subtitle, swatches = [], swatchesLabel = DEFAULT_SWATCHES_LABEL, title, ...rest } = handle.props;
|
|
29
|
+
let shown = swatches.slice(0, MAX_SWATCHES);
|
|
30
|
+
let extra = swatches.length - shown.length;
|
|
31
|
+
let Heading = `h${headingLevel}`;
|
|
32
|
+
return (_jsxs("article", { ...rest, "data-slot": "product-card", mix: mergeMix([
|
|
33
|
+
raw({
|
|
34
|
+
position: "relative",
|
|
35
|
+
display: "grid",
|
|
36
|
+
alignContent: "start",
|
|
37
|
+
gap: "0.75rem",
|
|
38
|
+
minInlineSize: "0",
|
|
39
|
+
"&:hover [data-slot='product-card-hover'], &:focus-within [data-slot='product-card-hover']": { opacity: "1" },
|
|
40
|
+
}),
|
|
41
|
+
], mix), children: [_jsxs("div", { "data-slot": "product-card-media", mix: [
|
|
42
|
+
raw({
|
|
43
|
+
position: "relative",
|
|
44
|
+
aspectRatio: ratio,
|
|
45
|
+
overflow: "clip",
|
|
46
|
+
borderRadius: "var(--ui-radius-md, 0.5rem)",
|
|
47
|
+
backgroundColor: mediaBackground ?? "var(--ui-neutral-bg-tint)",
|
|
48
|
+
}),
|
|
49
|
+
], children: [_jsx("div", { "data-slot": "product-card-image", mix: [raw({ position: "absolute", inset: "0", display: "grid", ...MEDIA_FILL })], children: media }), hoverMedia === undefined ? null : (_jsx("div", { "aria-hidden": "true", "data-slot": "product-card-hover", mix: [
|
|
50
|
+
raw({
|
|
51
|
+
position: "absolute",
|
|
52
|
+
inset: "0",
|
|
53
|
+
display: "grid",
|
|
54
|
+
opacity: "0",
|
|
55
|
+
transition: "opacity 240ms ease",
|
|
56
|
+
backgroundColor: mediaBackground ?? "var(--ui-neutral-bg-tint)",
|
|
57
|
+
...MEDIA_FILL,
|
|
58
|
+
}),
|
|
59
|
+
motionReduce(raw({ transition: "none" })),
|
|
60
|
+
], children: hoverMedia })), badges === undefined ? null : (_jsx("div", { "data-slot": "product-card-badges", mix: [
|
|
61
|
+
raw({
|
|
62
|
+
position: "absolute",
|
|
63
|
+
zIndex: "2",
|
|
64
|
+
insetBlockStart: "0.625rem",
|
|
65
|
+
insetInlineStart: "0.625rem",
|
|
66
|
+
display: "flex",
|
|
67
|
+
flexWrap: "wrap",
|
|
68
|
+
gap: "0.375rem",
|
|
69
|
+
}),
|
|
70
|
+
], children: badges })), action === undefined ? null : (_jsx("div", { "data-slot": "product-card-action", mix: [
|
|
71
|
+
raw({
|
|
72
|
+
position: "absolute",
|
|
73
|
+
zIndex: "2",
|
|
74
|
+
insetBlockStart: "0.5rem",
|
|
75
|
+
insetInlineEnd: "0.5rem",
|
|
76
|
+
}),
|
|
77
|
+
], children: action }))] }), _jsxs("div", { mix: [raw({ display: "grid", gap: "0.25rem", minInlineSize: "0" })], children: [_jsx(Heading, { "data-slot": "product-card-title", mix: [
|
|
78
|
+
raw({
|
|
79
|
+
margin: "0",
|
|
80
|
+
fontSize: "0.9375rem",
|
|
81
|
+
fontWeight: "600",
|
|
82
|
+
lineHeight: "1.35",
|
|
83
|
+
color: "var(--ui-neutral-fg-emphasis)",
|
|
84
|
+
}),
|
|
85
|
+
], children: _jsx("a", { href: href, mix: [
|
|
86
|
+
raw({
|
|
87
|
+
color: "inherit",
|
|
88
|
+
textDecoration: "none",
|
|
89
|
+
"&::after": {
|
|
90
|
+
content: '""',
|
|
91
|
+
position: "absolute",
|
|
92
|
+
inset: "0",
|
|
93
|
+
zIndex: "1",
|
|
94
|
+
borderRadius: "var(--ui-radius-md, 0.5rem)",
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
when("&:hover", raw({ textDecoration: "underline", textUnderlineOffset: "0.2em" })),
|
|
98
|
+
when("&:focus-visible", raw({ outline: "none" })),
|
|
99
|
+
when("&:focus-visible::after", raw({ outline: "2px solid var(--ui-brand-ring)", outlineOffset: "4px" })),
|
|
100
|
+
], children: title }) }), subtitle === undefined ? null : (_jsx("p", { "data-slot": "product-card-subtitle", mix: [
|
|
101
|
+
raw({ margin: "0", fontSize: "0.8125rem", color: "var(--ui-neutral-fg-muted)" }),
|
|
102
|
+
], children: subtitle })), _jsx("div", { "data-slot": "product-card-price", mix: [raw({ fontSize: "0.9375rem" })], children: price }), shown.length === 0 ? null : (_jsxs("ul", { "aria-label": swatchesLabel, "data-slot": "product-card-swatches", mix: [
|
|
103
|
+
raw({
|
|
104
|
+
display: "flex",
|
|
105
|
+
alignItems: "center",
|
|
106
|
+
gap: "0.375rem",
|
|
107
|
+
margin: "0",
|
|
108
|
+
marginBlockStart: "0.25rem",
|
|
109
|
+
padding: "0",
|
|
110
|
+
listStyle: "none",
|
|
111
|
+
}),
|
|
112
|
+
], children: [shown.map((swatch) => (_jsx("li", { title: swatch.name, "data-slot": "product-card-swatch", style: { background: swatch.color }, mix: [
|
|
113
|
+
raw({
|
|
114
|
+
inlineSize: "0.875rem",
|
|
115
|
+
blockSize: "0.875rem",
|
|
116
|
+
borderRadius: "999px",
|
|
117
|
+
boxShadow: "inset 0 0 0 1px rgb(0 0 0 / 0.14)",
|
|
118
|
+
}),
|
|
119
|
+
], children: _jsx("span", { mix: [visuallyHidden()], children: swatch.name }) }))), extra > 0 ? (_jsx("li", { "data-slot": "product-card-swatch-more", mix: [
|
|
120
|
+
raw({
|
|
121
|
+
fontSize: "0.75rem",
|
|
122
|
+
fontVariantNumeric: "tabular-nums",
|
|
123
|
+
color: "var(--ui-neutral-fg-muted)",
|
|
124
|
+
}),
|
|
125
|
+
], children: `+${extra}` })) : null] }))] })] }));
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A product's pictures: a large stage with a rail of thumbnail links on wide screens, and a
|
|
3
|
+
* swipeable strip with dots on a phone. Each thumbnail is a link to the page showing that
|
|
4
|
+
* picture, so it works without script; the stage zooms under the pointer and opens a Lightbox.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { EntryComponent, Handle, MixinFactory, Props as TagProps, RemixNode } from "remix/component";
|
|
10
|
+
/** Prop types for {@link ProductGallery}. */
|
|
11
|
+
export declare namespace ProductGallery {
|
|
12
|
+
/** One picture. */
|
|
13
|
+
interface Image {
|
|
14
|
+
/** Names the picture in `current` and keys its thumbnail. */
|
|
15
|
+
id: string;
|
|
16
|
+
/** The picture, such as an `<img>` or an inline SVG. */
|
|
17
|
+
media: RemixNode;
|
|
18
|
+
/** What the picture shows; the thumbnail link and the strip slide are named by it. */
|
|
19
|
+
alt: string;
|
|
20
|
+
/** The page showing this picture, such as `?image=2`. */
|
|
21
|
+
href: string;
|
|
22
|
+
}
|
|
23
|
+
/** The words the controls are named by; `{n}` and `{total}` are filled in. */
|
|
24
|
+
interface Labels {
|
|
25
|
+
/** The button that opens the Lightbox, such as "Zoom". */
|
|
26
|
+
zoom: string;
|
|
27
|
+
/** A slide's position, such as "Image {n} of {total}". */
|
|
28
|
+
image: string;
|
|
29
|
+
}
|
|
30
|
+
/** Props accepted by {@link ProductGallery}; the host is a `<div>`. */
|
|
31
|
+
interface Props extends Omit<TagProps<"div">, "children"> {
|
|
32
|
+
images: Image[];
|
|
33
|
+
/** The id of the picture on the stage; the first picture when it matches none. */
|
|
34
|
+
current: string;
|
|
35
|
+
/** The colour behind every picture. */
|
|
36
|
+
background?: string;
|
|
37
|
+
/** Every picture's aspect ratio. @default "4 / 5" */
|
|
38
|
+
ratio?: string;
|
|
39
|
+
/** The id of a root Lightbox dialog the zoom button opens at the current picture. */
|
|
40
|
+
lightbox?: string;
|
|
41
|
+
labels: Labels;
|
|
42
|
+
}
|
|
43
|
+
/** Props {@link ProductGalleryZoom} serializes for hydration. */
|
|
44
|
+
type ZoomProps = {
|
|
45
|
+
/** The id of the stage whose zoom follows the pointer. */
|
|
46
|
+
stage: string;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Zooms an element's first child to twice its size while a mouse hovers it, growing from
|
|
51
|
+
* the point under the pointer. It applies only where the device hovers with a fine pointer
|
|
52
|
+
* and the reader allows motion, so touch screens and reduced motion keep the plain picture.
|
|
53
|
+
*
|
|
54
|
+
* @example <div mix={[zoomOnHover()]}><img src="/poster.jpg" alt="" /></div>
|
|
55
|
+
*/
|
|
56
|
+
export declare const zoomOnHover: MixinFactory<HTMLElement>;
|
|
57
|
+
/**
|
|
58
|
+
* Renders the gallery. Wide, the stage sits beside a rail of thumbnail links marked
|
|
59
|
+
* `aria-current` at the current picture; on a phone, every picture sits in a scroll-snap strip
|
|
60
|
+
* with a dot per picture, and the rail hides.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* <ProductGallery images={images} current={url.searchParams.get("image") ?? "front"} lightbox="poster-photos" labels={{ zoom: "Zoom", image: "Image {n} of {total}" }} />
|
|
64
|
+
*/
|
|
65
|
+
export declare function ProductGallery(handle: Handle<ProductGallery.Props>): () => import("remix/component").RemixElement;
|
|
66
|
+
/**
|
|
67
|
+
* Makes a server-rendered stage's zoom follow the pointer. {@link ProductGallery} renders it
|
|
68
|
+
* beside its stage, and it loads from `@sdxc/ui/commerce/product-gallery`.
|
|
69
|
+
*/
|
|
70
|
+
export declare const ProductGalleryZoom: EntryComponent<ProductGallery.ZoomProps>;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "remix/component/jsx-runtime";
|
|
2
|
+
import { ZoomInIcon } from "@sdxc/icons";
|
|
3
|
+
import { mergeMix, raw } from "@sdxc/u/general";
|
|
4
|
+
import { media } from "@sdxc/u/responsive";
|
|
5
|
+
import { when } from "@sdxc/u/state";
|
|
6
|
+
import { clientEntry, createMixin } from "remix/component";
|
|
7
|
+
import { Lightbox } from "../components/lightbox.js";
|
|
8
|
+
/** The query below which the gallery becomes a swipeable strip. */
|
|
9
|
+
const PHONE = "(max-width: 47.99rem)";
|
|
10
|
+
/** Where the zoom applies: a fine pointer that hovers, for a reader who allows motion. */
|
|
11
|
+
const ZOOM_QUERY = "(hover: hover) and (pointer: fine) and (prefers-reduced-motion: no-preference)";
|
|
12
|
+
/** How far the stage's picture scales while the pointer is over it. */
|
|
13
|
+
const ZOOM_SCALE = 2;
|
|
14
|
+
/** Marks a stage whose pointer is already tracked, so a mixin and an island never both listen. */
|
|
15
|
+
const TRACKED_ATTRIBUTE = "data-zoom-tracked";
|
|
16
|
+
/**
|
|
17
|
+
* Moves the zoom's origin to the pointer while a mouse is over the stage, so the part under
|
|
18
|
+
* it is what grows. Touch and pen leave the origin centred.
|
|
19
|
+
*
|
|
20
|
+
* @param stage The element carrying {@link zoomOnHover}'s styles.
|
|
21
|
+
* @param signal Detaches the listeners.
|
|
22
|
+
*/
|
|
23
|
+
function trackZoom(stage, signal) {
|
|
24
|
+
if (stage.hasAttribute(TRACKED_ATTRIBUTE))
|
|
25
|
+
return;
|
|
26
|
+
stage.setAttribute(TRACKED_ATTRIBUTE, "");
|
|
27
|
+
signal.addEventListener("abort", () => stage.removeAttribute(TRACKED_ATTRIBUTE));
|
|
28
|
+
stage.addEventListener("pointermove", (event) => {
|
|
29
|
+
if (event.pointerType !== "mouse")
|
|
30
|
+
return;
|
|
31
|
+
let box = stage.getBoundingClientRect();
|
|
32
|
+
let x = ((event.clientX - box.left) / box.width) * 100;
|
|
33
|
+
let y = ((event.clientY - box.top) / box.height) * 100;
|
|
34
|
+
stage.style.setProperty("--ui-zoom-x", `${Math.min(100, Math.max(0, x))}%`);
|
|
35
|
+
stage.style.setProperty("--ui-zoom-y", `${Math.min(100, Math.max(0, y))}%`);
|
|
36
|
+
}, { signal });
|
|
37
|
+
stage.addEventListener("pointerleave", () => {
|
|
38
|
+
stage.style.removeProperty("--ui-zoom-x");
|
|
39
|
+
stage.style.removeProperty("--ui-zoom-y");
|
|
40
|
+
}, { signal });
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Zooms an element's first child to twice its size while a mouse hovers it, growing from
|
|
44
|
+
* the point under the pointer. It applies only where the device hovers with a fine pointer
|
|
45
|
+
* and the reader allows motion, so touch screens and reduced motion keep the plain picture.
|
|
46
|
+
*
|
|
47
|
+
* @example <div mix={[zoomOnHover()]}><img src="/poster.jpg" alt="" /></div>
|
|
48
|
+
*/
|
|
49
|
+
export const zoomOnHover = createMixin((handle) => {
|
|
50
|
+
handle.addEventListener("insert", (event) => trackZoom(event.node, handle.signal));
|
|
51
|
+
return () => (_jsx(handle.element, { mix: [
|
|
52
|
+
raw({ overflow: "clip" }),
|
|
53
|
+
media(ZOOM_QUERY, raw({
|
|
54
|
+
cursor: "zoom-in",
|
|
55
|
+
"& > :first-child": {
|
|
56
|
+
transformOrigin: "var(--ui-zoom-x, 50%) var(--ui-zoom-y, 50%)",
|
|
57
|
+
transition: "transform 200ms ease-out",
|
|
58
|
+
},
|
|
59
|
+
"&:hover > :first-child": { transform: `scale(${ZOOM_SCALE})` },
|
|
60
|
+
})),
|
|
61
|
+
] }));
|
|
62
|
+
});
|
|
63
|
+
/** The style every picture layer shares: fills its frame at the gallery's ratio. */
|
|
64
|
+
function frame(ratio, background) {
|
|
65
|
+
return raw({
|
|
66
|
+
position: "relative",
|
|
67
|
+
display: "grid",
|
|
68
|
+
aspectRatio: ratio,
|
|
69
|
+
overflow: "clip",
|
|
70
|
+
borderRadius: "var(--ui-radius-md, 0.5rem)",
|
|
71
|
+
backgroundColor: background ?? "var(--ui-neutral-bg-tint)",
|
|
72
|
+
"& > *": { gridArea: "1 / 1" },
|
|
73
|
+
"& img, & svg": {
|
|
74
|
+
display: "block",
|
|
75
|
+
inlineSize: "100%",
|
|
76
|
+
blockSize: "100%",
|
|
77
|
+
objectFit: "cover",
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
/** Replaces each `{name}` in a template with its value. */
|
|
82
|
+
function format(template, values) {
|
|
83
|
+
return template.replace(/\{(\w+)\}/g, (match, key) => key in values ? String(values[key]) : match);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Renders the gallery. Wide, the stage sits beside a rail of thumbnail links marked
|
|
87
|
+
* `aria-current` at the current picture; on a phone, every picture sits in a scroll-snap strip
|
|
88
|
+
* with a dot per picture, and the rail hides.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* <ProductGallery images={images} current={url.searchParams.get("image") ?? "front"} lightbox="poster-photos" labels={{ zoom: "Zoom", image: "Image {n} of {total}" }} />
|
|
92
|
+
*/
|
|
93
|
+
export function ProductGallery(handle) {
|
|
94
|
+
return () => {
|
|
95
|
+
let { background, current, id, images, labels, lightbox, mix, ratio = "4 / 5", ...rest } = handle.props;
|
|
96
|
+
let root = id ?? `${handle.id}-gallery`;
|
|
97
|
+
let stageId = `${root}-stage`;
|
|
98
|
+
let index = Math.max(0, images.findIndex((image) => image.id === current));
|
|
99
|
+
let shown = images[index];
|
|
100
|
+
let total = images.length;
|
|
101
|
+
return (_jsxs("div", { ...rest, id: id, "data-slot": "product-gallery", mix: mergeMix([
|
|
102
|
+
raw({
|
|
103
|
+
display: "grid",
|
|
104
|
+
gridTemplateColumns: "4.5rem minmax(0, 1fr)",
|
|
105
|
+
alignItems: "start",
|
|
106
|
+
gap: "0.75rem",
|
|
107
|
+
}),
|
|
108
|
+
media(PHONE, raw({ display: "block" })),
|
|
109
|
+
], mix), children: [_jsx("ul", { "data-slot": "product-gallery-thumbnails", mix: [
|
|
110
|
+
raw({
|
|
111
|
+
display: "grid",
|
|
112
|
+
gap: "0.5rem",
|
|
113
|
+
margin: "0",
|
|
114
|
+
padding: "0",
|
|
115
|
+
listStyle: "none",
|
|
116
|
+
}),
|
|
117
|
+
media(PHONE, raw({ display: "none" })),
|
|
118
|
+
], children: images.map((image, position) => (_jsx("li", { children: _jsx("a", { href: image.href, "aria-label": image.alt, "aria-current": position === index ? "true" : undefined, "data-slot": "product-gallery-thumbnail", mix: [
|
|
119
|
+
frame(ratio, background),
|
|
120
|
+
raw({
|
|
121
|
+
borderRadius: "var(--ui-radius-sm, 0.375rem)",
|
|
122
|
+
opacity: "0.72",
|
|
123
|
+
boxShadow: "inset 0 0 0 1px var(--ui-neutral-border)",
|
|
124
|
+
}),
|
|
125
|
+
when("&:hover", raw({ opacity: "1" })),
|
|
126
|
+
when("&[aria-current='true']", raw({
|
|
127
|
+
opacity: "1",
|
|
128
|
+
outline: "2px solid var(--ui-neutral-fg-emphasis)",
|
|
129
|
+
outlineOffset: "2px",
|
|
130
|
+
})),
|
|
131
|
+
when("&:focus-visible", raw({ outline: "2px solid var(--ui-brand-ring)", outlineOffset: "2px" })),
|
|
132
|
+
], children: image.media }) }))) }), _jsxs("div", { "data-slot": "product-gallery-main", mix: [raw({ position: "relative" }), media(PHONE, raw({ display: "none" }))], children: [_jsx("div", { id: stageId, role: "img", "aria-label": shown?.alt, "data-slot": "product-gallery-stage", mix: [frame(ratio, background), zoomOnHover()], children: _jsx("div", { mix: [raw({ display: "grid", inlineSize: "100%", blockSize: "100%" })], children: shown?.media }) }), _jsx(ProductGalleryZoom, { stage: stageId }), lightbox === undefined ? null : (_jsx(Lightbox.Trigger, { lightbox: lightbox, index: index, "aria-label": labels.zoom, mix: [
|
|
133
|
+
raw({
|
|
134
|
+
position: "absolute",
|
|
135
|
+
insetBlockEnd: "0.75rem",
|
|
136
|
+
insetInlineEnd: "0.75rem",
|
|
137
|
+
display: "inline-grid",
|
|
138
|
+
placeItems: "center",
|
|
139
|
+
inlineSize: "2.75rem",
|
|
140
|
+
blockSize: "2.75rem",
|
|
141
|
+
borderRadius: "999px",
|
|
142
|
+
color: "var(--ui-neutral-fg-emphasis)",
|
|
143
|
+
backgroundColor: "var(--ui-bg-raised, var(--ui-bg, white))",
|
|
144
|
+
boxShadow: "0 0 0 1px var(--ui-neutral-border)",
|
|
145
|
+
}),
|
|
146
|
+
], children: _jsx(ZoomInIcon, { size: 20, "aria-hidden": "true" }) }))] }), _jsxs("div", { "data-slot": "product-gallery-strip", mix: [raw({ display: "none" }), media(PHONE, raw({ display: "grid", gap: "0.625rem" }))], children: [_jsx("ul", { "data-slot": "product-gallery-track", mix: [
|
|
147
|
+
raw({
|
|
148
|
+
display: "flex",
|
|
149
|
+
gap: "0.5rem",
|
|
150
|
+
margin: "0",
|
|
151
|
+
padding: "0",
|
|
152
|
+
listStyle: "none",
|
|
153
|
+
overflowX: "auto",
|
|
154
|
+
scrollSnapType: "x mandatory",
|
|
155
|
+
overscrollBehaviorX: "contain",
|
|
156
|
+
scrollbarWidth: "none",
|
|
157
|
+
}),
|
|
158
|
+
when("&::-webkit-scrollbar", raw({ display: "none" })),
|
|
159
|
+
], children: images.map((image, position) => (_jsx("li", { id: `${root}-slide-${position + 1}`, role: "img", "aria-label": `${image.alt}, ${format(labels.image, { n: position + 1, total })}`, "data-slot": "product-gallery-slide", mix: [
|
|
160
|
+
frame(ratio, background),
|
|
161
|
+
raw({ flex: "0 0 100%", scrollSnapAlign: "center" }),
|
|
162
|
+
position === index ? raw({ scrollInitialTarget: "nearest" }) : undefined,
|
|
163
|
+
], children: image.media }))) }), total < 2 ? null : (_jsx("div", { "aria-hidden": "true", "data-slot": "product-gallery-dots", mix: [raw({ display: "flex", justifyContent: "center", gap: "0.375rem" })], children: images.map((image, position) => (_jsx("a", { href: `#${root}-slide-${position + 1}`, tabIndex: -1, "data-current": position === index ? "" : undefined, title: image.alt, mix: [
|
|
164
|
+
raw({
|
|
165
|
+
inlineSize: "0.375rem",
|
|
166
|
+
blockSize: "0.375rem",
|
|
167
|
+
borderRadius: "999px",
|
|
168
|
+
backgroundColor: "var(--ui-neutral-border-strong)",
|
|
169
|
+
}),
|
|
170
|
+
when("&[data-current]", raw({ backgroundColor: "var(--ui-neutral-fg-emphasis)" })),
|
|
171
|
+
] }))) }))] })] }));
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Makes a server-rendered stage's zoom follow the pointer. {@link ProductGallery} renders it
|
|
176
|
+
* beside its stage, and it loads from `@sdxc/ui/commerce/product-gallery`.
|
|
177
|
+
*/
|
|
178
|
+
export const ProductGalleryZoom = clientEntry("@sdxc/ui/commerce/product-gallery#ProductGalleryZoom", function ProductGalleryZoom(handle) {
|
|
179
|
+
handle.queueTask(() => {
|
|
180
|
+
let stage = document.getElementById(handle.props.stage);
|
|
181
|
+
if (stage === null || handle.signal.aborted)
|
|
182
|
+
return;
|
|
183
|
+
trackZoom(stage, handle.signal);
|
|
184
|
+
});
|
|
185
|
+
return () => _jsx("span", { hidden: true, "data-slot": "product-gallery-zoom-live" });
|
|
186
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The promo code box of a cart or checkout: a "Have a promo code?" disclosure holding a POST
|
|
3
|
+
* form with one field, the server's error under it, and every code already applied as a chip
|
|
4
|
+
* with its own remove button. It needs no script; the server answers each post.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Handle, Props as TagProps, RemixNode } from "remix/component";
|
|
10
|
+
/** Prop types for {@link PromoCode}. */
|
|
11
|
+
export declare namespace PromoCode {
|
|
12
|
+
/** The words the box carries. */
|
|
13
|
+
interface Labels {
|
|
14
|
+
/** The disclosure's summary, such as "Have a promo code?". */
|
|
15
|
+
toggle: string;
|
|
16
|
+
/** The field's label, such as "Promo code". */
|
|
17
|
+
field: string;
|
|
18
|
+
apply: string;
|
|
19
|
+
/** The remove button's name, followed by the code, such as "Remove". */
|
|
20
|
+
remove: string;
|
|
21
|
+
}
|
|
22
|
+
/** A code the cart already carries. */
|
|
23
|
+
interface Applied {
|
|
24
|
+
code: string;
|
|
25
|
+
/** What it does, such as "10% off prints". */
|
|
26
|
+
label: RemixNode;
|
|
27
|
+
/** The POST form that takes it off. */
|
|
28
|
+
remove: {
|
|
29
|
+
action: string;
|
|
30
|
+
fields?: Record<string, string>;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Props accepted by {@link PromoCode}; the host is a `<div>`. */
|
|
34
|
+
interface Props extends Omit<TagProps<"div">, "children"> {
|
|
35
|
+
/** Where the code posts. */
|
|
36
|
+
action: string;
|
|
37
|
+
/** @default "code" */
|
|
38
|
+
name?: string;
|
|
39
|
+
/** The code the reader last sent, kept in the field after an error. */
|
|
40
|
+
value?: string;
|
|
41
|
+
/** Why the server refused the code; the field is marked invalid and described by it. */
|
|
42
|
+
error?: RemixNode;
|
|
43
|
+
/** Hidden fields the post carries, such as the page to return to. */
|
|
44
|
+
fields?: Record<string, string>;
|
|
45
|
+
applied?: Applied[];
|
|
46
|
+
labels: Labels;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Renders the applied codes first, then the disclosure, open whenever the reader has typed a
|
|
51
|
+
* code or the server refused one, so a failed post lands on the field with its error showing.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* <PromoCode action="/cart/promo" error={state.error} value={state.code} applied={[{ code: "WALLS10", label: "10% off", remove: { action: "/cart/promo/remove", fields: { code: "WALLS10" } } }]} labels={{ toggle: "Have a promo code?", field: "Promo code", apply: "Apply", remove: "Remove" }} />
|
|
55
|
+
*/
|
|
56
|
+
export declare function PromoCode(handle: Handle<PromoCode.Props>): () => import("remix/component").RemixElement;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "remix/component/jsx-runtime";
|
|
2
|
+
import { ChevronDownIcon, TagIcon, XIcon } from "@sdxc/icons";
|
|
3
|
+
import { mergeMix, raw } from "@sdxc/u/general";
|
|
4
|
+
import { motionReduce } from "@sdxc/u/responsive";
|
|
5
|
+
import { Button } from "../components/button.js";
|
|
6
|
+
import { Input } from "../components/input.js";
|
|
7
|
+
/** Writes each entry of `fields` as a hidden input. */
|
|
8
|
+
function HiddenFields(handle) {
|
|
9
|
+
return () => (_jsx(_Fragment, { children: Object.entries(handle.props.fields ?? {}).map(([name, value]) => (_jsx("input", { type: "hidden", name: name, value: value }))) }));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Renders the applied codes first, then the disclosure, open whenever the reader has typed a
|
|
13
|
+
* code or the server refused one, so a failed post lands on the field with its error showing.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* <PromoCode action="/cart/promo" error={state.error} value={state.code} applied={[{ code: "WALLS10", label: "10% off", remove: { action: "/cart/promo/remove", fields: { code: "WALLS10" } } }]} labels={{ toggle: "Have a promo code?", field: "Promo code", apply: "Apply", remove: "Remove" }} />
|
|
17
|
+
*/
|
|
18
|
+
export function PromoCode(handle) {
|
|
19
|
+
return () => {
|
|
20
|
+
let { action, applied = [], error, fields, id, labels, mix, name = "code", value, ...rest } = handle.props;
|
|
21
|
+
let base = id ?? handle.id;
|
|
22
|
+
let inputId = `${base}-field`;
|
|
23
|
+
let errorId = `${base}-error`;
|
|
24
|
+
let hasError = error !== undefined && error !== null && error !== false;
|
|
25
|
+
return (_jsxs("div", { ...rest, id: id, "data-slot": "promo-code", mix: mergeMix([raw({ display: "grid", gap: "0.75rem" })], mix), children: [applied.length === 0 ? null : (_jsx("ul", { "data-slot": "promo-code-applied", mix: [
|
|
26
|
+
raw({
|
|
27
|
+
display: "flex",
|
|
28
|
+
flexWrap: "wrap",
|
|
29
|
+
gap: "0.5rem",
|
|
30
|
+
margin: "0",
|
|
31
|
+
padding: "0",
|
|
32
|
+
listStyle: "none",
|
|
33
|
+
}),
|
|
34
|
+
], children: applied.map((entry) => (_jsxs("li", { "data-code": entry.code, mix: [
|
|
35
|
+
raw({
|
|
36
|
+
display: "inline-flex",
|
|
37
|
+
alignItems: "center",
|
|
38
|
+
gap: "0.375rem",
|
|
39
|
+
paddingInlineStart: "0.625rem",
|
|
40
|
+
borderRadius: "999px",
|
|
41
|
+
fontSize: "0.8125rem",
|
|
42
|
+
color: "var(--ui-success-fg-emphasis, var(--ui-success-fg))",
|
|
43
|
+
backgroundColor: "var(--ui-success-bg-tint)",
|
|
44
|
+
"& > svg": { flex: "none", inlineSize: "0.875rem", blockSize: "0.875rem" },
|
|
45
|
+
}),
|
|
46
|
+
], children: [_jsx(TagIcon, { "aria-hidden": "true" }), _jsxs("span", { children: [_jsx("strong", { mix: [raw({ fontWeight: "700", letterSpacing: "0.02em" })], children: entry.code }), " ", _jsx("span", { children: entry.label })] }), _jsxs("form", { method: "post", action: entry.remove.action, mix: [raw({ display: "contents" })], children: [_jsx(HiddenFields, { fields: entry.remove.fields }), _jsx("button", { type: "submit", "aria-label": `${labels.remove} ${entry.code}`, mix: [
|
|
47
|
+
raw({
|
|
48
|
+
display: "inline-grid",
|
|
49
|
+
placeItems: "center",
|
|
50
|
+
inlineSize: "1.75rem",
|
|
51
|
+
blockSize: "1.75rem",
|
|
52
|
+
padding: "0",
|
|
53
|
+
border: "0",
|
|
54
|
+
borderRadius: "999px",
|
|
55
|
+
color: "inherit",
|
|
56
|
+
backgroundColor: "transparent",
|
|
57
|
+
cursor: "pointer",
|
|
58
|
+
"& > svg": { inlineSize: "0.875rem", blockSize: "0.875rem" },
|
|
59
|
+
"&:hover": { backgroundColor: "var(--ui-success-bg-tint-hover)" },
|
|
60
|
+
"&:focus-visible": {
|
|
61
|
+
outline: "2px solid var(--ui-brand-ring)",
|
|
62
|
+
outlineOffset: "-2px",
|
|
63
|
+
},
|
|
64
|
+
}),
|
|
65
|
+
], children: _jsx(XIcon, { "aria-hidden": "true" }) })] })] }))) })), _jsxs("details", { open: hasError || (value !== undefined && value !== ""), "data-slot": "promo-code-details", mix: [
|
|
66
|
+
raw({
|
|
67
|
+
"&[open] > summary svg": { rotate: "180deg" },
|
|
68
|
+
}),
|
|
69
|
+
], children: [_jsxs("summary", { mix: [
|
|
70
|
+
raw({
|
|
71
|
+
display: "inline-flex",
|
|
72
|
+
alignItems: "center",
|
|
73
|
+
gap: "0.375rem",
|
|
74
|
+
minBlockSize: "2.75rem",
|
|
75
|
+
fontSize: "0.875rem",
|
|
76
|
+
fontWeight: "600",
|
|
77
|
+
color: "var(--ui-neutral-fg-emphasis)",
|
|
78
|
+
cursor: "pointer",
|
|
79
|
+
listStyle: "none",
|
|
80
|
+
"&::-webkit-details-marker": { display: "none" },
|
|
81
|
+
"& > svg": {
|
|
82
|
+
inlineSize: "1rem",
|
|
83
|
+
blockSize: "1rem",
|
|
84
|
+
transition: "rotate 160ms ease",
|
|
85
|
+
},
|
|
86
|
+
"&:focus-visible": {
|
|
87
|
+
outline: "2px solid var(--ui-brand-ring)",
|
|
88
|
+
outlineOffset: "2px",
|
|
89
|
+
borderRadius: "0.25rem",
|
|
90
|
+
},
|
|
91
|
+
}),
|
|
92
|
+
motionReduce(raw({ "& > svg": { transition: "none" } })),
|
|
93
|
+
], children: [labels.toggle, _jsx(ChevronDownIcon, { "aria-hidden": "true" })] }), _jsxs("form", { method: "post", action: action, "data-slot": "promo-code-form", mix: [raw({ display: "grid", gap: "0.375rem", paddingBlockStart: "0.25rem" })], children: [_jsx(HiddenFields, { fields: fields }), _jsx("label", { htmlFor: inputId, mix: [raw({ fontSize: "0.8125rem", color: "var(--ui-neutral-fg-muted)" })], children: labels.field }), _jsxs("div", { mix: [raw({ display: "flex", gap: "0.5rem" })], children: [_jsx(Input, { id: inputId, name: name, value: value ?? "", autocomplete: "off", autocapitalize: "characters", spellcheck: false, "aria-invalid": hasError ? "true" : undefined, "aria-describedby": hasError ? errorId : undefined, mix: [raw({ flex: "1 1 auto", minInlineSize: "0" })] }), _jsx(Button, { type: "submit", variant: "outline", children: labels.apply })] }), hasError ? (_jsx("p", { id: errorId, "data-slot": "promo-code-error", mix: [
|
|
94
|
+
raw({
|
|
95
|
+
margin: "0",
|
|
96
|
+
fontSize: "0.8125rem",
|
|
97
|
+
color: "var(--ui-danger-fg)",
|
|
98
|
+
}),
|
|
99
|
+
], children: error })) : null] })] })] }));
|
|
100
|
+
};
|
|
101
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A − count + control for how many of something a cart holds, where each button is a form
|
|
3
|
+
* post naming the new count, so it works without script and the server stays the source of
|
|
4
|
+
* truth. At one, − becomes a bin that posts zero, which a cart reads as "remove".
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { Handle, Props as TagProps } from "remix/component";
|
|
10
|
+
/** Prop types for {@link QuantityStepper}. */
|
|
11
|
+
export declare namespace QuantityStepper {
|
|
12
|
+
/** What each button says to assistive tech, such as "One fewer Al pastor trio". */
|
|
13
|
+
interface Labels {
|
|
14
|
+
fewer: string;
|
|
15
|
+
more: string;
|
|
16
|
+
/** The − button's name at a count of one, when it posts zero. */
|
|
17
|
+
remove: string;
|
|
18
|
+
/** The count's name, such as "2 of Al pastor trio". */
|
|
19
|
+
count: string;
|
|
20
|
+
}
|
|
21
|
+
/** Props accepted by {@link QuantityStepper}; the host is a `<form>`. */
|
|
22
|
+
interface Props extends Omit<TagProps<"form">, "children" | "method"> {
|
|
23
|
+
/** Where the form posts. */
|
|
24
|
+
action: string;
|
|
25
|
+
/** The count now. */
|
|
26
|
+
value: number;
|
|
27
|
+
/** The field the new count posts as. @default "qty" */
|
|
28
|
+
name?: string;
|
|
29
|
+
/** The most the count may reach; + is disabled there. @default 99 */
|
|
30
|
+
max?: number;
|
|
31
|
+
/** Hidden fields the post carries, such as the line's index and the page to return to. */
|
|
32
|
+
fields?: Record<string, string>;
|
|
33
|
+
labels: Labels;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Renders the stepper as a pill-shaped form of two submit buttons around the count.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* <QuantityStepper action="/cart/line" value={2} fields={{ line: "0" }} labels={{ fewer: "One fewer taco", more: "One more taco", remove: "Remove taco", count: "2 tacos" }} />
|
|
41
|
+
*/
|
|
42
|
+
export declare function QuantityStepper(handle: Handle<QuantityStepper.Props>): () => import("remix/component").RemixElement;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "remix/component/jsx-runtime";
|
|
2
|
+
import { MinusIcon, PlusIcon, TrashIcon } from "@sdxc/icons";
|
|
3
|
+
import { mergeMix, raw } from "@sdxc/u/general";
|
|
4
|
+
import { when } from "@sdxc/u/state";
|
|
5
|
+
/** A stepper's round button. */
|
|
6
|
+
function stepButton() {
|
|
7
|
+
return [
|
|
8
|
+
raw({
|
|
9
|
+
display: "inline-grid",
|
|
10
|
+
placeItems: "center",
|
|
11
|
+
inlineSize: "2rem",
|
|
12
|
+
blockSize: "2rem",
|
|
13
|
+
padding: "0",
|
|
14
|
+
border: "0",
|
|
15
|
+
borderRadius: "999px",
|
|
16
|
+
color: "var(--ui-neutral-fg-emphasis)",
|
|
17
|
+
backgroundColor: "var(--ui-neutral-bg-tint)",
|
|
18
|
+
cursor: "pointer",
|
|
19
|
+
"& > svg": { inlineSize: "0.9375rem", blockSize: "0.9375rem" },
|
|
20
|
+
}),
|
|
21
|
+
when("&:hover", raw({ backgroundColor: "var(--ui-neutral-bg-tint-hover)" })),
|
|
22
|
+
when("&:focus-visible", raw({ outline: "2px solid var(--ui-brand-ring)", outlineOffset: "1px" })),
|
|
23
|
+
when("&:disabled", raw({ opacity: "0.4", cursor: "not-allowed" })),
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Renders the stepper as a pill-shaped form of two submit buttons around the count.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* <QuantityStepper action="/cart/line" value={2} fields={{ line: "0" }} labels={{ fewer: "One fewer taco", more: "One more taco", remove: "Remove taco", count: "2 tacos" }} />
|
|
31
|
+
*/
|
|
32
|
+
export function QuantityStepper(handle) {
|
|
33
|
+
return () => {
|
|
34
|
+
let { action, fields = {}, labels, max = 99, mix, name = "qty", value, ...rest } = handle.props;
|
|
35
|
+
return (_jsxs("form", { ...rest, method: "post", action: action, "data-slot": "quantity-stepper", mix: mergeMix([
|
|
36
|
+
raw({
|
|
37
|
+
display: "inline-flex",
|
|
38
|
+
alignItems: "center",
|
|
39
|
+
gap: "0.25rem",
|
|
40
|
+
padding: "0.125rem",
|
|
41
|
+
borderRadius: "999px",
|
|
42
|
+
boxShadow: "inset 0 0 0 1px var(--ui-neutral-border)",
|
|
43
|
+
}),
|
|
44
|
+
], mix), children: [Object.entries(fields).map(([field, fieldValue]) => (_jsx("input", { type: "hidden", name: field, value: fieldValue }))), _jsx("button", { type: "submit", name: name, value: String(value - 1), "aria-label": value <= 1 ? labels.remove : labels.fewer, "data-slot": "quantity-stepper-fewer", mix: stepButton(), children: value <= 1 ? _jsx(TrashIcon, { "aria-hidden": "true" }) : _jsx(MinusIcon, { "aria-hidden": "true" }) }), _jsx("output", { "aria-label": labels.count, mix: [
|
|
45
|
+
raw({
|
|
46
|
+
minInlineSize: "1.5rem",
|
|
47
|
+
textAlign: "center",
|
|
48
|
+
fontWeight: "700",
|
|
49
|
+
fontVariantNumeric: "tabular-nums",
|
|
50
|
+
}),
|
|
51
|
+
], children: value }), _jsx("button", { type: "submit", name: name, value: String(value + 1), "aria-label": labels.more, disabled: value >= max, "data-slot": "quantity-stepper-more", mix: stepButton(), children: _jsx(PlusIcon, { "aria-hidden": "true" }) })] }));
|
|
52
|
+
};
|
|
53
|
+
}
|