allaw-ui 4.8.6 → 4.8.7
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.
|
@@ -49,9 +49,11 @@ import React, { useState } from "react";
|
|
|
49
49
|
import styles from "./searchBar.module.css";
|
|
50
50
|
import "../../../styles/global.css";
|
|
51
51
|
import "../../../styles/icons.css";
|
|
52
|
+
import TinyInfo from "../typography/TinyInfo";
|
|
52
53
|
var SearchBar = function (_a) {
|
|
53
54
|
var _b = _a.placeholder, placeholder = _b === void 0 ? "Faites une recherche" : _b, endIcon = _a.endIcon, startIcon = _a.startIcon, _c = _a.value, controlledValue = _c === void 0 ? "" : _c, onChange = _a.onChange, _d = _a.showClear, showClear = _d === void 0 ? false : _d, _e = _a.size, size = _e === void 0 ? "normal" : _e, _f = _a.style, styleProp = _f === void 0 ? "classic" : _f, _g = _a.disableAutofill, disableAutofill = _g === void 0 ? false : _g, _h = _a.showLocate, showLocate = _h === void 0 ? false : _h, resolveCityFromCoords = _a.resolveCityFromCoords;
|
|
54
55
|
var _j = useState(controlledValue), value = _j[0], setValue = _j[1];
|
|
56
|
+
var _k = useState(null), locationError = _k[0], setLocationError = _k[1];
|
|
55
57
|
var handleChange = function (event) {
|
|
56
58
|
var newValue = event.target.value;
|
|
57
59
|
setValue(newValue);
|
|
@@ -91,8 +93,6 @@ var SearchBar = function (_a) {
|
|
|
91
93
|
undefined)];
|
|
92
94
|
case 3:
|
|
93
95
|
error_1 = _a.sent();
|
|
94
|
-
// eslint-disable-next-line no-console
|
|
95
|
-
console.warn("reverse geocoding failed", error_1);
|
|
96
96
|
return [2 /*return*/, undefined];
|
|
97
97
|
case 4: return [2 /*return*/];
|
|
98
98
|
}
|
|
@@ -100,50 +100,40 @@ var SearchBar = function (_a) {
|
|
|
100
100
|
}); };
|
|
101
101
|
var handleLocate = function () {
|
|
102
102
|
if (!(navigator === null || navigator === void 0 ? void 0 : navigator.geolocation)) {
|
|
103
|
-
|
|
103
|
+
setLocationError("La géolocalisation n'est pas supportée par ce navigateur. Saisissez votre ville pour continuer.");
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
|
-
|
|
106
|
+
setLocationError(null);
|
|
107
107
|
navigator.geolocation.getCurrentPosition(function (pos) { return __awaiter(void 0, void 0, void 0, function () {
|
|
108
108
|
var _a, latitude, longitude, resolver, city;
|
|
109
109
|
return __generator(this, function (_b) {
|
|
110
110
|
switch (_b.label) {
|
|
111
111
|
case 0:
|
|
112
|
-
console.log("Geolocation success:", pos.coords);
|
|
113
112
|
_a = pos.coords, latitude = _a.latitude, longitude = _a.longitude;
|
|
114
113
|
resolver = resolveCityFromCoords || defaultResolveCityFromCoords;
|
|
115
114
|
return [4 /*yield*/, resolver(latitude, longitude)];
|
|
116
115
|
case 1:
|
|
117
116
|
city = _b.sent();
|
|
118
117
|
if (city) {
|
|
119
|
-
console.log("City resolved:", city);
|
|
120
118
|
setValue(city);
|
|
121
119
|
onChange === null || onChange === void 0 ? void 0 : onChange(city);
|
|
120
|
+
setLocationError(null);
|
|
122
121
|
}
|
|
123
122
|
else {
|
|
124
|
-
|
|
123
|
+
setLocationError("Impossible de déterminer votre ville. Saisissez-la manuellement pour continuer.");
|
|
125
124
|
}
|
|
126
125
|
return [2 /*return*/];
|
|
127
126
|
}
|
|
128
127
|
});
|
|
129
128
|
}); }, function (err) {
|
|
130
|
-
console.error("Geolocation error:", err);
|
|
131
129
|
if (err.code === 1) {
|
|
132
|
-
|
|
133
|
-
// Proposer de réessayer
|
|
134
|
-
if (confirm("L'accès à la localisation a été refusé. Voulez-vous réessayer ?")) {
|
|
135
|
-
setTimeout(function () { return handleLocate(); }, 1000);
|
|
136
|
-
}
|
|
130
|
+
setLocationError("Accès à la localisation refusé. Saisissez votre ville pour continuer.");
|
|
137
131
|
}
|
|
138
132
|
else if (err.code === 2) {
|
|
139
|
-
|
|
133
|
+
setLocationError("Position indisponible. Saisissez votre ville pour continuer.");
|
|
140
134
|
}
|
|
141
135
|
else if (err.code === 3) {
|
|
142
|
-
|
|
143
|
-
// Réessayer en cas de timeout
|
|
144
|
-
if (confirm("La localisation a pris trop de temps. Voulez-vous réessayer ?")) {
|
|
145
|
-
setTimeout(function () { return handleLocate(); }, 1000);
|
|
146
|
-
}
|
|
136
|
+
setLocationError("La localisation a pris trop de temps. Saisissez votre ville pour continuer.");
|
|
147
137
|
}
|
|
148
138
|
}, { enableHighAccuracy: true, timeout: 10000, maximumAge: 0 });
|
|
149
139
|
};
|
|
@@ -154,23 +144,26 @@ var SearchBar = function (_a) {
|
|
|
154
144
|
]
|
|
155
145
|
.filter(Boolean)
|
|
156
146
|
.join(" ");
|
|
157
|
-
return (React.createElement("div",
|
|
158
|
-
|
|
159
|
-
React.createElement("
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
React.createElement("
|
|
168
|
-
|
|
169
|
-
React.createElement("
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
147
|
+
return (React.createElement("div", null,
|
|
148
|
+
React.createElement("div", { className: wrapperClassName },
|
|
149
|
+
startIcon && (React.createElement("span", { className: styles.searchBarStartIcon, "aria-hidden": "true" },
|
|
150
|
+
React.createElement("i", { className: startIcon }))),
|
|
151
|
+
React.createElement("input", __assign({ type: "text", placeholder: placeholder, className: styles.searchBarPlaceholder, value: controlledValue || value, onChange: handleChange }, (disableAutofill && {
|
|
152
|
+
autoComplete: "off",
|
|
153
|
+
"data-form-type": "other",
|
|
154
|
+
"data-lpignore": "true",
|
|
155
|
+
"data-1p-ignore": true,
|
|
156
|
+
}))),
|
|
157
|
+
showClear && (controlledValue || value) && (React.createElement("button", { type: "button", className: styles.searchBarClearButton, onClick: handleClear, "aria-label": "Effacer la recherche" },
|
|
158
|
+
React.createElement("i", { className: "allaw-icon-x-small" }))),
|
|
159
|
+
endIcon && (React.createElement("button", { className: styles.searchBarIconButton, tabIndex: -1, "aria-label": "Rechercher" },
|
|
160
|
+
React.createElement("i", { className: endIcon }))),
|
|
161
|
+
showLocate && (React.createElement("button", { type: "button", className: styles.searchBarLocateButton, onClick: function (e) {
|
|
162
|
+
e.preventDefault();
|
|
163
|
+
e.stopPropagation();
|
|
164
|
+
handleLocate();
|
|
165
|
+
}, "aria-label": "Me localiser", title: "Me localiser" }, "Me localiser"))),
|
|
166
|
+
locationError && (React.createElement("div", { className: styles.searchBarError },
|
|
167
|
+
React.createElement(TinyInfo, { variant: "medium12", color: "actions-error", text: locationError, align: "left" })))));
|
|
175
168
|
};
|
|
176
169
|
export default SearchBar;
|