@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.mjs CHANGED
@@ -455,6 +455,7 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
455
455
  useEffect(() => {
456
456
  const handleClickOutside = (event) => {
457
457
  const target = event.target;
458
+ if (target.closest("[data-tfsw-sheet]")) return;
458
459
  const isInsidePrimeDropdown = Boolean(
459
460
  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"]')
460
461
  );
@@ -470,7 +471,7 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
470
471
  const isInsideCustomDropdown = target.closest(dropdownSelector) !== null;
471
472
  const isInsideCalendar = target.closest(".p-datepicker") !== null || target.closest(".p-calendar") !== null;
472
473
  if (!isInsideCustomDropdown && !isInsideCalendar) {
473
- setSegmentDropdowns({});
474
+ setSegmentDropdowns((prev) => Object.keys(prev).length > 0 ? {} : prev);
474
475
  return;
475
476
  }
476
477
  Object.keys(segmentRefs.current).forEach((key) => {
@@ -478,19 +479,10 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
478
479
  const refs = segmentRefs.current[index];
479
480
  if (refs) {
480
481
  if (refs.origin && !refs.origin.contains(target)) {
481
- setSegmentDropdowns((prev) => ({
482
- ...prev,
483
- [index]: { ...prev[index] || { origin: false, destination: false }, origin: false }
484
- }));
482
+ setSegmentDropdowns((prev) => prev[index]?.origin ? { ...prev, [index]: { ...prev[index], origin: false } } : prev);
485
483
  }
486
484
  if (refs.destination && !refs.destination.contains(target)) {
487
- setSegmentDropdowns((prev) => ({
488
- ...prev,
489
- [index]: {
490
- ...prev[index] || { origin: false, destination: false },
491
- destination: false
492
- }
493
- }));
485
+ setSegmentDropdowns((prev) => prev[index]?.destination ? { ...prev, [index]: { ...prev[index], destination: false } } : prev);
494
486
  }
495
487
  }
496
488
  });
@@ -3012,7 +3004,8 @@ function FlightSearchFormStandard({
3012
3004
  }
3013
3005
 
3014
3006
  // src/modern/Modern.tsx
3015
- import { useId, useMemo as useMemo3, useRef as useRef3, useState as useState2 } from "react";
3007
+ import { useEffect as useEffect3, useId, useMemo as useMemo3, useRef as useRef3, useState as useState2 } from "react";
3008
+ import { createPortal } from "react-dom";
3016
3009
  import { Calendar as Calendar2 } from "primereact/calendar";
3017
3010
  import { PrimeReactProvider as PrimeReactProvider2 } from "primereact/api";
3018
3011
 
@@ -3839,6 +3832,13 @@ var modernStyles = `
3839
3832
  font-size: 15px;
3840
3833
  }
3841
3834
 
3835
+ /* Sheets are portalled to <body> (see renderSheet in Modern.tsx); the wrapper only carries the theme
3836
+ variables and must sit above any fixed host chrome such as an app's bottom tab bar. */
3837
+ .mdrn_root.mdrn_portal {
3838
+ --mdrn-z: 2147483000;
3839
+ display: contents;
3840
+ }
3841
+
3842
3842
  /* Dropdowns become full-screen sheets */
3843
3843
  .mdrn_dropdown,
3844
3844
  .mdrn_panel {
@@ -4071,6 +4071,33 @@ function FlightSearchFormModern({ config, ssoUser }) {
4071
4071
  if (fontName) style["--mdrn-font"] = fontName;
4072
4072
  return style;
4073
4073
  }, [theme?.primary, theme?.primaryLight, fontName]);
4074
+ const [isMobile, setIsMobile] = useState2(false);
4075
+ useEffect3(() => {
4076
+ const query = window.matchMedia("(max-width: 1024px)");
4077
+ const sync = () => setIsMobile(query.matches);
4078
+ sync();
4079
+ query.addEventListener("change", sync);
4080
+ return () => query.removeEventListener("change", sync);
4081
+ }, []);
4082
+ const renderSheet = (sheet) => isMobile ? createPortal(/* @__PURE__ */ jsx2("div", { className: "mdrn_root mdrn_portal", style: themeStyle, "data-tfsw-sheet": "", children: sheet }), document.body) : sheet;
4083
+ const [calendarHost, setCalendarHost] = useState2(null);
4084
+ const [openMobileCalendar, setOpenMobileCalendar] = useState2(null);
4085
+ const mobileCalendarProps = (key) => ({
4086
+ appendTo: calendarHost ?? "self",
4087
+ onShow: () => setOpenMobileCalendar(key),
4088
+ onHide: () => setOpenMobileCalendar((current) => current === key ? null : current)
4089
+ });
4090
+ useEffect3(() => setOpenMobileCalendar(null), [tripType, segments.length]);
4091
+ const isSheetOpen = isMobile && (isOriginDropdownOpen || isDestinationDropdownOpen || isRoomsGuestsMenuOpen || openMobileCalendar !== null || Object.values(segmentDropdowns).some((entry) => Boolean(entry?.origin || entry?.destination)));
4092
+ useEffect3(() => {
4093
+ if (!isSheetOpen) return;
4094
+ const { body } = document;
4095
+ const previousOverflow = body.style.overflow;
4096
+ body.style.overflow = "hidden";
4097
+ return () => {
4098
+ body.style.overflow = previousOverflow;
4099
+ };
4100
+ }, [isSheetOpen]);
4074
4101
  const isMultiCity = tripType === "multi-city" || tripType === "custom-search";
4075
4102
  const first = segments[0];
4076
4103
  const travellerCount = (first?.adultCount ?? 0) + (first?.childCount ?? 0) + (first?.infantCount ?? 0);
@@ -4131,44 +4158,46 @@ function FlightSearchFormModern({ config, ssoUser }) {
4131
4158
  /* @__PURE__ */ jsxs2("div", { className: "mdrn_custom-dropdown", ref: dropdownRef, children: [
4132
4159
  /* @__PURE__ */ jsx2("input", { ...inputProps, id: inputId, className: "mdrn_input mdrn_desktop-only" }),
4133
4160
  /* @__PURE__ */ jsx2("input", { ...inputProps, id: `${inputId}-mobile`, readOnly: true, className: "mdrn_input mdrn_mobile-only" }),
4134
- isOpen && /* @__PURE__ */ jsxs2("div", { className: "mdrn_dropdown", children: [
4135
- renderMobileHead(placeholder, () => closeAirportDropdown(dropdownType, segmentIndex)),
4136
- /* @__PURE__ */ jsx2("div", { className: "mdrn_mobile-search mdrn_mobile-only", children: /* @__PURE__ */ jsx2(
4137
- "input",
4138
- {
4139
- type: "search",
4140
- autoFocus: true,
4141
- placeholder: `Search ${placeholder.toLowerCase()}`,
4142
- value: value === placeholder ? "" : value,
4143
- onChange: (e) => onSearch(e.target.value),
4144
- onKeyDown: (e) => handleKeyDown(e, dropdownType, segmentIndex)
4145
- }
4146
- ) }),
4147
- /* @__PURE__ */ jsx2("p", { className: "mdrn_dropdown-title", children: results.length > 0 ? "Airports" : "Popular airports" }),
4148
- /* @__PURE__ */ jsx2("ul", { className: "mdrn_airport-list", role: "listbox", children: airports.map((airport, i) => {
4149
- const isActive = results.length > 0 && selectedIndex === i;
4150
- return /* @__PURE__ */ jsxs2(
4151
- "li",
4161
+ isOpen && renderSheet(
4162
+ /* @__PURE__ */ jsxs2("div", { className: "mdrn_dropdown", children: [
4163
+ renderMobileHead(placeholder, () => closeAirportDropdown(dropdownType, segmentIndex)),
4164
+ /* @__PURE__ */ jsx2("div", { className: "mdrn_mobile-search mdrn_mobile-only", children: /* @__PURE__ */ jsx2(
4165
+ "input",
4152
4166
  {
4153
- role: "option",
4154
- "aria-selected": isActive,
4155
- className: `mdrn_airport-item${isActive ? " mdrn_is-active" : ""}`,
4156
- onClick: () => selectAirport(airport, dropdownType, segmentIndex),
4157
- children: [
4158
- /* @__PURE__ */ jsx2("span", { className: "mdrn_airport-code", children: getAirportCode(airport) }),
4159
- /* @__PURE__ */ jsxs2("span", { className: "mdrn_airport-text", children: [
4160
- /* @__PURE__ */ jsx2("span", { className: "mdrn_airport-name", children: formatAirportDisplay(airport) }),
4161
- /* @__PURE__ */ jsxs2("span", { className: "mdrn_airport-place", children: [
4162
- airport.ct,
4163
- airport.cn ? `, ${airport.cn}` : ""
4167
+ type: "search",
4168
+ autoFocus: true,
4169
+ placeholder: `Search ${placeholder.toLowerCase()}`,
4170
+ value: value === placeholder ? "" : value,
4171
+ onChange: (e) => onSearch(e.target.value),
4172
+ onKeyDown: (e) => handleKeyDown(e, dropdownType, segmentIndex)
4173
+ }
4174
+ ) }),
4175
+ /* @__PURE__ */ jsx2("p", { className: "mdrn_dropdown-title", children: results.length > 0 ? "Airports" : "Popular airports" }),
4176
+ /* @__PURE__ */ jsx2("ul", { className: "mdrn_airport-list", role: "listbox", children: airports.map((airport, i) => {
4177
+ const isActive = results.length > 0 && selectedIndex === i;
4178
+ return /* @__PURE__ */ jsxs2(
4179
+ "li",
4180
+ {
4181
+ role: "option",
4182
+ "aria-selected": isActive,
4183
+ className: `mdrn_airport-item${isActive ? " mdrn_is-active" : ""}`,
4184
+ onClick: () => selectAirport(airport, dropdownType, segmentIndex),
4185
+ children: [
4186
+ /* @__PURE__ */ jsx2("span", { className: "mdrn_airport-code", children: getAirportCode(airport) }),
4187
+ /* @__PURE__ */ jsxs2("span", { className: "mdrn_airport-text", children: [
4188
+ /* @__PURE__ */ jsx2("span", { className: "mdrn_airport-name", children: formatAirportDisplay(airport) }),
4189
+ /* @__PURE__ */ jsxs2("span", { className: "mdrn_airport-place", children: [
4190
+ airport.ct,
4191
+ airport.cn ? `, ${airport.cn}` : ""
4192
+ ] })
4164
4193
  ] })
4165
- ] })
4166
- ]
4167
- },
4168
- airport.id ?? airport.ac ?? i
4169
- );
4170
- }) })
4171
- ] })
4194
+ ]
4195
+ },
4196
+ airport.id ?? airport.ac ?? i
4197
+ );
4198
+ }) })
4199
+ ] })
4200
+ )
4172
4201
  ] })
4173
4202
  ] });
4174
4203
  };
@@ -4212,7 +4241,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
4212
4241
  {
4213
4242
  ref: mobileDateRangeCalendarRef,
4214
4243
  numberOfMonths: 10,
4215
- appendTo: "self",
4244
+ ...mobileCalendarProps("round-trip"),
4216
4245
  selectionMode: "range",
4217
4246
  readOnlyInput: true,
4218
4247
  value: first?.dateRange ?? null,
@@ -4258,7 +4287,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
4258
4287
  {
4259
4288
  ref: oneWayMobileCalendarRef,
4260
4289
  numberOfMonths: 10,
4261
- appendTo: "self",
4290
+ ...mobileCalendarProps("one-way"),
4262
4291
  readOnlyInput: true,
4263
4292
  value: first?.departureDate ?? null,
4264
4293
  minDate: /* @__PURE__ */ new Date(),
@@ -4302,7 +4331,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
4302
4331
  segmentMobileCalendarRefs.current[index] = el;
4303
4332
  },
4304
4333
  numberOfMonths: 10,
4305
- appendTo: "self",
4334
+ ...mobileCalendarProps(`segment-${index}`),
4306
4335
  readOnlyInput: true,
4307
4336
  value: segment.departureDate ?? null,
4308
4337
  minDate: getMinDateForSegment(index),
@@ -4329,49 +4358,51 @@ function FlightSearchFormModern({ config, ssoUser }) {
4329
4358
  ]
4330
4359
  }
4331
4360
  ),
4332
- isRoomsGuestsMenuOpen && /* @__PURE__ */ jsxs2("div", { className: "mdrn_panel mdrn_pax-panel", children: [
4333
- renderMobileHead("Travelers & Class", () => setIsRoomsGuestsMenuOpen(false)),
4334
- /* @__PURE__ */ jsxs2("div", { className: "mdrn_panel-body", children: [
4335
- /* @__PURE__ */ jsx2("h3", { className: "mdrn_panel-title", children: "Number of travelers" }),
4336
- PASSENGER_ROWS.map((row) => /* @__PURE__ */ jsxs2("div", { className: "mdrn_pax-row", children: [
4337
- /* @__PURE__ */ jsxs2("div", { className: "mdrn_pax-info", children: [
4338
- /* @__PURE__ */ jsx2("span", { className: "mdrn_pax-label", children: row.label }),
4339
- /* @__PURE__ */ jsx2("span", { className: "mdrn_pax-hint", children: row.hint })
4340
- ] }),
4341
- /* @__PURE__ */ jsx2("div", { className: "mdrn_pax-options", children: row.options.map((count) => {
4342
- const isActive = (first?.[row.field] ?? 0) === count;
4343
- return /* @__PURE__ */ jsx2(
4344
- "button",
4361
+ isRoomsGuestsMenuOpen && renderSheet(
4362
+ /* @__PURE__ */ jsxs2("div", { className: "mdrn_panel mdrn_pax-panel", children: [
4363
+ renderMobileHead("Travelers & Class", () => setIsRoomsGuestsMenuOpen(false)),
4364
+ /* @__PURE__ */ jsxs2("div", { className: "mdrn_panel-body", children: [
4365
+ /* @__PURE__ */ jsx2("h3", { className: "mdrn_panel-title", children: "Number of travelers" }),
4366
+ PASSENGER_ROWS.map((row) => /* @__PURE__ */ jsxs2("div", { className: "mdrn_pax-row", children: [
4367
+ /* @__PURE__ */ jsxs2("div", { className: "mdrn_pax-info", children: [
4368
+ /* @__PURE__ */ jsx2("span", { className: "mdrn_pax-label", children: row.label }),
4369
+ /* @__PURE__ */ jsx2("span", { className: "mdrn_pax-hint", children: row.hint })
4370
+ ] }),
4371
+ /* @__PURE__ */ jsx2("div", { className: "mdrn_pax-options", children: row.options.map((count) => {
4372
+ const isActive = (first?.[row.field] ?? 0) === count;
4373
+ return /* @__PURE__ */ jsx2(
4374
+ "button",
4375
+ {
4376
+ type: "button",
4377
+ className: `mdrn_pax-btn${isActive ? " mdrn_is-active" : ""}`,
4378
+ disabled: isPassengerOptionDisabled(row.field, count),
4379
+ onClick: () => row.field === "adultCount" ? selectAdultCount(count) : handleTravellerChange(row.field, count),
4380
+ children: count
4381
+ },
4382
+ count
4383
+ );
4384
+ }) })
4385
+ ] }, row.field)),
4386
+ /* @__PURE__ */ jsx2("h3", { className: "mdrn_panel-title", children: "Travel class" }),
4387
+ /* @__PURE__ */ jsx2("div", { className: "mdrn_chips", children: TRAVEL_CLASSES.map((travelClass) => /* @__PURE__ */ jsxs2("label", { className: "mdrn_chip", children: [
4388
+ /* @__PURE__ */ jsx2(
4389
+ "input",
4345
4390
  {
4346
- type: "button",
4347
- className: `mdrn_pax-btn${isActive ? " mdrn_is-active" : ""}`,
4348
- disabled: isPassengerOptionDisabled(row.field, count),
4349
- onClick: () => row.field === "adultCount" ? selectAdultCount(count) : handleTravellerChange(row.field, count),
4350
- children: count
4351
- },
4352
- count
4353
- );
4354
- }) })
4355
- ] }, row.field)),
4356
- /* @__PURE__ */ jsx2("h3", { className: "mdrn_panel-title", children: "Travel class" }),
4357
- /* @__PURE__ */ jsx2("div", { className: "mdrn_chips", children: TRAVEL_CLASSES.map((travelClass) => /* @__PURE__ */ jsxs2("label", { className: "mdrn_chip", children: [
4358
- /* @__PURE__ */ jsx2(
4359
- "input",
4360
- {
4361
- type: "radio",
4362
- name: `${uid}-travel-class`,
4363
- checked: (first?.travelerClass ?? "Economy") === travelClass,
4364
- onChange: () => handleTravellerChange("travelerClass", travelClass)
4365
- }
4366
- ),
4367
- /* @__PURE__ */ jsx2("span", { children: travelClass })
4368
- ] }, travelClass)) })
4369
- ] }),
4370
- /* @__PURE__ */ jsxs2("div", { className: "mdrn_panel-foot", children: [
4371
- /* @__PURE__ */ jsx2("button", { type: "button", className: "mdrn_btn mdrn_btn--ghost", onClick: resetTravellers, children: "Reset" }),
4372
- /* @__PURE__ */ jsx2("button", { type: "button", className: "mdrn_btn mdrn_btn--primary", onClick: () => setIsRoomsGuestsMenuOpen(false), children: "Apply" })
4391
+ type: "radio",
4392
+ name: `${uid}-travel-class`,
4393
+ checked: (first?.travelerClass ?? "Economy") === travelClass,
4394
+ onChange: () => handleTravellerChange("travelerClass", travelClass)
4395
+ }
4396
+ ),
4397
+ /* @__PURE__ */ jsx2("span", { children: travelClass })
4398
+ ] }, travelClass)) })
4399
+ ] }),
4400
+ /* @__PURE__ */ jsxs2("div", { className: "mdrn_panel-foot", children: [
4401
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "mdrn_btn mdrn_btn--ghost", onClick: resetTravellers, children: "Reset" }),
4402
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "mdrn_btn mdrn_btn--primary", onClick: () => setIsRoomsGuestsMenuOpen(false), children: "Apply" })
4403
+ ] })
4373
4404
  ] })
4374
- ] })
4405
+ )
4375
4406
  ] });
4376
4407
  const searchButton = /* @__PURE__ */ jsx2("button", { type: "submit", className: "mdrn_search", children: "Search" });
4377
4408
  const renderMultiCity = () => /* @__PURE__ */ jsxs2("div", { className: "mdrn_mc", children: [
@@ -4452,7 +4483,11 @@ function FlightSearchFormModern({ config, ssoUser }) {
4452
4483
  /* @__PURE__ */ jsx2("span", { className: "mdrn_checkbox-box", "aria-hidden": "true" }),
4453
4484
  label
4454
4485
  ] }, key)) })
4455
- ] })
4486
+ ] }),
4487
+ isMobile && createPortal(
4488
+ /* @__PURE__ */ jsx2("div", { className: "mdrn_root mdrn_portal", style: themeStyle, children: /* @__PURE__ */ jsx2("div", { className: "mdrn_calendar", ref: setCalendarHost }) }),
4489
+ document.body
4490
+ )
4456
4491
  ] }) });
4457
4492
  }
4458
4493