@travelswitchhq/flight-search-react 1.2.4 → 1.2.6
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 +128 -93
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +129 -94
- 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
|
);
|
|
@@ -496,7 +497,7 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
|
|
|
496
497
|
const isInsideCustomDropdown = target.closest(dropdownSelector) !== null;
|
|
497
498
|
const isInsideCalendar = target.closest(".p-datepicker") !== null || target.closest(".p-calendar") !== null;
|
|
498
499
|
if (!isInsideCustomDropdown && !isInsideCalendar) {
|
|
499
|
-
setSegmentDropdowns({});
|
|
500
|
+
setSegmentDropdowns((prev) => Object.keys(prev).length > 0 ? {} : prev);
|
|
500
501
|
return;
|
|
501
502
|
}
|
|
502
503
|
Object.keys(segmentRefs.current).forEach((key) => {
|
|
@@ -504,19 +505,10 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
|
|
|
504
505
|
const refs = segmentRefs.current[index];
|
|
505
506
|
if (refs) {
|
|
506
507
|
if (refs.origin && !refs.origin.contains(target)) {
|
|
507
|
-
setSegmentDropdowns((prev) =>
|
|
508
|
-
...prev,
|
|
509
|
-
[index]: { ...prev[index] || { origin: false, destination: false }, origin: false }
|
|
510
|
-
}));
|
|
508
|
+
setSegmentDropdowns((prev) => prev[index]?.origin ? { ...prev, [index]: { ...prev[index], origin: false } } : prev);
|
|
511
509
|
}
|
|
512
510
|
if (refs.destination && !refs.destination.contains(target)) {
|
|
513
|
-
setSegmentDropdowns((prev) =>
|
|
514
|
-
...prev,
|
|
515
|
-
[index]: {
|
|
516
|
-
...prev[index] || { origin: false, destination: false },
|
|
517
|
-
destination: false
|
|
518
|
-
}
|
|
519
|
-
}));
|
|
511
|
+
setSegmentDropdowns((prev) => prev[index]?.destination ? { ...prev, [index]: { ...prev[index], destination: false } } : prev);
|
|
520
512
|
}
|
|
521
513
|
}
|
|
522
514
|
});
|
|
@@ -3039,6 +3031,7 @@ function FlightSearchFormStandard({
|
|
|
3039
3031
|
|
|
3040
3032
|
// src/modern/Modern.tsx
|
|
3041
3033
|
var import_react3 = require("react");
|
|
3034
|
+
var import_react_dom = require("react-dom");
|
|
3042
3035
|
var import_calendar2 = require("primereact/calendar");
|
|
3043
3036
|
var import_api2 = require("primereact/api");
|
|
3044
3037
|
|
|
@@ -3865,6 +3858,13 @@ var modernStyles = `
|
|
|
3865
3858
|
font-size: 15px;
|
|
3866
3859
|
}
|
|
3867
3860
|
|
|
3861
|
+
/* Sheets are portalled to <body> (see renderSheet in Modern.tsx); the wrapper only carries the theme
|
|
3862
|
+
variables and must sit above any fixed host chrome such as an app's bottom tab bar. */
|
|
3863
|
+
.mdrn_root.mdrn_portal {
|
|
3864
|
+
--mdrn-z: 2147483000;
|
|
3865
|
+
display: contents;
|
|
3866
|
+
}
|
|
3867
|
+
|
|
3868
3868
|
/* Dropdowns become full-screen sheets */
|
|
3869
3869
|
.mdrn_dropdown,
|
|
3870
3870
|
.mdrn_panel {
|
|
@@ -4097,6 +4097,33 @@ function FlightSearchFormModern({ config, ssoUser }) {
|
|
|
4097
4097
|
if (fontName) style["--mdrn-font"] = fontName;
|
|
4098
4098
|
return style;
|
|
4099
4099
|
}, [theme?.primary, theme?.primaryLight, fontName]);
|
|
4100
|
+
const [isMobile, setIsMobile] = (0, import_react3.useState)(false);
|
|
4101
|
+
(0, import_react3.useEffect)(() => {
|
|
4102
|
+
const query = window.matchMedia("(max-width: 1024px)");
|
|
4103
|
+
const sync = () => setIsMobile(query.matches);
|
|
4104
|
+
sync();
|
|
4105
|
+
query.addEventListener("change", sync);
|
|
4106
|
+
return () => query.removeEventListener("change", sync);
|
|
4107
|
+
}, []);
|
|
4108
|
+
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;
|
|
4109
|
+
const [calendarHost, setCalendarHost] = (0, import_react3.useState)(null);
|
|
4110
|
+
const [openMobileCalendar, setOpenMobileCalendar] = (0, import_react3.useState)(null);
|
|
4111
|
+
const mobileCalendarProps = (key) => ({
|
|
4112
|
+
appendTo: calendarHost ?? "self",
|
|
4113
|
+
onShow: () => setOpenMobileCalendar(key),
|
|
4114
|
+
onHide: () => setOpenMobileCalendar((current) => current === key ? null : current)
|
|
4115
|
+
});
|
|
4116
|
+
(0, import_react3.useEffect)(() => setOpenMobileCalendar(null), [tripType, segments.length]);
|
|
4117
|
+
const isSheetOpen = isMobile && (isOriginDropdownOpen || isDestinationDropdownOpen || isRoomsGuestsMenuOpen || openMobileCalendar !== null || Object.values(segmentDropdowns).some((entry) => Boolean(entry?.origin || entry?.destination)));
|
|
4118
|
+
(0, import_react3.useEffect)(() => {
|
|
4119
|
+
if (!isSheetOpen) return;
|
|
4120
|
+
const { body } = document;
|
|
4121
|
+
const previousOverflow = body.style.overflow;
|
|
4122
|
+
body.style.overflow = "hidden";
|
|
4123
|
+
return () => {
|
|
4124
|
+
body.style.overflow = previousOverflow;
|
|
4125
|
+
};
|
|
4126
|
+
}, [isSheetOpen]);
|
|
4100
4127
|
const isMultiCity = tripType === "multi-city" || tripType === "custom-search";
|
|
4101
4128
|
const first = segments[0];
|
|
4102
4129
|
const travellerCount = (first?.adultCount ?? 0) + (first?.childCount ?? 0) + (first?.infantCount ?? 0);
|
|
@@ -4157,44 +4184,46 @@ function FlightSearchFormModern({ config, ssoUser }) {
|
|
|
4157
4184
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_custom-dropdown", ref: dropdownRef, children: [
|
|
4158
4185
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("input", { ...inputProps, id: inputId, className: "mdrn_input mdrn_desktop-only" }),
|
|
4159
4186
|
/* @__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",
|
|
4187
|
+
isOpen && renderSheet(
|
|
4188
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_dropdown", children: [
|
|
4189
|
+
renderMobileHead(placeholder, () => closeAirportDropdown(dropdownType, segmentIndex)),
|
|
4190
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_mobile-search mdrn_mobile-only", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
4191
|
+
"input",
|
|
4178
4192
|
{
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4193
|
+
type: "search",
|
|
4194
|
+
autoFocus: true,
|
|
4195
|
+
placeholder: `Search ${placeholder.toLowerCase()}`,
|
|
4196
|
+
value: value === placeholder ? "" : value,
|
|
4197
|
+
onChange: (e) => onSearch(e.target.value),
|
|
4198
|
+
onKeyDown: (e) => handleKeyDown(e, dropdownType, segmentIndex)
|
|
4199
|
+
}
|
|
4200
|
+
) }),
|
|
4201
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "mdrn_dropdown-title", children: results.length > 0 ? "Airports" : "Popular airports" }),
|
|
4202
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("ul", { className: "mdrn_airport-list", role: "listbox", children: airports.map((airport, i) => {
|
|
4203
|
+
const isActive = results.length > 0 && selectedIndex === i;
|
|
4204
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
4205
|
+
"li",
|
|
4206
|
+
{
|
|
4207
|
+
role: "option",
|
|
4208
|
+
"aria-selected": isActive,
|
|
4209
|
+
className: `mdrn_airport-item${isActive ? " mdrn_is-active" : ""}`,
|
|
4210
|
+
onClick: () => selectAirport(airport, dropdownType, segmentIndex),
|
|
4211
|
+
children: [
|
|
4212
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_airport-code", children: getAirportCode(airport) }),
|
|
4213
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "mdrn_airport-text", children: [
|
|
4214
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_airport-name", children: formatAirportDisplay(airport) }),
|
|
4215
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "mdrn_airport-place", children: [
|
|
4216
|
+
airport.ct,
|
|
4217
|
+
airport.cn ? `, ${airport.cn}` : ""
|
|
4218
|
+
] })
|
|
4190
4219
|
] })
|
|
4191
|
-
]
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
)
|
|
4196
|
-
|
|
4197
|
-
|
|
4220
|
+
]
|
|
4221
|
+
},
|
|
4222
|
+
airport.id ?? airport.ac ?? i
|
|
4223
|
+
);
|
|
4224
|
+
}) })
|
|
4225
|
+
] })
|
|
4226
|
+
)
|
|
4198
4227
|
] })
|
|
4199
4228
|
] });
|
|
4200
4229
|
};
|
|
@@ -4238,7 +4267,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
|
|
|
4238
4267
|
{
|
|
4239
4268
|
ref: mobileDateRangeCalendarRef,
|
|
4240
4269
|
numberOfMonths: 10,
|
|
4241
|
-
|
|
4270
|
+
...mobileCalendarProps("round-trip"),
|
|
4242
4271
|
selectionMode: "range",
|
|
4243
4272
|
readOnlyInput: true,
|
|
4244
4273
|
value: first?.dateRange ?? null,
|
|
@@ -4284,7 +4313,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
|
|
|
4284
4313
|
{
|
|
4285
4314
|
ref: oneWayMobileCalendarRef,
|
|
4286
4315
|
numberOfMonths: 10,
|
|
4287
|
-
|
|
4316
|
+
...mobileCalendarProps("one-way"),
|
|
4288
4317
|
readOnlyInput: true,
|
|
4289
4318
|
value: first?.departureDate ?? null,
|
|
4290
4319
|
minDate: /* @__PURE__ */ new Date(),
|
|
@@ -4328,7 +4357,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
|
|
|
4328
4357
|
segmentMobileCalendarRefs.current[index] = el;
|
|
4329
4358
|
},
|
|
4330
4359
|
numberOfMonths: 10,
|
|
4331
|
-
|
|
4360
|
+
...mobileCalendarProps(`segment-${index}`),
|
|
4332
4361
|
readOnlyInput: true,
|
|
4333
4362
|
value: segment.departureDate ?? null,
|
|
4334
4363
|
minDate: getMinDateForSegment(index),
|
|
@@ -4355,49 +4384,51 @@ function FlightSearchFormModern({ config, ssoUser }) {
|
|
|
4355
4384
|
]
|
|
4356
4385
|
}
|
|
4357
4386
|
),
|
|
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
|
-
|
|
4387
|
+
isRoomsGuestsMenuOpen && renderSheet(
|
|
4388
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_panel mdrn_pax-panel", children: [
|
|
4389
|
+
renderMobileHead("Travelers & Class", () => setIsRoomsGuestsMenuOpen(false)),
|
|
4390
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_panel-body", children: [
|
|
4391
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { className: "mdrn_panel-title", children: "Number of travelers" }),
|
|
4392
|
+
PASSENGER_ROWS.map((row) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_pax-row", children: [
|
|
4393
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_pax-info", children: [
|
|
4394
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_pax-label", children: row.label }),
|
|
4395
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_pax-hint", children: row.hint })
|
|
4396
|
+
] }),
|
|
4397
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "mdrn_pax-options", children: row.options.map((count) => {
|
|
4398
|
+
const isActive = (first?.[row.field] ?? 0) === count;
|
|
4399
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
4400
|
+
"button",
|
|
4401
|
+
{
|
|
4402
|
+
type: "button",
|
|
4403
|
+
className: `mdrn_pax-btn${isActive ? " mdrn_is-active" : ""}`,
|
|
4404
|
+
disabled: isPassengerOptionDisabled(row.field, count),
|
|
4405
|
+
onClick: () => row.field === "adultCount" ? selectAdultCount(count) : handleTravellerChange(row.field, count),
|
|
4406
|
+
children: count
|
|
4407
|
+
},
|
|
4408
|
+
count
|
|
4409
|
+
);
|
|
4410
|
+
}) })
|
|
4411
|
+
] }, row.field)),
|
|
4412
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { className: "mdrn_panel-title", children: "Travel class" }),
|
|
4413
|
+
/* @__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: [
|
|
4414
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
4415
|
+
"input",
|
|
4371
4416
|
{
|
|
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" })
|
|
4417
|
+
type: "radio",
|
|
4418
|
+
name: `${uid}-travel-class`,
|
|
4419
|
+
checked: (first?.travelerClass ?? "Economy") === travelClass,
|
|
4420
|
+
onChange: () => handleTravellerChange("travelerClass", travelClass)
|
|
4421
|
+
}
|
|
4422
|
+
),
|
|
4423
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: travelClass })
|
|
4424
|
+
] }, travelClass)) })
|
|
4425
|
+
] }),
|
|
4426
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_panel-foot", children: [
|
|
4427
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "mdrn_btn mdrn_btn--ghost", onClick: resetTravellers, children: "Reset" }),
|
|
4428
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "button", className: "mdrn_btn mdrn_btn--primary", onClick: () => setIsRoomsGuestsMenuOpen(false), children: "Apply" })
|
|
4429
|
+
] })
|
|
4399
4430
|
] })
|
|
4400
|
-
|
|
4431
|
+
)
|
|
4401
4432
|
] });
|
|
4402
4433
|
const searchButton = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { type: "submit", className: "mdrn_search", children: "Search" });
|
|
4403
4434
|
const renderMultiCity = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "mdrn_mc", children: [
|
|
@@ -4478,7 +4509,11 @@ function FlightSearchFormModern({ config, ssoUser }) {
|
|
|
4478
4509
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "mdrn_checkbox-box", "aria-hidden": "true" }),
|
|
4479
4510
|
label
|
|
4480
4511
|
] }, key)) })
|
|
4481
|
-
] })
|
|
4512
|
+
] }),
|
|
4513
|
+
isMobile && (0, import_react_dom.createPortal)(
|
|
4514
|
+
/* @__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 }) }),
|
|
4515
|
+
document.body
|
|
4516
|
+
)
|
|
4482
4517
|
] }) });
|
|
4483
4518
|
}
|
|
4484
4519
|
|