@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.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
  );
@@ -3012,7 +3013,8 @@ function FlightSearchFormStandard({
3012
3013
  }
3013
3014
 
3014
3015
  // src/modern/Modern.tsx
3015
- import { useId, useMemo as useMemo3, useRef as useRef3, useState as useState2 } from "react";
3016
+ import { useEffect as useEffect3, useId, useMemo as useMemo3, useRef as useRef3, useState as useState2 } from "react";
3017
+ import { createPortal } from "react-dom";
3016
3018
  import { Calendar as Calendar2 } from "primereact/calendar";
3017
3019
  import { PrimeReactProvider as PrimeReactProvider2 } from "primereact/api";
3018
3020
 
@@ -3839,6 +3841,13 @@ var modernStyles = `
3839
3841
  font-size: 15px;
3840
3842
  }
3841
3843
 
3844
+ /* Sheets are portalled to <body> (see renderSheet in Modern.tsx); the wrapper only carries the theme
3845
+ variables and must sit above any fixed host chrome such as an app's bottom tab bar. */
3846
+ .mdrn_root.mdrn_portal {
3847
+ --mdrn-z: 2147483000;
3848
+ display: contents;
3849
+ }
3850
+
3842
3851
  /* Dropdowns become full-screen sheets */
3843
3852
  .mdrn_dropdown,
3844
3853
  .mdrn_panel {
@@ -4071,6 +4080,33 @@ function FlightSearchFormModern({ config, ssoUser }) {
4071
4080
  if (fontName) style["--mdrn-font"] = fontName;
4072
4081
  return style;
4073
4082
  }, [theme?.primary, theme?.primaryLight, fontName]);
4083
+ const [isMobile, setIsMobile] = useState2(false);
4084
+ useEffect3(() => {
4085
+ const query = window.matchMedia("(max-width: 1024px)");
4086
+ const sync = () => setIsMobile(query.matches);
4087
+ sync();
4088
+ query.addEventListener("change", sync);
4089
+ return () => query.removeEventListener("change", sync);
4090
+ }, []);
4091
+ const renderSheet = (sheet) => isMobile ? createPortal(/* @__PURE__ */ jsx2("div", { className: "mdrn_root mdrn_portal", style: themeStyle, "data-tfsw-sheet": "", children: sheet }), document.body) : sheet;
4092
+ const [calendarHost, setCalendarHost] = useState2(null);
4093
+ const [openMobileCalendar, setOpenMobileCalendar] = useState2(null);
4094
+ const mobileCalendarProps = (key) => ({
4095
+ appendTo: calendarHost ?? "self",
4096
+ onShow: () => setOpenMobileCalendar(key),
4097
+ onHide: () => setOpenMobileCalendar((current) => current === key ? null : current)
4098
+ });
4099
+ useEffect3(() => setOpenMobileCalendar(null), [tripType, segments.length]);
4100
+ const isSheetOpen = isMobile && (isOriginDropdownOpen || isDestinationDropdownOpen || isRoomsGuestsMenuOpen || openMobileCalendar !== null || Object.values(segmentDropdowns).some((entry) => Boolean(entry?.origin || entry?.destination)));
4101
+ useEffect3(() => {
4102
+ if (!isSheetOpen) return;
4103
+ const { body } = document;
4104
+ const previousOverflow = body.style.overflow;
4105
+ body.style.overflow = "hidden";
4106
+ return () => {
4107
+ body.style.overflow = previousOverflow;
4108
+ };
4109
+ }, [isSheetOpen]);
4074
4110
  const isMultiCity = tripType === "multi-city" || tripType === "custom-search";
4075
4111
  const first = segments[0];
4076
4112
  const travellerCount = (first?.adultCount ?? 0) + (first?.childCount ?? 0) + (first?.infantCount ?? 0);
@@ -4131,44 +4167,46 @@ function FlightSearchFormModern({ config, ssoUser }) {
4131
4167
  /* @__PURE__ */ jsxs2("div", { className: "mdrn_custom-dropdown", ref: dropdownRef, children: [
4132
4168
  /* @__PURE__ */ jsx2("input", { ...inputProps, id: inputId, className: "mdrn_input mdrn_desktop-only" }),
4133
4169
  /* @__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",
4170
+ isOpen && renderSheet(
4171
+ /* @__PURE__ */ jsxs2("div", { className: "mdrn_dropdown", children: [
4172
+ renderMobileHead(placeholder, () => closeAirportDropdown(dropdownType, segmentIndex)),
4173
+ /* @__PURE__ */ jsx2("div", { className: "mdrn_mobile-search mdrn_mobile-only", children: /* @__PURE__ */ jsx2(
4174
+ "input",
4152
4175
  {
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}` : ""
4176
+ type: "search",
4177
+ autoFocus: true,
4178
+ placeholder: `Search ${placeholder.toLowerCase()}`,
4179
+ value: value === placeholder ? "" : value,
4180
+ onChange: (e) => onSearch(e.target.value),
4181
+ onKeyDown: (e) => handleKeyDown(e, dropdownType, segmentIndex)
4182
+ }
4183
+ ) }),
4184
+ /* @__PURE__ */ jsx2("p", { className: "mdrn_dropdown-title", children: results.length > 0 ? "Airports" : "Popular airports" }),
4185
+ /* @__PURE__ */ jsx2("ul", { className: "mdrn_airport-list", role: "listbox", children: airports.map((airport, i) => {
4186
+ const isActive = results.length > 0 && selectedIndex === i;
4187
+ return /* @__PURE__ */ jsxs2(
4188
+ "li",
4189
+ {
4190
+ role: "option",
4191
+ "aria-selected": isActive,
4192
+ className: `mdrn_airport-item${isActive ? " mdrn_is-active" : ""}`,
4193
+ onClick: () => selectAirport(airport, dropdownType, segmentIndex),
4194
+ children: [
4195
+ /* @__PURE__ */ jsx2("span", { className: "mdrn_airport-code", children: getAirportCode(airport) }),
4196
+ /* @__PURE__ */ jsxs2("span", { className: "mdrn_airport-text", children: [
4197
+ /* @__PURE__ */ jsx2("span", { className: "mdrn_airport-name", children: formatAirportDisplay(airport) }),
4198
+ /* @__PURE__ */ jsxs2("span", { className: "mdrn_airport-place", children: [
4199
+ airport.ct,
4200
+ airport.cn ? `, ${airport.cn}` : ""
4201
+ ] })
4164
4202
  ] })
4165
- ] })
4166
- ]
4167
- },
4168
- airport.id ?? airport.ac ?? i
4169
- );
4170
- }) })
4171
- ] })
4203
+ ]
4204
+ },
4205
+ airport.id ?? airport.ac ?? i
4206
+ );
4207
+ }) })
4208
+ ] })
4209
+ )
4172
4210
  ] })
4173
4211
  ] });
4174
4212
  };
@@ -4212,7 +4250,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
4212
4250
  {
4213
4251
  ref: mobileDateRangeCalendarRef,
4214
4252
  numberOfMonths: 10,
4215
- appendTo: "self",
4253
+ ...mobileCalendarProps("round-trip"),
4216
4254
  selectionMode: "range",
4217
4255
  readOnlyInput: true,
4218
4256
  value: first?.dateRange ?? null,
@@ -4258,7 +4296,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
4258
4296
  {
4259
4297
  ref: oneWayMobileCalendarRef,
4260
4298
  numberOfMonths: 10,
4261
- appendTo: "self",
4299
+ ...mobileCalendarProps("one-way"),
4262
4300
  readOnlyInput: true,
4263
4301
  value: first?.departureDate ?? null,
4264
4302
  minDate: /* @__PURE__ */ new Date(),
@@ -4302,7 +4340,7 @@ function FlightSearchFormModern({ config, ssoUser }) {
4302
4340
  segmentMobileCalendarRefs.current[index] = el;
4303
4341
  },
4304
4342
  numberOfMonths: 10,
4305
- appendTo: "self",
4343
+ ...mobileCalendarProps(`segment-${index}`),
4306
4344
  readOnlyInput: true,
4307
4345
  value: segment.departureDate ?? null,
4308
4346
  minDate: getMinDateForSegment(index),
@@ -4329,49 +4367,51 @@ function FlightSearchFormModern({ config, ssoUser }) {
4329
4367
  ]
4330
4368
  }
4331
4369
  ),
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",
4370
+ isRoomsGuestsMenuOpen && renderSheet(
4371
+ /* @__PURE__ */ jsxs2("div", { className: "mdrn_panel mdrn_pax-panel", children: [
4372
+ renderMobileHead("Travelers & Class", () => setIsRoomsGuestsMenuOpen(false)),
4373
+ /* @__PURE__ */ jsxs2("div", { className: "mdrn_panel-body", children: [
4374
+ /* @__PURE__ */ jsx2("h3", { className: "mdrn_panel-title", children: "Number of travelers" }),
4375
+ PASSENGER_ROWS.map((row) => /* @__PURE__ */ jsxs2("div", { className: "mdrn_pax-row", children: [
4376
+ /* @__PURE__ */ jsxs2("div", { className: "mdrn_pax-info", children: [
4377
+ /* @__PURE__ */ jsx2("span", { className: "mdrn_pax-label", children: row.label }),
4378
+ /* @__PURE__ */ jsx2("span", { className: "mdrn_pax-hint", children: row.hint })
4379
+ ] }),
4380
+ /* @__PURE__ */ jsx2("div", { className: "mdrn_pax-options", children: row.options.map((count) => {
4381
+ const isActive = (first?.[row.field] ?? 0) === count;
4382
+ return /* @__PURE__ */ jsx2(
4383
+ "button",
4384
+ {
4385
+ type: "button",
4386
+ className: `mdrn_pax-btn${isActive ? " mdrn_is-active" : ""}`,
4387
+ disabled: isPassengerOptionDisabled(row.field, count),
4388
+ onClick: () => row.field === "adultCount" ? selectAdultCount(count) : handleTravellerChange(row.field, count),
4389
+ children: count
4390
+ },
4391
+ count
4392
+ );
4393
+ }) })
4394
+ ] }, row.field)),
4395
+ /* @__PURE__ */ jsx2("h3", { className: "mdrn_panel-title", children: "Travel class" }),
4396
+ /* @__PURE__ */ jsx2("div", { className: "mdrn_chips", children: TRAVEL_CLASSES.map((travelClass) => /* @__PURE__ */ jsxs2("label", { className: "mdrn_chip", children: [
4397
+ /* @__PURE__ */ jsx2(
4398
+ "input",
4345
4399
  {
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" })
4400
+ type: "radio",
4401
+ name: `${uid}-travel-class`,
4402
+ checked: (first?.travelerClass ?? "Economy") === travelClass,
4403
+ onChange: () => handleTravellerChange("travelerClass", travelClass)
4404
+ }
4405
+ ),
4406
+ /* @__PURE__ */ jsx2("span", { children: travelClass })
4407
+ ] }, travelClass)) })
4408
+ ] }),
4409
+ /* @__PURE__ */ jsxs2("div", { className: "mdrn_panel-foot", children: [
4410
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "mdrn_btn mdrn_btn--ghost", onClick: resetTravellers, children: "Reset" }),
4411
+ /* @__PURE__ */ jsx2("button", { type: "button", className: "mdrn_btn mdrn_btn--primary", onClick: () => setIsRoomsGuestsMenuOpen(false), children: "Apply" })
4412
+ ] })
4373
4413
  ] })
4374
- ] })
4414
+ )
4375
4415
  ] });
4376
4416
  const searchButton = /* @__PURE__ */ jsx2("button", { type: "submit", className: "mdrn_search", children: "Search" });
4377
4417
  const renderMultiCity = () => /* @__PURE__ */ jsxs2("div", { className: "mdrn_mc", children: [
@@ -4452,7 +4492,11 @@ function FlightSearchFormModern({ config, ssoUser }) {
4452
4492
  /* @__PURE__ */ jsx2("span", { className: "mdrn_checkbox-box", "aria-hidden": "true" }),
4453
4493
  label
4454
4494
  ] }, key)) })
4455
- ] })
4495
+ ] }),
4496
+ isMobile && createPortal(
4497
+ /* @__PURE__ */ jsx2("div", { className: "mdrn_root mdrn_portal", style: themeStyle, children: /* @__PURE__ */ jsx2("div", { className: "mdrn_calendar", ref: setCalendarHost }) }),
4498
+ document.body
4499
+ )
4456
4500
  ] }) });
4457
4501
  }
4458
4502