@travelswitchhq/flight-search-react 1.1.2 → 1.1.4
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 +35 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.mjs +35 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
@@ -95,6 +95,9 @@ var flightSearchWidgetStyles = `
|
|
|
95
95
|
.sw-container h5 {
|
|
96
96
|
font-size: 14px;
|
|
97
97
|
}
|
|
98
|
+
.sw-container .font14 {
|
|
99
|
+
font-size: 14px;
|
|
100
|
+
}
|
|
98
101
|
.sw-container h6,
|
|
99
102
|
.sw-container small {
|
|
100
103
|
font-size: 12px;
|
|
@@ -842,6 +845,7 @@ padding-inline-start: 25px;
|
|
|
842
845
|
flex: 1 1 50%;
|
|
843
846
|
min-width: 0;
|
|
844
847
|
justify-content: center;
|
|
848
|
+
border: 1px solid transparent;
|
|
845
849
|
}
|
|
846
850
|
.sw-add-return-label label {
|
|
847
851
|
color: var(--primary) !important;
|
|
@@ -1319,8 +1323,8 @@ padding-inline-start: 25px;
|
|
|
1319
1323
|
.sw-fsrh-chk-main{
|
|
1320
1324
|
flex-wrap: wrap;
|
|
1321
1325
|
}
|
|
1322
|
-
.
|
|
1323
|
-
|
|
1326
|
+
.mobiBox{
|
|
1327
|
+
flex-direction: row;
|
|
1324
1328
|
}
|
|
1325
1329
|
}
|
|
1326
1330
|
`;
|
|
@@ -1465,7 +1469,9 @@ function FlightSearchWidget({
|
|
|
1465
1469
|
const urls = API_URLS[env];
|
|
1466
1470
|
const airportSearchApiBaseUrl = urls.airport;
|
|
1467
1471
|
const airlineSearchApiBaseUrl = urls.airline;
|
|
1468
|
-
const
|
|
1472
|
+
const countryCodeConfig = (config?.countryCode ?? "").trim();
|
|
1473
|
+
const languageCodeConfig = (config?.languageCode ?? "").trim();
|
|
1474
|
+
const langCode = languageCodeConfig || "en";
|
|
1469
1475
|
const [airlineQuery, setAirlineQuery] = useState("");
|
|
1470
1476
|
const [airlineSuggestions, setAirlineSuggestions] = useState([]);
|
|
1471
1477
|
const [selectedAirlines, setSelectedAirlines] = useState([]);
|
|
@@ -1511,6 +1517,7 @@ function FlightSearchWidget({
|
|
|
1511
1517
|
const [isDestinationDropdownOpen, setIsDestinationDropdownOpen] = useState(false);
|
|
1512
1518
|
const [isRoomsGuestsMenuOpen, setIsRoomsGuestsMenuOpen] = useState(false);
|
|
1513
1519
|
const originDropdownRef = useRef(null);
|
|
1520
|
+
const firstOriginDesktopInputRef = useRef(null);
|
|
1514
1521
|
const destinationDropdownRef = useRef(null);
|
|
1515
1522
|
const roomsGuestsMenuRef = useRef(null);
|
|
1516
1523
|
const dateRangeCalendarRef = useRef(null);
|
|
@@ -1741,6 +1748,21 @@ function FlightSearchWidget({
|
|
|
1741
1748
|
ensureStylesInjected();
|
|
1742
1749
|
ensurePrimeIconsLoaded();
|
|
1743
1750
|
}, []);
|
|
1751
|
+
useEffect(() => {
|
|
1752
|
+
if (typeof window === "undefined") return;
|
|
1753
|
+
const focusFirstOrigin = () => {
|
|
1754
|
+
const desktop = firstOriginDesktopInputRef.current;
|
|
1755
|
+
desktop?.focus({ preventScroll: true });
|
|
1756
|
+
};
|
|
1757
|
+
let innerRaf = 0;
|
|
1758
|
+
const outerRaf = window.requestAnimationFrame(() => {
|
|
1759
|
+
innerRaf = window.requestAnimationFrame(focusFirstOrigin);
|
|
1760
|
+
});
|
|
1761
|
+
return () => {
|
|
1762
|
+
window.cancelAnimationFrame(outerRaf);
|
|
1763
|
+
if (innerRaf) window.cancelAnimationFrame(innerRaf);
|
|
1764
|
+
};
|
|
1765
|
+
}, []);
|
|
1744
1766
|
useEffect(() => {
|
|
1745
1767
|
const handleClickOutside = (event) => {
|
|
1746
1768
|
const target = event.target;
|
|
@@ -2094,7 +2116,8 @@ function FlightSearchWidget({
|
|
|
2094
2116
|
console.log("Query String:", queryString);
|
|
2095
2117
|
const base = getNormalizedRedirectionBase();
|
|
2096
2118
|
if (base) {
|
|
2097
|
-
const
|
|
2119
|
+
const listingPath = countryCodeConfig.length > 0 ? `/${countryCodeConfig.toUpperCase()}-${languageCodeConfig ? languageCodeConfig.toUpperCase() : "EN"}/flight/listing` : "/flight/listing";
|
|
2120
|
+
const url = `${base}${listingPath}?${queryString}`;
|
|
2098
2121
|
window.location.href = url;
|
|
2099
2122
|
}
|
|
2100
2123
|
};
|
|
@@ -2126,6 +2149,7 @@ function FlightSearchWidget({
|
|
|
2126
2149
|
const label = isOrigin ? "From" : "To";
|
|
2127
2150
|
const list = isOrigin ? getPredictiveState(segmentIndex).fromAirport : getPredictiveState(segmentIndex).toAirport;
|
|
2128
2151
|
const selectedIndex = isOrigin ? getPredictiveState(segmentIndex).selectedFromIndex : getPredictiveState(segmentIndex).selectedToIndex;
|
|
2152
|
+
const isFirstOrigin = segmentIndex === 0 && isOrigin;
|
|
2129
2153
|
return /* @__PURE__ */ jsxs("div", { className: `sw-form-field sw-pos-rel${isOrigin ? " br-left" : ""} ${validationErrors[segmentIndex]?.[dropdownType] ? "sw-is-invalid" : ""}`, children: [
|
|
2130
2154
|
/* @__PURE__ */ jsx("label", { htmlFor: `${dropdownType}-${segmentIndex}`, children: label }),
|
|
2131
2155
|
/* @__PURE__ */ jsxs("div", { className: `sw-custom-dropdown ${validationErrors[segmentIndex]?.[dropdownType] ? "sw-has-error" : ""}`, ref: dropdownRef, children: [
|
|
@@ -2133,8 +2157,9 @@ function FlightSearchWidget({
|
|
|
2133
2157
|
"input",
|
|
2134
2158
|
{
|
|
2135
2159
|
type: "text",
|
|
2160
|
+
readOnly: true,
|
|
2136
2161
|
id: `${dropdownType}-${segmentIndex}`,
|
|
2137
|
-
className: `sw-custom-dropdown-trigger
|
|
2162
|
+
className: `sw-custom-dropdown-trigger MobileShow ${value === placeholder || !value ? "sw-placeholder" : ""}`,
|
|
2138
2163
|
value: value === placeholder ? "" : value ?? "",
|
|
2139
2164
|
placeholder,
|
|
2140
2165
|
onFocus: (e) => {
|
|
@@ -2154,9 +2179,9 @@ function FlightSearchWidget({
|
|
|
2154
2179
|
"input",
|
|
2155
2180
|
{
|
|
2156
2181
|
type: "text",
|
|
2157
|
-
readOnly: true,
|
|
2158
2182
|
id: `${dropdownType}-${segmentIndex}`,
|
|
2159
|
-
|
|
2183
|
+
ref: isFirstOrigin ? firstOriginDesktopInputRef : void 0,
|
|
2184
|
+
className: `sw-custom-dropdown-trigger MobileHide ${value === placeholder || !value ? "sw-placeholder" : ""}`,
|
|
2160
2185
|
value: value === placeholder ? "" : value ?? "",
|
|
2161
2186
|
placeholder,
|
|
2162
2187
|
onFocus: (e) => {
|
|
@@ -2234,7 +2259,7 @@ function FlightSearchWidget({
|
|
|
2234
2259
|
renderAirportDropdown(index, "destination", destinationDropdownRef || destinationRef, isDestOpen, () => toggleSegmentDropdown(index, "destination"))
|
|
2235
2260
|
] }, index),
|
|
2236
2261
|
isMultiCityOrCustom && /* @__PURE__ */ jsxs("div", { className: "sw-srh-wrap sw-pos-rel", children: [
|
|
2237
|
-
/* @__PURE__ */ jsxs("div", { className: "sw-form-field sw-com-cal", children: [
|
|
2262
|
+
/* @__PURE__ */ jsxs("div", { className: "sw-form-field sw-com-cal ", children: [
|
|
2238
2263
|
/* @__PURE__ */ jsx("label", { htmlFor: `departure-${index}`, children: "Departure" }),
|
|
2239
2264
|
/* @__PURE__ */ jsx(
|
|
2240
2265
|
Calendar,
|
|
@@ -2353,7 +2378,7 @@ function FlightSearchWidget({
|
|
|
2353
2378
|
),
|
|
2354
2379
|
renderAirportDropdown(0, "destination", destinationDropdownRef, isDestinationDropdownOpen, () => setIsDestinationDropdownOpen(true))
|
|
2355
2380
|
] }),
|
|
2356
|
-
(tripType === "round-trip" || tripType === "one-way") && /* @__PURE__ */ jsx("div", { className: "sw-srh-wrap sw-pos-rel ", children: tripType === "round-trip" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2381
|
+
(tripType === "round-trip" || tripType === "one-way") && /* @__PURE__ */ jsx("div", { className: "sw-srh-wrap sw-pos-rel mobiBox", children: tripType === "round-trip" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2357
2382
|
/* @__PURE__ */ jsxs("div", { style: { cursor: "pointer" }, onClick: () => {
|
|
2358
2383
|
dateRangeCalendarRef.current?.show?.();
|
|
2359
2384
|
mobileDateRangeCalendarRef.current?.show?.();
|
|
@@ -2538,7 +2563,7 @@ function FlightSearchWidget({
|
|
|
2538
2563
|
/* @__PURE__ */ jsx("div", { className: "sw-form-field sw-pos-rel sw-com-cal sw-add-return-label", style: { cursor: "pointer" }, onClick: () => {
|
|
2539
2564
|
setTripType("round-trip");
|
|
2540
2565
|
setTimeout(() => document.getElementById("dateRange")?.querySelector("input")?.focus?.(), 100);
|
|
2541
|
-
}, children: /* @__PURE__ */ jsx("label", { children: "Add return" }) })
|
|
2566
|
+
}, children: /* @__PURE__ */ jsx("label", { className: "font14", children: "Add return" }) })
|
|
2542
2567
|
] }) }),
|
|
2543
2568
|
(tripType === "multi-city" || tripType === "custom-search") && /* @__PURE__ */ jsx("div", { className: "sw-srh-mc-foot", children: segments.length < getMaxSegments() && /* @__PURE__ */ jsxs("button", { type: "button", className: "sw-srh-add-btn", onClick: addFlightSegment, children: [
|
|
2544
2569
|
/* @__PURE__ */ jsxs("svg", { width: "14", height: "14", viewBox: "0 0 16 16", xmlns: "http://www.w3.org/2000/svg", children: [
|