@travelswitchhq/flight-search-react 1.1.3 → 1.1.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.d.cts CHANGED
@@ -45,6 +45,18 @@ type FlightSearchWidgetProps = {
45
45
  fontName?: string;
46
46
  /** "dev" | "prod" – selects API base URLs. Defaults to "dev". */
47
47
  env?: FlightSearchEnv;
48
+ /**
49
+ * ISO 3166-1 alpha-2 country code (e.g. "AE").
50
+ * When set, the search redirect becomes `{base}/{countryCode}-{languageSegment}/flight/listing?...`
51
+ * where `languageSegment` is {@link languageCode} uppercased, or "EN" if {@link languageCode} is omitted.
52
+ */
53
+ countryCode?: string;
54
+ /**
55
+ * Language code for airport/airline APIs and the `lc` query param (e.g. "en", "ar").
56
+ * Defaults to `"en"` when omitted.
57
+ * If {@link countryCode} is set and this is omitted, the locale path segment still uses "EN".
58
+ */
59
+ languageCode?: string;
48
60
  };
49
61
  ssoUser?: FlightSearchSsoUser;
50
62
  };
package/dist/index.d.ts CHANGED
@@ -45,6 +45,18 @@ type FlightSearchWidgetProps = {
45
45
  fontName?: string;
46
46
  /** "dev" | "prod" – selects API base URLs. Defaults to "dev". */
47
47
  env?: FlightSearchEnv;
48
+ /**
49
+ * ISO 3166-1 alpha-2 country code (e.g. "AE").
50
+ * When set, the search redirect becomes `{base}/{countryCode}-{languageSegment}/flight/listing?...`
51
+ * where `languageSegment` is {@link languageCode} uppercased, or "EN" if {@link languageCode} is omitted.
52
+ */
53
+ countryCode?: string;
54
+ /**
55
+ * Language code for airport/airline APIs and the `lc` query param (e.g. "en", "ar").
56
+ * Defaults to `"en"` when omitted.
57
+ * If {@link countryCode} is set and this is omitted, the locale path segment still uses "EN".
58
+ */
59
+ languageCode?: string;
48
60
  };
49
61
  ssoUser?: FlightSearchSsoUser;
50
62
  };
package/dist/index.mjs CHANGED
@@ -277,9 +277,11 @@ padding-inline-start: 25px;
277
277
  visibility: visible;
278
278
  opacity: 1;
279
279
  }
280
+ .sw-dropdown{
281
+ width: 380px;
282
+ }
280
283
  .sw-dropdown,
281
284
  .p-autocomplete-panel {
282
- width: 380px;
283
285
  max-height: 310px;
284
286
  margin: 0;
285
287
  padding: 0;
@@ -293,9 +295,16 @@ padding-inline-start: 25px;
293
295
  .sw-dropdown::-webkit-scrollbar {
294
296
  display: none;
295
297
  }
296
- .sw-dropdown-list-card,
297
- .sw-dropdown-list-box,
298
298
  .p-autocomplete-item {
299
+ display: flex;
300
+ align-items: center;
301
+ gap: 15px;
302
+ padding: 10px 20px;
303
+ cursor: pointer;
304
+ font-family: var(--sw-font-family);
305
+ }
306
+ .sw-dropdown-list-card,
307
+ .sw-dropdown-list-box {
299
308
  display: flex;
300
309
  align-items: center;
301
310
  gap: 15px;
@@ -1469,7 +1478,9 @@ function FlightSearchWidget({
1469
1478
  const urls = API_URLS[env];
1470
1479
  const airportSearchApiBaseUrl = urls.airport;
1471
1480
  const airlineSearchApiBaseUrl = urls.airline;
1472
- const langCode = "en";
1481
+ const countryCodeConfig = (config?.countryCode ?? "").trim();
1482
+ const languageCodeConfig = (config?.languageCode ?? "").trim();
1483
+ const langCode = languageCodeConfig || "en";
1473
1484
  const [airlineQuery, setAirlineQuery] = useState("");
1474
1485
  const [airlineSuggestions, setAirlineSuggestions] = useState([]);
1475
1486
  const [selectedAirlines, setSelectedAirlines] = useState([]);
@@ -1515,6 +1526,7 @@ function FlightSearchWidget({
1515
1526
  const [isDestinationDropdownOpen, setIsDestinationDropdownOpen] = useState(false);
1516
1527
  const [isRoomsGuestsMenuOpen, setIsRoomsGuestsMenuOpen] = useState(false);
1517
1528
  const originDropdownRef = useRef(null);
1529
+ const firstOriginDesktopInputRef = useRef(null);
1518
1530
  const destinationDropdownRef = useRef(null);
1519
1531
  const roomsGuestsMenuRef = useRef(null);
1520
1532
  const dateRangeCalendarRef = useRef(null);
@@ -1745,10 +1757,27 @@ function FlightSearchWidget({
1745
1757
  ensureStylesInjected();
1746
1758
  ensurePrimeIconsLoaded();
1747
1759
  }, []);
1760
+ useEffect(() => {
1761
+ if (typeof window === "undefined") return;
1762
+ const focusFirstOrigin = () => {
1763
+ const desktop = firstOriginDesktopInputRef.current;
1764
+ desktop?.focus({ preventScroll: true });
1765
+ };
1766
+ let innerRaf = 0;
1767
+ const outerRaf = window.requestAnimationFrame(() => {
1768
+ innerRaf = window.requestAnimationFrame(focusFirstOrigin);
1769
+ });
1770
+ return () => {
1771
+ window.cancelAnimationFrame(outerRaf);
1772
+ if (innerRaf) window.cancelAnimationFrame(innerRaf);
1773
+ };
1774
+ }, []);
1748
1775
  useEffect(() => {
1749
1776
  const handleClickOutside = (event) => {
1750
1777
  const target = event.target;
1751
- const isInsidePrimeDropdown = target.closest(".p-dropdown-panel") !== null || target.closest(".p-dropdown-items-wrapper") !== null || target.closest(".p-dropdown-item") !== null || target.closest(".p-component")?.classList.contains("p-dropdown") !== false || target.closest('[data-pc-section="panel"]') !== null || target.closest('[data-pc-name="dropdown"]') !== null;
1778
+ const isInsidePrimeDropdown = Boolean(
1779
+ 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"]')
1780
+ );
1752
1781
  if (originDropdownRef.current && !originDropdownRef.current.contains(target)) {
1753
1782
  setIsOriginDropdownOpen(false);
1754
1783
  }
@@ -2098,7 +2127,8 @@ function FlightSearchWidget({
2098
2127
  console.log("Query String:", queryString);
2099
2128
  const base = getNormalizedRedirectionBase();
2100
2129
  if (base) {
2101
- const url = `${base}/flight/listing?${queryString}`;
2130
+ const listingPath = countryCodeConfig.length > 0 ? `/${countryCodeConfig.toUpperCase()}-${languageCodeConfig ? languageCodeConfig.toUpperCase() : "EN"}/flight/listing` : "/flight/listing";
2131
+ const url = `${base}${listingPath}?${queryString}`;
2102
2132
  window.location.href = url;
2103
2133
  }
2104
2134
  };
@@ -2130,6 +2160,7 @@ function FlightSearchWidget({
2130
2160
  const label = isOrigin ? "From" : "To";
2131
2161
  const list = isOrigin ? getPredictiveState(segmentIndex).fromAirport : getPredictiveState(segmentIndex).toAirport;
2132
2162
  const selectedIndex = isOrigin ? getPredictiveState(segmentIndex).selectedFromIndex : getPredictiveState(segmentIndex).selectedToIndex;
2163
+ const isFirstOrigin = segmentIndex === 0 && isOrigin;
2133
2164
  return /* @__PURE__ */ jsxs("div", { className: `sw-form-field sw-pos-rel${isOrigin ? " br-left" : ""} ${validationErrors[segmentIndex]?.[dropdownType] ? "sw-is-invalid" : ""}`, children: [
2134
2165
  /* @__PURE__ */ jsx("label", { htmlFor: `${dropdownType}-${segmentIndex}`, children: label }),
2135
2166
  /* @__PURE__ */ jsxs("div", { className: `sw-custom-dropdown ${validationErrors[segmentIndex]?.[dropdownType] ? "sw-has-error" : ""}`, ref: dropdownRef, children: [
@@ -2160,6 +2191,7 @@ function FlightSearchWidget({
2160
2191
  {
2161
2192
  type: "text",
2162
2193
  id: `${dropdownType}-${segmentIndex}`,
2194
+ ref: isFirstOrigin ? firstOriginDesktopInputRef : void 0,
2163
2195
  className: `sw-custom-dropdown-trigger MobileHide ${value === placeholder || !value ? "sw-placeholder" : ""}`,
2164
2196
  value: value === placeholder ? "" : value ?? "",
2165
2197
  placeholder,
@@ -2734,6 +2766,7 @@ function FlightSearchWidget({
2734
2766
  preferredAirlineList: next.map((item) => item.airline_code)
2735
2767
  }));
2736
2768
  },
2769
+ appendTo: "self",
2737
2770
  field: "airline_name",
2738
2771
  multiple: true,
2739
2772
  forceSelection: true,