allaw-ui 4.8.3 → 4.8.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.
@@ -10,6 +10,9 @@ export interface SearchBarProps {
10
10
  showClear?: boolean;
11
11
  size?: "normal" | "big";
12
12
  style?: "classic" | "form";
13
+ disableAutofill?: boolean;
14
+ showLocate?: boolean;
15
+ resolveCityFromCoords?: (lat: number, lon: number) => Promise<string | undefined>;
13
16
  }
14
17
  declare const SearchBar: React.FC<SearchBarProps>;
15
18
  export default SearchBar;
@@ -1,10 +1,57 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
23
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
1
48
  import React, { useState } from "react";
2
49
  import styles from "./searchBar.module.css";
3
50
  import "../../../styles/global.css";
4
51
  import "../../../styles/icons.css";
5
52
  var SearchBar = function (_a) {
6
- 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;
7
- var _g = useState(controlledValue), value = _g[0], setValue = _g[1];
53
+ 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
+ var _j = useState(controlledValue), value = _j[0], setValue = _j[1];
8
55
  var handleChange = function (event) {
9
56
  var newValue = event.target.value;
10
57
  setValue(newValue);
@@ -18,6 +65,67 @@ var SearchBar = function (_a) {
18
65
  onChange("");
19
66
  }
20
67
  };
68
+ var defaultResolveCityFromCoords = function (lat, lon) { return __awaiter(void 0, void 0, void 0, function () {
69
+ var url, response, data, address, error_1;
70
+ return __generator(this, function (_a) {
71
+ switch (_a.label) {
72
+ case 0:
73
+ _a.trys.push([0, 3, , 4]);
74
+ url = "https://nominatim.openstreetmap.org/reverse?format=jsonv2&lat=".concat(lat, "&lon=").concat(lon);
75
+ return [4 /*yield*/, fetch(url, {
76
+ headers: { Accept: "application/json" },
77
+ })];
78
+ case 1:
79
+ response = _a.sent();
80
+ if (!response.ok)
81
+ return [2 /*return*/, undefined];
82
+ return [4 /*yield*/, response.json()];
83
+ case 2:
84
+ data = _a.sent();
85
+ address = (data === null || data === void 0 ? void 0 : data.address) || {};
86
+ return [2 /*return*/, (address.city ||
87
+ address.town ||
88
+ address.village ||
89
+ address.municipality ||
90
+ address.state ||
91
+ undefined)];
92
+ case 3:
93
+ error_1 = _a.sent();
94
+ // eslint-disable-next-line no-console
95
+ console.warn("reverse geocoding failed", error_1);
96
+ return [2 /*return*/, undefined];
97
+ case 4: return [2 /*return*/];
98
+ }
99
+ });
100
+ }); };
101
+ var handleLocate = function () {
102
+ if (!(navigator === null || navigator === void 0 ? void 0 : navigator.geolocation)) {
103
+ // eslint-disable-next-line no-console
104
+ console.warn("Geolocation not supported by this browser");
105
+ return;
106
+ }
107
+ navigator.geolocation.getCurrentPosition(function (pos) { return __awaiter(void 0, void 0, void 0, function () {
108
+ var _a, latitude, longitude, resolver, city;
109
+ return __generator(this, function (_b) {
110
+ switch (_b.label) {
111
+ case 0:
112
+ _a = pos.coords, latitude = _a.latitude, longitude = _a.longitude;
113
+ resolver = resolveCityFromCoords || defaultResolveCityFromCoords;
114
+ return [4 /*yield*/, resolver(latitude, longitude)];
115
+ case 1:
116
+ city = _b.sent();
117
+ if (city) {
118
+ setValue(city);
119
+ onChange === null || onChange === void 0 ? void 0 : onChange(city);
120
+ }
121
+ return [2 /*return*/];
122
+ }
123
+ });
124
+ }); }, function (err) {
125
+ // eslint-disable-next-line no-console
126
+ console.warn("Geolocation error", err);
127
+ }, { enableHighAccuracy: true, timeout: 10000, maximumAge: 0 });
128
+ };
21
129
  var wrapperClassName = [
22
130
  styles.searchBar,
23
131
  styleProp === "form" ? styles.styleForm : "",
@@ -28,10 +136,16 @@ var SearchBar = function (_a) {
28
136
  return (React.createElement("div", { className: wrapperClassName },
29
137
  startIcon && (React.createElement("span", { className: styles.searchBarStartIcon, "aria-hidden": "true" },
30
138
  React.createElement("i", { className: startIcon }))),
31
- React.createElement("input", { type: "text", placeholder: placeholder, className: styles.searchBarPlaceholder, value: controlledValue || value, onChange: handleChange }),
139
+ React.createElement("input", __assign({ type: "text", placeholder: placeholder, className: styles.searchBarPlaceholder, value: controlledValue || value, onChange: handleChange }, (disableAutofill && {
140
+ autoComplete: "off",
141
+ "data-form-type": "other",
142
+ "data-lpignore": "true",
143
+ "data-1p-ignore": true,
144
+ }))),
32
145
  showClear && (controlledValue || value) && (React.createElement("button", { type: "button", className: styles.searchBarClearButton, onClick: handleClear, "aria-label": "Effacer la recherche" },
33
146
  React.createElement("i", { className: "allaw-icon-x-small" }))),
34
147
  endIcon && (React.createElement("button", { className: styles.searchBarIconButton, tabIndex: -1, "aria-label": "Rechercher" },
35
- React.createElement("i", { className: endIcon })))));
148
+ React.createElement("i", { className: endIcon }))),
149
+ showLocate && (React.createElement("button", { type: "button", className: styles.searchBarLocateButton, onClick: handleLocate, "aria-label": "Me localiser", title: "Me localiser" }, "Me localiser"))));
36
150
  };
37
151
  export default SearchBar;
@@ -14,6 +14,8 @@ declare namespace _default {
14
14
  let size: string;
15
15
  let style: string;
16
16
  let startIcon: undefined;
17
+ let showLocate: boolean;
18
+ let locateIcon: string;
17
19
  }
18
20
  export namespace argTypes {
19
21
  export namespace placeholder {
@@ -38,37 +40,54 @@ declare namespace _default {
38
40
  export let description: string;
39
41
  }
40
42
  export { startIcon_1 as startIcon };
41
- export namespace size_1 {
42
- export namespace control_3 {
43
+ export namespace showLocate_1 {
44
+ let control_3: string;
45
+ export { control_3 as control };
46
+ let description_1: string;
47
+ export { description_1 as description };
48
+ }
49
+ export { showLocate_1 as showLocate };
50
+ export namespace locateIcon_1 {
51
+ export namespace control_4 {
43
52
  let type_3: string;
44
53
  export { type_3 as type };
45
54
  }
46
- export { control_3 as control };
55
+ export { control_4 as control };
56
+ let description_2: string;
57
+ export { description_2 as description };
58
+ }
59
+ export { locateIcon_1 as locateIcon };
60
+ export namespace size_1 {
61
+ export namespace control_5 {
62
+ let type_4: string;
63
+ export { type_4 as type };
64
+ }
65
+ export { control_5 as control };
47
66
  export let options: string[];
48
67
  }
49
68
  export { size_1 as size };
50
69
  export namespace style_1 {
51
- export namespace control_4 {
52
- let type_4: string;
53
- export { type_4 as type };
70
+ export namespace control_6 {
71
+ let type_5: string;
72
+ export { type_5 as type };
54
73
  }
55
- export { control_4 as control };
74
+ export { control_6 as control };
56
75
  let options_1: string[];
57
76
  export { options_1 as options };
58
77
  }
59
78
  export { style_1 as style };
60
79
  export namespace value {
61
- export namespace control_5 {
62
- let type_5: string;
63
- export { type_5 as type };
80
+ export namespace control_7 {
81
+ let type_6: string;
82
+ export { type_6 as type };
64
83
  }
65
- export { control_5 as control };
84
+ export { control_7 as control };
66
85
  }
67
86
  export namespace showClear_1 {
68
- let control_6: string;
69
- export { control_6 as control };
70
- let description_1: string;
71
- export { description_1 as description };
87
+ let control_8: string;
88
+ export { control_8 as control };
89
+ let description_3: string;
90
+ export { description_3 as description };
72
91
  }
73
92
  export { showClear_1 as showClear };
74
93
  export namespace onChange_1 {
@@ -95,4 +114,5 @@ export const Big: any;
95
114
  export const FormStyle: any;
96
115
  export const WithStartIcon: any;
97
116
  export const BigFormStartIconNoEnd: any;
117
+ export const WithLocate: any;
98
118
  import SearchBar from "./SearchBar";
@@ -21,7 +21,7 @@ export default {
21
21
  component: SearchBar,
22
22
  tags: ["autodocs"],
23
23
  excludeStories: /.*Data$/,
24
- args: __assign(__assign({}, ActionsData), { endIcon: "allaw-icon-search", showClear: false, size: "normal", style: "classic", startIcon: undefined }),
24
+ args: __assign(__assign({}, ActionsData), { endIcon: "allaw-icon-search", showClear: false, size: "normal", style: "classic", startIcon: undefined, showLocate: false, locateIcon: "allaw-icon-map-pin" }),
25
25
  argTypes: {
26
26
  placeholder: {
27
27
  control: {
@@ -39,6 +39,14 @@ export default {
39
39
  },
40
40
  description: "Icône au début du champ (ex: allaw-icon-map-pin)",
41
41
  },
42
+ showLocate: {
43
+ control: "boolean",
44
+ description: "Affiche un bouton 'Me localiser' en bout de champ",
45
+ },
46
+ locateIcon: {
47
+ control: { type: "text" },
48
+ description: "Classe d'icône pour le bouton de localisation",
49
+ },
42
50
  size: {
43
51
  control: {
44
52
  type: "radio",
@@ -134,3 +142,14 @@ BigFormStartIconNoEnd.args = {
134
142
  size: "big",
135
143
  style: "form",
136
144
  };
145
+ export var WithLocate = Template.bind({});
146
+ WithLocate.args = {
147
+ placeholder: "Ville",
148
+ startIcon: "allaw-icon-map-pin",
149
+ endIcon: undefined,
150
+ showClear: false,
151
+ size: "normal",
152
+ style: "form",
153
+ showLocate: true,
154
+ locateIcon: "allaw-icon-map-pin",
155
+ };
@@ -63,6 +63,10 @@
63
63
  cursor: pointer;
64
64
  }
65
65
 
66
+ .searchBarIconButton:hover {
67
+ filter: brightness(0.95);
68
+ }
69
+
66
70
  .sizeBig .searchBarIconButton {
67
71
  width: 36px;
68
72
  height: 36px;
@@ -79,6 +83,28 @@
79
83
  justify-content: center;
80
84
  }
81
85
 
86
+ .searchBarLocateButton {
87
+ display: inline-flex;
88
+ align-items: center;
89
+ justify-content: center;
90
+ height: 28px;
91
+ padding: 0 10px;
92
+ margin-right: 3px;
93
+ border-radius: 16px;
94
+ border: 1px solid rgba(0, 0, 0, 0.05);
95
+ background: #25beeb;
96
+ color: #fff;
97
+ font-family: "Open Sans";
98
+ font-size: 12px;
99
+ font-weight: 600;
100
+ cursor: pointer;
101
+ }
102
+
103
+ .sizeBig .searchBarLocateButton {
104
+ height: 32px;
105
+ font-size: 13px;
106
+ }
107
+
82
108
  .searchBarClearButton {
83
109
  display: flex;
84
110
  align-items: center;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "allaw-ui",
3
- "version": "4.8.3",
3
+ "version": "4.8.4",
4
4
  "description": "Composants UI pour l'application Allaw",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.esm.js",