@travelswitchhq/flight-search-react 1.0.9 → 1.1.1

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
@@ -39,6 +39,7 @@ type FlightSearchWidgetProps = {
39
39
  primary?: string;
40
40
  secondary?: string;
41
41
  primaryLight?: string;
42
+ secondaryBgText?: string;
42
43
  };
43
44
  redirectionDomain?: string;
44
45
  fontName?: string;
package/dist/index.d.ts CHANGED
@@ -39,6 +39,7 @@ type FlightSearchWidgetProps = {
39
39
  primary?: string;
40
40
  secondary?: string;
41
41
  primaryLight?: string;
42
+ secondaryBgText?: string;
42
43
  };
43
44
  redirectionDomain?: string;
44
45
  fontName?: string;
package/dist/index.mjs CHANGED
@@ -11,7 +11,6 @@ var flightSearchWidgetStyles = `
11
11
  .sw-container {
12
12
  --sw-font-family: Montserrat, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
13
13
  --sw-en-font-family: Arial, sans-serif;
14
- --sw-secondary-bg-text: #ffffff;
15
14
  --sw-label-color: #66797F;
16
15
  --sw-body-text: #0B1215;
17
16
  --sw-btn-radius: 8px;
@@ -736,7 +735,7 @@ padding-inline-start: 25px;
736
735
  gap: 10px;
737
736
  cursor: pointer;
738
737
  user-select: none;
739
- color: var(--sw-body-text);
738
+ color: var(--secondary-bg-text);
740
739
  font-size: 14px;
741
740
  }
742
741
  .sw-material-checkbox input {
@@ -789,10 +788,13 @@ padding-inline-start: 25px;
789
788
  background-color: var(--primary-light);
790
789
  color: var(--primary);
791
790
  }
791
+ .sw-card-box .sw-srh-class .sw-tab-content {
792
+ border: 1px solid var(--sw-form-border);
793
+ }
792
794
  .sw-card-box .sw-tab-content {
793
795
  height: 40px;
794
796
  padding: 6px 15px;
795
- border: 1px solid var(--sw-secondary-bg-text);
797
+ border: 1px solid var(--secondary-bg-text);
796
798
  border-radius: var(--sw-radius);
797
799
  align-content: center;
798
800
  }
@@ -862,11 +864,11 @@ padding-inline-start: 25px;
862
864
  height: 40px;
863
865
  }
864
866
  .sw-srh-round-text .sw-tab-content{
865
- color: var(--sw-secondary-bg-text);
867
+ color: var(--secondary-bg-text);
866
868
  }
867
869
  .sw-advanced-search-options .p-accordion-header-text,
868
870
  .sw-card-box .p-accordion-toggle-icon{
869
- color: var(--sw-secondary-bg-text);
871
+ color: var(--secondary-bg-text);
870
872
  }
871
873
  .sw-remove-segment{
872
874
  fill: var(--primary);
@@ -945,10 +947,11 @@ padding-inline-start: 25px;
945
947
  }
946
948
  .p-autocomplete-multiple-container {
947
949
  width: 100%;
950
+ background-color: var(--sw-white);
948
951
  min-width: 270px;
949
952
  padding: 10px;
950
953
  padding-inline-end: 2rem;
951
- border: 1px solid var(--sw-form-border);
954
+ border: 1px solid var(--secondary-bg-text);
952
955
  border-radius: var(--sw-radius);
953
956
  gap: 0.5rem;
954
957
  font-size: 14px;
@@ -1084,6 +1087,9 @@ padding-inline-start: 25px;
1084
1087
  font-size: 14px;
1085
1088
  line-height: 1;
1086
1089
  }
1090
+ .sw-container .sw-is-invalid{
1091
+ border: 1px solid var(--sw-error);
1092
+ }
1087
1093
  .sw-checkbox-wrap .sw-star-checkbox {
1088
1094
  display: flex;
1089
1095
  align-items: center;
@@ -1154,6 +1160,7 @@ padding-inline-start: 25px;
1154
1160
  display: none;
1155
1161
  }
1156
1162
  }
1163
+
1157
1164
  .sw-container .sw-form-field {
1158
1165
  border-radius: var(--sw-radius);
1159
1166
  }
@@ -1223,6 +1230,7 @@ padding-inline-start: 25px;
1223
1230
  width: 100%;
1224
1231
  max-height: 100vh;
1225
1232
  overflow: auto;
1233
+ display: block !important;
1226
1234
  -webkit-overflow-scrolling: touch;
1227
1235
  scroll-behavior: smooth;
1228
1236
  padding: 0 !important;
@@ -1445,8 +1453,9 @@ function FlightSearchWidget({
1445
1453
  }) {
1446
1454
  const theme = config?.theme;
1447
1455
  const primaryColor = theme?.primary ?? "#2c0a82";
1448
- const secondaryColor = theme?.secondary ?? "#2c0a82";
1449
1456
  const primaryLightColor = theme?.primaryLight ?? "#f3e2ff";
1457
+ const secondaryColor = theme?.secondary ?? "#2c0a82";
1458
+ const secondaryBgText = theme?.secondaryBgText ?? "#ffffff";
1450
1459
  const fontName = config?.fontName;
1451
1460
  const redirectionDomain = config?.redirectionDomain;
1452
1461
  const env = config?.env ?? "dev";
@@ -1615,6 +1624,23 @@ function FlightSearchWidget({
1615
1624
  [segmentIndex]: { ...prev[segmentIndex] ?? {}, [dropdownType]: false }
1616
1625
  }));
1617
1626
  closeAirportDropdown(dropdownType, segmentIndex);
1627
+ setValidationErrors((prev) => {
1628
+ const next = { ...prev };
1629
+ const clearForSegment = (segIndex, type) => {
1630
+ const segErr = next[segIndex];
1631
+ if (!segErr) return;
1632
+ const updatedSegErr = { ...segErr };
1633
+ if (type === "origin") delete updatedSegErr.origin;
1634
+ else delete updatedSegErr.destination;
1635
+ if (Object.keys(updatedSegErr).length === 0) delete next[segIndex];
1636
+ else next[segIndex] = updatedSegErr;
1637
+ };
1638
+ clearForSegment(segmentIndex, dropdownType);
1639
+ if ((tripType === "multi-city" || tripType === "custom-search") && dropdownType === "destination") {
1640
+ clearForSegment(segmentIndex + 1, "origin");
1641
+ }
1642
+ return next;
1643
+ });
1618
1644
  }, [closeAirportDropdown, tripType]);
1619
1645
  const updateSelectedIndex = useCallback((segmentIndex, dropdownType, newIndex) => {
1620
1646
  setPredictiveSearchList((prev) => {
@@ -1697,15 +1723,16 @@ function FlightSearchWidget({
1697
1723
  () => {
1698
1724
  const style = {
1699
1725
  ["--primary"]: primaryColor,
1726
+ ["--primary-light"]: primaryLightColor,
1700
1727
  ["--secondary"]: secondaryColor,
1701
- ["--primary-light"]: primaryLightColor
1728
+ ["--secondary-bg-text"]: secondaryBgText
1702
1729
  };
1703
1730
  if (fontName) {
1704
1731
  style["--font-family"] = fontName;
1705
1732
  }
1706
1733
  return style;
1707
1734
  },
1708
- [primaryColor, secondaryColor, primaryLightColor]
1735
+ [primaryColor, secondaryColor, primaryLightColor, secondaryBgText]
1709
1736
  );
1710
1737
  useEffect(() => {
1711
1738
  ensureStylesInjected();
@@ -1847,19 +1874,6 @@ function FlightSearchWidget({
1847
1874
  }
1848
1875
  return updated;
1849
1876
  });
1850
- if (field === "origin" || field === "destination") {
1851
- setSegmentDropdowns((prev) => ({
1852
- ...prev,
1853
- [index]: { ...prev[index], [field]: false }
1854
- }));
1855
- const placeholder = field === "origin" ? "Origin" : "Destination";
1856
- if (isValidLocationValue(value, placeholder)) {
1857
- setValidationErrors((prev) => ({
1858
- ...prev,
1859
- [index]: { ...prev[index] ?? {}, [field]: false }
1860
- }));
1861
- }
1862
- }
1863
1877
  };
1864
1878
  const handleTravellerChange = (field, value) => {
1865
1879
  setSegments((prev) => {
@@ -1870,13 +1884,25 @@ function FlightSearchWidget({
1870
1884
  });
1871
1885
  };
1872
1886
  const toggleSegmentDropdown = (index, field) => {
1873
- setSegmentDropdowns((prev) => ({
1874
- ...prev,
1875
- [index]: {
1876
- ...prev[index] || { origin: false, destination: false },
1877
- [field]: !prev[index]?.[field]
1887
+ setSegmentDropdowns((prev) => {
1888
+ const shouldOpen = !prev[index]?.[field];
1889
+ if (!shouldOpen) {
1890
+ return {
1891
+ ...prev,
1892
+ [index]: {
1893
+ ...prev[index] || { origin: false, destination: false },
1894
+ [field]: false
1895
+ }
1896
+ };
1878
1897
  }
1879
- }));
1898
+ const next = {};
1899
+ Object.keys(prev).forEach((key) => {
1900
+ const idx = Number.parseInt(key, 10);
1901
+ next[idx] = { origin: false, destination: false };
1902
+ });
1903
+ next[index] = { origin: false, destination: false, [field]: true };
1904
+ return next;
1905
+ });
1880
1906
  };
1881
1907
  const swapSegmentLocations = (index) => {
1882
1908
  setSegments((prev) => {
@@ -2129,7 +2155,7 @@ function FlightSearchWidget({
2129
2155
  ] }) }),
2130
2156
  /* @__PURE__ */ jsx("h4", { children: isOrigin ? "Origin" : "Destination" })
2131
2157
  ] }),
2132
- /* @__PURE__ */ jsx("div", { className: "mobileSrgInput MobileShow", children: /* @__PURE__ */ jsx("input", { type: "text", placeholder: `Search ${isOrigin ? "Origin" : "Destination"}`, value: value ?? "", onChange: (e) => {
2158
+ /* @__PURE__ */ jsx("div", { className: "mobileSrgInput MobileShow", children: /* @__PURE__ */ jsx("input", { type: "search", placeholder: `Search ${isOrigin ? "Origin" : "Destination"}`, value: value ?? "", onChange: (e) => {
2133
2159
  const val = e.target.value;
2134
2160
  handleSegmentFieldChange(segmentIndex, dropdownType, val);
2135
2161
  triggerSearchAirport(segmentIndex, dropdownType, val);
@@ -2191,6 +2217,7 @@ function FlightSearchWidget({
2191
2217
  numberOfMonths: 2,
2192
2218
  id: `departure-${index}`,
2193
2219
  appendTo: "self",
2220
+ readOnlyInput: true,
2194
2221
  value: segment.departureDate ?? null,
2195
2222
  onChange: (e) => {
2196
2223
  const raw = e.value;
@@ -2213,6 +2240,10 @@ function FlightSearchWidget({
2213
2240
  numberOfMonths: 10,
2214
2241
  id: `departure-${index}`,
2215
2242
  appendTo: "self",
2243
+ ref: (el) => {
2244
+ segmentCalendarRefs.current[index] = el;
2245
+ },
2246
+ readOnlyInput: true,
2216
2247
  value: segment.departureDate ?? null,
2217
2248
  onChange: (e) => {
2218
2249
  const raw = e.value;
@@ -2230,7 +2261,7 @@ function FlightSearchWidget({
2230
2261
  headerTemplate: () => /* @__PURE__ */ jsxs("div", { className: "mobileHead MobileShow", children: [
2231
2262
  /* @__PURE__ */ jsx("a", { type: "button", onClick: (e) => {
2232
2263
  e.stopPropagation();
2233
- mobileDateRangeCalendarRef.current?.hide?.();
2264
+ segmentCalendarRefs.current[index]?.hide?.();
2234
2265
  }, children: /* @__PURE__ */ jsxs("svg", { width: "20px", height: "20px", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: [
2235
2266
  /* @__PURE__ */ jsx("path", { d: "M19 5L5 19", stroke: "black", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }),
2236
2267
  /* @__PURE__ */ jsx("path", { d: "M5 5L19 19", stroke: "black", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" })
@@ -2244,7 +2275,7 @@ function FlightSearchWidget({
2244
2275
  className: "sw-confirm-btn",
2245
2276
  onClick: (e) => {
2246
2277
  e.stopPropagation();
2247
- mobileDateRangeCalendarRef.current?.hide?.();
2278
+ segmentCalendarRefs.current[index]?.hide?.();
2248
2279
  },
2249
2280
  children: "Confirm"
2250
2281
  }