@travelswitchhq/flight-search-react 1.2.4 → 1.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +125 -81
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +126 -82
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -481,6 +481,7 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
|
|
|
481
481
|
(0, import_react.useEffect)(() => {
|
|
482
482
|
const handleClickOutside = (event) => {
|
|
483
483
|
const target = event.target;
|
|
484
|
+
if (target.closest("[data-tfsw-sheet]")) return;
|
|
484
485
|
const isInsidePrimeDropdown = Boolean(
|
|
485
486
|
target.closest(".p-dropdown-panel") || target.closest(".p-dropdown-items-wrapper") || target.closest(".p-dropdown-item") || target.closest('[data-pc-section="panel"]') || target.closest('[data-pc-name="dropdown"]')
|
|
486
487
|
);
|
|
@@ -3039,6 +3040,7 @@ function FlightSearchFormStandard({
|
|
|
3039
3040
|
|
|
3040
3041
|
// src/modern/Modern.tsx
|
|
3041
3042
|
var import_react3 = require("react");
|
|
3043
|
+
var import_react_dom = require("react-dom");
|
|
3042
3044
|
var import_calendar2 = require("primereact/calendar");
|
|
3043
3045
|
var import_api2 = require("primereact/api");
|
|
3044
3046
|
|
|
@@ -3865,6 +3867,13 @@ var modernStyles = `
|
|
|
3865
3867
|
font-size: 15px;
|
|
3866
3868
|
}
|
|
3867
3869
|
|
|
3870
|
+
/* Sheets are portalled to <body> (see renderSheet in Modern.tsx); the wrapper only carries the theme
|
|
3871
|
+
variables and must sit above any fixed host chrome such as an app's bottom tab bar. */
|
|
3872
|
+
.mdrn_root.mdrn_portal {
|
|
3873
|
+
--mdrn-z: 2147483000;
|
|
3874
|
+
display: contents;
|
|
3875
|
+
}
|
|
3876
|
+
|
|
3868
3877
|
/* Dropdowns become full-screen sheets */
|
|
3869
3878
|
.mdrn_dropdown,
|
|
3870
3879
|
.mdrn_panel {
|
|
@@ -4097,6 +4106,33 @@ function FlightSearchFormModern({ config, ssoUser }) {
|
|
|
4097
4106
|
if (fontName) style["--mdrn-font"] = fontName;
|
|
4098
4107
|
return style;
|
|
4099
4108
|
}, [theme?.primary, theme?.primaryLight, fontName]);
|
|
4109
|
+
const [isMobile, setIsMobile] = (0, import_react3.useState)(false);
|
|
4110
|
+
(0, import_react3.useEffect)(() => {
|
|
4111
|
+
const query = window.matchMedia("(max-width: 1024px)");
|
|
4112
|
+
const sync = () => setIsMobile(query.matches);
|
|
4113
|
+
sync();
|
|
4114
|
+
query.addEventListener("change", sync);
|
|
4115
|
+
return () => query.removeEventListener("change", sync);
|
|
4116
|
+
}, []);
|
|
4117
|
+
const renderSheet = (sheet) => isMobile ? (0, import_react_dom.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_root mdrn_portal", style: themeStyle, "data-tfsw-sheet": "", children: sheet }), document.body) : sheet;
|
|
4118
|
+
const [calendarHost, setCalendarHost] = (0, import_react3.useState)(null);
|
|
4119
|
+
const [openMobileCalendar, setOpenMobileCalendar] = (0, import_react3.useState)(null);
|
|
4120
|
+
const mobileCalendarProps = (key) => ({
|
|
4121
|
+
appendTo: calendarHost ?? "self",
|
|
4122
|
+
onShow: () => setOpenMobileCalendar(key),
|
|
4123
|
+
onHide: () => setOpenMobileCalendar((current) => current === key ? null : current)
|
|
4124
|
+
});
|
|
4125
|
+
(0, import_react3.useEffect)(() => setOpenMobileCalendar(null), [tripType, segments.length]);
|
|
4126
|
+
const isSheetOpen = isMobile && (isOriginDropdownOpen || isDestinationDropdownOpen || isRoomsGuestsMenuOpen || openMobileCalendar !== null || Object.values(segmentDropdowns).some((entry) => Boolean(entry?.origin || entry?.destination)));
|
|
4127
|
+
(0, import_react3.useEffect)(() => {
|
|
4128
|
+
if (!isSheetOpen) return;
|
|
4129
|
+
const { body } = document;
|
|
4130
|
+
const previousOverflow = body.style.overflow;
|
|
4131
|
+
body.style.overflow = "hidden";
|
|
4132
|
+
return () => {
|
|
4133
|
+
body.style.overflow = previousOverflow;
|
|
4134
|
+
};
|
|
4135
|
+
}, [isSheetOpen]);
|
|
4100
4136
|
const isMultiCity = tripType === "multi-city" || tripType === "custom-search";
|
|
4101
4137
|
const first = segments[0];
|
|
4102
4138
|
const travellerCount = (first?.adultCount ?? 0) + (first?.childCount ?? 0) + (first?.infantCount ?? 0);
|
|
@@ -4157,44 +4193,46 @@ function FlightSearchFormModern({ config, ssoUser }) {
|
|
|
4157
4193
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_custom-dropdown", ref: dropdownRef, children: [
|
|
4158
4194
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { ...inputProps, id: inputId, className: "mdrn_input mdrn_desktop-only" }),
|
|
4159
4195
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { ...inputProps, id: `${inputId}-mobile`, readOnly: true, className: "mdrn_input mdrn_mobile-only" }),
|
|
4160
|
-
isOpen &&
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
"
|
|
4164
|
-
|
|
4165
|
-
type: "search",
|
|
4166
|
-
autoFocus: true,
|
|
4167
|
-
placeholder: `Search ${placeholder.toLowerCase()}`,
|
|
4168
|
-
value: value === placeholder ? "" : value,
|
|
4169
|
-
onChange: (e) => onSearch(e.target.value),
|
|
4170
|
-
onKeyDown: (e) => handleKeyDown(e, dropdownType, segmentIndex)
|
|
4171
|
-
}
|
|
4172
|
-
) }),
|
|
4173
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "mdrn_dropdown-title", children: results.length > 0 ? "Airports" : "Popular airports" }),
|
|
4174
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ul", { className: "mdrn_airport-list", role: "listbox", children: airports.map((airport, i) => {
|
|
4175
|
-
const isActive = results.length > 0 && selectedIndex === i;
|
|
4176
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
4177
|
-
"li",
|
|
4196
|
+
isOpen && renderSheet(
|
|
4197
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_dropdown", children: [
|
|
4198
|
+
renderMobileHead(placeholder, () => closeAirportDropdown(dropdownType, segmentIndex)),
|
|
4199
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_mobile-search mdrn_mobile-only", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
4200
|
+
"input",
|
|
4178
4201
|
{
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4202
|
+
type: "search",
|
|
4203
|
+
autoFocus: true,
|
|
4204
|
+
placeholder: `Search ${placeholder.toLowerCase()}`,
|
|
4205
|
+
value: value === placeholder ? "" : value,
|
|
4206
|
+
onChange: (e) => onSearch(e.target.value),
|
|
4207
|
+
onKeyDown: (e) => handleKeyDown(e, dropdownType, segmentIndex)
|
|
4208
|
+
}
|
|
4209
|
+
) }),
|
|
4210
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "mdrn_dropdown-title", children: results.length > 0 ? "Airports" : "Popular airports" }),
|
|
4211
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ul", { className: "mdrn_airport-list", role: "listbox", children: airports.map((airport, i) => {
|
|
4212
|
+
const isActive = results.length > 0 && selectedIndex === i;
|
|
4213
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
4214
|
+
"li",
|
|
4215
|
+
{
|
|
4216
|
+
role: "option",
|
|
4217
|
+
"aria-selected": isActive,
|
|
4218
|
+
className: `mdrn_airport-item${isActive ? " mdrn_is-active" : ""}`,
|
|
4219
|
+
onClick: () => selectAirport(airport, dropdownType, segmentIndex),
|
|
4220
|
+
children: [
|
|
4221
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_airport-code", children: getAirportCode(airport) }),
|
|
4222
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "mdrn_airport-text", children: [
|
|
4223
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_airport-name", children: formatAirportDisplay(airport) }),
|
|
4224
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "mdrn_airport-place", children: [
|
|
4225
|
+
airport.ct,
|
|
4226
|
+
airport.cn ? `, ${airport.cn}` : ""
|
|
4227
|
+
] })
|
|
4190
4228
|
] })
|
|
4191
|
-
]
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
)
|
|
4196
|
-
|
|
4197
|
-
|
|
4229
|
+
]
|
|
4230
|
+
},
|
|
4231
|
+
airport.id ?? airport.ac ?? i
|
|
4232
|
+
);
|
|
4233
|
+
}) })
|
|
4234
|
+
] })
|
|
4235
|
+
)
|
|
4198
4236
|
] })
|
|
4199
4237
|
] });
|
|
4200
4238
|
};
|
|
@@ -4238,7 +4276,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
|
|
|
4238
4276
|
{
|
|
4239
4277
|
ref: mobileDateRangeCalendarRef,
|
|
4240
4278
|
numberOfMonths: 10,
|
|
4241
|
-
|
|
4279
|
+
...mobileCalendarProps("round-trip"),
|
|
4242
4280
|
selectionMode: "range",
|
|
4243
4281
|
readOnlyInput: true,
|
|
4244
4282
|
value: first?.dateRange ?? null,
|
|
@@ -4284,7 +4322,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
|
|
|
4284
4322
|
{
|
|
4285
4323
|
ref: oneWayMobileCalendarRef,
|
|
4286
4324
|
numberOfMonths: 10,
|
|
4287
|
-
|
|
4325
|
+
...mobileCalendarProps("one-way"),
|
|
4288
4326
|
readOnlyInput: true,
|
|
4289
4327
|
value: first?.departureDate ?? null,
|
|
4290
4328
|
minDate: /* @__PURE__ */ new Date(),
|
|
@@ -4328,7 +4366,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
|
|
|
4328
4366
|
segmentMobileCalendarRefs.current[index] = el;
|
|
4329
4367
|
},
|
|
4330
4368
|
numberOfMonths: 10,
|
|
4331
|
-
|
|
4369
|
+
...mobileCalendarProps(`segment-${index}`),
|
|
4332
4370
|
readOnlyInput: true,
|
|
4333
4371
|
value: segment.departureDate ?? null,
|
|
4334
4372
|
minDate: getMinDateForSegment(index),
|
|
@@ -4355,49 +4393,51 @@ function FlightSearchFormModern({ config, ssoUser }) {
|
|
|
4355
4393
|
]
|
|
4356
4394
|
}
|
|
4357
4395
|
),
|
|
4358
|
-
isRoomsGuestsMenuOpen &&
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.
|
|
4362
|
-
|
|
4363
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_pax-
|
|
4364
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4396
|
+
isRoomsGuestsMenuOpen && renderSheet(
|
|
4397
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_panel mdrn_pax-panel", children: [
|
|
4398
|
+
renderMobileHead("Travelers & Class", () => setIsRoomsGuestsMenuOpen(false)),
|
|
4399
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_panel-body", children: [
|
|
4400
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { className: "mdrn_panel-title", children: "Number of travelers" }),
|
|
4401
|
+
PASSENGER_ROWS.map((row) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_pax-row", children: [
|
|
4402
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_pax-info", children: [
|
|
4403
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_pax-label", children: row.label }),
|
|
4404
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_pax-hint", children: row.hint })
|
|
4405
|
+
] }),
|
|
4406
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_pax-options", children: row.options.map((count) => {
|
|
4407
|
+
const isActive = (first?.[row.field] ?? 0) === count;
|
|
4408
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
4409
|
+
"button",
|
|
4410
|
+
{
|
|
4411
|
+
type: "button",
|
|
4412
|
+
className: `mdrn_pax-btn${isActive ? " mdrn_is-active" : ""}`,
|
|
4413
|
+
disabled: isPassengerOptionDisabled(row.field, count),
|
|
4414
|
+
onClick: () => row.field === "adultCount" ? selectAdultCount(count) : handleTravellerChange(row.field, count),
|
|
4415
|
+
children: count
|
|
4416
|
+
},
|
|
4417
|
+
count
|
|
4418
|
+
);
|
|
4419
|
+
}) })
|
|
4420
|
+
] }, row.field)),
|
|
4421
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { className: "mdrn_panel-title", children: "Travel class" }),
|
|
4422
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_chips", children: TRAVEL_CLASSES.map((travelClass) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: "mdrn_chip", children: [
|
|
4423
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
4424
|
+
"input",
|
|
4371
4425
|
{
|
|
4372
|
-
type: "
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
"input",
|
|
4386
|
-
{
|
|
4387
|
-
type: "radio",
|
|
4388
|
-
name: `${uid}-travel-class`,
|
|
4389
|
-
checked: (first?.travelerClass ?? "Economy") === travelClass,
|
|
4390
|
-
onChange: () => handleTravellerChange("travelerClass", travelClass)
|
|
4391
|
-
}
|
|
4392
|
-
),
|
|
4393
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: travelClass })
|
|
4394
|
-
] }, travelClass)) })
|
|
4395
|
-
] }),
|
|
4396
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_panel-foot", children: [
|
|
4397
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "mdrn_btn mdrn_btn--ghost", onClick: resetTravellers, children: "Reset" }),
|
|
4398
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "mdrn_btn mdrn_btn--primary", onClick: () => setIsRoomsGuestsMenuOpen(false), children: "Apply" })
|
|
4426
|
+
type: "radio",
|
|
4427
|
+
name: `${uid}-travel-class`,
|
|
4428
|
+
checked: (first?.travelerClass ?? "Economy") === travelClass,
|
|
4429
|
+
onChange: () => handleTravellerChange("travelerClass", travelClass)
|
|
4430
|
+
}
|
|
4431
|
+
),
|
|
4432
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: travelClass })
|
|
4433
|
+
] }, travelClass)) })
|
|
4434
|
+
] }),
|
|
4435
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_panel-foot", children: [
|
|
4436
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "mdrn_btn mdrn_btn--ghost", onClick: resetTravellers, children: "Reset" }),
|
|
4437
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "mdrn_btn mdrn_btn--primary", onClick: () => setIsRoomsGuestsMenuOpen(false), children: "Apply" })
|
|
4438
|
+
] })
|
|
4399
4439
|
] })
|
|
4400
|
-
|
|
4440
|
+
)
|
|
4401
4441
|
] });
|
|
4402
4442
|
const searchButton = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "submit", className: "mdrn_search", children: "Search" });
|
|
4403
4443
|
const renderMultiCity = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_mc", children: [
|
|
@@ -4478,7 +4518,11 @@ function FlightSearchFormModern({ config, ssoUser }) {
|
|
|
4478
4518
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_checkbox-box", "aria-hidden": "true" }),
|
|
4479
4519
|
label
|
|
4480
4520
|
] }, key)) })
|
|
4481
|
-
] })
|
|
4521
|
+
] }),
|
|
4522
|
+
isMobile && (0, import_react_dom.createPortal)(
|
|
4523
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_root mdrn_portal", style: themeStyle, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_calendar", ref: setCalendarHost }) }),
|
|
4524
|
+
document.body
|
|
4525
|
+
)
|
|
4482
4526
|
] }) });
|
|
4483
4527
|
}
|
|
4484
4528
|
|