@travel-match/ui 0.2.0 → 0.4.0
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/components/CtaSentence/CtaSentence.cjs +1 -1
- package/dist/components/CtaSentence/CtaSentence.cjs.map +1 -1
- package/dist/components/CtaSentence/CtaSentence.js +142 -69
- package/dist/components/CtaSentence/CtaSentence.js.map +1 -1
- package/dist/components/HeroColumns/heroMotion.cjs +1 -1
- package/dist/components/HeroColumns/heroMotion.cjs.map +1 -1
- package/dist/components/HeroColumns/heroMotion.js +7 -44
- package/dist/components/HeroColumns/heroMotion.js.map +1 -1
- package/dist/components/HeroMap/HeroMap.cjs +1 -1
- package/dist/components/HeroMap/HeroMap.cjs.map +1 -1
- package/dist/components/HeroMap/HeroMap.js +58 -67
- package/dist/components/HeroMap/HeroMap.js.map +1 -1
- package/dist/components/HeroSwitcher/HeroSwitcher.cjs +1 -1
- package/dist/components/HeroSwitcher/HeroSwitcher.cjs.map +1 -1
- package/dist/components/HeroSwitcher/HeroSwitcher.js +85 -92
- package/dist/components/HeroSwitcher/HeroSwitcher.js.map +1 -1
- package/dist/components/HowItWorksSteps/HowItWorksSteps.cjs +1 -1
- package/dist/components/HowItWorksSteps/HowItWorksSteps.cjs.map +1 -1
- package/dist/components/HowItWorksSteps/HowItWorksSteps.js +84 -102
- package/dist/components/HowItWorksSteps/HowItWorksSteps.js.map +1 -1
- package/dist/components/LogoAnimation/LogoAnimation.cjs +2 -0
- package/dist/components/LogoAnimation/LogoAnimation.cjs.map +1 -0
- package/dist/components/LogoAnimation/LogoAnimation.js +202 -0
- package/dist/components/LogoAnimation/LogoAnimation.js.map +1 -0
- package/dist/components/LogoAnimation/LogoAnimationArtwork.cjs +2 -0
- package/dist/components/LogoAnimation/LogoAnimationArtwork.cjs.map +1 -0
- package/dist/components/LogoAnimation/LogoAnimationArtwork.js +57 -0
- package/dist/components/LogoAnimation/LogoAnimationArtwork.js.map +1 -0
- package/dist/components/LogoAnimation/motion.cjs +2 -0
- package/dist/components/LogoAnimation/motion.cjs.map +1 -0
- package/dist/components/LogoAnimation/motion.js +180 -0
- package/dist/components/LogoAnimation/motion.js.map +1 -0
- package/dist/components/PackageAnimation/PackageAnimation.cjs +1 -1
- package/dist/components/PackageAnimation/PackageAnimation.cjs.map +1 -1
- package/dist/components/PackageAnimation/PackageAnimation.js +31 -40
- package/dist/components/PackageAnimation/PackageAnimation.js.map +1 -1
- package/dist/components/PartnerCarousel/PartnerCarousel.cjs +1 -1
- package/dist/components/PartnerCarousel/PartnerCarousel.cjs.map +1 -1
- package/dist/components/PartnerCarousel/PartnerCarousel.js +94 -101
- package/dist/components/PartnerCarousel/PartnerCarousel.js.map +1 -1
- package/dist/components/PartnerCarousel/autoplay.cjs +1 -1
- package/dist/components/PartnerCarousel/autoplay.cjs.map +1 -1
- package/dist/components/PartnerCarousel/autoplay.js +13 -9
- package/dist/components/PartnerCarousel/autoplay.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +62 -55
- package/dist/index.d.ts +62 -55
- package/dist/index.js +100 -99
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/dist/components/PartnerCarousel/AutoplayToggle.cjs +0 -2
- package/dist/components/PartnerCarousel/AutoplayToggle.cjs.map +0 -1
- package/dist/components/PartnerCarousel/AutoplayToggle.js +0 -36
- package/dist/components/PartnerCarousel/AutoplayToggle.js.map +0 -1
|
@@ -1,39 +1,41 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { CheckmarkIcon as e } from "../../icons/generated/CheckmarkIcon.js";
|
|
3
3
|
import { cn as t } from "../../utils/cn.js";
|
|
4
|
-
import {
|
|
4
|
+
import { useOnScreen as n, usePrefersReducedMotion as r } from "../HeroColumns/heroMotion.js";
|
|
5
5
|
/* empty css */
|
|
6
|
-
import { forwardRef as
|
|
7
|
-
import { Fragment as
|
|
6
|
+
import { forwardRef as i, useCallback as a, useEffect as o, useId as s, useLayoutEffect as c, useRef as l, useState as u } from "react";
|
|
7
|
+
import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
8
8
|
// src/components/HeroSwitcher/HeroSwitcher.tsx
|
|
9
|
-
var
|
|
10
|
-
let
|
|
11
|
-
let t =
|
|
12
|
-
t && (
|
|
9
|
+
var m = typeof window > "u" ? o : c, h = /* @__PURE__ */ i(function({ items: i, value: c, defaultValue: h, onValueChange: g, autoPlay: _ = !0, interval: v = 3600, paused: y = !1, "aria-label": b, headingLevel: x = 3, className: S, onPointerEnter: C, onPointerLeave: w, onFocus: T, onBlur: E, ...D }, O) {
|
|
10
|
+
let k = s(), A = l(null), j = l(null), M = l([]), [N, P] = u(h), F = c === void 0 ? N : c, I = i.findIndex((e) => e.value === F), L = I === -1 ? 0 : I, [R, z] = u(!1), [B, V] = u(!1), [H, U] = u(!1), W = n(A), G = r(), K = _ && !G && i.length > 1 && !y && !B && !H && W, q = a((e) => {
|
|
11
|
+
let t = i[e];
|
|
12
|
+
t && (c === void 0 && P(t.value), t.value !== i[L]?.value && g?.(t.value));
|
|
13
13
|
}, [
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
i,
|
|
15
|
+
c,
|
|
16
|
+
L,
|
|
17
|
+
g
|
|
18
18
|
]);
|
|
19
|
-
|
|
20
|
-
if (!
|
|
21
|
-
let e = window.setTimeout(() =>
|
|
19
|
+
o(() => {
|
|
20
|
+
if (!K) return;
|
|
21
|
+
let e = window.setTimeout(() => {
|
|
22
|
+
z(!1), q((L + 1) % i.length);
|
|
23
|
+
}, Math.max(v, 0));
|
|
22
24
|
return () => window.clearTimeout(e);
|
|
23
25
|
}, [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
K,
|
|
27
|
+
L,
|
|
28
|
+
v,
|
|
29
|
+
i.length,
|
|
30
|
+
q
|
|
29
31
|
]);
|
|
30
|
-
let [
|
|
31
|
-
|
|
32
|
-
let e =
|
|
32
|
+
let [J, Y] = u(null);
|
|
33
|
+
m(() => {
|
|
34
|
+
let e = j.current;
|
|
33
35
|
if (!e) return;
|
|
34
36
|
let t = () => {
|
|
35
|
-
let e =
|
|
36
|
-
e && e.offsetWidth !== 0 &&
|
|
37
|
+
let e = M.current[L];
|
|
38
|
+
e && e.offsetWidth !== 0 && Y((t) => t && t.x === e.offsetLeft && t.width === e.offsetWidth ? t : {
|
|
37
39
|
x: e.offsetLeft,
|
|
38
40
|
width: e.offsetWidth
|
|
39
41
|
});
|
|
@@ -41,53 +43,53 @@ var g = typeof window > "u" ? c : u, _ = /* @__PURE__ */ o(function({ items: o,
|
|
|
41
43
|
if (t(), typeof ResizeObserver > "u") return;
|
|
42
44
|
let n = new ResizeObserver(t);
|
|
43
45
|
return n.observe(e), () => n.disconnect();
|
|
44
|
-
}, [
|
|
45
|
-
let
|
|
46
|
-
|
|
47
|
-
},
|
|
48
|
-
let n =
|
|
49
|
-
if (e.key === "ArrowRight")
|
|
50
|
-
else if (e.key === "ArrowLeft")
|
|
51
|
-
else if (e.key === "Home")
|
|
52
|
-
else if (e.key === "End")
|
|
46
|
+
}, [L, i.length]);
|
|
47
|
+
let X = (e) => {
|
|
48
|
+
z(!0), q(e);
|
|
49
|
+
}, Z = (e, t) => {
|
|
50
|
+
let n = i.length - 1, r = typeof getComputedStyle == "function" && getComputedStyle(e.currentTarget).direction === "rtl", a;
|
|
51
|
+
if (e.key === "ArrowRight") a = r ? t - 1 : t + 1;
|
|
52
|
+
else if (e.key === "ArrowLeft") a = r ? t + 1 : t - 1;
|
|
53
|
+
else if (e.key === "Home") a = 0;
|
|
54
|
+
else if (e.key === "End") a = n;
|
|
53
55
|
else return;
|
|
54
|
-
e.preventDefault(),
|
|
55
|
-
},
|
|
56
|
-
return /* @__PURE__ */
|
|
56
|
+
e.preventDefault(), a = a < 0 ? n : a > n ? 0 : a, X(a), M.current[a]?.focus();
|
|
57
|
+
}, Q = `h${x}`;
|
|
58
|
+
return /* @__PURE__ */ p("div", {
|
|
57
59
|
ref: (e) => {
|
|
58
|
-
|
|
60
|
+
A.current = e, typeof O == "function" ? O(e) : O && (O.current = e);
|
|
59
61
|
},
|
|
60
|
-
className: t("tm-hero-switcher",
|
|
61
|
-
"data-playing":
|
|
62
|
-
"data-picked":
|
|
62
|
+
className: t("tm-hero-switcher", S),
|
|
63
|
+
"data-playing": K ? "" : void 0,
|
|
64
|
+
"data-picked": R ? "" : void 0,
|
|
63
65
|
onPointerEnter: (e) => {
|
|
64
|
-
|
|
66
|
+
C?.(e), e.pointerType === "mouse" && V(!0);
|
|
65
67
|
},
|
|
66
68
|
onPointerLeave: (e) => {
|
|
67
|
-
|
|
69
|
+
w?.(e), V(!1);
|
|
68
70
|
},
|
|
69
71
|
onFocus: (e) => {
|
|
70
|
-
|
|
72
|
+
T?.(e);
|
|
71
73
|
let t = !0;
|
|
72
74
|
try {
|
|
73
75
|
t = e.target.matches(":focus-visible");
|
|
74
76
|
} catch {}
|
|
75
|
-
t &&
|
|
77
|
+
t && U(!0);
|
|
76
78
|
},
|
|
77
79
|
onBlur: (e) => {
|
|
78
|
-
|
|
80
|
+
E?.(e), e.currentTarget.contains(e.relatedTarget) || U(!1);
|
|
79
81
|
},
|
|
80
|
-
...
|
|
82
|
+
...D,
|
|
81
83
|
children: [
|
|
82
|
-
/* @__PURE__ */
|
|
84
|
+
/* @__PURE__ */ f("div", {
|
|
83
85
|
className: "tm-hero-switcher__photo",
|
|
84
|
-
children:
|
|
85
|
-
let n = t ===
|
|
86
|
-
return /* @__PURE__ */
|
|
86
|
+
children: i.map((e, t) => {
|
|
87
|
+
let n = t === L;
|
|
88
|
+
return /* @__PURE__ */ f("div", {
|
|
87
89
|
className: "tm-hero-switcher__slide",
|
|
88
90
|
"data-active": n ? "" : void 0,
|
|
89
91
|
"aria-hidden": !n || void 0,
|
|
90
|
-
children: e.image ?? (e.imageSrc ? /* @__PURE__ */
|
|
92
|
+
children: e.image ?? (e.imageSrc ? /* @__PURE__ */ f("img", {
|
|
91
93
|
className: "tm-hero-switcher__image",
|
|
92
94
|
src: e.imageSrc,
|
|
93
95
|
alt: e.imageAlt ?? "",
|
|
@@ -96,91 +98,82 @@ var g = typeof window > "u" ? c : u, _ = /* @__PURE__ */ o(function({ items: o,
|
|
|
96
98
|
}, e.value);
|
|
97
99
|
})
|
|
98
100
|
}),
|
|
99
|
-
/* @__PURE__ */
|
|
100
|
-
ref:
|
|
101
|
+
/* @__PURE__ */ p("div", {
|
|
102
|
+
ref: j,
|
|
101
103
|
className: "tm-hero-switcher__switch",
|
|
102
104
|
role: "tablist",
|
|
103
|
-
"aria-label":
|
|
104
|
-
"data-measured":
|
|
105
|
-
children: [/* @__PURE__ */
|
|
105
|
+
"aria-label": b,
|
|
106
|
+
"data-measured": J ? "" : void 0,
|
|
107
|
+
children: [/* @__PURE__ */ f("span", {
|
|
106
108
|
className: "tm-hero-switcher__indicator",
|
|
107
109
|
"aria-hidden": "true",
|
|
108
|
-
style:
|
|
109
|
-
width:
|
|
110
|
-
transform: `translateX(${
|
|
110
|
+
style: J ? {
|
|
111
|
+
width: J.width,
|
|
112
|
+
transform: `translateX(${J.x}px)`
|
|
111
113
|
} : void 0
|
|
112
|
-
}),
|
|
113
|
-
let n = t ===
|
|
114
|
-
return /* @__PURE__ */
|
|
114
|
+
}), i.map((e, t) => {
|
|
115
|
+
let n = t === L;
|
|
116
|
+
return /* @__PURE__ */ p("button", {
|
|
115
117
|
ref: (e) => {
|
|
116
|
-
|
|
118
|
+
M.current[t] = e;
|
|
117
119
|
},
|
|
118
120
|
type: "button",
|
|
119
121
|
role: "tab",
|
|
120
|
-
id: `${
|
|
122
|
+
id: `${k}-tab-${t}`,
|
|
121
123
|
className: "tm-hero-switcher__tab",
|
|
122
124
|
"data-tm-icon-size": "sm",
|
|
123
125
|
"aria-selected": n,
|
|
124
|
-
"aria-controls": `${
|
|
126
|
+
"aria-controls": `${k}-panel-${t}`,
|
|
125
127
|
tabIndex: n ? 0 : -1,
|
|
126
|
-
onClick: () =>
|
|
127
|
-
onKeyDown: (e) =>
|
|
128
|
-
children: [e.icon, /* @__PURE__ */
|
|
128
|
+
onClick: () => X(t),
|
|
129
|
+
onKeyDown: (e) => Z(e, t),
|
|
130
|
+
children: [e.icon, /* @__PURE__ */ f("span", {
|
|
129
131
|
className: "tm-hero-switcher__tab-label",
|
|
130
132
|
children: e.label
|
|
131
133
|
})]
|
|
132
134
|
}, e.value);
|
|
133
135
|
})]
|
|
134
136
|
}),
|
|
135
|
-
/* @__PURE__ */
|
|
137
|
+
/* @__PURE__ */ f("div", {
|
|
136
138
|
className: "tm-hero-switcher__card",
|
|
137
|
-
children:
|
|
138
|
-
let r = n ===
|
|
139
|
-
return /* @__PURE__ */
|
|
139
|
+
children: i.map((t, n) => {
|
|
140
|
+
let r = n === L;
|
|
141
|
+
return /* @__PURE__ */ p("div", {
|
|
140
142
|
role: "tabpanel",
|
|
141
|
-
id: `${
|
|
142
|
-
"aria-labelledby": `${
|
|
143
|
+
id: `${k}-panel-${n}`,
|
|
144
|
+
"aria-labelledby": `${k}-tab-${n}`,
|
|
143
145
|
className: "tm-hero-switcher__panel",
|
|
144
146
|
"data-active": r ? "" : void 0,
|
|
145
147
|
"aria-hidden": !r || void 0,
|
|
146
148
|
children: [
|
|
147
|
-
t.overline == null ? null : /* @__PURE__ */
|
|
149
|
+
t.overline == null ? null : /* @__PURE__ */ f("p", {
|
|
148
150
|
className: "tm-hero-switcher__overline",
|
|
149
151
|
children: t.overline
|
|
150
152
|
}),
|
|
151
|
-
/* @__PURE__ */
|
|
153
|
+
/* @__PURE__ */ f(Q, {
|
|
152
154
|
className: "tm-hero-switcher__title",
|
|
153
155
|
children: t.title
|
|
154
156
|
}),
|
|
155
|
-
t.details?.length ? /* @__PURE__ */
|
|
157
|
+
t.details?.length ? /* @__PURE__ */ f("ul", {
|
|
156
158
|
className: "tm-hero-switcher__details",
|
|
157
159
|
"data-tm-icon-size": "sm",
|
|
158
|
-
children: t.details.map((e, t) => /* @__PURE__ */
|
|
160
|
+
children: t.details.map((e, t) => /* @__PURE__ */ p("li", {
|
|
159
161
|
className: "tm-hero-switcher__detail",
|
|
160
|
-
children: [e.icon, /* @__PURE__ */
|
|
162
|
+
children: [e.icon, /* @__PURE__ */ f("span", { children: e.label })]
|
|
161
163
|
}, e.key ?? t))
|
|
162
164
|
}) : null,
|
|
163
|
-
t.status == null ? null : /* @__PURE__ */
|
|
165
|
+
t.status == null ? null : /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f("hr", { className: "tm-hero-switcher__divider" }), /* @__PURE__ */ p("p", {
|
|
164
166
|
className: "tm-hero-switcher__status",
|
|
165
167
|
"data-tm-icon-size": "sm",
|
|
166
|
-
children: [t.statusIcon ?? /* @__PURE__ */
|
|
168
|
+
children: [t.statusIcon ?? /* @__PURE__ */ f(e, {}), /* @__PURE__ */ f("span", { children: t.status })]
|
|
167
169
|
})] })
|
|
168
170
|
]
|
|
169
171
|
}, t.value);
|
|
170
172
|
})
|
|
171
|
-
})
|
|
172
|
-
Y ? /* @__PURE__ */ m("button", {
|
|
173
|
-
type: "button",
|
|
174
|
-
className: "tm-hero-switcher__playback",
|
|
175
|
-
"aria-label": z || b ? w : C,
|
|
176
|
-
title: z || b ? w : C,
|
|
177
|
-
disabled: b,
|
|
178
|
-
onClick: () => B((e) => !e),
|
|
179
|
-
children: m(z || b ? r : n, {})
|
|
180
|
-
}) : null
|
|
173
|
+
})
|
|
181
174
|
]
|
|
182
175
|
});
|
|
183
176
|
});
|
|
184
|
-
export {
|
|
177
|
+
export { h as HeroSwitcher };
|
|
185
178
|
|
|
186
179
|
//# sourceMappingURL=HeroSwitcher.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HeroSwitcher.js","names":["_Fragment","Fragment$1","useIsomorphicLayoutEffect","useEffect","useLayoutEffect","HeroSwitcher","ariaLabel","props","id","useId","rootRef","useRef","listRef","tabRefs","internal","setInternal","useState","defaultValue","requested","value","found","items","item","activeIndex","stopped","setStopped","picked","setPicked","hovered","setHovered","focused","setFocused","onScreen","useOnScreen","reducedMotion","usePrefersReducedMotion","canPlay","autoPlay","running","paused","select","useCallback","next","index","onValueChange","timer","interval","indicator","setIndicator","list","measure","tab","previous","observer","pick","handleKeyDown","last","rtl","event","Heading","headingLevel","node","ref","cn","className","onPointerEnter","onPointerLeave","keyboard","onBlur","active","detail","row","CheckmarkIcon","playLabel","pauseLabel","current","jsx","PlayGlyph","PauseGlyph"],"sources":["../../../src/components/HeroSwitcher/HeroSwitcher.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n type CSSProperties,\n type HTMLAttributes,\n type KeyboardEvent,\n type ReactNode,\n} from 'react';\nimport { CheckmarkIcon } from '../../icons';\nimport { cn } from '../../utils/cn';\nimport { PauseGlyph, PlayGlyph, useOnScreen, usePrefersReducedMotion } from '../HeroColumns/heroMotion';\nimport './HeroSwitcher.css';\n\nexport interface HeroSwitcherDetail {\n /** Icon in front of the text, e.g. `<CalendarIcon />`; drawn at 16px. */\n icon?: ReactNode;\n /** Already formatted, translated text: dates, travelers, what is included… */\n label: ReactNode;\n /** React key; defaults to the row's index. */\n key?: string | number;\n}\n\nexport interface HeroSwitcherItem {\n /** Identifier of the state (Figma \"Type\": `package`, `flight`). */\n value: string;\n /** Text of the segment in the switch, e.g. \"Travel Package\". */\n label: ReactNode;\n /** Icon of the segment, e.g. `<RoadmapIcon />`; drawn at 16px. */\n icon?: ReactNode;\n /** Photo URL. Without it (and without `image`) a neutral tile is shown. */\n imageSrc?: string;\n /** Alternative text of the photo; leave empty when it is decorative. */\n imageAlt?: string;\n /** Custom photo element (e.g. a framework `<Image>`); it fills the frame and replaces `imageSrc`. */\n image?: ReactNode;\n /** Small caps line above the title (Figma \"Overline\"), e.g. \"Your request\". */\n overline?: ReactNode;\n /** Title of the sample request, e.g. \"Weekend at Lake Sevan\". */\n title: ReactNode;\n /** Icon + text rows under the title. */\n details?: HeroSwitcherDetail[];\n /** Text of the green pill at the bottom of the card (Figma \"Status\"), e.g. \"3 offers to compare\". */\n status?: ReactNode;\n /** Icon of the status pill. Defaults to a check mark. */\n statusIcon?: ReactNode;\n}\n\nexport interface HeroSwitcherProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {\n /** The states to switch between (Figma: Package and Flight), in the order of the switch. */\n items: HeroSwitcherItem[];\n /** Selected item (controlled). */\n value?: string;\n /** Initially selected item when uncontrolled; defaults to the first one. */\n defaultValue?: string;\n /** Called with the new value when the user picks a segment or autoplay advances. */\n onValueChange?: (value: string) => void;\n /** Advances to the next item on its own until the user picks a segment or presses pause. */\n autoPlay?: boolean;\n /** Milliseconds each item stays before autoplay moves on (Figma prototype: 3s delay + 0.6s transition). */\n interval?: number;\n /** Holds autoplay from outside (the selected item stays as it is). */\n paused?: boolean;\n /** Accessible name of the switch (tab list). */\n 'aria-label'?: string;\n /** Heading level of the card title; pick the one that fits the page outline. */\n headingLevel?: 2 | 3 | 4 | 5 | 6;\n /** Accessible name of the pause button shown while autoplay runs. */\n pauseLabel?: string;\n /** Accessible name of the same button once autoplay is stopped. */\n playLabel?: string;\n}\n\nconst useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\n/**\n * Photo, segmented switch and a sample request card that change together (Figma component set\n * \"Travel Requests / Hero switcher\"). The switch is a real tab list — click or use the arrow keys — and autoplay\n * stops for good once the user takes over, pauses on hover and focus, off-screen, in hidden tabs and never starts\n * for users who prefer reduced motion.\n */\nexport const HeroSwitcher = /* @__PURE__ */ forwardRef<HTMLDivElement, HeroSwitcherProps>(function HeroSwitcher(\n {\n items,\n value,\n defaultValue,\n onValueChange,\n autoPlay = true,\n interval = 3600,\n paused = false,\n 'aria-label': ariaLabel,\n headingLevel = 3,\n pauseLabel = 'Pause',\n playLabel = 'Play',\n className,\n onPointerEnter,\n onPointerLeave,\n onFocus,\n onBlur,\n ...props\n },\n ref,\n) {\n const id = useId();\n const rootRef = useRef<HTMLDivElement | null>(null);\n const listRef = useRef<HTMLDivElement | null>(null);\n const tabRefs = useRef<Array<HTMLButtonElement | null>>([]);\n\n const [internal, setInternal] = useState(defaultValue);\n const requested = value !== undefined ? value : internal;\n const found = items.findIndex((item) => item.value === requested);\n const activeIndex = found === -1 ? 0 : found;\n\n const [stopped, setStopped] = useState(false);\n // The last change came from the user picking a segment (Figma: those switches animate in 0.4s, autoplay in 0.6s).\n const [picked, setPicked] = useState(false);\n const [hovered, setHovered] = useState(false);\n const [focused, setFocused] = useState(false);\n const onScreen = useOnScreen(rootRef);\n const reducedMotion = usePrefersReducedMotion();\n const canPlay = autoPlay && !reducedMotion && items.length > 1;\n const running = canPlay && !paused && !stopped && !hovered && !focused && onScreen;\n\n const select = useCallback(\n (index: number) => {\n const next = items[index];\n if (!next) return;\n if (value === undefined) setInternal(next.value);\n if (next.value !== items[activeIndex]?.value) onValueChange?.(next.value);\n },\n [items, value, activeIndex, onValueChange],\n );\n\n useEffect(() => {\n if (!running) return;\n const timer = window.setTimeout(() => select((activeIndex + 1) % items.length), Math.max(interval, 0));\n return () => window.clearTimeout(timer);\n }, [running, activeIndex, interval, items.length, select]);\n\n // The sliding pill (Figma \"Indicator\") takes the position and width of the selected segment.\n const [indicator, setIndicator] = useState<{ x: number; width: number } | null>(null);\n useIsomorphicLayoutEffect(() => {\n const list = listRef.current;\n if (!list) return;\n const measure = () => {\n const tab = tabRefs.current[activeIndex];\n if (!tab || tab.offsetWidth === 0) return;\n setIndicator((previous) =>\n previous && previous.x === tab.offsetLeft && previous.width === tab.offsetWidth\n ? previous\n : { x: tab.offsetLeft, width: tab.offsetWidth },\n );\n };\n measure();\n if (typeof ResizeObserver === 'undefined') return;\n const observer = new ResizeObserver(measure);\n observer.observe(list);\n return () => observer.disconnect();\n }, [activeIndex, items.length]);\n\n const pick = (index: number) => {\n setStopped(true);\n setPicked(true);\n select(index);\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>, index: number) => {\n const last = items.length - 1;\n const rtl = typeof getComputedStyle === 'function' && getComputedStyle(event.currentTarget).direction === 'rtl';\n let next: number;\n if (event.key === 'ArrowRight') next = rtl ? index - 1 : index + 1;\n else if (event.key === 'ArrowLeft') next = rtl ? index + 1 : index - 1;\n else if (event.key === 'Home') next = 0;\n else if (event.key === 'End') next = last;\n else return;\n event.preventDefault();\n next = next < 0 ? last : next > last ? 0 : next;\n pick(next);\n tabRefs.current[next]?.focus();\n };\n\n const Heading = `h${headingLevel}` as const;\n\n return (\n <div\n ref={(node) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n }}\n className={cn('tm-hero-switcher', className)}\n data-playing={running ? '' : undefined}\n data-picked={picked ? '' : undefined}\n onPointerEnter={(event) => {\n onPointerEnter?.(event);\n if (event.pointerType === 'mouse') setHovered(true);\n }}\n onPointerLeave={(event) => {\n onPointerLeave?.(event);\n setHovered(false);\n }}\n onFocus={(event) => {\n onFocus?.(event);\n // Keyboard focus only: a mouse click on the pause button must not hold autoplay until the next blur.\n let keyboard = true;\n try {\n keyboard = event.target.matches(':focus-visible');\n } catch {\n /* :focus-visible unsupported — treat every focus as keyboard focus */\n }\n if (keyboard) setFocused(true);\n }}\n onBlur={(event) => {\n onBlur?.(event);\n if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false);\n }}\n {...props}\n >\n <div className=\"tm-hero-switcher__photo\">\n {items.map((item, index) => {\n const active = index === activeIndex;\n return (\n <div key={item.value} className=\"tm-hero-switcher__slide\" data-active={active ? '' : undefined} aria-hidden={active ? undefined : true}>\n {item.image ??\n (item.imageSrc ? (\n <img className=\"tm-hero-switcher__image\" src={item.imageSrc} alt={item.imageAlt ?? ''} draggable={false} />\n ) : null)}\n </div>\n );\n })}\n </div>\n\n <div ref={listRef} className=\"tm-hero-switcher__switch\" role=\"tablist\" aria-label={ariaLabel} data-measured={indicator ? '' : undefined}>\n <span\n className=\"tm-hero-switcher__indicator\"\n aria-hidden=\"true\"\n style={indicator ? ({ width: indicator.width, transform: `translateX(${indicator.x}px)` } as CSSProperties) : undefined}\n />\n {items.map((item, index) => {\n const active = index === activeIndex;\n return (\n <button\n key={item.value}\n ref={(node) => {\n tabRefs.current[index] = node;\n }}\n type=\"button\"\n role=\"tab\"\n id={`${id}-tab-${index}`}\n className=\"tm-hero-switcher__tab\"\n data-tm-icon-size=\"sm\"\n aria-selected={active}\n aria-controls={`${id}-panel-${index}`}\n tabIndex={active ? 0 : -1}\n onClick={() => pick(index)}\n onKeyDown={(event) => handleKeyDown(event, index)}\n >\n {item.icon}\n <span className=\"tm-hero-switcher__tab-label\">{item.label}</span>\n </button>\n );\n })}\n </div>\n\n <div className=\"tm-hero-switcher__card\">\n {items.map((item, index) => {\n const active = index === activeIndex;\n return (\n <div\n key={item.value}\n role=\"tabpanel\"\n id={`${id}-panel-${index}`}\n aria-labelledby={`${id}-tab-${index}`}\n className=\"tm-hero-switcher__panel\"\n data-active={active ? '' : undefined}\n aria-hidden={active ? undefined : true}\n >\n {item.overline != null ? <p className=\"tm-hero-switcher__overline\">{item.overline}</p> : null}\n <Heading className=\"tm-hero-switcher__title\">{item.title}</Heading>\n {item.details?.length ? (\n <ul className=\"tm-hero-switcher__details\" data-tm-icon-size=\"sm\">\n {item.details.map((detail, row) => (\n <li key={detail.key ?? row} className=\"tm-hero-switcher__detail\">\n {detail.icon}\n <span>{detail.label}</span>\n </li>\n ))}\n </ul>\n ) : null}\n {item.status != null ? (\n <>\n <hr className=\"tm-hero-switcher__divider\" />\n <p className=\"tm-hero-switcher__status\" data-tm-icon-size=\"sm\">\n {item.statusIcon ?? <CheckmarkIcon />}\n <span>{item.status}</span>\n </p>\n </>\n ) : null}\n </div>\n );\n })}\n </div>\n\n {canPlay ? (\n <button\n type=\"button\"\n className=\"tm-hero-switcher__playback\"\n aria-label={stopped || paused ? playLabel : pauseLabel}\n title={stopped || paused ? playLabel : pauseLabel}\n disabled={paused}\n onClick={() => setStopped((current) => !current)}\n >\n {stopped || paused ? <PlayGlyph /> : <PauseGlyph />}\n </button>\n ) : null}\n </div>\n );\n});\n"],"mappings":";;;;;;;;AA6EA,IAAME,IAA4B,OAAO,SAAW,MAAcC,IAAYC,GAQjEC,IAA+B,kBAA8C,SACxF,EACE,UACA,UACA,iBACA,kBACA,eAAW,IACX,cAAW,MACX,YAAS,IACT,cAAcC,GACd,kBAAe,GACf,gBAAa,SACb,eAAY,QACZ,eACA,oBACA,mBACA,YACA,WACA,GAAGC,KAEL,GACA;CACA,IAAMC,IAAKC,EAAM,GACXC,IAAUC,EAA8B,IAAI,GAC5CC,IAAUD,EAA8B,IAAI,GAC5CE,IAAUF,EAAwC,CAAC,CAAC,GAEpD,CAACG,GAAUC,KAAeC,EAASC,CAAY,GAC/CC,IAAYC,MAAU,KAAA,IAAoBL,IAARK,GAClCC,IAAQC,EAAM,WAAW,MAASC,EAAK,UAAUJ,CAAS,GAC1DK,IAAcH,MAAU,KAAK,IAAIA,GAEjC,CAACI,GAASC,KAAcT,EAAS,EAAK,GAEtC,CAACU,GAAQC,KAAaX,EAAS,EAAK,GACpC,CAACY,GAASC,KAAcb,EAAS,EAAK,GACtC,CAACc,GAASC,KAAcf,EAAS,EAAK,GACtCgB,IAAWC,EAAYvB,CAAO,GAC9BwB,IAAgBC,EAAwB,GACxCC,IAAUC,MAAY,CAACH,KAAiBb,EAAM,SAAS,GACvDiB,IAAUF,KAAW,CAACG,KAAU,CAACf,KAAW,CAACI,KAAW,CAACE,KAAWE,GAEpEQ,IAASC,GACZ,MAAkB;EACjB,IAAMC,IAAOrB,EAAMsB;EACnB,AAAKD,MACDvB,MAAU,KAAA,KAAWJ,EAAY2B,EAAK,KAAK,GAC3CA,EAAK,UAAUrB,EAAME,EAAY,EAAE,SAAOqB,IAAgBF,EAAK,KAAK;CAC1E,GACA;EAACrB;EAAOF;EAAOI;EAAaqB;CAAa,CAC3C;CAEA,QAAgB;EACd,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AK;OAAe,CAAA;OACjEA,EAAK,SAAS,SACb,kBAAC,MAAD;QAAI,WAAU;QAA4B,qBAAkB;QACzD,UAAAA,EAAK,QAAQ,KAAK,GAAQ,MACzB,kBAAC,MAAD;SAA4B,WAAU;SAAtC,UAAA,CACGgD,EAAO,MACR,kBAAC,QAAD,EAAA,UAAOA,EAAO,MAAY,CAAA,CACxB;QAHK,GAAAA,EAAO,OAAOC,CAGnB,CACL;OACC,CAAA,IACF;OACHjD,EAAK,UAAU,OAQZ,OAPF,kBAAAtB,GAAA,EAAA,UAAA,CACE,kBAAC,MAAD,EAAI,WAAU,4BAA6B,CAAA,GAC3C,kBAAC,KAAD;QAAG,WAAU;QAA2B,qBAAkB;QAA1D,UAAA,CACGsB,EAAK,cAAc,kBAACkD,GAAD,CAAgB,CAAA,GACpC,kBAAC,QAAD,EAAA,UAAOlD,EAAK,OAAa,CAAA,CACxB;OACH,CAAA,CAAA,EAAA,CAAA;MAED;KA7BE,GAAAA,EAAK,KA6BP;IAET,CAAC;GACE,CAAA;GAEJc,IACC,kBAAC,UAAD;IACE,MAAK;IACL,WAAU;IACV,cAAYZ,KAAWe,IAASkC,IAAYC;IAC5C,OAAOlD,KAAWe,IAASkC,IAAYC;IACvC,UAAUnC;IACV,eAAed,GAAY,MAAY,CAACkD,CAAO;IAE9C,UAAoBC,EAApBpD,KAAWe,IAAUsC,IAAgBC,GAAjB,CAAY,CAAiB;GAC5C,CAAA,IACN;EACD;;AAET,CAAC"}
|
|
1
|
+
{"version":3,"file":"HeroSwitcher.js","names":["_Fragment","Fragment$1","useIsomorphicLayoutEffect","useEffect","useLayoutEffect","HeroSwitcher","ariaLabel","props","id","useId","rootRef","useRef","listRef","tabRefs","internal","setInternal","useState","defaultValue","requested","value","found","items","item","activeIndex","picked","setPicked","hovered","setHovered","focused","setFocused","onScreen","useOnScreen","reducedMotion","usePrefersReducedMotion","running","autoPlay","paused","select","useCallback","next","index","onValueChange","timer","interval","indicator","setIndicator","list","measure","tab","previous","observer","pick","handleKeyDown","last","rtl","event","Heading","headingLevel","node","ref","cn","className","onPointerEnter","onPointerLeave","keyboard","onBlur","active","detail","row","CheckmarkIcon"],"sources":["../../../src/components/HeroSwitcher/HeroSwitcher.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useLayoutEffect,\n useRef,\n useState,\n type CSSProperties,\n type HTMLAttributes,\n type KeyboardEvent,\n type ReactNode,\n} from 'react';\nimport { CheckmarkIcon } from '../../icons';\nimport { cn } from '../../utils/cn';\nimport { useOnScreen, usePrefersReducedMotion } from '../HeroColumns/heroMotion';\nimport './HeroSwitcher.css';\n\nexport interface HeroSwitcherDetail {\n /** Icon in front of the text, e.g. `<CalendarIcon />`; drawn at 16px. */\n icon?: ReactNode;\n /** Already formatted, translated text: dates, travelers, what is included… */\n label: ReactNode;\n /** React key; defaults to the row's index. */\n key?: string | number;\n}\n\nexport interface HeroSwitcherItem {\n /** Identifier of the state (Figma \"Type\": `package`, `flight`). */\n value: string;\n /** Text of the segment in the switch, e.g. \"Travel Package\". */\n label: ReactNode;\n /** Icon of the segment, e.g. `<RoadmapIcon />`; drawn at 16px. */\n icon?: ReactNode;\n /** Photo URL. Without it (and without `image`) a neutral tile is shown. */\n imageSrc?: string;\n /** Alternative text of the photo; leave empty when it is decorative. */\n imageAlt?: string;\n /** Custom photo element (e.g. a framework `<Image>`); it fills the frame and replaces `imageSrc`. */\n image?: ReactNode;\n /** Small caps line above the title (Figma \"Overline\"), e.g. \"Your request\". */\n overline?: ReactNode;\n /** Title of the sample request, e.g. \"Weekend at Lake Sevan\". */\n title: ReactNode;\n /** Icon + text rows under the title. */\n details?: HeroSwitcherDetail[];\n /** Text of the green pill at the bottom of the card (Figma \"Status\"), e.g. \"3 offers to compare\". */\n status?: ReactNode;\n /** Icon of the status pill. Defaults to a check mark. */\n statusIcon?: ReactNode;\n}\n\nexport interface HeroSwitcherProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange' | 'defaultValue'> {\n /** The states to switch between (Figma: Package and Flight), in the order of the switch. */\n items: HeroSwitcherItem[];\n /** Selected item (controlled). */\n value?: string;\n /** Initially selected item when uncontrolled; defaults to the first one. */\n defaultValue?: string;\n /** Called with the new value when the user picks a segment or autoplay advances. */\n onValueChange?: (value: string) => void;\n /** Advances to the next item on its own, in an endless loop; after the user picks a segment it carries on from that item. */\n autoPlay?: boolean;\n /** Milliseconds each item stays before autoplay moves on (Figma prototype: 3s delay + 0.6s transition). */\n interval?: number;\n /** Holds autoplay from outside (the selected item stays as it is); it carries on once this is `false` again. */\n paused?: boolean;\n /** Accessible name of the switch (tab list). */\n 'aria-label'?: string;\n /** Heading level of the card title; pick the one that fits the page outline. */\n headingLevel?: 2 | 3 | 4 | 5 | 6;\n}\n\nconst useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;\n\n/**\n * Photo, segmented switch and a sample request card that change together (Figma component set\n * \"Travel Requests / Hero switcher\"). The switch is a real tab list — click or use the arrow keys — and autoplay\n * is an endless loop: it carries on from the segment the user picked, holds on hover and keyboard focus, off-screen\n * and in hidden tabs, and never starts for users who prefer reduced motion.\n */\nexport const HeroSwitcher = /* @__PURE__ */ forwardRef<HTMLDivElement, HeroSwitcherProps>(function HeroSwitcher(\n {\n items,\n value,\n defaultValue,\n onValueChange,\n autoPlay = true,\n interval = 3600,\n paused = false,\n 'aria-label': ariaLabel,\n headingLevel = 3,\n className,\n onPointerEnter,\n onPointerLeave,\n onFocus,\n onBlur,\n ...props\n },\n ref,\n) {\n const id = useId();\n const rootRef = useRef<HTMLDivElement | null>(null);\n const listRef = useRef<HTMLDivElement | null>(null);\n const tabRefs = useRef<Array<HTMLButtonElement | null>>([]);\n\n const [internal, setInternal] = useState(defaultValue);\n const requested = value !== undefined ? value : internal;\n const found = items.findIndex((item) => item.value === requested);\n const activeIndex = found === -1 ? 0 : found;\n\n // The last change came from the user picking a segment (Figma: those switches animate in 0.4s, autoplay in 0.6s).\n const [picked, setPicked] = useState(false);\n const [hovered, setHovered] = useState(false);\n const [focused, setFocused] = useState(false);\n const onScreen = useOnScreen(rootRef);\n const reducedMotion = usePrefersReducedMotion();\n const running = autoPlay && !reducedMotion && items.length > 1 && !paused && !hovered && !focused && onScreen;\n\n const select = useCallback(\n (index: number) => {\n const next = items[index];\n if (!next) return;\n if (value === undefined) setInternal(next.value);\n if (next.value !== items[activeIndex]?.value) onValueChange?.(next.value);\n },\n [items, value, activeIndex, onValueChange],\n );\n\n useEffect(() => {\n if (!running) return;\n const timer = window.setTimeout(() => {\n setPicked(false);\n select((activeIndex + 1) % items.length);\n }, Math.max(interval, 0));\n return () => window.clearTimeout(timer);\n }, [running, activeIndex, interval, items.length, select]);\n\n // The sliding pill (Figma \"Indicator\") takes the position and width of the selected segment.\n const [indicator, setIndicator] = useState<{ x: number; width: number } | null>(null);\n useIsomorphicLayoutEffect(() => {\n const list = listRef.current;\n if (!list) return;\n const measure = () => {\n const tab = tabRefs.current[activeIndex];\n if (!tab || tab.offsetWidth === 0) return;\n setIndicator((previous) =>\n previous && previous.x === tab.offsetLeft && previous.width === tab.offsetWidth\n ? previous\n : { x: tab.offsetLeft, width: tab.offsetWidth },\n );\n };\n measure();\n if (typeof ResizeObserver === 'undefined') return;\n const observer = new ResizeObserver(measure);\n observer.observe(list);\n return () => observer.disconnect();\n }, [activeIndex, items.length]);\n\n // Shows the segment the user chose; the loop carries on from it once the pointer and keyboard focus have left.\n const pick = (index: number) => {\n setPicked(true);\n select(index);\n };\n\n const handleKeyDown = (event: KeyboardEvent<HTMLButtonElement>, index: number) => {\n const last = items.length - 1;\n const rtl = typeof getComputedStyle === 'function' && getComputedStyle(event.currentTarget).direction === 'rtl';\n let next: number;\n if (event.key === 'ArrowRight') next = rtl ? index - 1 : index + 1;\n else if (event.key === 'ArrowLeft') next = rtl ? index + 1 : index - 1;\n else if (event.key === 'Home') next = 0;\n else if (event.key === 'End') next = last;\n else return;\n event.preventDefault();\n next = next < 0 ? last : next > last ? 0 : next;\n pick(next);\n tabRefs.current[next]?.focus();\n };\n\n const Heading = `h${headingLevel}` as const;\n\n return (\n <div\n ref={(node) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n }}\n className={cn('tm-hero-switcher', className)}\n data-playing={running ? '' : undefined}\n data-picked={picked ? '' : undefined}\n onPointerEnter={(event) => {\n onPointerEnter?.(event);\n if (event.pointerType === 'mouse') setHovered(true);\n }}\n onPointerLeave={(event) => {\n onPointerLeave?.(event);\n setHovered(false);\n }}\n onFocus={(event) => {\n onFocus?.(event);\n // Keyboard focus only: the focus a mouse click or a tap leaves on a segment must not hold autoplay until the next blur.\n let keyboard = true;\n try {\n keyboard = event.target.matches(':focus-visible');\n } catch {\n /* :focus-visible unsupported — treat every focus as keyboard focus */\n }\n if (keyboard) setFocused(true);\n }}\n onBlur={(event) => {\n onBlur?.(event);\n if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false);\n }}\n {...props}\n >\n <div className=\"tm-hero-switcher__photo\">\n {items.map((item, index) => {\n const active = index === activeIndex;\n return (\n <div key={item.value} className=\"tm-hero-switcher__slide\" data-active={active ? '' : undefined} aria-hidden={active ? undefined : true}>\n {item.image ??\n (item.imageSrc ? (\n <img className=\"tm-hero-switcher__image\" src={item.imageSrc} alt={item.imageAlt ?? ''} draggable={false} />\n ) : null)}\n </div>\n );\n })}\n </div>\n\n <div ref={listRef} className=\"tm-hero-switcher__switch\" role=\"tablist\" aria-label={ariaLabel} data-measured={indicator ? '' : undefined}>\n <span\n className=\"tm-hero-switcher__indicator\"\n aria-hidden=\"true\"\n style={indicator ? ({ width: indicator.width, transform: `translateX(${indicator.x}px)` } as CSSProperties) : undefined}\n />\n {items.map((item, index) => {\n const active = index === activeIndex;\n return (\n <button\n key={item.value}\n ref={(node) => {\n tabRefs.current[index] = node;\n }}\n type=\"button\"\n role=\"tab\"\n id={`${id}-tab-${index}`}\n className=\"tm-hero-switcher__tab\"\n data-tm-icon-size=\"sm\"\n aria-selected={active}\n aria-controls={`${id}-panel-${index}`}\n tabIndex={active ? 0 : -1}\n onClick={() => pick(index)}\n onKeyDown={(event) => handleKeyDown(event, index)}\n >\n {item.icon}\n <span className=\"tm-hero-switcher__tab-label\">{item.label}</span>\n </button>\n );\n })}\n </div>\n\n <div className=\"tm-hero-switcher__card\">\n {items.map((item, index) => {\n const active = index === activeIndex;\n return (\n <div\n key={item.value}\n role=\"tabpanel\"\n id={`${id}-panel-${index}`}\n aria-labelledby={`${id}-tab-${index}`}\n className=\"tm-hero-switcher__panel\"\n data-active={active ? '' : undefined}\n aria-hidden={active ? undefined : true}\n >\n {item.overline != null ? <p className=\"tm-hero-switcher__overline\">{item.overline}</p> : null}\n <Heading className=\"tm-hero-switcher__title\">{item.title}</Heading>\n {item.details?.length ? (\n <ul className=\"tm-hero-switcher__details\" data-tm-icon-size=\"sm\">\n {item.details.map((detail, row) => (\n <li key={detail.key ?? row} className=\"tm-hero-switcher__detail\">\n {detail.icon}\n <span>{detail.label}</span>\n </li>\n ))}\n </ul>\n ) : null}\n {item.status != null ? (\n <>\n <hr className=\"tm-hero-switcher__divider\" />\n <p className=\"tm-hero-switcher__status\" data-tm-icon-size=\"sm\">\n {item.statusIcon ?? <CheckmarkIcon />}\n <span>{item.status}</span>\n </p>\n </>\n ) : null}\n </div>\n );\n })}\n </div>\n </div>\n );\n});\n"],"mappings":";;;;;;;;AAyEA,IAAME,IAA4B,OAAO,SAAW,MAAcC,IAAYC,GAQjEC,IAA+B,kBAA8C,SACxF,EACE,UACA,UACA,iBACA,kBACA,cAAW,IACX,cAAW,MACX,YAAS,IACT,cAAcC,GACd,kBAAe,GACf,cACA,mBACA,mBACA,YACA,WACA,GAAGC,KAEL,GACA;CACA,IAAMC,IAAKC,EAAM,GACXC,IAAUC,EAA8B,IAAI,GAC5CC,IAAUD,EAA8B,IAAI,GAC5CE,IAAUF,EAAwC,CAAC,CAAC,GAEpD,CAACG,GAAUC,KAAeC,EAASC,CAAY,GAC/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A,CAAA,EAAA,CAAA;MAED;KA7BE,GAAAA,EAAK,KA6BP;IAET,CAAC;GACE,CAAA;EACF;;AAET,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";const e=require("../../icons/generated/CheckmarkIcon.cjs"),t=require("../../utils/cn.cjs");;/* empty css */let n=require("react"),r=require("react/jsx-runtime");var i=(0,n.forwardRef)(function({icon:e,className:n,children:i,...a},o){return(0,r.jsxs)(`span`,{ref:o,className:t.cn(`tm-how-it-works-steps__tag`,n),"data-tm-icon-size":`sm`,...a,children:[e,i]})}),a=500,o=()=>{let[e,t]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(prefers-reduced-motion: reduce)`),n=()=>t(e.matches);return n(),e.addEventListener?.(`change`,n),()=>e.removeEventListener?.(`change`,n)},[]),e},s=(e,t)=>{let[r,i]=(0,n.useState)(!0),[a,o]=(0,n.useState)(!0);return(0,n.useEffect)(()=>{if(!t)return;let n=()=>o(document.visibilityState!==`hidden`);n(),document.addEventListener(`visibilitychange`,n);let r;return e.current&&typeof IntersectionObserver==`function`&&(r=new IntersectionObserver(([e])=>i(e.isIntersecting)),r.observe(e.current)),()=>{document.removeEventListener(`visibilitychange`,n),r?.disconnect()}},[e,t]),r&&a},c=(0,n.forwardRef)(function({items:i,value:c,defaultValue:l,onValueChange:u,autoPlay:d=!
|
|
1
|
+
"use client";const e=require("../../icons/generated/CheckmarkIcon.cjs"),t=require("../../utils/cn.cjs");;/* empty css */let n=require("react"),r=require("react/jsx-runtime");var i=(0,n.forwardRef)(function({icon:e,className:n,children:i,...a},o){return(0,r.jsxs)(`span`,{ref:o,className:t.cn(`tm-how-it-works-steps__tag`,n),"data-tm-icon-size":`sm`,...a,children:[e,i]})}),a=500,o=()=>{let[e,t]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(prefers-reduced-motion: reduce)`),n=()=>t(e.matches);return n(),e.addEventListener?.(`change`,n),()=>e.removeEventListener?.(`change`,n)},[]),e},s=(e,t)=>{let[r,i]=(0,n.useState)(!0),[a,o]=(0,n.useState)(!0);return(0,n.useEffect)(()=>{if(!t)return;let n=()=>o(document.visibilityState!==`hidden`);n(),document.addEventListener(`visibilitychange`,n);let r;return e.current&&typeof IntersectionObserver==`function`&&(r=new IntersectionObserver(([e])=>i(e.isIntersecting)),r.observe(e.current)),()=>{document.removeEventListener(`visibilitychange`,n),r?.disconnect()}},[e,t]),r&&a},c=(0,n.forwardRef)(function({items:i,value:c,defaultValue:l,onValueChange:u,autoPlay:d=!0,interval:f=2200,paused:p=!1,label:m,collapseBelow:h,className:g,style:_,onPointerEnter:v,onPointerLeave:y,onFocus:b,onBlur:x,...S},C){let w=(0,n.useRef)(null),T=(0,n.useCallback)(e=>{w.current=e,typeof C==`function`?C(e):C&&(C.current=e)},[C]),[E,D]=(0,n.useState)(l),[O,k]=(0,n.useState)(!1),[A,j]=(0,n.useState)(!1),M=o(),N=s(w,d),P=i.length,F=c===void 0?E:c,I=i.findIndex(e=>e.value===F),L=I===-1?0:I,R=e=>{let t=i[e];t&&e!==L&&(c===void 0&&D(t.value),u?.(t.value))},z=(0,n.useRef)(R);z.current=R;let B=d&&P>1&&!M&&!p&&!O&&!A&&N;if((0,n.useEffect)(()=>{if(!B)return;let e=window.setTimeout(()=>z.current((L+1)%P),Math.max(f,0)+a);return()=>window.clearTimeout(e)},[B,L,P,f]),P===0)return null;let V=Math.max(480,h??P*136+(P-1)*16),H={"--_count":P,"--_progress":P>1?L/(P-1):0,"--_collapse":V,..._};return(0,r.jsx)(`div`,{ref:T,className:t.cn(`tm-how-it-works-steps`,g),style:H,"data-playing":B?``:void 0,onPointerEnter:e=>{v?.(e),e.pointerType!==`touch`&&k(!0)},onPointerLeave:e=>{y?.(e),k(!1)},onFocus:e=>{b?.(e);let t=!0;try{t=e.target.matches(`:focus-visible`)}catch{}t&&j(!0)},onBlur:e=>{x?.(e),e.currentTarget.contains(e.relatedTarget)||j(!1)},...S,children:(0,r.jsx)(`div`,{className:`tm-how-it-works-steps__frame`,children:(0,r.jsxs)(`div`,{className:`tm-how-it-works-steps__inner`,children:[(0,r.jsxs)(`div`,{className:`tm-how-it-works-steps__rail`,"aria-hidden":`true`,"data-tm-icon-size":`sm`,children:[(0,r.jsx)(`span`,{className:`tm-how-it-works-steps__track`}),(0,r.jsx)(`span`,{className:`tm-how-it-works-steps__progress`}),i.map((t,n)=>(0,r.jsxs)(`span`,{className:`tm-how-it-works-steps__node`,"data-state":n<L?`done`:n===L?`current`:`upcoming`,children:[(0,r.jsx)(`span`,{className:`tm-how-it-works-steps__number`,children:n+1}),(0,r.jsx)(e.CheckmarkIcon,{className:`tm-how-it-works-steps__check`})]},t.value))]}),(0,r.jsx)(`ol`,{className:`tm-how-it-works-steps__list`,"aria-label":m,children:i.map((e,t)=>{let n=t===L;return(0,r.jsx)(`li`,{className:`tm-how-it-works-steps__item`,children:(0,r.jsxs)(`button`,{type:`button`,className:`tm-how-it-works-steps__card`,"aria-current":n?`step`:void 0,"data-current":n?``:void 0,onClick:()=>R(t),children:[(0,r.jsxs)(`span`,{className:`tm-how-it-works-steps__main`,children:[e.icon?(0,r.jsx)(`span`,{className:`tm-how-it-works-steps__icon`,"data-tm-icon-size":`md`,children:e.icon}):null,(0,r.jsxs)(`span`,{className:`tm-how-it-works-steps__text`,children:[(0,r.jsx)(`span`,{className:`tm-how-it-works-steps__title`,children:e.title}),e.description?(0,r.jsx)(`span`,{className:`tm-how-it-works-steps__description`,children:e.description}):null]})]}),e.badge?(0,r.jsx)(`span`,{className:`tm-how-it-works-steps__badge`,children:e.badge}):null]})},e.value)})})]})})})});exports.HowItWorksStepTag=i,exports.HowItWorksSteps=c;
|
|
2
2
|
//# sourceMappingURL=HowItWorksSteps.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HowItWorksSteps.cjs","names":["cn","useState","useRef","useCallback","CheckmarkIcon","require_CheckmarkIcon","require_cn","react","react_jsx_runtime","HowItWorksStepTag","props","className","icon","children","STEP_DURATION","useReducedMotion","reduced","setReduced","query","update","useOnScreen","inView","setInView","tabVisible","setTabVisible","enabled","observer","ref","entry","HowItWorksSteps","rootRef","setRef","node","uncontrolled","setUncontrolled","defaultValue","stopped","setStopped","hovered","setHovered","focused","setFocused","reducedMotion","onScreen","autoPlay","count","items","requested","value","found","item","activeIndex","select","next","index","onValueChange","selectRef","canPlay","playing","paused","timer","interval","threshold","collapseBelow","rootStyle","style","onPointerEnter","event","onPointerLeave","onFocus","onBlur","playLabel","pauseLabel","current","label","isCurrent"],"sources":["../../../src/components/HowItWorksSteps/HowItWorksSteps.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n useState,\n type CSSProperties,\n type FocusEvent,\n type HTMLAttributes,\n type PointerEvent,\n type ReactNode,\n} from 'react';\nimport { CheckmarkIcon } from '../../icons';\nimport { cn } from '../../utils/cn';\nimport './HowItWorksSteps.css';\n\nexport interface HowItWorksStepItem {\n /** Identifies the step in `value` / `onValueChange`. */\n value: string;\n /** One icon from `@travel-match/ui` for the icon tile, e.g. `<PaperIcon />`. */\n icon?: ReactNode;\n /** Step name, e.g. \"Submit a request\". Phrasing content only — it is rendered inside a button. */\n title: ReactNode;\n /** One or two sentences about the step. Phrasing content only. */\n description?: ReactNode;\n /** Pill at the bottom of the card, e.g. a `<RequestStatus>` or a `<Tag>`. Must not be interactive. */\n badge?: ReactNode;\n}\n\nexport interface HowItWorksStepsProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'defaultValue' | 'onChange'> {\n /** The steps, in order. Nothing is rendered for an empty list. */\n items: HowItWorksStepItem[];\n /** Controlled: `value` of the current step (Figma \"Step\"). */\n value?: string;\n /** Uncontrolled: `value` of the step that starts current. Defaults to the first one. */\n defaultValue?: string;\n /** Called with the `value` of the step that became current, by a click or by auto-play. */\n onValueChange?: (value: string) => void;\n /** Advances to the next step on a timer and loops. Stops for good once the user picks a step or presses pause. */\n autoPlay?: boolean;\n /** Time a step rests once its 500ms transition has finished, in ms (Figma: 2200 — a new step every 2.7s). */\n interval?: number;\n /** Holds auto-play without unmounting it (e.g. while a dialog is open). */\n paused?: boolean;\n /** Accessible name of the list of steps, e.g. \"How it works\". */\n label?: string;\n /** Accessible name of the pause button shown while auto-playing. Translate it in the app. */\n pauseLabel?: string;\n /** Accessible name of the same button once auto-play is paused. Translate it in the app. */\n playLabel?: string;\n /** Width of the component in px below which the steps stack (the Figma mobile layout). Default: 136px per step plus the gaps, at least 480. */\n collapseBelow?: number;\n}\n\nexport interface HowItWorksStepTagProps extends HTMLAttributes<HTMLSpanElement> {\n /** One icon from `@travel-match/ui`, e.g. `<CompareIcon />`. */\n icon?: ReactNode;\n}\n\n/** The tinted pill Figma draws at the bottom of the steps that have no request status (\"Up to 3 offers\"). Use it as a step's `badge`. */\nexport const HowItWorksStepTag = /* @__PURE__ */ forwardRef<HTMLSpanElement, HowItWorksStepTagProps>(function HowItWorksStepTag(\n { icon, className, children, ...props },\n ref,\n) {\n return (\n <span ref={ref} className={cn('tm-how-it-works-steps__tag', className)} data-tm-icon-size=\"sm\" {...props}>\n {icon}\n {children}\n </span>\n );\n});\n\n/** Figma prototype: Smart animate, ease in and out, 500ms. Keep in sync with `--_duration` in the stylesheet. */\nconst STEP_DURATION = 500;\n\nconst useReducedMotion = () => {\n const [reduced, setReduced] = useState(false);\n useEffect(() => {\n if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;\n const query = window.matchMedia('(prefers-reduced-motion: reduce)');\n const update = () => setReduced(query.matches);\n update();\n query.addEventListener?.('change', update);\n return () => query.removeEventListener?.('change', update);\n }, []);\n return reduced;\n};\n\n/** True while the element is on screen and the tab is visible — the only time a timer should run. */\nconst useOnScreen = (ref: { current: Element | null }, enabled: boolean) => {\n const [inView, setInView] = useState(true);\n const [tabVisible, setTabVisible] = useState(true);\n useEffect(() => {\n if (!enabled) return;\n const update = () => setTabVisible(document.visibilityState !== 'hidden');\n update();\n document.addEventListener('visibilitychange', update);\n let observer: IntersectionObserver | undefined;\n if (ref.current && typeof IntersectionObserver === 'function') {\n observer = new IntersectionObserver(([entry]) => setInView(entry.isIntersecting));\n observer.observe(ref.current);\n }\n return () => {\n document.removeEventListener('visibilitychange', update);\n observer?.disconnect();\n };\n }, [ref, enabled]);\n return inView && tabVisible;\n};\n\n/**\n * The request journey as a numbered rail over a row of step cards, one of which is current\n * (Figma \"How it works / Steps\"; its \"Step=1…7\" variants are the `value`). Every card is a button that makes its step\n * current; with `autoPlay` the steps also advance on a timer until the user takes over. Below `collapseBelow` the\n * cards stack and the rail is dropped (Figma \"Mobile / How it works / Steps\").\n */\nexport const HowItWorksSteps = /* @__PURE__ */ forwardRef<HTMLDivElement, HowItWorksStepsProps>(function HowItWorksSteps(\n {\n items,\n value,\n defaultValue,\n onValueChange,\n autoPlay = false,\n interval = 2200,\n paused = false,\n label,\n pauseLabel = 'Pause',\n playLabel = 'Play',\n collapseBelow,\n className,\n style,\n onPointerEnter,\n onPointerLeave,\n onFocus,\n onBlur,\n ...props\n },\n ref,\n) {\n const rootRef = useRef<HTMLDivElement | null>(null);\n const setRef = useCallback(\n (node: HTMLDivElement | null) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n },\n [ref],\n );\n\n const [uncontrolled, setUncontrolled] = useState(defaultValue);\n const [stopped, setStopped] = useState(false);\n const [hovered, setHovered] = useState(false);\n const [focused, setFocused] = useState(false);\n const reducedMotion = useReducedMotion();\n const onScreen = useOnScreen(rootRef, autoPlay);\n\n const count = items.length;\n const requested = value !== undefined ? value : uncontrolled;\n const found = items.findIndex((item) => item.value === requested);\n // One step is always current: an unknown or missing value falls back to the first step.\n const activeIndex = found === -1 ? 0 : found;\n\n const select = (index: number) => {\n const next = items[index];\n if (!next || index === activeIndex) return;\n if (value === undefined) setUncontrolled(next.value);\n onValueChange?.(next.value);\n };\n const selectRef = useRef(select);\n selectRef.current = select;\n\n const canPlay = autoPlay && count > 1 && !reducedMotion;\n const playing = canPlay && !stopped && !paused && !hovered && !focused && onScreen;\n\n useEffect(() => {\n if (!playing) return;\n const timer = window.setTimeout(() => selectRef.current((activeIndex + 1) % count), Math.max(interval, 0) + STEP_DURATION);\n return () => window.clearTimeout(timer);\n }, [playing, activeIndex, count, interval]);\n\n if (count === 0) return null;\n\n // 136px per step keeps the Figma card (157px at 1200) readable; below that the row would crush the text.\n const threshold = Math.max(480, collapseBelow ?? count * 136 + (count - 1) * 16);\n const rootStyle = {\n '--_count': count,\n '--_progress': count > 1 ? activeIndex / (count - 1) : 0,\n '--_collapse': threshold,\n ...style,\n } as CSSProperties;\n\n return (\n <div\n ref={setRef}\n className={cn('tm-how-it-works-steps', className)}\n style={rootStyle}\n data-playing={playing ? '' : undefined}\n onPointerEnter={(event: PointerEvent<HTMLDivElement>) => {\n onPointerEnter?.(event);\n // A touch \"enters\" just before it taps; only a resting mouse or pen holds the timer.\n if (event.pointerType !== 'touch') setHovered(true);\n }}\n onPointerLeave={(event: PointerEvent<HTMLDivElement>) => {\n onPointerLeave?.(event);\n setHovered(false);\n }}\n onFocus={(event: FocusEvent<HTMLDivElement>) => {\n onFocus?.(event);\n setFocused(true);\n }}\n onBlur={(event: FocusEvent<HTMLDivElement>) => {\n onBlur?.(event);\n if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false);\n }}\n {...props}\n >\n <div className=\"tm-how-it-works-steps__frame\">\n <div className=\"tm-how-it-works-steps__inner\">\n {canPlay ? (\n <div className=\"tm-how-it-works-steps__controls\">\n <button\n type=\"button\"\n className=\"tm-how-it-works-steps__toggle\"\n aria-label={stopped ? playLabel : pauseLabel}\n onClick={() => setStopped((current) => !current)}\n >\n <svg viewBox=\"0 0 16 16\" width=\"16\" height=\"16\" fill=\"currentColor\" aria-hidden=\"true\" focusable=\"false\">\n {stopped ? <path d=\"M5 3.2v9.6a.6.6 0 0 0 .92.5l7.4-4.8a.6.6 0 0 0 0-1L5.92 2.7a.6.6 0 0 0-.92.5Z\" /> : <path d=\"M4 3h3v10H4zM9 3h3v10H9z\" />}\n </svg>\n </button>\n </div>\n ) : null}\n\n {/* The rail repeats what the list below already says (order, current step), so it is decorative. */}\n <div className=\"tm-how-it-works-steps__rail\" aria-hidden=\"true\" data-tm-icon-size=\"sm\">\n <span className=\"tm-how-it-works-steps__track\" />\n <span className=\"tm-how-it-works-steps__progress\" />\n {items.map((item, index) => (\n <span\n key={item.value}\n className=\"tm-how-it-works-steps__node\"\n data-state={index < activeIndex ? 'done' : index === activeIndex ? 'current' : 'upcoming'}\n >\n <span className=\"tm-how-it-works-steps__number\">{index + 1}</span>\n <CheckmarkIcon className=\"tm-how-it-works-steps__check\" />\n </span>\n ))}\n </div>\n\n <ol className=\"tm-how-it-works-steps__list\" aria-label={label}>\n {items.map((item, index) => {\n const isCurrent = index === activeIndex;\n return (\n <li key={item.value} className=\"tm-how-it-works-steps__item\">\n <button\n type=\"button\"\n className=\"tm-how-it-works-steps__card\"\n aria-current={isCurrent ? 'step' : undefined}\n data-current={isCurrent ? '' : undefined}\n onClick={() => {\n // The user has taken over: auto-play does not fight their choice.\n setStopped(true);\n select(index);\n }}\n >\n <span className=\"tm-how-it-works-steps__main\">\n {item.icon ? (\n <span className=\"tm-how-it-works-steps__icon\" data-tm-icon-size=\"md\">\n {item.icon}\n </span>\n ) : null}\n <span className=\"tm-how-it-works-steps__text\">\n <span className=\"tm-how-it-works-steps__title\">{item.title}</span>\n {item.description ? <span className=\"tm-how-it-works-steps__description\">{item.description}</span> : null}\n </span>\n </span>\n {item.badge ? <span className=\"tm-how-it-works-steps__badge\">{item.badge}</span> : null}\n </button>\n </li>\n );\n })}\n </ol>\n </div>\n </div>\n </div>\n );\n});\n"],"mappings":"A,mMA4DA,IAAaS,GAAoC,EAAAF,EAAA,WAAA,CAAoD,SACnG,CAAE,OAAM,YAAW,WAAU,GAAGG,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,KAAA,CAAC,OAAD,CAAM,UAAU,8BAAhB,SAAA,CACG0C,EAAK,MACJ,EAAA1C,EAAA,IAAA,CAAC,OAAD,CAAM,UAAU,8BAA8B,oBAAkB,KAC7D,SAAA0C,EAAK,IACF,CAAA,EACJ,MACJ,EAAA1C,EAAA,KAAA,CAAC,OAAD,CAAM,UAAU,8BAAhB,SAAA,EACE,EAAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAU,+BAAgC,SAAA0C,EAAK,KAAY,CAAA,EAChEA,EAAK,aAAc,EAAA1C,EAAA,IAAA,CAAC,OAAD,CAAM,UAAU,qCAAsC,SAAA0C,EAAK,WAAkB,CAAA,EAAI,IACjG,CACF,CAAA,CAAA,CACL,CAAA,EAAAA,EAAK,OAAQ,EAAA1C,EAAA,IAAA,CAAC,OAAD,CAAM,UAAU,+BAAgC,SAAA0C,EAAK,KAAY,CAAA,EAAI,IAC7E,C,EACN,EAzBKA,EAAK,KAyBV,CAER,CAAC,CACC,CAAA,CACD,C,EACF,CAAA,CACF,CAAA,CAET,CAAC,E"}
|
|
1
|
+
{"version":3,"file":"HowItWorksSteps.cjs","names":["cn","useState","useRef","useCallback","CheckmarkIcon","require_CheckmarkIcon","require_cn","react","react_jsx_runtime","HowItWorksStepTag","props","className","icon","children","STEP_DURATION","useReducedMotion","reduced","setReduced","query","update","useOnScreen","inView","setInView","tabVisible","setTabVisible","enabled","observer","ref","entry","HowItWorksSteps","rootRef","setRef","node","uncontrolled","setUncontrolled","defaultValue","hovered","setHovered","focused","setFocused","reducedMotion","onScreen","autoPlay","count","items","requested","value","found","item","activeIndex","select","next","index","onValueChange","selectRef","playing","paused","timer","interval","threshold","collapseBelow","rootStyle","style","onPointerEnter","event","onPointerLeave","onFocus","keyboard","onBlur","label","isCurrent"],"sources":["../../../src/components/HowItWorksSteps/HowItWorksSteps.tsx"],"sourcesContent":["import {\n forwardRef,\n useCallback,\n useEffect,\n useRef,\n useState,\n type CSSProperties,\n type FocusEvent,\n type HTMLAttributes,\n type PointerEvent,\n type ReactNode,\n} from 'react';\nimport { CheckmarkIcon } from '../../icons';\nimport { cn } from '../../utils/cn';\nimport './HowItWorksSteps.css';\n\nexport interface HowItWorksStepItem {\n /** Identifies the step in `value` / `onValueChange`. */\n value: string;\n /** One icon from `@travel-match/ui` for the icon tile, e.g. `<PaperIcon />`. */\n icon?: ReactNode;\n /** Step name, e.g. \"Submit a request\". Phrasing content only — it is rendered inside a button. */\n title: ReactNode;\n /** One or two sentences about the step. Phrasing content only. */\n description?: ReactNode;\n /** Pill at the bottom of the card, e.g. a `<RequestStatus>` or a `<Tag>`. Must not be interactive. */\n badge?: ReactNode;\n}\n\nexport interface HowItWorksStepsProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'defaultValue' | 'onChange'> {\n /** The steps, in order. Nothing is rendered for an empty list. */\n items: HowItWorksStepItem[];\n /** Controlled: `value` of the current step (Figma \"Step\"). */\n value?: string;\n /** Uncontrolled: `value` of the step that starts current. Defaults to the first one. */\n defaultValue?: string;\n /** Called with the `value` of the step that became current, by a click or by auto-play. */\n onValueChange?: (value: string) => void;\n /** Advances to the next step on a timer, in an endless loop (on by default); after the user picks a step it carries on from that step. */\n autoPlay?: boolean;\n /** Time a step rests once its 500ms transition has finished, in ms (Figma: 2200 — a new step every 2.7s). */\n interval?: number;\n /** Holds auto-play without unmounting it (e.g. while a dialog is open); it carries on once this is `false` again. */\n paused?: boolean;\n /** Accessible name of the list of steps, e.g. \"How it works\". */\n label?: string;\n /** Width of the component in px below which the steps stack (the Figma mobile layout). Default: 136px per step plus the gaps, at least 480. */\n collapseBelow?: number;\n}\n\nexport interface HowItWorksStepTagProps extends HTMLAttributes<HTMLSpanElement> {\n /** One icon from `@travel-match/ui`, e.g. `<CompareIcon />`. */\n icon?: ReactNode;\n}\n\n/** The tinted pill Figma draws at the bottom of the steps that have no request status (\"Up to 3 offers\"). Use it as a step's `badge`. */\nexport const HowItWorksStepTag = /* @__PURE__ */ forwardRef<HTMLSpanElement, HowItWorksStepTagProps>(function HowItWorksStepTag(\n { icon, className, children, ...props },\n ref,\n) {\n return (\n <span ref={ref} className={cn('tm-how-it-works-steps__tag', className)} data-tm-icon-size=\"sm\" {...props}>\n {icon}\n {children}\n </span>\n );\n});\n\n/** Figma prototype: Smart animate, ease in and out, 500ms. Keep in sync with `--_duration` in the stylesheet. */\nconst STEP_DURATION = 500;\n\nconst useReducedMotion = () => {\n const [reduced, setReduced] = useState(false);\n useEffect(() => {\n if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') return;\n const query = window.matchMedia('(prefers-reduced-motion: reduce)');\n const update = () => setReduced(query.matches);\n update();\n query.addEventListener?.('change', update);\n return () => query.removeEventListener?.('change', update);\n }, []);\n return reduced;\n};\n\n/** True while the element is on screen and the tab is visible — the only time a timer should run. */\nconst useOnScreen = (ref: { current: Element | null }, enabled: boolean) => {\n const [inView, setInView] = useState(true);\n const [tabVisible, setTabVisible] = useState(true);\n useEffect(() => {\n if (!enabled) return;\n const update = () => setTabVisible(document.visibilityState !== 'hidden');\n update();\n document.addEventListener('visibilitychange', update);\n let observer: IntersectionObserver | undefined;\n if (ref.current && typeof IntersectionObserver === 'function') {\n observer = new IntersectionObserver(([entry]) => setInView(entry.isIntersecting));\n observer.observe(ref.current);\n }\n return () => {\n document.removeEventListener('visibilitychange', update);\n observer?.disconnect();\n };\n }, [ref, enabled]);\n return inView && tabVisible;\n};\n\n/**\n * The request journey as a numbered rail over a row of step cards, one of which is current\n * (Figma \"How it works / Steps\"; its \"Step=1…7\" variants are the `value`). Every card is a button that makes its step\n * current; with `autoPlay` the steps also advance on a timer in an endless loop, which holds while the pointer or\n * keyboard focus is inside and carries on from the step the user picked. Below `collapseBelow` the cards stack and the\n * rail is dropped (Figma \"Mobile / How it works / Steps\").\n */\nexport const HowItWorksSteps = /* @__PURE__ */ forwardRef<HTMLDivElement, HowItWorksStepsProps>(function HowItWorksSteps(\n {\n items,\n value,\n defaultValue,\n onValueChange,\n autoPlay = true,\n interval = 2200,\n paused = false,\n label,\n collapseBelow,\n className,\n style,\n onPointerEnter,\n onPointerLeave,\n onFocus,\n onBlur,\n ...props\n },\n ref,\n) {\n const rootRef = useRef<HTMLDivElement | null>(null);\n const setRef = useCallback(\n (node: HTMLDivElement | null) => {\n rootRef.current = node;\n if (typeof ref === 'function') ref(node);\n else if (ref) ref.current = node;\n },\n [ref],\n );\n\n const [uncontrolled, setUncontrolled] = useState(defaultValue);\n const [hovered, setHovered] = useState(false);\n const [focused, setFocused] = useState(false);\n const reducedMotion = useReducedMotion();\n const onScreen = useOnScreen(rootRef, autoPlay);\n\n const count = items.length;\n const requested = value !== undefined ? value : uncontrolled;\n const found = items.findIndex((item) => item.value === requested);\n // One step is always current: an unknown or missing value falls back to the first step.\n const activeIndex = found === -1 ? 0 : found;\n\n const select = (index: number) => {\n const next = items[index];\n if (!next || index === activeIndex) return;\n if (value === undefined) setUncontrolled(next.value);\n onValueChange?.(next.value);\n };\n const selectRef = useRef(select);\n selectRef.current = select;\n\n const playing = autoPlay && count > 1 && !reducedMotion && !paused && !hovered && !focused && onScreen;\n\n useEffect(() => {\n if (!playing) return;\n const timer = window.setTimeout(() => selectRef.current((activeIndex + 1) % count), Math.max(interval, 0) + STEP_DURATION);\n return () => window.clearTimeout(timer);\n }, [playing, activeIndex, count, interval]);\n\n if (count === 0) return null;\n\n // 136px per step keeps the Figma card (157px at 1200) readable; below that the row would crush the text.\n const threshold = Math.max(480, collapseBelow ?? count * 136 + (count - 1) * 16);\n const rootStyle = {\n '--_count': count,\n '--_progress': count > 1 ? activeIndex / (count - 1) : 0,\n '--_collapse': threshold,\n ...style,\n } as CSSProperties;\n\n return (\n <div\n ref={setRef}\n className={cn('tm-how-it-works-steps', className)}\n style={rootStyle}\n data-playing={playing ? '' : undefined}\n onPointerEnter={(event: PointerEvent<HTMLDivElement>) => {\n onPointerEnter?.(event);\n // A touch \"enters\" just before it taps; only a resting mouse or pen holds the timer.\n if (event.pointerType !== 'touch') setHovered(true);\n }}\n onPointerLeave={(event: PointerEvent<HTMLDivElement>) => {\n onPointerLeave?.(event);\n setHovered(false);\n }}\n onFocus={(event: FocusEvent<HTMLDivElement>) => {\n onFocus?.(event);\n // Keyboard focus only: the focus a click or a tap leaves on a card must not hold auto-play until the next blur.\n let keyboard = true;\n try {\n keyboard = event.target.matches(':focus-visible');\n } catch {\n /* :focus-visible unsupported — treat every focus as keyboard focus */\n }\n if (keyboard) setFocused(true);\n }}\n onBlur={(event: FocusEvent<HTMLDivElement>) => {\n onBlur?.(event);\n if (!event.currentTarget.contains(event.relatedTarget)) setFocused(false);\n }}\n {...props}\n >\n <div className=\"tm-how-it-works-steps__frame\">\n <div className=\"tm-how-it-works-steps__inner\">\n {/* The rail repeats what the list below already says (order, current step), so it is decorative. */}\n <div className=\"tm-how-it-works-steps__rail\" aria-hidden=\"true\" data-tm-icon-size=\"sm\">\n <span className=\"tm-how-it-works-steps__track\" />\n <span className=\"tm-how-it-works-steps__progress\" />\n {items.map((item, index) => (\n <span\n key={item.value}\n className=\"tm-how-it-works-steps__node\"\n data-state={index < activeIndex ? 'done' : index === activeIndex ? 'current' : 'upcoming'}\n >\n <span className=\"tm-how-it-works-steps__number\">{index + 1}</span>\n <CheckmarkIcon className=\"tm-how-it-works-steps__check\" />\n </span>\n ))}\n </div>\n\n <ol className=\"tm-how-it-works-steps__list\" aria-label={label}>\n {items.map((item, index) => {\n const isCurrent = index === activeIndex;\n return (\n <li key={item.value} className=\"tm-how-it-works-steps__item\">\n <button\n type=\"button\"\n className=\"tm-how-it-works-steps__card\"\n aria-current={isCurrent ? 'step' : undefined}\n data-current={isCurrent ? '' : undefined}\n // Shows the chosen step; auto-play carries on from it once the pointer and keyboard focus have left.\n onClick={() => select(index)}\n >\n <span className=\"tm-how-it-works-steps__main\">\n {item.icon ? (\n <span className=\"tm-how-it-works-steps__icon\" data-tm-icon-size=\"md\">\n {item.icon}\n </span>\n ) : null}\n <span className=\"tm-how-it-works-steps__text\">\n <span className=\"tm-how-it-works-steps__title\">{item.title}</span>\n {item.description ? <span className=\"tm-how-it-works-steps__description\">{item.description}</span> : null}\n </span>\n </span>\n {item.badge ? <span className=\"tm-how-it-works-steps__badge\">{item.badge}</span> : null}\n </button>\n </li>\n );\n })}\n </ol>\n </div>\n </div>\n </div>\n );\n});\n"],"mappings":"A,mMAwDA,IAAaS,GAAoC,EAAAF,EAAA,WAAA,CAAoD,SACnG,CAAE,OAAM,YAAW,WAAU,GAAGG,GAChC,EACA,CACA,OACE,EAAAF,EAAA,KAAA,CAAC,OAAD,CAAW,MAAK,UAAWR,EAAAA,GAAG,6BAA8BW,CAAS,EAAG,oBAAkB,KAAK,GAAID,EAAnG,SAAA,CACGE,EACAC,CACG,C,EAEV,CAAC,EAGKC,EAAgB,IAEhBC,MAAyB,CAC7B,GAAM,CAACC,EAASC,IAAA,EAAchB,EAAAA,SAAAA,CAAS,EAAK,EAS5C,OARA,EAAAM,EAAA,UAAA,KAAgB,CACd,GAAI,OAAO,OAAW,KAAe,OAAO,OAAO,YAAe,WAAY,OAC9E,IAAMW,EAAQ,OAAO,WAAW,kCAAkC,EAC5DC,MAAeF,EAAWC,EAAM,OAAO,EAG7C,OAFAC,EAAO,EACPD,EAAM,mBAAmB,SAAUC,CAAM,MAC5BD,EAAM,sBAAsB,SAAUC,CAAM,CAC3D,EAAG,CAAC,CAAC,EACEH,CACT,EAGMI,GAAe,EAAkC,IAAqB,CAC1E,GAAM,CAACC,EAAQC,IAAA,EAAarB,EAAAA,SAAAA,CAAS,EAAI,EACnC,CAACsB,EAAYC,IAAA,EAAiBvB,EAAAA,SAAAA,CAAS,EAAI,EAgBjD,OAfA,EAAAM,EAAA,UAAA,KAAgB,CACd,GAAI,CAACkB,EAAS,OACd,IAAMN,MAAeK,EAAc,SAAS,kBAAoB,QAAQ,EACxEL,EAAO,EACP,SAAS,iBAAiB,mBAAoBA,CAAM,EACpD,IAAIO,EAKJ,OAJIC,EAAI,SAAW,OAAO,sBAAyB,aACjD,E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